Grafana dashboard: Watchmen Uptime Dashboard

This dashboard show uptime for service health check using watchmen-plugin-history.

{
  "__inputs": [
    {
      "name": "DS_POSTGRES",
      "label": "postgres",
      "description": "",
      "type": "datasource",
      "pluginId": "postgres",
      "pluginName": "PostgreSQL"
    }
  ],
  "__requires": [
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "5.3.1"
    },
    {
      "type": "datasource",
      "id": "postgres",
      "name": "PostgreSQL",
      "version": "5.0.0"
    },
    {
      "type": "panel",
      "id": "singlestat",
      "name": "Singlestat",
      "version": "5.0.0"
    },
    {
      "type": "panel",
      "id": "table",
      "name": "Table",
      "version": "5.0.0"
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "gnetId": 8735,
  "graphTooltip": 0,
  "id": null,
  "iteration": 1541392133390,
  "links": [],
  "panels": [
    {
      "columns": [],
      "datasource": "${DS_POSTGRES}",
      "fontSize": "100%",
      "gridPos": {
        "h": 8,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 13,
      "links": [],
      "pageSize": null,
      "scroll": true,
      "showHeader": true,
      "sort": {
        "col": 2,
        "desc": true
      },
      "styles": [
        {
          "alias": "Last OK Timestamp",
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "pattern": "time",
          "type": "date"
        },
        {
          "alias": "Service Name",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 1,
          "mappingType": 1,
          "pattern": "service",
          "thresholds": [],
          "type": "string",
          "unit": "ms"
        },
        {
          "alias": "Total Down Time",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 2,
          "mappingType": 1,
          "pattern": "duration",
          "thresholds": [],
          "type": "number",
          "unit": "ms"
        },
        {
          "alias": "",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "decimals": 2,
          "pattern": "/.*/",
          "thresholds": [],
          "type": "number",
          "unit": "short"
        }
      ],
      "targets": [
        {
          "expr": "",
          "format": "table",
          "group": [],
          "intervalFactor": 1,
          "metricColumn": "none",
          "rawQuery": true,
          "rawSql": "SELECT b.name, b.first_ping, COALESCE (a.duration, 0) AS duration\nFROM (SELECT name, sum(duration)/10 AS duration, max(last_outage) as last_outage FROM service_back WHERE last_outage > $__timeFrom() GROUP BY name) AS a \nRIGHT JOIN service_status AS b ON a.name=b.name\n",
          "refId": "A",
          "select": [
            [
              {
                "params": [
                  "value"
                ],
                "type": "column"
              }
            ]
          ],
          "timeColumn": "time",
          "where": [
            {
              "name": "$__timeFilter",
              "params": [],
              "type": "macro"
            }
          ]
        }
      ],
      "title": "Service Status",
      "transform": "table",
      "type": "table"
    },
    {
      "cacheTimeout": null,
      "colorBackground": false,
      "colorValue": false,
      "colors": [
        "#d44a3a",
        "rgba(237, 129, 40, 0.89)",
        "#629e51"
      ],
      "datasource": "${DS_POSTGRES}",
      "decimals": 2,
      "description": "Change Service Name Variable, to check uptime for each service",
      "format": "percent",
      "gauge": {
        "maxValue": 100,
        "minValue": 99,
        "show": true,
        "thresholdLabels": true,
        "thresholdMarkers": true
      },
      "gridPos": {
        "h": 8,
        "w": 8,
        "x": 0,
        "y": 8
      },
      "id": 9,
      "interval": null,
      "links": [],
      "mappingType": 1,
      "mappingTypes": [
        {
          "name": "value to text",
          "value": 1
        },
        {
          "name": "range to text",
          "value": 2
        }
      ],
      "maxDataPoints": 100,
      "nullPointMode": "connected",
      "nullText": null,
      "postfix": "",
      "postfixFontSize": "50%",
      "prefix": "",
      "prefixFontSize": "50%",
      "rangeMaps": [
        {
          "from": "null",
          "text": "N/A",
          "to": "null"
        }
      ],
      "sparkline": {
        "fillColor": "rgba(31, 118, 189, 0.18)",
        "full": false,
        "lineColor": "rgb(31, 120, 193)",
        "show": false
      },
      "tableColumn": "duration",
      "targets": [
        {
          "expr": "",
          "format": "table",
          "group": [],
          "intervalFactor": 1,
          "metricColumn": "name",
          "rawQuery": true,
          "rawSql": "SELECT ((($__unixEpochTo()-$__unixEpochFrom())::BIGINT - AVG(COALESCE (a.duration, 0)/1000::float))/($__unixEpochTo()-$__unixEpochFrom())::BIGINT)*100 AS duration\nFROM (SELECT name, sum(duration) AS duration FROM service_back WHERE name IN ($name) AND $__timeFilter(last_outage) GROUP BY name ) AS a \nRIGHT JOIN service_status AS b ON a.name=b.name\n\n",
          "refId": "A",
          "select": [
            [
              {
                "params": [
                  "duration"
                ],
                "type": "column"
              }
            ]
          ],
          "table": "service_back",
          "timeColumn": "last_outage",
          "timeColumnType": "timestamp",
          "where": [
            {
              "name": "$__timeFilter",
              "params": [],
              "type": "macro"
            }
          ]
        }
      ],
      "thresholds": "99.5, 99.8",
      "title": "Service Uptime",
      "type": "singlestat",
      "valueFontSize": "80%",
      "valueMaps": [
        {
          "op": "=",
          "text": "100%",
          "value": "null"
        }
      ],
      "valueName": "avg"
    },
    {
      "columns": [],
      "datasource": "${DS_POSTGRES}",
      "fontSize": "100%",
      "gridPos": {
        "h": 8,
        "w": 16,
        "x": 8,
        "y": 8
      },
      "id": 11,
      "links": [],
      "pageSize": null,
      "scroll": true,
      "showHeader": true,
      "sort": {
        "col": 0,
        "desc": true
      },
      "styles": [
        {
          "alias": "Outage Time",
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "pattern": "time",
          "type": "date"
        },
        {
          "alias": "duration",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "dateFormat": "YYYY-MM-DD HH:mm:ss",
          "decimals": 1,
          "mappingType": 1,
          "pattern": "duration",
          "thresholds": [],
          "type": "number",
          "unit": "ms"
        },
        {
          "alias": "",
          "colorMode": null,
          "colors": [
            "rgba(245, 54, 54, 0.9)",
            "rgba(237, 129, 40, 0.89)",
            "rgba(50, 172, 45, 0.97)"
          ],
          "decimals": 2,
          "pattern": "/.*/",
          "thresholds": [],
          "type": "number",
          "unit": "short"
        }
      ],
      "targets": [
        {
          "expr": "",
          "format": "table",
          "group": [],
          "intervalFactor": 1,
          "metricColumn": "none",
          "rawQuery": true,
          "rawSql": "SELECT\n  $__timeGroup(\"last_outage\",'1s'),\n  last_outage + CONCAT(SUM(DURATION), ' ms')::interval + interval '7 hour'  AS \"Resolved Time\",\n  name as \"Service Name\",\n  sum(\"duration\")/10 as \"duration\"\nFROM service_back\nWHERE $__timeFilter(\"last_outage\") AND name IN ($name)\nGROUP BY time, name,last_outage\nORDER BY time",
          "refId": "A",
          "select": [
            [
              {
                "params": [
                  "value"
                ],
                "type": "column"
              }
            ]
          ],
          "timeColumn": "time",
          "where": [
            {
              "name": "$__timeFilter",
              "params": [],
              "type": "macro"
            }
          ]
        }
      ],
      "title": "Incident Table",
      "transform": "table",
      "type": "table"
    }
  ],
  "refresh": false,
  "schemaVersion": 16,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": [
      {
        "allValue": null,
        "current": {},
        "datasource": "${DS_POSTGRES}",
        "hide": 0,
        "includeAll": true,
        "label": "Service Name",
        "multi": true,
        "name": "name",
        "options": [],
        "query": "SELECT name from service_status",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      }
    ]
  },
  "time": {
    "from": "now/M",
    "to": "now"
  },
  "timepicker": {
    "refresh_intervals": [
      "5s",
      "10s",
      "30s",
      "1m",
      "5m",
      "15m",
      "30m",
      "1h",
      "2h",
      "1d"
    ],
    "time_options": [
      "5m",
      "15m",
      "1h",
      "6h",
      "12h",
      "24h",
      "2d",
      "7d",
      "30d"
    ]
  },
  "timezone": "",
  "title": "Watchmen Uptime Dashboard",
  "uid": "MXJhdM-mk",
  "version": 39
}