FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Python/CpuToInfluxdb.py at master · JavaCoderFan/Python · GitHub
JavaCoderFan
Python
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Python
/
CpuToInfluxdb.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (31 loc) · 952 Bytes
Breadcrumbs
Python
/
CpuToInfluxdb.py
Copy path
File metadata and controls
37 lines (31 loc) · 952 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
)
Back
|
FazBrowse Home
|
New Git URL