Skip to content

Commit

Permalink
update dashboard queries
Browse files Browse the repository at this point in the history
  • Loading branch information
blesswinsamuel committed Feb 16, 2024
1 parent 45c009d commit 09fefa0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
12 changes: 6 additions & 6 deletions dashboard/router-monitor-dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@
"targets": [
{
"editorMode": "code",
"expr": "\nlabel_replace(\n sum by(dst) (\n increase(\n router_monitor_bytes_total{dst=~\"$localips\",src=~\"internet\",instance=~\"$instance\"}[$__range]\n ) > 0\n ),\n \"ip_addr\", \"$1\", \"dst\", \"(.*)\"\n)\n* on(ip_addr) group_left(hw_addr, device) last_over_time(group by (ip_addr, hw_addr, device) (router_monitor_arp_devices{instance=~\"$instance\"}[$__range]))\n* on(ip_addr) group_left(hostname) last_over_time(router_monitor_hostnames{instance=~\"$instance\"}[$__range])\n",
"expr": "\nlabel_replace(\n sum by(dst) (\n increase(\n router_monitor_bytes_total{dst=~\"$localips\",src=~\"internet\",instance=~\"$instance\"}[$__range]\n ) > 0\n ),\n \"ip_addr\", \"$1\", \"dst\", \"(.*)\"\n)\n* on(ip_addr) group_left(hw_addr, device, hostname) (keep_last_value(\n sum by (ip_addr, hw_addr, device, hostname) (\n router_monitor_arp_devices{instance=~\"$instance\"} \n * on (ip_addr) group_left (hostname) router_monitor_hostnames{instance=~\"$instance\"}\n )\n ) * 0 + 1)\n",
"legendFormat": "{{ hostname }} ({{ ip_addr }})",
"range": false,
"instant": true,
Expand Down Expand Up @@ -988,7 +988,7 @@
"targets": [
{
"editorMode": "code",
"expr": "\nlabel_replace(\n sum by(src) (\n increase(\n router_monitor_bytes_total{src=~\"$localips\",dst=~\"internet\",instance=~\"$instance\"}[$__range]\n ) > 0\n ),\n \"ip_addr\", \"$1\", \"src\", \"(.*)\"\n)\n* on(ip_addr) group_left(hw_addr, device) last_over_time(group by (ip_addr, hw_addr, device) (router_monitor_arp_devices{instance=~\"$instance\"}[$__range]))\n* on(ip_addr) group_left(hostname) last_over_time(router_monitor_hostnames{instance=~\"$instance\"}[$__range])\n",
"expr": "\nlabel_replace(\n sum by(src) (\n increase(\n router_monitor_bytes_total{src=~\"$localips\",dst=~\"internet\",instance=~\"$instance\"}[$__range]\n ) > 0\n ),\n \"ip_addr\", \"$1\", \"src\", \"(.*)\"\n)\n* on(ip_addr) group_left(hw_addr, device, hostname) (keep_last_value(\n sum by (ip_addr, hw_addr, device, hostname) (\n router_monitor_arp_devices{instance=~\"$instance\"} \n * on (ip_addr) group_left (hostname) router_monitor_hostnames{instance=~\"$instance\"}\n )\n ) * 0 + 1)\n",
"legendFormat": "{{ hostname }} ({{ ip_addr }})",
"range": false,
"instant": true,
Expand Down Expand Up @@ -1049,7 +1049,7 @@
"targets": [
{
"editorMode": "code",
"expr": "\nlabel_replace(\n sum by(dst) (\n increase(\n router_monitor_bytes_total{dst=~\"$localips\",src=~\"internet\",instance=~\"$instance\"}[$__interval]\n ) > 0\n ),\n \"ip_addr\", \"$1\", \"dst\", \"(.*)\"\n)\n* on(ip_addr) group_left(hw_addr, device) last_over_time(group by (ip_addr, hw_addr, device) (router_monitor_arp_devices{instance=~\"$instance\"}[$__interval]))\n* on(ip_addr) group_left(hostname) last_over_time(router_monitor_hostnames{instance=~\"$instance\"}[$__interval])\n",
"expr": "\nlabel_replace(\n sum by(dst) (\n increase(\n router_monitor_bytes_total{dst=~\"$localips\",src=~\"internet\",instance=~\"$instance\"}[$__interval]\n ) > 0\n ),\n \"ip_addr\", \"$1\", \"dst\", \"(.*)\"\n)\n* on(ip_addr) group_left(hw_addr, device, hostname) ((\n sum by (ip_addr, hw_addr, device, hostname) (\n router_monitor_arp_devices{instance=~\"$instance\"} \n * on (ip_addr) group_left (hostname) router_monitor_hostnames{instance=~\"$instance\"}\n )\n ) * 0 + 1)\n",
"legendFormat": "{{ hostname }} ({{ ip_addr }})",
"range": true,
"instant": false,
Expand Down Expand Up @@ -1142,7 +1142,7 @@
"targets": [
{
"editorMode": "code",
"expr": "\nlabel_replace(\n sum by(src) (\n increase(\n router_monitor_bytes_total{src=~\"$localips\",dst=~\"internet\",instance=~\"$instance\"}[$__interval]\n ) > 0\n ),\n \"ip_addr\", \"$1\", \"src\", \"(.*)\"\n)\n* on(ip_addr) group_left(hw_addr, device) last_over_time(group by (ip_addr, hw_addr, device) (router_monitor_arp_devices{instance=~\"$instance\"}[$__interval]))\n* on(ip_addr) group_left(hostname) last_over_time(router_monitor_hostnames{instance=~\"$instance\"}[$__interval])\n",
"expr": "\nlabel_replace(\n sum by(src) (\n increase(\n router_monitor_bytes_total{src=~\"$localips\",dst=~\"internet\",instance=~\"$instance\"}[$__interval]\n ) > 0\n ),\n \"ip_addr\", \"$1\", \"src\", \"(.*)\"\n)\n* on(ip_addr) group_left(hw_addr, device, hostname) ((\n sum by (ip_addr, hw_addr, device, hostname) (\n router_monitor_arp_devices{instance=~\"$instance\"} \n * on (ip_addr) group_left (hostname) router_monitor_hostnames{instance=~\"$instance\"}\n )\n ) * 0 + 1)\n",
"legendFormat": "{{ hostname }} ({{ ip_addr }})",
"range": true,
"instant": false,
Expand Down Expand Up @@ -1235,7 +1235,7 @@
"targets": [
{
"editorMode": "code",
"expr": "\nlabel_replace(\n sum by(dst) (\n rate(\n router_monitor_bytes_total{dst=~\"$localips\",src=~\"internet\",instance=~\"$instance\"}[$__rate_interval]\n ) > 0\n ),\n \"ip_addr\", \"$1\", \"dst\", \"(.*)\"\n)\n* on(ip_addr) group_left(hw_addr, device) last_over_time(group by (ip_addr, hw_addr, device) (router_monitor_arp_devices{instance=~\"$instance\"}[$__rate_interval]))\n* on(ip_addr) group_left(hostname) last_over_time(router_monitor_hostnames{instance=~\"$instance\"}[$__rate_interval])\n",
"expr": "\nlabel_replace(\n sum by(dst) (\n rate(\n router_monitor_bytes_total{dst=~\"$localips\",src=~\"internet\",instance=~\"$instance\"}[$__rate_interval]\n ) > 0\n ),\n \"ip_addr\", \"$1\", \"dst\", \"(.*)\"\n)\n* on(ip_addr) group_left(hw_addr, device, hostname) ((\n sum by (ip_addr, hw_addr, device, hostname) (\n router_monitor_arp_devices{instance=~\"$instance\"} \n * on (ip_addr) group_left (hostname) router_monitor_hostnames{instance=~\"$instance\"}\n )\n ) * 0 + 1)\n",
"legendFormat": "{{ hostname }} ({{ ip_addr }})",
"range": true,
"instant": false,
Expand Down Expand Up @@ -1330,7 +1330,7 @@
"targets": [
{
"editorMode": "code",
"expr": "\nlabel_replace(\n sum by(src) (\n rate(\n router_monitor_bytes_total{src=~\"$localips\",dst=~\"internet\",instance=~\"$instance\"}[$__rate_interval]\n ) > 0\n ),\n \"ip_addr\", \"$1\", \"src\", \"(.*)\"\n)\n* on(ip_addr) group_left(hw_addr, device) last_over_time(group by (ip_addr, hw_addr, device) (router_monitor_arp_devices{instance=~\"$instance\"}[$__rate_interval]))\n* on(ip_addr) group_left(hostname) last_over_time(router_monitor_hostnames{instance=~\"$instance\"}[$__rate_interval])\n",
"expr": "\nlabel_replace(\n sum by(src) (\n rate(\n router_monitor_bytes_total{src=~\"$localips\",dst=~\"internet\",instance=~\"$instance\"}[$__rate_interval]\n ) > 0\n ),\n \"ip_addr\", \"$1\", \"src\", \"(.*)\"\n)\n* on(ip_addr) group_left(hw_addr, device, hostname) ((\n sum by (ip_addr, hw_addr, device, hostname) (\n router_monitor_arp_devices{instance=~\"$instance\"} \n * on (ip_addr) group_left (hostname) router_monitor_hostnames{instance=~\"$instance\"}\n )\n ) * 0 + 1)\n",
"legendFormat": "{{ hostname }} ({{ ip_addr }})",
"range": true,
"instant": false,
Expand Down
18 changes: 12 additions & 6 deletions dashboard/router-monitor-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const datasource: DataSourceRef = {
uid: '${DS_PROMETHEUS}',
}

const totalBytesByLocalIPQuery = (labels: string, ipLabel: string, queryType: string = '$__range', queryFunc: string = 'increase', extraFields: boolean = true) =>
const totalBytesByLocalIPQuery = (labels: string, ipLabel: string, queryType: string, queryFunc: string, extraFields: boolean = true) =>
`
label_replace(
sum by(${ipLabel}) (
Expand All @@ -34,15 +34,19 @@ label_replace(
)` +
(extraFields
? `
* on(ip_addr) group_left(hw_addr, device) last_over_time(group by (ip_addr, hw_addr, device) (router_monitor_arp_devices{instance=~"$instance"}[${queryType}]))
* on(ip_addr) group_left(hostname) last_over_time(router_monitor_hostnames{instance=~"$instance"}[${queryType}])
`
* on(ip_addr) group_left(hw_addr, device, hostname) (${queryType === '$__range' ? 'keep_last_value' : ''}(
sum by (ip_addr, hw_addr, device, hostname) (
router_monitor_arp_devices{instance=~"$instance"}
* on (ip_addr) group_left (hostname) router_monitor_hostnames{instance=~"$instance"}
)
) * 0 + 1)
` // hack: $__range is used only in pie chart, which is an instant query
: '')

const totalBytesByLocalIPPieChartPanel = (uploadOrDownload: string, labels: string, ipLabel: string) =>
NewPieChartPanel({
title: `Total Bytes ${uploadOrDownload}ed - by local IP (pie chart)`,
targets: [{ expr: totalBytesByLocalIPQuery(labels, ipLabel), legendFormat: '{{ hostname }} ({{ ip_addr }})', type: 'instant' }],
targets: [{ expr: totalBytesByLocalIPQuery(labels, ipLabel, '$__range', 'increase'), legendFormat: '{{ hostname }} ({{ ip_addr }})', type: 'instant' }],
defaultUnit: Unit.BYTES_SI,
})

Expand Down Expand Up @@ -252,7 +256,9 @@ const panels: PanelRowAndGroups = [
title: 'Connected Devices',
targets: [
{
expr: 'last_over_time(sum by (ip_addr, hw_addr, device) (router_monitor_arp_devices{instance=~"$instance"})[$__range]) * on(ip_addr) group_left(hostname) last_over_time(sum by (ip_addr, hostname) (router_monitor_hostnames{instance=~"$instance"})[$__range])',
expr:
'last_over_time(sum by (ip_addr, hw_addr, device) (router_monitor_arp_devices{instance=~"$instance"})[$__range]) ' +
'* on(ip_addr) group_left(hostname) last_over_time(sum by (ip_addr, hostname) (router_monitor_hostnames{instance=~"$instance"})[$__range])',
// expr: 'sum by (ip_addr, hw_addr, device) (last_over_time(router_monitor_arp_devices{instance=~"$instance"}[$__range])) * on(ip_addr) group_left(hostname) max by (ip_addr, hostname) (last_over_time(router_monitor_hostnames{instance=~"$instance"}[$__range]))',
format: 'table',
type: 'instant',
Expand Down

0 comments on commit 09fefa0

Please sign in to comment.