欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

Linux下安装grafana并且添加influxdb监控的方法

程序员文章站 2022-09-10 18:38:29
安装grafana,官网提供了ubuntu的安装包,直接进行安装 wget https://dl.grafana.com/oss/release/grafana_6.5.1_...

安装grafana,官网提供了ubuntu的安装包,直接进行安装

wget https://dl.grafana.com/oss/release/grafana_6.5.1_amd64.deb 
dpkg -i grafana_6.5.1_amd64.deb 
update-rc.d grafana-server defaults 95 10
service grafana-server start

使用influxdb的http api添加数据和查询数据

添加数据

while true;do curl -i -xpost 'http://127.0.0.1:8086/write?db=sinamail' --data-binary "webface,ip=10.2.2.1,httpstatus=404 prototype=\"get /favicon.ico http/1.1\" `date +%s`000000000";done

查询数据

curl -get 'http://127.0.0.1:8086/query?pretty=true' --data-urlencode "db=sinamail" --data-urlencode "q=select * from webface where httpstatus='404'"

添加grafana的influxdb数据源

Linux下安装grafana并且添加influxdb监控的方法

Linux下安装grafana并且添加influxdb监控的方法

查询表数据绘制出折线图

Linux下安装grafana并且添加influxdb监控的方法

{
 "xhrstatus": "complete",
 "request": {
  "method": "get",
  "url": "api/datasources/proxy/1/query",
  "params": {
   "db": "sinamail",
   "q": "select count(\"prototype\") from \"webface\" where (\"httpstatus\" = '404') and time >= now() - 15m group by time(1m) fill(null)",
   "epoch": "ms"
  },
  "data": null,
  "precision": "ms"
 },
 "response": {
  "results": [
   {
    "statement_id": 0,
    "series": [
     {
      "name": "webface",
      "columns": [
       "time",
       "count"
      ],
      "values": [
       [
        1575211320000,
        0
       ],
       [
        1575211380000,
        0
       ],
       [
        1575211440000,
        0
       ],
       [
        1575211500000,
        0
       ],
       [
        1575211560000,
        1
       ],
       [
        1575211620000,
        0
       ],
       [
        1575211680000,
        4
       ],
       [
        1575211740000,
        8
       ],
       [
        1575211800000,
        0
       ],
       [
        1575211860000,
        0
       ],
       [
        1575211920000,
        41
       ],
       [
        1575211980000,
        8
       ],
       [
        1575212040000,
        0
       ],
       [
        1575212100000,
        0
       ],
       [
        1575212160000,
        0
       ],
       [
        1575212220000,
        0
       ]
      ]
     }
    ]
   }
  ]
 }
}

总结

以上所述是小编给大家介绍的linux下安装grafana并且添加influxdb监控的方法,希望对大家有所帮助