WIP: monitoring improvements - containers dashboard

This commit is contained in:
Yuri Tatishchev 2024-10-12 23:30:55 -07:00
parent 6504100cd5
commit 581346f019
Signed by: CaZzzer
GPG Key ID: 28BE602058C08557
2 changed files with 95 additions and 59 deletions

View File

@ -0,0 +1,95 @@
from grafanalib.core import (
Dashboard, TimeSeries,
Target, GridPos,
Templating, Template, REFRESH_ON_TIME_RANGE_CHANGE
)
from grafanalib.formatunits import BYTES_IEC, SECONDS, BYTES_SEC_IEC
prom_datasource='prometheus'
dashboard = Dashboard(
title='Containers',
uid='containers',
description='Data for compose projects from default Prometheus datasource collected by Cadvisor',
tags=[
'example'
],
templating=Templating(list=[
Template(
name='compose_project',
label='Compose Project',
dataSource=prom_datasource,
query='label_values({__name__=~"container.*"}, container_label_com_docker_compose_project)',
includeAll=True,
multi=True,
refresh=REFRESH_ON_TIME_RANGE_CHANGE,
),
Template(
name='container_name',
label='Container',
dataSource=prom_datasource,
query='label_values({__name__=~"container.*", container_label_com_docker_compose_project=~"$compose_project"}, name)',
includeAll=True,
multi=True,
refresh=REFRESH_ON_TIME_RANGE_CHANGE,
),
]),
timezone='browser',
panels=[
TimeSeries(
title='Container Memory Usage',
unit=BYTES_IEC,
gridPos=GridPos(h=8, w=12, x=0, y=0),
lineWidth=2,
fillOpacity=10,
showPoints='never',
targets=[
Target(
datasource=prom_datasource,
expr='max by (name) (container_memory_usage_bytes{name=~"$container_name", container_label_com_docker_compose_project=~"$compose_project"})',
legendFormat='{{ name }}',
refId='A',
),
],
),
TimeSeries(
title='Container CPU Usage',
unit=SECONDS,
gridPos=GridPos(h=8, w=12, x=12, y=0),
lineWidth=2,
fillOpacity=10,
showPoints='never',
targets=[
Target(
datasource=prom_datasource,
expr='max by (name) (rate(container_cpu_usage_seconds_total{name=~"$container_name", container_label_com_docker_compose_project=~"$compose_project"}[$__rate_interval]))',
legendFormat='{{ name }}',
refId='A',
),
],
),
TimeSeries(
title='Container Network Traffic',
unit=BYTES_SEC_IEC,
gridPos=GridPos(h=8, w=12, x=0, y=8),
lineWidth=2,
fillOpacity=10,
showPoints='never',
targets=[
Target(
datasource=prom_datasource,
expr='sum by (name) (rate(container_network_receive_bytes_total{name=~"$container_name", container_label_com_docker_compose_project=~"$compose_project"}[$__rate_interval]))',
legendFormat="recv {{ name }}",
refId='A',
),
Target(
datasource=prom_datasource,
expr='-sum by (name) (rate(container_network_transmit_bytes_total{name=~"$container_name", container_label_com_docker_compose_project=~"$compose_project"}[$__rate_interval]))',
legendFormat="trans {{ name }}",
refId='B',
),
],
),
],
).auto_panel_ids()

View File

@ -1,59 +0,0 @@
from grafanalib.core import (
Dashboard, TimeSeries, GaugePanel,
Target, GridPos,
OPS_FORMAT, Templating, Template, REFRESH_ON_TIME_RANGE_CHANGE
)
from grafanalib.formatunits import BYTES_IEC
dashboard = Dashboard(
title="Containers",
description="Data for compose projects from default Prometheus datasource collected by Cadvisor",
tags=[
'example'
],
templating=Templating(list=[
# TODO: test how much of this is actually necessary
Template(
name="compose_project",
label="compose_project",
dataSource="prometheus",
query='label_values({__name__=~"container.*"}, container_label_com_docker_compose_project)',
includeAll=True,
multi=True,
hide=0,
sort=1,
type="query",
refresh=REFRESH_ON_TIME_RANGE_CHANGE,
),
Template(
name="container_name",
label="container_name",
dataSource="prometheus",
query='label_values({__name__=~"container.*", container_label_com_docker_compose_project=~"$compose_project"}, name)',
includeAll=True,
multi=True,
hide=0,
sort=1,
type="query",
refresh=REFRESH_ON_TIME_RANGE_CHANGE,
),
]),
timezone="browser",
panels=[
TimeSeries(
title="Container Memory Usage",
# dataSource='prometheus',
targets=[
Target(
datasource='prometheus',
expr='max by (name) (container_memory_usage_bytes{name=~"$container_name", container_label_com_docker_compose_project=~"$compose_project"})',
legendFormat="{{ name }}",
refId='A',
),
],
unit=BYTES_IEC,
gridPos=GridPos(h=8, w=16, x=0, y=0),
),
],
).auto_panel_ids()