python获取播测数据通过grafana展示(二)
2018-06-08 本文已影响7人
小王同学123321
上一节说到"http_ip_address"表的建立,这个建表的过程使用的是python shell直接执行的。我只列出其中的一条,因为使用的是python shell,所以有多少ip就需要建立多少次:
conn_db = InfluxDBClient('数据库ip','8086','数据库用户','数据库用户密码','存储数据数据库') #连接上grafana数据库
json_body = [{"measurement": "http_ip_address","tags":{"address":节点名称,"http_ip":上一个表中获取到的所有ip地址},"fields":{"provinces":" "}}] #provinces字段可以定义为空
conn_db.write_points(json_body) #将数据写入数据库
数据库里面的表建好,并且获取数据已经存入数据库,这个项目的工作已经完成一半了。
安装最新稳定版grafana:
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.1.3-1.x86_64.rpm
yum localinstall grafana-5.1.3-1.x86_64.rpm
grafana-cli plugins list-remote
service grafana-server restart
grafana中配置对接influxdb数据


图2中注意URL的填写,http://数据库ip地址:8086
最下面的数据填写你创建的数据库名称
User和Password分别填写为数据库创建的用户名和密码
创建好数据来源之后就创建dashboard

下一节重点讲解dashboard中下拉列表的实现