Use flux to show online and offline host

Hi,
I use grafana 7.3.6 with influxdb 2 and flux to create a table with this query:

import "influxdata/influxdb/monitor"
import "experimental"

from(bucket: "test")
    |> range(start: -10m)
    |> filter(fn: (r) => r._measurement == "system")
    |> filter(fn: (r) => r._field == "uptime")
    |> group(columns: ["host"])
    |> monitor.deadman(t: experimental.subDuration(d: 5m, from: now() ))
    |> map(fn: (r) => ({
      host: r.host,
      dead : if r.dead == true then 0 else 1
    }))

but i have an issue because i want to to display a single stat where my display value is the host but the color of Thresholds is set by the value of dead. I dont know if its possible or not or if i can bypass the problem ?

Thanks
Mike

Hi Mike, i am researching the same thing as wanting to do a deadman check, I have tried your query but cant seem to get it to work for me, are you checking against windows or Linux servers?

Also for you to pull the data whats the config your using for Telegraf etc?

Stu

Hi,
I use it to check windows and linux server.
I push the data with telegraph you just need the [[inputs.system]]

You have maybe to change the bucket name ?

Mike

Hi,
I have find a solution with that:

import "influxdata/influxdb/monitor"
import "experimental"

from(bucket: "${bucket}")
    |> range(start: -10m)
    |> filter(fn: (r) => r._measurement == "system")
    |> filter(fn: (r) => r._field == "uptime")
    |> group(columns: ["host"])
    |> monitor.deadman(t: experimental.subDuration(d: 15s, from: now() ))

and panel is:

{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "InfluxDB",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "limit": 100,
        "name": "Annotations & Alerts",
        "showIn": 0,
        "type": "dashboard"
      }
    ]
  },
  "description": "general test",
  "editable": true,
  "gnetId": null,
  "graphTooltip": 0,
  "id": 1,
  "iteration": 1612428678385,
  "links": [],
  "panels": [
    {
      "datasource": null,
      "description": "",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": null,
            "filterable": false
          },
          "displayName": "${__field.labels.host}",
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "rgb(42, 46, 42)",
                "value": null
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byRegexp",
              "options": "/.*dead=\"false\".*/"
            },
            "properties": [
              {
                "id": "thresholds",
                "value": {
                  "mode": "absolute",
                  "steps": [
                    {
                      "color": "dark-green",
                      "value": null
                    }
                  ]
                }
              }
            ]
          },
          {
            "matcher": {
              "id": "byRegexp",
              "options": "/.*dead=\"true\".*/"
            },
            "properties": [
              {
                "id": "thresholds",
                "value": {
                  "mode": "absolute",
                  "steps": [
                    {
                      "color": "dark-red",
                      "value": null
                    }
                  ]
                }
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 4,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 4,
      "options": {
        "colorMode": "background",
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "mean"
          ],
          "fields": "",
          "values": true
        },
        "textMode": "name"
      },
      "pluginVersion": "7.3.6",
      "repeat": "bucket",
      "repeatDirection": "v",
      "scopedVars": {
        "bucket": {
          "selected": true,
          "text": "test",
          "value": "test"
        }
      },
      "targets": [
        {
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "orderByTime": "ASC",
          "policy": "default",
          "query": "import \"influxdata/influxdb/monitor\"\r\nimport \"experimental\"\r\n\r\nfrom(bucket: \"${bucket}\")\r\n    |> range(start: -10m)\r\n    |> filter(fn: (r) => r._measurement == \"system\")\r\n    |> filter(fn: (r) => r._field == \"uptime\")\r\n    |> group(columns: [\"host\"])\r\n    |> monitor.deadman(t: experimental.subDuration(d: 15s, from: now() ))\r\n",
          "refId": "A",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "value"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": []
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Host",
      "transparent": true,
      "type": "stat"
    }
  ],
  "refresh": "5s",
  "schemaVersion": 26,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": [
      {
        "allValue": null,
        "current": {
          "selected": true,
          "text": [
            "test"
          ],
          "value": [
            "test"
          ]
        },
        "datasource": "InfluxDB",
        "definition": "",
        "error": null,
        "hide": 0,
        "includeAll": false,
        "label": null,
        "multi": true,
        "name": "bucket",
        "options": [],
        "query": "buckets()\r\n  |> filter(fn: (r) => r.name !~ /^_/)\r\n  |> rename(columns: {name: \"_value\"})\r\n  |> keep(columns: [\"_value\"])",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 1,
        "tagValuesQuery": "",
        "tags": [],
        "tagsQuery": "",
        "type": "query",
        "useTags": false
      }
    ]
  },
  "time": {
    "from": "now-6h",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "eureka",
  "uid": "EZbB-JLGk",
  "version": 10
}

Hope it can help people :wink:
Mike

Hi Mike,

Thanks I have added in the [[InPuts.System]] - was using [[inputs.win_perf_counters.object]]

when applying the panel and script i get the following error did you come across this when you were building?

dead has unknown data type boolean

Stu

Hi,
Try with this one i have try to use it with a new server and it works fine,

{
      "annotations": {
        "list": [
          {
            "builtIn": 1,
            "datasource": "InfluxDB",
            "enable": true,
            "hide": true,
            "iconColor": "rgba(0, 211, 255, 1)",
            "limit": 100,
            "name": "Annotations & Alerts",
            "showIn": 0,
            "type": "dashboard"
          }
        ]
      },
      "description": "general test",
      "editable": true,
      "gnetId": null,
      "graphTooltip": 0,
      "id": 1,
      "iteration": 1612518109922,
      "links": [],
      "panels": [
        {
          "datasource": null,
          "fieldConfig": {
            "defaults": {
              "color": {
                "fixedColor": "yellow",
                "mode": "fixed"
              },
              "custom": {
                "align": null,
                "filterable": false
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "yellow",
                    "value": null
                  }
                ]
              }
            },
            "overrides": []
          },
          "gridPos": {
            "h": 4,
            "w": 2,
            "x": 0,
            "y": 0
          },
          "id": 8,
          "options": {
            "colorMode": "value",
            "graphMode": "area",
            "justifyMode": "auto",
            "orientation": "auto",
            "reduceOptions": {
              "calcs": [
                "last"
              ],
              "fields": "/.*/",
              "values": true
            },
            "textMode": "auto"
          },
          "pluginVersion": "7.3.6",
          "repeat": "bucket",
          "repeatDirection": "v",
          "scopedVars": {
            "bucket": {
              "selected": true,
              "text": "test",
              "value": "test"
            }
          },
          "targets": [
            {
              "groupBy": [
                {
                  "params": [
                    "$__interval"
                  ],
                  "type": "time"
                },
                {
                  "params": [
                    "null"
                  ],
                  "type": "fill"
                }
              ],
              "orderByTime": "ASC",
              "policy": "default",
              "query": "buckets()\r\n    |> filter(fn: (r) => r.name == \"${bucket}\")\r\n    |> keep(columns: [\"name\"])",
              "refId": "A",
              "resultFormat": "time_series",
              "select": [
                [
                  {
                    "params": [
                      "value"
                    ],
                    "type": "field"
                  },
                  {
                    "params": [],
                    "type": "mean"
                  }
                ]
              ],
              "tags": []
            }
          ],
          "timeFrom": null,
          "timeShift": null,
          "title": "Bucket",
          "transparent": true,
          "type": "stat"
        },
        {
          "datasource": null,
          "description": "",
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "thresholds"
              },
              "custom": {
                "align": null,
                "filterable": false
              },
              "displayName": "${__field.labels.host}",
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "rgb(42, 46, 42)",
                    "value": null
                  }
                ]
              }
            },
            "overrides": [
              {
                "matcher": {
                  "id": "byRegexp",
                  "options": "/.*dead=\"false\".*/"
                },
                "properties": [
                  {
                    "id": "thresholds",
                    "value": {
                      "mode": "absolute",
                      "steps": [
                        {
                          "color": "dark-green",
                          "value": null
                        }
                      ]
                    }
                  }
                ]
              },
              {
                "matcher": {
                  "id": "byRegexp",
                  "options": "/.*dead=\"true\".*/"
                },
                "properties": [
                  {
                    "id": "thresholds",
                    "value": {
                      "mode": "absolute",
                      "steps": [
                        {
                          "color": "dark-red",
                          "value": null
                        }
                      ]
                    }
                  }
                ]
              }
            ]
          },
          "gridPos": {
            "h": 4,
            "w": 21,
            "x": 2,
            "y": 0
          },
          "id": 4,
          "options": {
            "colorMode": "background",
            "graphMode": "area",
            "justifyMode": "auto",
            "orientation": "auto",
            "reduceOptions": {
              "calcs": [
                "mean"
              ],
              "fields": "",
              "values": true
            },
            "textMode": "name"
          },
          "pluginVersion": "7.3.6",
          "repeat": "bucket",
          "repeatDirection": "v",
          "scopedVars": {
            "bucket": {
              "selected": true,
              "text": "test",
              "value": "test"
            }
          },
          "targets": [
            {
              "groupBy": [
                {
                  "params": [
                    "$__interval"
                  ],
                  "type": "time"
                },
                {
                  "params": [
                    "null"
                  ],
                  "type": "fill"
                }
              ],
              "orderByTime": "ASC",
              "policy": "default",
              "query": "import \"influxdata/influxdb/monitor\"\r\nimport \"experimental\"\r\n\r\nfrom(bucket: \"${bucket}\")\r\n    |> range(start: -10m)\r\n    |> filter(fn: (r) => r._measurement == \"system\")\r\n    |> filter(fn: (r) => r._field == \"uptime\")\r\n    |> group(columns: [\"host\"])\r\n    |> monitor.deadman(t: experimental.subDuration(d: 15s, from: now() ))\r\n",
              "refId": "A",
              "resultFormat": "time_series",
              "select": [
                [
                  {
                    "params": [
                      "value"
                    ],
                    "type": "field"
                  },
                  {
                    "params": [],
                    "type": "mean"
                  }
                ]
              ],
              "tags": []
            }
          ],
          "timeFrom": null,
          "timeShift": null,
          "title": "Host",
          "transparent": true,
          "type": "stat"
        },
        {
          "alert": {
            "alertRuleTags": {},
            "conditions": [
              {
                "evaluator": {
                  "params": [
                    0.1
                  ],
                  "type": "lt"
                },
                "operator": {
                  "type": "and"
                },
                "query": {
                  "params": [
                    "A",
                    "5m",
                    "now"
                  ]
                },
                "reducer": {
                  "params": [],
                  "type": "avg"
                },
                "type": "query"
              }
            ],
            "executionErrorState": "alerting",
            "for": "5m",
            "frequency": "1m",
            "handler": 1,
            "message": "Host down",
            "name": "Alert host down",
            "noDataState": "no_data",
            "notifications": [
              {
                "uid": "UhSyu8YMz"
              }
            ]
          },
          "aliasColors": {},
          "bars": false,
          "dashLength": 10,
          "dashes": false,
          "datasource": null,
          "fieldConfig": {
            "defaults": {
              "custom": {
                "align": null,
                "filterable": false
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "green",
                    "value": null
                  },
                  {
                    "color": "red",
                    "value": 80
                  }
                ]
              }
            },
            "overrides": []
          },
          "fill": 1,
          "fillGradient": 0,
          "gridPos": {
            "h": 1,
            "w": 24,
            "x": 0,
            "y": 4
          },
          "hiddenSeries": false,
          "id": 6,
          "legend": {
            "alignAsTable": false,
            "avg": false,
            "current": false,
            "hideEmpty": false,
            "max": false,
            "min": false,
            "rightSide": false,
            "show": false,
            "total": false,
            "values": false
          },
          "lines": false,
          "linewidth": 1,
          "nullPointMode": "connected",
          "options": {
            "alertThreshold": true
          },
          "percentage": false,
          "pluginVersion": "7.3.6",
          "pointradius": 3,
          "points": true,
          "renderer": "flot",
          "repeat": "bucket",
          "scopedVars": {
            "bucket": {
              "selected": true,
              "text": "test",
              "value": "test"
            }
          },
          "seriesOverrides": [],
          "spaceLength": 10,
          "stack": false,
          "steppedLine": false,
          "targets": [
            {
              "groupBy": [
                {
                  "params": [
                    "$__interval"
                  ],
                  "type": "time"
                },
                {
                  "params": [
                    "null"
                  ],
                  "type": "fill"
                }
              ],
              "orderByTime": "ASC",
              "policy": "default",
              "query": "import \"influxdata/influxdb/monitor\"\r\nimport \"experimental\"\r\n\r\nfrom(bucket: \"${bucket}\")\r\n    |> range(start: -10m)\r\n    |> filter(fn: (r) => r._measurement == \"system\")\r\n    |> filter(fn: (r) => r._field == \"uptime\")\r\n    |> group(columns: [\"host\"])\r\n    |> monitor.deadman(t: experimental.subDuration(d: 15s, from: now() ))\r\n    |> map(fn: (r) => ({\r\n      time: r._time,\r\n      host: r.host,\r\n      dead : if r.dead == true then 0 else 1\r\n    }))",
              "refId": "A",
              "resultFormat": "time_series",
              "select": [
                [
                  {
                    "params": [
                      "value"
                    ],
                    "type": "field"
                  },
                  {
                    "params": [],
                    "type": "mean"
                  }
                ]
              ],
              "tags": []
            }
          ],
          "thresholds": [
            {
              "colorMode": "critical",
              "fill": true,
              "line": true,
              "op": "lt",
              "value": 0.1
            }
          ],
          "timeFrom": null,
          "timeRegions": [],
          "timeShift": null,
          "title": "Alert",
          "tooltip": {
            "shared": true,
            "sort": 0,
            "value_type": "individual"
          },
          "transparent": true,
          "type": "graph",
          "xaxis": {
            "buckets": null,
            "mode": "time",
            "name": null,
            "show": true,
            "values": []
          },
          "yaxes": [
            {
              "format": "short",
              "label": null,
              "logBase": 1,
              "max": "1.1",
              "min": "-0.1",
              "show": true
            },
            {
              "format": "short",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": true
            }
          ],
          "yaxis": {
            "align": false,
            "alignLevel": null
          }
        }
      ],
      "refresh": "5s",
      "schemaVersion": 26,
      "style": "dark",
      "tags": [],
      "templating": {
        "list": [
          {
            "allValue": null,
            "current": {
              "selected": true,
              "text": [
                "test"
              ],
              "value": [
                "test"
              ]
            },
            "datasource": "InfluxDB",
            "definition": "",
            "error": null,
            "hide": 0,
            "includeAll": false,
            "label": null,
            "multi": true,
            "name": "bucket",
            "options": [],
            "query": "buckets()\r\n  |> filter(fn: (r) => r.name !~ /^_/)\r\n  |> rename(columns: {name: \"_value\"})\r\n  |> keep(columns: [\"_value\"])",
            "refresh": 2,
            "regex": "",
            "skipUrlSync": false,
            "sort": 1,
            "tagValuesQuery": "",
            "tags": [],
            "tagsQuery": "",
            "type": "query",
            "useTags": false
          }
        ]
      },
      "time": {
        "from": "now-6h",
        "to": "now"
      },
      "timepicker": {},
      "timezone": "",
      "title": "eureka",
      "uid": "EZbB-JLGk",
      "version": 14
    }