Skip to content

Instantly share code, notes, and snippets.

@gilangvperdana
Created September 30, 2023 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilangvperdana/f726b744829a7bfe7c618a47293505f1 to your computer and use it in GitHub Desktop.
Save gilangvperdana/f726b744829a7bfe7c618a47293505f1 to your computer and use it in GitHub Desktop.
Monitoring Docker Container

General

Do you want to monitor your Docker Contianer on your VM/Server? You can use this method.

Prerequisites

  • Prometheus
  • Grafana
  • Docker

Create daemon.json

  • Create daemon.json
touch /etc/docker/daemon.json
nano /etc/docker/daemon.json
  • Fill with this
{
        "metrics-addr" : "0.0.0.0:9323",
        "experimental" : true
}

Fill Prometheus YAML

nano /etc/prometheus/prometheus.yml
  - job_name: 'docker'
    scrape_interval: 5s
    metrics_path: /metrics
    static_configs:
      - targets: ['XXX.XXX.XXX.XXX:9323']

Create Grafana Dashboard

You can use docker.json like the template below.

{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 22,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": {
"type": "prometheus",
"uid": "dfab7219-d9bc-4628-9afe-fdfb45920701"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0
},
"id": 4,
"options": {
"orientation": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showThresholdLabels": false,
"showThresholdMarkers": true
},
"pluginVersion": "10.0.3",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "dfab7219-d9bc-4628-9afe-fdfb45920701"
},
"editorMode": "code",
"expr": "engine_daemon_engine_cpus_cpus{instance=\"$Instance\", job=\"docker\"}",
"instant": false,
"range": true,
"refId": "A"
}
],
"title": "Engine CPU",
"type": "gauge"
},
{
"datasource": {
"type": "prometheus",
"uid": "dfab7219-d9bc-4628-9afe-fdfb45920701"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 0
},
"id": 2,
"options": {
"orientation": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showThresholdLabels": false,
"showThresholdMarkers": true
},
"pluginVersion": "10.0.3",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "dfab7219-d9bc-4628-9afe-fdfb45920701"
},
"editorMode": "code",
"expr": "engine_daemon_container_states_containers{instance=\"$Instance\", state=\"stopped\"}",
"instant": false,
"range": true,
"refId": "A"
}
],
"title": "Stopped Containers",
"type": "gauge"
},
{
"datasource": {
"type": "prometheus",
"uid": "dfab7219-d9bc-4628-9afe-fdfb45920701"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 8
},
"id": 1,
"options": {
"orientation": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showThresholdLabels": false,
"showThresholdMarkers": true
},
"pluginVersion": "10.0.3",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "dfab7219-d9bc-4628-9afe-fdfb45920701"
},
"editorMode": "code",
"expr": "engine_daemon_container_states_containers{instance=\"$Instance\", state=\"paused\"}",
"instant": false,
"range": true,
"refId": "A"
}
],
"title": "Paused Containers",
"type": "gauge"
},
{
"datasource": {
"type": "prometheus",
"uid": "dfab7219-d9bc-4628-9afe-fdfb45920701"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 8
},
"id": 3,
"options": {
"orientation": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showThresholdLabels": false,
"showThresholdMarkers": true
},
"pluginVersion": "10.0.3",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "dfab7219-d9bc-4628-9afe-fdfb45920701"
},
"editorMode": "code",
"expr": "engine_daemon_container_states_containers{instance=\"$Instance\", state=\"running\"}",
"instant": false,
"range": true,
"refId": "A"
}
],
"title": "Running Containers",
"type": "gauge"
}
],
"refresh": "5s",
"schemaVersion": 38,
"style": "dark",
"tags": [],
"templating": {
"list": [
{
"current": {
"selected": false,
"text": "192.168.100.246:9323",
"value": "192.168.100.246:9323"
},
"datasource": {
"type": "prometheus",
"uid": "dfab7219-d9bc-4628-9afe-fdfb45920701"
},
"definition": "label_values(engine_daemon_engine_info,instance)",
"hide": 0,
"includeAll": false,
"label": "Instance",
"multi": false,
"name": "Instance",
"options": [],
"query": {
"query": "label_values(engine_daemon_engine_info,instance)",
"refId": "PrometheusVariableQueryEditor-VariableQuery"
},
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 0,
"type": "query"
}
]
},
"time": {
"from": "now-1h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "Docker",
"uid": "e941b05d-c7ff-40be-9ba9-509d2f422bce",
"version": 11,
"weekStart": ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment