218 lines
12 KiB
Nix
218 lines
12 KiB
Nix
{ lib }: let
|
|
ds = { type = "prometheus"; uid = "prometheus"; };
|
|
h = ''instance=~"$host"'';
|
|
phys = ''device=~"en.*|wl.*|eth.*"'';
|
|
realfs = ''fstype=~"ext4|btrfs|xfs|zfs",mountpoint!~"/boot.*|/nix/store"'';
|
|
svc = e: ''label_replace(${e}, "svc", "$1", "instance", "https://([^.]+)[.].*")'';
|
|
|
|
q = expr: legendFormat: { inherit expr legendFormat; datasource = ds; };
|
|
qi = expr: { inherit expr; datasource = ds; instant = true; range = false; format = "table"; };
|
|
refs = lib.imap0 (i: t: t // { refId = lib.elemAt [ "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" ] i; });
|
|
|
|
thresh = steps: { mode = "absolute"; steps = map (s: { color = s.c; value = s.v or null; }) steps; };
|
|
pctThresh = thresh [ { c = "green"; } { c = "yellow"; v = 70; } { c = "red"; v = 90; } ];
|
|
|
|
panel = type: title: x: y: w: hh: targets: extra: lib.recursiveUpdate {
|
|
inherit type title;
|
|
datasource = ds;
|
|
gridPos = { inherit x y w; h = hh; };
|
|
targets = refs targets;
|
|
} extra;
|
|
|
|
ts = title: x: y: w: hh: unit: targets: extra: panel "timeseries" title x y w hh targets (lib.recursiveUpdate {
|
|
fieldConfig.defaults = {
|
|
inherit unit;
|
|
custom = { lineWidth = 1; fillOpacity = 12; showPoints = "never"; gradientMode = "opacity"; };
|
|
};
|
|
options = {
|
|
legend = { displayMode = "list"; placement = "bottom"; showLegend = true; };
|
|
tooltip = { mode = "multi"; sort = "desc"; };
|
|
};
|
|
} extra);
|
|
|
|
mirrored = suffix: {
|
|
fieldConfig.overrides = [{
|
|
matcher = { id = "byRegexp"; options = ".* ${suffix}$"; };
|
|
properties = [{ id = "custom.transform"; value = "negative-Y"; }];
|
|
}];
|
|
};
|
|
|
|
col = name: props: { matcher = { id = "byName"; options = name; }; properties = props; };
|
|
gaugeCol = name: col name [
|
|
{ id = "unit"; value = "percent"; } { id = "min"; value = 0; } { id = "max"; value = 100; }
|
|
{ id = "thresholds"; value = pctThresh; }
|
|
{ id = "decimals"; value = 0; }
|
|
{ id = "custom.width"; value = 58; }
|
|
{ id = "custom.cellOptions"; value = { type = "color-text"; }; }
|
|
];
|
|
unitCol = name: unit: col name [ { id = "unit"; value = unit; } ];
|
|
|
|
table = title: x: y: w: hh: targets: names: overrides: sort: panel "table" title x y w hh targets {
|
|
options = { showHeader = true; cellHeight = "sm"; footer.show = false; sortBy = [ sort ]; };
|
|
fieldConfig = { defaults.custom = { align = "auto"; cellOptions.type = "auto"; }; inherit overrides; };
|
|
transformations = [
|
|
{ id = "merge"; options = { }; }
|
|
{ id = "organize"; options = {
|
|
excludeByName = { Time = true; };
|
|
renameByName = names;
|
|
}; }
|
|
];
|
|
};
|
|
|
|
row = title: y: { type = "row"; inherit title; collapsed = false; gridPos = { x = 0; inherit y; w = 24; h = 1; }; panels = [ ]; };
|
|
|
|
cpu = by: ''100 * (1 - avg by (${by}) (rate(node_cpu_seconds_total{mode="idle",${h}}[$__rate_interval])))'';
|
|
ram = ''100 * (1 - max by (instance) (node_memory_MemAvailable_bytes{${h}}) / max by (instance) (node_memory_MemTotal_bytes{${h}}))'';
|
|
|
|
panels = [
|
|
(table "Hosts" 0 0 13 7 [
|
|
(qi ''time() - max by (instance) (max_over_time(node_time_seconds{${h}}[7d]))'')
|
|
(qi ''max by (instance) (time() - node_boot_time_seconds{${h}})'')
|
|
(qi ''100 * (1 - avg by (instance) (rate(node_cpu_seconds_total{mode="idle",${h}}[2m])))'')
|
|
(qi ram)
|
|
(qi ''max by (instance) (node_drm_gpu_busy_percent{${h}}) or max by (instance) (100 * nvidia_smi_utilization_gpu_ratio{${h}})'')
|
|
(qi ''100 * sum by (instance) (node_drm_memory_vram_used_bytes{${h}}) / sum by (instance) (node_drm_memory_vram_size_bytes{${h}}) or 100 * sum by (instance) (nvidia_smi_memory_used_bytes{${h}}) / sum by (instance) (nvidia_smi_memory_total_bytes{${h}})'')
|
|
(qi ''100 * max by (instance) (1 - node_filesystem_avail_bytes{${realfs},${h}} / node_filesystem_size_bytes{${realfs},${h}})'')
|
|
(qi ''sum by (instance) (rate(node_network_receive_bytes_total{${phys},${h}}[2m]))'')
|
|
(qi ''sum by (instance) (rate(node_network_transmit_bytes_total{${phys},${h}}[2m]))'')
|
|
] {
|
|
instance = "Host"; "Value #A" = "Status"; "Value #B" = "Uptime"; "Value #C" = "CPU"; "Value #D" = "RAM";
|
|
"Value #E" = "GPU"; "Value #F" = "VRAM"; "Value #G" = "Disk"; "Value #H" = "Net in"; "Value #I" = "Net out";
|
|
} [
|
|
(col "Status" [
|
|
{ id = "mappings"; value = [
|
|
{ type = "range"; options = { from = 0; to = 180; result = { text = "online"; color = "green"; index = 0; }; }; }
|
|
{ type = "range"; options = { from = 180; to = 1.0e12; result = { text = "offline"; color = "red"; index = 1; }; }; }
|
|
]; }
|
|
{ id = "custom.cellOptions"; value = { type = "color-text"; }; }
|
|
{ id = "custom.width"; value = 70; }
|
|
])
|
|
(col "Uptime" [ { id = "unit"; value = "dtdurations"; } { id = "custom.width"; value = 95; } ])
|
|
(gaugeCol "CPU") (gaugeCol "RAM") (gaugeCol "GPU") (gaugeCol "VRAM") (gaugeCol "Disk")
|
|
(col "Net in" [ { id = "unit"; value = "Bps"; } { id = "custom.width"; value = 85; } ])
|
|
(col "Net out" [ { id = "unit"; value = "Bps"; } { id = "custom.width"; value = 85; } ])
|
|
(col "Host" [ { id = "custom.width"; value = 60; } ])
|
|
] { displayName = "Host"; desc = false; })
|
|
|
|
(panel "state-timeline" "Services" 13 0 11 7 [
|
|
(q (svc ''avg by (instance) (probe_success{from=~"$host"})'') "{{svc}}")
|
|
] {
|
|
options = { showValue = "never"; mergeValues = true; rowHeight = 0.85; alignValue = "left"; legend.showLegend = false; tooltip.mode = "single"; };
|
|
fieldConfig.defaults = {
|
|
color.mode = "thresholds";
|
|
mappings = [
|
|
{ type = "value"; options."1" = { text = "up"; color = "green"; index = 0; }; }
|
|
{ type = "value"; options."0" = { text = "down"; color = "red"; index = 1; }; }
|
|
{ type = "range"; options = { from = 0.01; to = 0.99; result = { text = "partly down"; color = "yellow"; index = 2; }; }; }
|
|
];
|
|
custom = { lineWidth = 0; fillOpacity = 85; };
|
|
};
|
|
})
|
|
|
|
(ts "CPU" 0 7 6 7 "percent" [ (q (cpu "instance") "{{instance}}") ] { fieldConfig.defaults = { min = 0; max = 100; }; })
|
|
(ts "RAM" 6 7 6 7 "percent" [ (q ram "{{instance}}") ] { fieldConfig.defaults = { min = 0; max = 100; }; })
|
|
(ts "GPU" 12 7 6 7 "percent" [
|
|
(q ''node_drm_gpu_busy_percent{${h}}'' "{{instance}} {{card}}")
|
|
(q ''100 * nvidia_smi_utilization_gpu_ratio{${h}}'' "{{instance}} nvidia")
|
|
] { fieldConfig.defaults = { min = 0; max = 100; }; })
|
|
(ts "Network (physical)" 18 7 6 7 "Bps" [
|
|
(q ''sum by (instance) (rate(node_network_receive_bytes_total{${phys},${h}}[$__rate_interval]))'' "{{instance}} in")
|
|
(q ''sum by (instance) (rate(node_network_transmit_bytes_total{${phys},${h}}[$__rate_interval]))'' "{{instance}} out")
|
|
] (mirrored "out"))
|
|
|
|
(panel "bargauge" "Disks" 0 14 8 10 [
|
|
(q ''100 * (1 - node_filesystem_avail_bytes{${realfs},${h}} / node_filesystem_size_bytes{${realfs},${h}})'' "{{instance}} {{mountpoint}}" // { instant = true; })
|
|
] {
|
|
options = { orientation = "horizontal"; displayMode = "gradient"; showUnfilled = true; minVizHeight = 12; valueMode = "color"; namePlacement = "left"; text = { titleSize = 13; valueSize = 15; }; };
|
|
fieldConfig.defaults = { unit = "percent"; min = 0; max = 100; thresholds = pctThresh; };
|
|
})
|
|
|
|
(table "Service details" 8 14 16 10 [
|
|
(qi (svc ''min by (instance) (probe_success{from=~"$host"})''))
|
|
(qi (svc ''100 * avg by (instance) (avg_over_time(probe_success{from=~"$host"}[$__range]))''))
|
|
(qi (svc ''avg by (instance) (probe_duration_seconds{from=~"$host"})''))
|
|
(qi (svc ''min by (instance) ((probe_ssl_earliest_cert_expiry{from=~"$host"} - time()) / 86400)''))
|
|
] {
|
|
svc = "Service"; "Value #A" = "Now"; "Value #B" = "Uptime"; "Value #C" = "Response"; "Value #D" = "TLS days";
|
|
} [
|
|
(col "instance" [ { id = "custom.hidden"; value = true; } ])
|
|
(col "Now" [
|
|
{ id = "mappings"; value = [
|
|
{ type = "value"; options."1" = { text = "up"; color = "green"; index = 0; }; }
|
|
{ type = "value"; options."0" = { text = "down"; color = "red"; index = 1; }; }
|
|
]; }
|
|
{ id = "custom.cellOptions"; value = { type = "color-text"; }; }
|
|
])
|
|
(col "Uptime" [
|
|
{ id = "unit"; value = "percent"; } { id = "decimals"; value = 2; }
|
|
{ id = "thresholds"; value = thresh [ { c = "red"; } { c = "yellow"; v = 95; } { c = "green"; v = 99.5; } ]; }
|
|
{ id = "custom.cellOptions"; value = { type = "color-text"; }; }
|
|
])
|
|
(unitCol "Response" "s")
|
|
(col "TLS days" [
|
|
{ id = "decimals"; value = 0; }
|
|
{ id = "thresholds"; value = thresh [ { c = "red"; } { c = "yellow"; v = 14; } { c = "green"; v = 30; } ]; }
|
|
{ id = "custom.cellOptions"; value = { type = "color-text"; }; }
|
|
])
|
|
] { displayName = "Uptime"; desc = false; })
|
|
|
|
(row "Processes (box)" 24)
|
|
(table "Top processes" 0 25 10 8 (let
|
|
top = ''topk(15, 100 * sum by (groupname) (rate(namedprocess_namegroup_cpu_seconds_total{instance="box"}[2m])))'';
|
|
in [
|
|
(qi top)
|
|
(qi ''sum by (groupname) (namedprocess_namegroup_memory_bytes{instance="box",memtype="resident"}) and on (groupname) ${top}'')
|
|
(qi ''sum by (groupname) (namedprocess_namegroup_num_procs{instance="box"}) and on (groupname) ${top}'')
|
|
]) { groupname = "Process"; "Value #A" = "CPU"; "Value #B" = "Memory"; "Value #C" = "Count"; } [
|
|
(col "CPU" [ { id = "unit"; value = "percent"; } { id = "decimals"; value = 1; } ])
|
|
(unitCol "Memory" "bytes")
|
|
] { displayName = "CPU"; desc = true; })
|
|
(ts "Process CPU (top 8)" 10 25 14 8 "percent" [
|
|
(q ''topk(8, 100 * sum by (groupname) (rate(namedprocess_namegroup_cpu_seconds_total{instance="box"}[$__rate_interval])))'' "{{groupname}}")
|
|
] { fieldConfig.defaults.custom = { stacking.mode = "normal"; fillOpacity = 40; }; })
|
|
|
|
(row "Details" 33)
|
|
(ts "Temperatures" 0 34 12 7 "celsius" [
|
|
(q ''max by (instance, chip_name) (node_hwmon_temp_celsius{${h}} * on (instance, chip) group_left (chip_name) node_hwmon_chip_names{chip_name=~"k10temp|coretemp"})'' "{{instance}} cpu")
|
|
(q ''label_replace(max by (instance, chip) (node_hwmon_temp_celsius{${h}} * on (instance, chip) group_left (chip_name) node_hwmon_chip_names{chip_name="amdgpu"}), "pci", "$1", "chip", ".*_0000:([0-9a-f]+):.*")'' "{{instance}} gpu {{pci}}")
|
|
(q ''nvidia_smi_temperature_gpu{${h}}'' "{{instance}} gpu nvidia")
|
|
(q ''max by (instance, chip) (node_hwmon_temp_celsius{${h}} * on (instance, chip) group_left (chip_name) node_hwmon_chip_names{chip_name="nvme"})'' "{{instance}} {{chip}}")
|
|
] { })
|
|
(ts "Network per interface" 12 34 12 7 "Bps" [
|
|
(q ''rate(node_network_receive_bytes_total{device!~"lo|veth.*",${h}}[$__rate_interval])'' "{{instance}} {{device}} in")
|
|
(q ''rate(node_network_transmit_bytes_total{device!~"lo|veth.*",${h}}[$__rate_interval])'' "{{instance}} {{device}} out")
|
|
] (mirrored "out"))
|
|
(ts "Disk I/O" 0 41 8 7 "Bps" [
|
|
(q ''sum by (instance, device) (rate(node_disk_read_bytes_total{device!~"loop.*|zram.*|dm-.*|sr.*",${h}}[$__rate_interval]))'' "{{instance}} {{device}} read")
|
|
(q ''sum by (instance, device) (rate(node_disk_written_bytes_total{device!~"loop.*|zram.*|dm-.*|sr.*",${h}}[$__rate_interval]))'' "{{instance}} {{device}} write")
|
|
] (mirrored "write"))
|
|
(ts "Tunnel requests" 8 41 8 7 "reqps" [
|
|
(q ''sum(rate(cloudflared_tunnel_total_requests[$__rate_interval]))'' "requests")
|
|
(q ''sum(rate(cloudflared_tunnel_request_errors[$__rate_interval]))'' "errors")
|
|
] { })
|
|
(ts "Tunnel responses by code" 16 41 8 7 "reqps" [
|
|
(q ''sum by (status_code) (rate(cloudflared_tunnel_response_by_code[$__rate_interval]))'' "{{status_code}}")
|
|
] { fieldConfig.defaults.custom = { stacking.mode = "normal"; fillOpacity = 40; }; })
|
|
(ts "Load (1m)" 0 48 12 6 "short" [ (q ''node_load1{${h}}'' "{{instance}}") ] { })
|
|
(ts "Swap / zram used" 12 48 12 6 "bytes" [
|
|
(q ''node_memory_SwapTotal_bytes{${h}} - node_memory_SwapFree_bytes{${h}}'' "{{instance}}")
|
|
] { })
|
|
];
|
|
in {
|
|
uid = "overview";
|
|
title = "Overview";
|
|
editable = false;
|
|
graphTooltip = 1;
|
|
refresh = "30s";
|
|
time = { from = "now-6h"; to = "now"; };
|
|
timepicker.refresh_intervals = [ "30s" "1m" "5m" ];
|
|
schemaVersion = 39;
|
|
templating.list = [{
|
|
type = "query"; name = "host"; label = "Host"; datasource = ds;
|
|
query = { query = "label_values(node_uname_info, instance)"; refId = "host"; };
|
|
includeAll = true; multi = true; refresh = 2; sort = 1;
|
|
current = { text = [ "All" ]; value = [ "$__all" ]; };
|
|
}];
|
|
panels = lib.imap1 (id: p: p // { inherit id; }) panels;
|
|
}
|