Skip to content

Commit

Permalink
migrate: user.jsonnet
Browse files Browse the repository at this point in the history
  • Loading branch information
consideRatio committed Apr 6, 2024
1 parent 1348cd2 commit 2342033
Showing 1 changed file with 117 additions and 106 deletions.
223 changes: 117 additions & 106 deletions dashboards/user.jsonnet
Original file line number Diff line number Diff line change
@@ -1,130 +1,141 @@
#!/usr/bin/env -S jsonnet -J ../vendor
local grafonnet = import 'grafonnet/main.libsonnet';
local dashboard = grafonnet.dashboard;
local singlestat = grafonnet.singlestat;
local graphPanel = grafonnet.graphPanel;
local prometheus = grafonnet.prometheus;
local tablePanel = grafonnet.tablePanel;
local row = grafonnet.row;
local heatmapPanel = grafonnet.heatmapPanel;
local ts = grafonnet.panel.timeSeries;
local prometheus = grafonnet.query.prometheus;

local common = import './common.libsonnet';
local jupyterhub = import 'jupyterhub.libsonnet';
local standardDims = jupyterhub.standardDims;

local memoryUsage = graphPanel.new(
'Memory Usage',
description=|||
Per-user per-server memory usage
|||,
formatY1='bytes',
datasource='$PROMETHEUS_DS'
).addTarget(
prometheus.target(
local memoryUsage =
common.tsOptions
+ ts.new('Memory Usage')
+ ts.panelOptions.withDescription(
|||
sum(
# exclude name="" because the same container can be reported
# with both no name and `name=k8s_...`,
# in which case sum() by (pod) reports double the actual metric
container_memory_working_set_bytes{name!="", instance=~"$instance"}
* on (namespace, pod) group_left(container)
group(
kube_pod_labels{label_app="jupyterhub", label_component="singleuser-server", namespace=~"$hub", pod=~"$user_pod"}
Per-user per-server memory usage
|||
)
+ ts.standardOptions.withUnit('bytes')
+ ts.queryOptions.withTargets([
prometheus.new(
'$PROMETHEUS_DS',
|||
sum(
# exclude name="" because the same container can be reported
# with both no name and `name=k8s_...`,
# in which case sum() by (pod) reports double the actual metric
container_memory_working_set_bytes{name!="", instance=~"$instance"}
* on (namespace, pod) group_left(container)
group(
kube_pod_labels{label_app="jupyterhub", label_component="singleuser-server", namespace=~"$hub", pod=~"$user_pod"}
) by (pod, namespace)
) by (pod, namespace)
) by (pod, namespace)
|||,
legendFormat='{{ pod }} - ({{ namespace }})'
),
);
|||
)
+ prometheus.withLegendFormat('{{ pod }} - ({{ namespace }})'),
]);

local cpuUsage = graphPanel.new(
'CPU Usage',
description=|||
Per-user per-server CPU usage
|||,
formatY1='percentunit',
datasource='$PROMETHEUS_DS'
).addTarget(
prometheus.target(

local cpuUsage =
common.tsOptions
+ ts.new('CPU Usage')
+ ts.panelOptions.withDescription(
|||
Per-user per-server CPU usage
|||
sum(
# exclude name="" because the same container can be reported
# with both no name and `name=k8s_...`,
# in which case sum() by (pod) reports double the actual metric
irate(container_cpu_usage_seconds_total{name!="", instance=~"$instance"}[5m])
* on (namespace, pod) group_left(container)
group(
kube_pod_labels{label_app="jupyterhub", label_component="singleuser-server", namespace=~"$hub", pod=~"$user_pod"}
)
+ ts.standardOptions.withUnit('percentunit')
+ ts.queryOptions.withTargets([
prometheus.new(
'$PROMETHEUS_DS',
|||
sum(
# exclude name="" because the same container can be reported
# with both no name and `name=k8s_...`,
# in which case sum() by (pod) reports double the actual metric
irate(container_cpu_usage_seconds_total{name!="", instance=~"$instance"}[5m])
* on (namespace, pod) group_left(container)
group(
kube_pod_labels{label_app="jupyterhub", label_component="singleuser-server", namespace=~"$hub", pod=~"$user_pod"}
) by (pod, namespace)
) by (pod, namespace)
) by (pod, namespace)
|||,
legendFormat='{{ pod }} - ({{ namespace }})'
),
);
|||
)
+ prometheus.withLegendFormat('{{ pod }} - ({{ namespace }})'),
]);

local homedirSharedUsage = graphPanel.new(
'Home Directory Usage (on shared home directories)',
description=|||
Per user home directory size, when using a shared home directory.
local homedirSharedUsage =
common.tsOptions
+ ts.new('Home Directory Usage (on shared home directories)')
+ ts.panelOptions.withDescription(
|||
Per user home directory size, when using a shared home directory.
Requires https://github.com/yuvipanda/prometheus-dirsize-exporter to
be set up.
Requires https://github.com/yuvipanda/prometheus-dirsize-exporter to
be set up.
Similar to server pod names, user names will be *encoded* here
using the escapism python library (https://github.com/minrk/escapism).
You can unencode them with the following python snippet:
Similar to server pod names, user names will be *encoded* here
using the escapism python library (https://github.com/minrk/escapism).
You can unencode them with the following python snippet:
from escapism import unescape
unescape('<escaped-username>', '-')
|||,
formatY1='bytes',
datasource='$PROMETHEUS_DS'
).addTarget(
prometheus.target(
from escapism import unescape
unescape('<escaped-username>', '-')
|||
max(
dirsize_total_size_bytes{namespace="$hub"}
) by (directory, namespace)
|||,
legendFormat='{{ directory }} - ({{ namespace }})'
),
);
)
+ ts.standardOptions.withUnit('bytes')
+ ts.queryOptions.withTargets([
prometheus.new(
'$PROMETHEUS_DS',
|||
max(
dirsize_total_size_bytes{namespace="$hub"}
) by (directory, namespace)
|||
)
+ prometheus.withLegendFormat('{{ directory }} - ({{ namespace }})'),
]);

local memoryRequests = graphPanel.new(
'Memory Requests',
description=|||
Per-user per-server memory Requests
|||,
formatY1='bytes',
datasource='$PROMETHEUS_DS'
).addTarget(
prometheus.target(
local memoryRequests =
common.tsOptions
+ ts.new('Memory Requests')
+ ts.panelOptions.withDescription(
|||
sum(
kube_pod_container_resource_requests{resource="memory", namespace=~"$hub", node=~"$instance"}
) by (pod, namespace)
|||,
legendFormat='{{ pod }} - ({{ namespace }})'
),
);
Per-user per-server memory Requests
|||
)
+ ts.standardOptions.withUnit('bytes')
+ ts.queryOptions.withTargets([
prometheus.new(
'$PROMETHEUS_DS',
|||
sum(
kube_pod_container_resource_requests{resource="memory", namespace=~"$hub", node=~"$instance"}
) by (pod, namespace)
|||
)
+ prometheus.withLegendFormat('{{ pod }} - ({{ namespace }})'),
]);

local cpuRequests = graphPanel.new(
'CPU Requests',
description=|||
Per-user per-server CPU Requests
|||,
formatY1='percentunit',
datasource='$PROMETHEUS_DS'
).addTarget(
prometheus.target(
local cpuRequests =
common.tsOptions
+ ts.new('CPU Requests')
+ ts.panelOptions.withDescription(
|||
sum(
kube_pod_container_resource_requests{resource="cpu", namespace=~"$hub", node=~"$instance"}
) by (pod, namespace)
|||,
legendFormat='{{ pod }} - ({{ namespace }})'
),
);
Per-user per-server CPU Requests
|||
)
+ ts.standardOptions.withUnit('percentunit')
+ ts.queryOptions.withTargets([
prometheus.new(
'$PROMETHEUS_DS',
|||
sum(
kube_pod_container_resource_requests{resource="cpu", namespace=~"$hub", node=~"$instance"}
) by (pod, namespace)
|||
)
+ prometheus.withLegendFormat('{{ pod }} - ({{ namespace }})'),
]);

dashboard.new('User Diagnostics Dashboard')
+ dashboard.withTags(['jupyterhub'])
Expand Down

0 comments on commit 2342033

Please sign in to comment.