centos7上數據庫
下載influxdb:json
#wget https://dl.influxdata.com/influxdb/releases/influxdb-0.13.0.x86_64.rpmcentos
安裝:dom
#sudo yum localinstall influxdb-0.13.0.x86_64.rpmcentos7
運行:orm
#systemctl start influxdb.serviceserver
進入終端flux
#influx內存
> create database cadvisor ## 建立數據庫cadvisorrem
> show databases
name: databases name
---- _internal cadvisor
> CREATE USER testuser WITH PASSWORD 'testpwd' ## 建立用戶和設置密碼
> GRANT ALL PRIVILEGES ON cadvisor TO testuser ## 受權數據庫給指定用戶
> CREATE RETENTION POLICY "cadvisor_retention" ON "cadvisor" DURATION 30d REPLICATION 1 DEFAULT## 建立默認的數據保留策略,設置保存時間30天,副本爲1
-----------------------------------------------
import psutil
import os
frominfluxdb import InfluxDBClient
import time,math,random
pidp1=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, 'testuser', 'testpwd', 'xxyyxx')
client.create_database('xxyyxx')
client.write_points(json_body)
#result = client.query('select value from cpu_load_short;')
#print("Result: {0}".format(result))
time.sleep(2)