InfluxDB

docker run -d -p 8086:8086 --restart=always --name=influxdb -v /data-0/docker-influxdb:/var/lib/influxdb influxdb

Grafana

docker run -d --restart=always --name=grafana -p 3000:3000 -v /data-0/docker-grafana:/var/lib/grafana grafana/grafana

InfluxDB常用命令

-- 查看所有库
show databases
curl -i 'https://influxdb.cdeyun.com/query?pretty=true' -d 'q=SHOW DATABASES'

-- 使用库
use xxx

-- 查看最后10条数据
select * from /.*/ limit 10

-- 插入数据
insert table,a=1,b=2 value=3 [timestamp]

crontab shell

#!/bin/sh
# qps: 0/s | 1/5s | 19/m | 99/5m | 1369/h
#      2     4       6       8      10

curl -s 'http://192.168.1.155:8086/query' -d 'q=create database qps' >/dev/null 2>&1 || exit 1

ss='static staticsg staticfr'
for i in $ss;
do
    r=`curl -s "https://${i}.cdeyun.cn/qps"|grep qps`;echo $r|sed -e 's/qps: \([0-9]*\)\/s | \([0-9]*\)\/5s | \([0-9]*\)\/m | \([0-9]*\)\/5m | \([0-9]*\)\/h/s1=\1,s5=\2,m1=\3,m5=\4,h1=\5/g'|xargs -I {} curl -s 'http://192.168.1.155:8086/write?db=qps' -d "qps,area=${i} {}" > /dev/null 2>&1
done

Grafana json

{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "description": "每分钟采集的数据",
  "editable": true,
  "gnetId": null,
  "graphTooltip": 0,
  "hideControls": false,
  "id": 1,
  "links": [],
  "refresh": false,
  "rows": [
    {
      "collapse": false,
      "height": 239,
      "panels": [
        {
          "aliasColors": {},
          "bars": false,
          "dashLength": 10,
          "dashes": false,
          "datasource": null,
          "fill": 1,
          "id": 1,
          "legend": {
            "avg": false,
            "current": false,
            "max": false,
            "min": false,
            "show": true,
            "total": false,
            "values": false
          },
          "lines": true,
          "linewidth": 1,
          "links": [],
          "minSpan": null,
          "nullPointMode": "null",
          "percentage": false,
          "pointradius": 5,
          "points": false,
          "renderer": "flot",
          "seriesOverrides": [],
          "spaceLength": 10,
          "span": 6,
          "stack": false,
          "steppedLine": false,
          "targets": [
            {
              "alias": "US",
              "dsType": "influxdb",
              "groupBy": [],
              "hide": false,
              "measurement": "qps",
              "orderByTime": "ASC",
              "policy": "default",
              "refId": "A",
              "resultFormat": "time_series",
              "select": [
                [
                  {
                    "params": [
                      "value"
                    ],
                    "type": "field"
                  }
                ]
              ],
              "tags": [
                {
                  "key": "area",
                  "operator": "=",
                  "value": "static"
                },
                {
                  "condition": "AND",
                  "key": "type",
                  "operator": "=",
                  "value": "s1"
                }
              ]
            },
            {
              "alias": "SG",
              "dsType": "influxdb",
              "groupBy": [],
              "hide": false,
              "measurement": "qps",
              "orderByTime": "ASC",
              "policy": "default",
              "refId": "B",
              "resultFormat": "time_series",
              "select": [
                [
                  {
                    "params": [
                      "value"
                    ],
                    "type": "field"
                  }
                ]
              ],
              "tags": [
                {
                  "key": "area",
                  "operator": "=",
                  "value": "staticsg"
                },
                {
                  "condition": "AND",
                  "key": "type",
                  "operator": "=",
                  "value": "s1"
                }
              ]
            },
            {
              "alias": "FR",
              "dsType": "influxdb",
              "groupBy": [],
              "hide": false,
              "measurement": "qps",
              "orderByTime": "ASC",
              "policy": "default",
              "refId": "C",
              "resultFormat": "time_series",
              "select": [
                [
                  {
                    "params": [
                      "value"
                    ],
                    "type": "field"
                  }
                ]
              ],
              "tags": [
                {
                  "key": "area",
                  "operator": "=",
                  "value": "staticfr"
                },
                {
                  "condition": "AND",
                  "key": "type",
                  "operator": "=",
                  "value": "s1"
                }
              ]
            }
          ],
          "thresholds": [],
          "timeFrom": null,
          "timeShift": null,
          "title": "1 second",
          "tooltip": {
            "shared": true,
            "sort": 0,
            "value_type": "individual"
          },
          "transparent": false,
          "type": "graph",
          "xaxis": {
            "buckets": null,
            "mode": "time",
            "name": null,
            "show": true,
            "values": []
          },
          "yaxes": [
            {
              "format": "short",
              "label": "qps",
              "logBase": 1,
              "max": null,
              "min": "0",
              "show": true
            },
            {
              "format": "short",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": true
            }
          ]
        },
        {
          "aliasColors": {},
          "bars": false,
          "dashLength": 10,
          "dashes": false,
          "datasource": null,
          "fill": 1,
          "id": 2,
          "legend": {
            "avg": false,
            "current": false,
            "max": false,
            "min": false,
            "show": true,
            "total": false,
            "values": false
          },
          "lines": true,
          "linewidth": 1,
          "links": [],
          "minSpan": null,
          "nullPointMode": "null",
          "percentage": false,
          "pointradius": 5,
          "points": false,
          "renderer": "flot",
          "seriesOverrides": [],
          "spaceLength": 10,
          "span": 6,
          "stack": false,
          "steppedLine": false,
          "targets": [
            {
              "alias": "US",
              "dsType": "influxdb",
              "groupBy": [],
              "hide": false,
              "measurement": "qps",
              "orderByTime": "ASC",
              "policy": "default",
              "refId": "A",
              "resultFormat": "time_series",
              "select": [
                [
                  {
                    "params": [
                      "value"
                    ],
                    "type": "field"
                  }
                ]
              ],
              "tags": [
                {
                  "key": "area",
                  "operator": "=",
                  "value": "static"
                },
                {
                  "condition": "AND",
                  "key": "type",
                  "operator": "=",
                  "value": "s5"
                }
              ]
            },
            {
              "alias": "SG",
              "dsType": "influxdb",
              "groupBy": [],
              "hide": false,
              "measurement": "qps",
              "orderByTime": "ASC",
              "policy": "default",
              "refId": "B",
              "resultFormat": "time_series",
              "select": [
                [
                  {
                    "params": [
                      "value"
                    ],
                    "type": "field"
                  }
                ]
              ],
              "tags": [
                {
                  "key": "area",
                  "operator": "=",
                  "value": "staticsg"
                },
                {
                  "condition": "AND",
                  "key": "type",
                  "operator": "=",
                  "value": "s5"
                }
              ]
            },
            {
              "alias": "FR",
              "dsType": "influxdb",
              "groupBy": [],
              "hide": false,
              "measurement": "qps",
              "orderByTime": "ASC",
              "policy": "default",
              "refId": "C",
              "resultFormat": "time_series",
              "select": [
                [
                  {
                    "params": [
                      "value"
                    ],
                    "type": "field"
                  }
                ]
              ],
              "tags": [
                {
                  "key": "area",
                  "operator": "=",
                  "value": "staticfr"
                },
                {
                  "condition": "AND",
                  "key": "type",
                  "operator": "=",
                  "value": "s5"
                }
              ]
            }
          ],
          "thresholds": [],
          "timeFrom": null,
          "timeShift": null,
          "title": "5 second",
          "tooltip": {
            "shared": true,
            "sort": 0,
            "value_type": "individual"
          },
          "transparent": false,
          "type": "graph",
          "xaxis": {
            "buckets": null,
            "mode": "time",
            "name": null,
            "show": true,
            "values": []
          },
          "yaxes": [
            {
              "format": "short",
              "label": "qps",
              "logBase": 1,
              "max": null,
              "min": "0",
              "show": true
            },
            {
              "format": "short",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": true
            }
          ]
        }
      ],
      "repeat": null,
      "repeatIteration": null,
      "repeatRowId": null,
      "showTitle": false,
      "title": "Dashboard Row",
      "titleSize": "h6"
    },
    {
      "collapse": false,
      "height": 216,
      "panels": [
        {
          "aliasColors": {},
          "bars": false,
          "dashLength": 10,
          "dashes": false,
          "datasource": null,
          "fill": 1,
          "id": 3,
          "legend": {
            "avg": false,
            "current": false,
            "max": false,
            "min": false,
            "show": true,
            "total": false,
            "values": false
          },
          "lines": true,
          "linewidth": 1,
          "links": [],
          "minSpan": 6,
          "nullPointMode": "null",
          "percentage": false,
          "pointradius": 5,
          "points": false,
          "renderer": "flot",
          "seriesOverrides": [],
          "spaceLength": 10,
          "span": 6,
          "stack": false,
          "steppedLine": false,
          "targets": [
            {
              "alias": "US",
              "dsType": "influxdb",
              "groupBy": [],
              "hide": false,
              "measurement": "qps",
              "orderByTime": "ASC",
              "policy": "default",
              "refId": "A",
              "resultFormat": "time_series",
              "select": [
                [
                  {
                    "params": [
                      "value"
                    ],
                    "type": "field"
                  }
                ]
              ],
              "tags": [
                {
                  "key": "area",
                  "operator": "=",
                  "value": "static"
                },
                {
                  "condition": "AND",
                  "key": "type",
                  "operator": "=",
                  "value": "m1"
                }
              ]
            },
            {
              "alias": "SG",
              "dsType": "influxdb",
              "groupBy": [],
              "hide": false,
              "measurement": "qps",
              "orderByTime": "ASC",
              "policy": "default",
              "refId": "B",
              "resultFormat": "time_series",
              "select": [
                [
                  {
                    "params": [
                      "value"
                    ],
                    "type": "field"
                  }
                ]
              ],
              "tags": [
                {
                  "key": "area",
                  "operator": "=",
                  "value": "staticsg"
                },
                {
                  "condition": "AND",
                  "key": "type",
                  "operator": "=",
                  "value": "m1"
                }
              ]
            },
            {
              "alias": "FR",
              "dsType": "influxdb",
              "groupBy": [],
              "hide": false,
              "measurement": "qps",
              "orderByTime": "ASC",
              "policy": "default",
              "refId": "C",
              "resultFormat": "time_series",
              "select": [
                [
                  {
                    "params": [
                      "value"
                    ],
                    "type": "field"
                  }
                ]
              ],
              "tags": [
                {
                  "key": "area",
                  "operator": "=",
                  "value": "staticfr"
                },
                {
                  "condition": "AND",
                  "key": "type",
                  "operator": "=",
                  "value": "m1"
                }
              ]
            }
          ],
          "thresholds": [],
          "timeFrom": null,
          "timeShift": null,
          "title": "1 mintue",
          "tooltip": {
            "shared": true,
            "sort": 0,
            "value_type": "individual"
          },
          "transparent": false,
          "type": "graph",
          "xaxis": {
            "buckets": null,
            "mode": "time",
            "name": null,
            "show": true,
            "values": []
          },
          "yaxes": [
            {
              "format": "short",
              "label": "qps",
              "logBase": 1,
              "max": null,
              "min": "0",
              "show": true
            },
            {
              "format": "short",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": true
            }
          ]
        },
        {
          "aliasColors": {},
          "bars": false,
          "dashLength": 10,
          "dashes": false,
          "datasource": null,
          "fill": 1,
          "id": 4,
          "legend": {
            "avg": false,
            "current": false,
            "max": false,
            "min": false,
            "show": true,
            "total": false,
            "values": false
          },
          "lines": true,
          "linewidth": 1,
          "links": [],
          "minSpan": 6,
          "nullPointMode": "null",
          "percentage": false,
          "pointradius": 5,
          "points": false,
          "renderer": "flot",
          "seriesOverrides": [],
          "spaceLength": 10,
          "span": 6,
          "stack": false,
          "steppedLine": false,
          "targets": [
            {
              "alias": "US",
              "dsType": "influxdb",
              "groupBy": [],
              "hide": false,
              "measurement": "qps",
              "orderByTime": "ASC",
              "policy": "default",
              "refId": "A",
              "resultFormat": "time_series",
              "select": [
                [
                  {
                    "params": [
                      "value"
                    ],
                    "type": "field"
                  }
                ]
              ],
              "tags": [
                {
                  "key": "area",
                  "operator": "=",
                  "value": "static"
                },
                {
                  "condition": "AND",
                  "key": "type",
                  "operator": "=",
                  "value": "m5"
                }
              ]
            },
            {
              "alias": "SG",
              "dsType": "influxdb",
              "groupBy": [],
              "hide": false,
              "measurement": "qps",
              "orderByTime": "ASC",
              "policy": "default",
              "refId": "B",
              "resultFormat": "time_series",
              "select": [
                [
                  {
                    "params": [
                      "value"
                    ],
                    "type": "field"
                  }
                ]
              ],
              "tags": [
                {
                  "key": "area",
                  "operator": "=",
                  "value": "staticsg"
                },
                {
                  "condition": "AND",
                  "key": "type",
                  "operator": "=",
                  "value": "m5"
                }
              ]
            },
            {
              "alias": "FR",
              "dsType": "influxdb",
              "groupBy": [],
              "hide": false,
              "measurement": "qps",
              "orderByTime": "ASC",
              "policy": "default",
              "refId": "C",
              "resultFormat": "time_series",
              "select": [
                [
                  {
                    "params": [
                      "value"
                    ],
                    "type": "field"
                  }
                ]
              ],
              "tags": [
                {
                  "key": "area",
                  "operator": "=",
                  "value": "staticfr"
                },
                {
                  "condition": "AND",
                  "key": "type",
                  "operator": "=",
                  "value": "m5"
                }
              ]
            }
          ],
          "thresholds": [],
          "timeFrom": null,
          "timeShift": null,
          "title": "5 mintue",
          "tooltip": {
            "shared": true,
            "sort": 0,
            "value_type": "individual"
          },
          "transparent": false,
          "type": "graph",
          "xaxis": {
            "buckets": null,
            "mode": "time",
            "name": null,
            "show": true,
            "values": []
          },
          "yaxes": [
            {
              "format": "short",
              "label": "qps",
              "logBase": 1,
              "max": null,
              "min": "0",
              "show": true
            },
            {
              "format": "short",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": true
            }
          ]
        }
      ],
      "repeat": null,
      "repeatIteration": null,
      "repeatRowId": null,
      "showTitle": false,
      "title": "Dashboard Row",
      "titleSize": "h6"
    },
    {
      "collapse": false,
      "height": 250,
      "panels": [
        {
          "aliasColors": {},
          "bars": false,
          "dashLength": 10,
          "dashes": false,
          "datasource": null,
          "fill": 1,
          "id": 5,
          "legend": {
            "avg": false,
            "current": false,
            "max": false,
            "min": false,
            "show": true,
            "total": false,
            "values": false
          },
          "lines": true,
          "linewidth": 1,
          "links": [],
          "minSpan": 6,
          "nullPointMode": "null",
          "percentage": false,
          "pointradius": 5,
          "points": false,
          "renderer": "flot",
          "seriesOverrides": [],
          "spaceLength": 10,
          "span": 12,
          "stack": false,
          "steppedLine": false,
          "targets": [
            {
              "alias": "US",
              "dsType": "influxdb",
              "groupBy": [],
              "hide": false,
              "measurement": "qps",
              "orderByTime": "ASC",
              "policy": "default",
              "refId": "A",
              "resultFormat": "time_series",
              "select": [
                [
                  {
                    "params": [
                      "value"
                    ],
                    "type": "field"
                  }
                ]
              ],
              "tags": [
                {
                  "key": "area",
                  "operator": "=",
                  "value": "static"
                },
                {
                  "condition": "AND",
                  "key": "type",
                  "operator": "=",
                  "value": "h1"
                }
              ]
            },
            {
              "alias": "SG",
              "dsType": "influxdb",
              "groupBy": [],
              "hide": false,
              "measurement": "qps",
              "orderByTime": "ASC",
              "policy": "default",
              "refId": "B",
              "resultFormat": "time_series",
              "select": [
                [
                  {
                    "params": [
                      "value"
                    ],
                    "type": "field"
                  }
                ]
              ],
              "tags": [
                {
                  "key": "area",
                  "operator": "=",
                  "value": "staticsg"
                },
                {
                  "condition": "AND",
                  "key": "type",
                  "operator": "=",
                  "value": "h1"
                }
              ]
            },
            {
              "alias": "FR",
              "dsType": "influxdb",
              "groupBy": [],
              "hide": false,
              "measurement": "qps",
              "orderByTime": "ASC",
              "policy": "default",
              "refId": "C",
              "resultFormat": "time_series",
              "select": [
                [
                  {
                    "params": [
                      "value"
                    ],
                    "type": "field"
                  }
                ]
              ],
              "tags": [
                {
                  "key": "area",
                  "operator": "=",
                  "value": "staticfr"
                },
                {
                  "condition": "AND",
                  "key": "type",
                  "operator": "=",
                  "value": "h1"
                }
              ]
            }
          ],
          "thresholds": [],
          "timeFrom": null,
          "timeShift": null,
          "title": "1 hour",
          "tooltip": {
            "shared": true,
            "sort": 0,
            "value_type": "individual"
          },
          "transparent": false,
          "type": "graph",
          "xaxis": {
            "buckets": null,
            "mode": "time",
            "name": null,
            "show": true,
            "values": []
          },
          "yaxes": [
            {
              "format": "short",
              "label": "qps",
              "logBase": 1,
              "max": null,
              "min": "0",
              "show": true
            },
            {
              "format": "short",
              "label": null,
              "logBase": 1,
              "max": null,
              "min": null,
              "show": true
            }
          ]
        }
      ],
      "repeat": null,
      "repeatIteration": null,
      "repeatRowId": null,
      "showTitle": false,
      "title": "Dashboard Row",
      "titleSize": "h6"
    }
  ],
  "schemaVersion": 14,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": []
  },
  "time": {
    "from": "now-1h",
    "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": "browser",
  "title": "qps",
  "version": 10
}

获取本机CPU/MEM信息

curl -s 'http://192.168.1.155:8086/query' -d 'q=create database device' >/dev/null 2>&1 || exit 1
# CPU
cpuM1=$(sar -u 1 5|grep 'Average'|awk -F ' ' '{print $3 "+" $5}'|bc)
# MEM total
MemTotal=$(free|grep 'Mem'|awk -F ' ' '{print $2}')
# MEM free
MemUsed=$(free|grep 'Mem'|awk -F ' ' '{print $2 "-" $4 "-" $6 "-" $7}'|bc)
# save
curl -s 'http://192.168.1.155:8086/write?db=device' -d "192.168.1.155 cpum1=${cpuM1},memTotal=${MemTotal},memUsed=${MemUsed}" > /dev/null 2>&1