Skip to content

Commit 0ab705f

Browse files
committed
modify influxdb
1 parent dab8715 commit 0ab705f

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

CpuToInfluxdb.py

+3-19
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,13 @@
77
#获取当前运行的pid
88
p1=psutil.Process(os.getpid())
99

10-
#打印本机的内存信息
11-
#print ('直接打印内存占用: '+(str)(psutil.virtual_memory))
12-
13-
#打印内存的占用率
14-
15-
16-
17-
18-
1910

2011
from influxdb import InfluxDBClient
2112
import time,math,random
2213
while True:
23-
# for i in range(360):
24-
25-
# sin = round(random.random()*1000,2)
26-
# print (sin)
27-
a = psutil.virtual_memory().percent
14+
a = psutil.virtual_memory().percent #内存占用率
2815

29-
#本机cpu的总占用率
30-
b = psutil.cpu_percent(interval=1.0)
16+
b = psutil.cpu_percent(interval=1.0) #cpu占用率
3117

3218
json_body = [
3319
{
@@ -44,9 +30,7 @@
4430
}
4531
]
4632
client = InfluxDBClient('localhost', 8086, 'root', 'root', 'xxyyxx')
47-
print('aaaaaa')
48-
#client.create_database('xxyyxx',if_not_exists=False)
49-
print('bbbbb')
33+
client.create_database('xxyyxx',if_not_exists=False)
5034
client.write_points(json_body)
5135
#result = client.query('select value from cpu_load_short;')
5236
#print("Result: {0}".format(result))

0 commit comments

Comments
 (0)