Skip to content

Visualization using InfluxDB and Grafana Toolkit

Shreshth Tuli edited this page Nov 19, 2020 · 6 revisions

Grafana is used in COSCO to visualize the host and container utilization statistics updated at every interval of execution. Grafana has a straightforward interface to extract the data from InfluxDB.

Setting up grafana in Windows

  1. Download Grafana tool from the following repository from here. (Note: Choose Windows and Edition: Opensource)
  2. Run the downloaded installer. 3.To run Grafana, open your browser and go to the Grafana port (http://localhost:3000/ is default) and then follow the instructions for further guidance at the getting started page.
  3. Connecting InfluxDB and Grafana: Open the Grafana dashboard using link http://localhost:3000/, log in as default user (press the skip button). On the left pane, click on settings and click on add data source. Select InfluxDB, provide information about your database name, port number etc.
  4. Creating dashboards or visualization graphs: Use the following json script
{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "gnetId": null,
  "graphTooltip": 0,
  "id": 1,
  "links": [],
  "panels": [
    {
      "aliasColors": {},
      "bars": false,
      "dashLength": 10,
      "dashes": false,
      "datasource": null,
      "fieldConfig": {
        "defaults": {
          "custom": {}
        },
        "overrides": []
      },
      "fill": 1,
      "fillGradient": 0,
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 0
      },
      "hiddenSeries": false,
      "id": 6,
      "legend": {
        "avg": false,
        "current": false,
        "max": false,
        "min": false,
        "show": true,
        "total": false,
        "values": false
      },
      "lines": true,
      "linewidth": 1,
      "nullPointMode": "null",
      "options": {
        "alertThreshold": true
      },
      "percentage": false,
      "pluginVersion": "7.3.2",
      "pointradius": 2,
      "points": false,
      "renderer": "flot",
      "seriesOverrides": [],
      "spaceLength": 10,
      "stack": false,
      "steppedLine": false,
      "thresholds": [],
      "timeFrom": null,
      "timeRegions": [],
      "timeShift": null,
      "title": "Panel Title",
      "tooltip": {
        "shared": true,
        "sort": 0,
        "value_type": "individual"
      },
      "type": "graph",
      "xaxis": {
        "buckets": null,
        "mode": "time",
        "name": null,
        "show": true,
        "values": []
      },
      "yaxes": [
        {
          "format": "short",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        },
        {
          "format": "short",
          "label": null,
          "logBase": 1,
          "max": null,
          "min": null,
          "show": true
        }
      ],
      "yaxis": {
        "align": false,
        "alignLevel": null
      }
    },
    {
      "datasource": "InfluxDB",
      "fieldConfig": {
        "defaults": {
          "custom": {
            "align": null,
            "filterable": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 16,
        "w": 24,
        "x": 0,
        "y": 8
      },
      "id": 4,
      "options": {
        "colorMode": "value",
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "mean"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "7.3.2",
      "targets": [
        {
          "groupBy": [
            {
              "params": [
                "container_name"
              ],
              "type": "tag"
            }
          ],
          "measurement": "ContainerStat",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "C",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "cpu"
                ],
                "type": "field"
              }
            ]
          ],
          "tags": []
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Container CPU Utilization",
      "type": "stat"
    },
    {
      "datasource": "InfluxDB",
      "fieldConfig": {
        "defaults": {
          "custom": {
            "align": null,
            "filterable": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 15,
        "w": 24,
        "x": 0,
        "y": 24
      },
      "id": 2,
      "interval": "5",
      "options": {
        "colorMode": "value",
        "graphMode": "area",
        "justifyMode": "auto",
        "orientation": "auto",
        "reduceOptions": {
          "calcs": [
            "mean"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "7.3.2",
      "targets": [
        {
          "alias": "Host 1(2 Core,4GB)",
          "groupBy": [
            {
              "params": [
                "$interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "linear"
              ],
              "type": "fill"
            }
          ],
          "measurement": "hostStat",
          "orderByTime": "ASC",
          "policy": "default",
          "query": "SELECT mean(\"cpu\") FROM \"hostStat\" WHERE (\"host_ip\" = '172.17.64.178') AND $timeFilter GROUP BY time($interval) fill(linear)",
          "rawQuery": false,
          "refId": "A",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "cpu"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "host_ip",
              "operator": "=",
              "value": "172.17.64.178"
            }
          ]
        },
        {
          "alias": "Host 2(2 Core,4GB)",
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "linear"
              ],
              "type": "fill"
            }
          ],
          "measurement": "hostStat",
          "orderByTime": "ASC",
          "policy": "default",
          "query": "SELECT mean(\"cpu\") FROM \"hostStat\" WHERE (\"host_ip\" = '172.17.64.201') AND $timeFilter GROUP BY time($__interval) fill(linear)",
          "rawQuery": false,
          "refId": "B",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "cpu"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "host_ip",
              "operator": "=",
              "value": "172.17.64.201"
            }
          ]
        },
        {
          "alias": "Host 3(2 Core,4GB)",
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "linear"
              ],
              "type": "fill"
            }
          ],
          "measurement": "hostStat",
          "orderByTime": "ASC",
          "policy": "default",
          "query": "SELECT mean(\"cpu\") FROM \"hostStat\" WHERE (\"host_ip\" = '172.17.65.149') AND $timeFilter GROUP BY time($__interval) fill(linear)",
          "rawQuery": false,
          "refId": "C",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "cpu"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "host_ip",
              "operator": "=",
              "value": "172.17.65.149"
            }
          ]
        },
        {
          "alias": "Host 4(2 Core,4GB)",
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "linear"
              ],
              "type": "fill"
            }
          ],
          "measurement": "hostStat",
          "orderByTime": "ASC",
          "policy": "default",
          "query": "SELECT mean(\"cpu\") FROM \"hostStat\" WHERE (\"host_ip\" = '172.17.65.205') AND $timeFilter GROUP BY time($__interval) fill(linear)",
          "rawQuery": false,
          "refId": "D",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "cpu"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "host_ip",
              "operator": "=",
              "value": "172.17.65.205"
            }
          ]
        },
        {
          "alias": "Host 5(4 Core,16GB)",
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "linear"
              ],
              "type": "fill"
            }
          ],
          "measurement": "hostStat",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "E",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "cpu"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "host_ip",
              "operator": "=",
              "value": "172.17.65.36"
            }
          ]
        },
        {
          "alias": "Host 6(4 Core,16GB)",
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "linear"
              ],
              "type": "fill"
            }
          ],
          "measurement": "hostStat",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "F",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "cpu"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "host_ip",
              "operator": "=",
              "value": "172.17.66.250"
            }
          ]
        },
        {
          "alias": "Host 7(4 Core,16GB)",
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "linear"
              ],
              "type": "fill"
            }
          ],
          "measurement": "hostStat",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "G",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "cpu"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "host_ip",
              "operator": "=",
              "value": "172.17.66.92"
            }
          ]
        },
        {
          "alias": "Host 8(8 Core,32GB)",
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "linear"
              ],
              "type": "fill"
            }
          ],
          "measurement": "hostStat",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "H",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "cpu"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "host_ip",
              "operator": "=",
              "value": "172.17.67.162"
            }
          ]
        },
        {
          "alias": "Host 9(8 Core,32GB)",
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "linear"
              ],
              "type": "fill"
            }
          ],
          "measurement": "hostStat",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "I",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "cpu"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "host_ip",
              "operator": "=",
              "value": "172.17.67.95"
            }
          ]
        },
        {
          "alias": "Host 7(4 Core,16GB)",
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "linear"
              ],
              "type": "fill"
            }
          ],
          "measurement": "hostStat",
          "orderByTime": "ASC",
          "policy": "default",
          "refId": "J",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "cpu"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": [
            {
              "key": "host_ip",
              "operator": "=",
              "value": "172.17.66.186"
            }
          ]
        }
      ],
      "timeFrom": null,
      "timeShift": null,
      "title": "Host CPU Utilization",
      "type": "stat"
    }
  ],
  "refresh": "5m",
  "schemaVersion": 26,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": []
  },
  "time": {
    "from": "now-30m",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "COSCO",
  "uid": "j4mpEKoMz",
  "version": 3
}