influx+grafana自定义python采集数据和一些坑的总结
作者:大囚长 时间:2022-08-23 14:55:54
先上网卡数据采集脚本,这个基本上是最大的坑,因为一些数据的类型不正确会导致no datapoint的错误,真是令人抓狂,注意其中几个key的值必须是int或者float类型,如果你不慎写成了string,那就麻烦了,其他的tag是string类型。
另外数据采集时间间隔一般就是10秒,这是潜规则,大家都懂。
有图有真相
#! /usr/bin/env python
#-*- coding:utf-8 -*-
import os
import arrow
import time
from time import sleep
from influxdb import InfluxDBClient
client = InfluxDBClient('localhost', 8086, 'root', '', 'telegraf')
while True:
if int(time.time())%10 == 0:
cmd = 'cat /proc/net/dev|grep "ens4"'
rawline = os.popen(cmd).read().strip()
rxbytes = int(rawline.split()[1])
txbytes = int(rawline.split()[9])
rxpks = int(rawline.split()[2])
txpks = int(rawline.split()[10])
now = str(arrow.now()).split('.')[0] + 'Z'
print time.time(), rxbytes,txbytes,rxpks,txpks
json_body = [
{
"measurement": "network",
"tags": {
"host": "gc-u16",
"nio": "ens4"
},
#"time": now,
"fields": {
"rxbytes": rxbytes,
"txbytes": txbytes,
"rxpks": rxpks,
"txpks": txpks
}
}
]
client.write_points(json_body)
sleep(1)
运行脚本,查看influxdb数据,至于后台+独立线程这些东西就见仁见智了
然后配置图形,这个就简单了,只要你数据没写错,基本上grafana都能采集到,这里忽略配置数据源创建dashboard和表格等乱七八糟的,直接上配置的sql图形,大致就是这样吧
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对脚本之家的支持。如果你想了解更多相关内容请查看下面相关链接
来源:https://blog.csdn.net/Jailman/article/details/78913824
标签:python,influx,grafana
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
对django2.0 关联表的必填on_delete参数的含义解析
2023-04-01 22:59:28
如何高效使用Python字典的方法详解
2021-07-26 04:29:03
我是如何从玩Photoshop变成老板的
2008-04-10 11:33:00
![](https://img.aspxhome.com/file/UploadPic/20084/10/2008410114044665s.jpg)
Python+Turtle绘制航海王草帽路飞详解
2023-12-31 18:08:09
![](https://img.aspxhome.com/file/2023/4/87794_0s.gif)
Python匹配中文的正则表达式
2022-03-21 18:05:50
python教程之进程和线程
2021-09-27 02:54:00
![](https://img.aspxhome.com/file/2023/5/83725_0s.png)
MySQL分页优化解析
2008-12-22 14:56:00
JavaScript的9个陷阱及评点
2007-08-28 15:10:00
Python内建类型float源码学习
2022-05-05 17:07:37
![](https://img.aspxhome.com/file/2023/2/90642_0s.png)
javascript 时间脚本收集
2013-07-17 19:52:50
在Python中操作时间之mktime()方法的使用教程
2023-02-07 11:38:58
python检测远程端口是否打开的方法
2022-01-28 01:45:19
Python连接phoenix的方法示例
2023-05-24 06:25:19
python matplotlib 画dataframe的时间序列图实例
2023-05-17 00:12:34
Python 3.8新特征之asyncio REPL
2023-10-08 02:59:58
Python利用PyExecJS库执行JS函数的案例分析
2022-10-26 08:53:19
![](https://img.aspxhome.com/file/2023/4/94154_0s.jpg)
pytorch DistributedDataParallel 多卡训练结果变差的解决方案
2021-09-24 14:31:43
![](https://img.aspxhome.com/file/2023/7/95317_0s.jpg)
浅谈python正则的常用方法 覆盖范围70%以上
2022-05-18 21:01:13
![](https://img.aspxhome.com/file/2023/4/77034_0s.png)
轻松在线制作各种Logo标志
2008-05-26 12:54:00
![](https://img.aspxhome.com/file/UploadPic/20085/26/20085261329597s.jpg)
python基于pygame实现飞机大作战小游戏
2021-04-27 07:59:17
![](https://img.aspxhome.com/file/2023/8/81528_0s.jpg)