1 Star 0 Fork 0

wangsong/Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CpuToInfluxdb.py 952 Bytes
一键复制 编辑 原始数据 按行查看 历史
injetlee 提交于 2016-06-24 09:36 . modify influxdb
import psutil
import os
from influxdb import InfluxDBClient
import time,math,random
#获取当前运行的pid
p1=psutil.Process(os.getpid())
from influxdb import InfluxDBClient
import time,math,random
while True:
a = psutil.virtual_memory().percent #内存占用率
b = psutil.cpu_percent(interval=1.0) #cpu占用率
json_body = [
{
"measurement": "cpu_load_short",
"tags": {
"host": "server01",
"region": "us-west"
},
#"time": "2009-11-10T23:00:00Z",
"fields": {
"cpu": b,
"mem": a
}
}
]
client = InfluxDBClient('localhost', 8086, 'root', 'root', 'xxyyxx')
client.create_database('xxyyxx',if_not_exists=False)
client.write_points(json_body)
#result = client.query('select value from cpu_load_short;')
#print("Result: {0}".format(result))
time.sleep(2)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wanghuan1989/Python.git
git@gitee.com:wanghuan1989/Python.git
wanghuan1989
Python
Python
master

搜索帮助