zoukankan      html  css  js  c++  java
  • influxdb

    centos7上

    下载influxdb:

    #wget https://dl.influxdata.com/influxdb/releases/influxdb-0.13.0.x86_64.rpm

    安装:

    #sudo yum localinstall influxdb-0.13.0.x86_64.rpm

    运行:

    #systemctl start influxdb.service

    进入终端

    #influx

    > create database cadvisor ## 创建数据库cadvisor

    > 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)

  • 相关阅读:
    SPF(poj 1523) 割点入门
    从一个例子讲解拷贝构造函数与return
    还是引用
    引用的实质
    const
    三目运算符
    关于C语言链表的学习
    CS2013调试DLL
    fread与fwrite的自我理解
    可见字符与不可见字符
  • 原文地址:https://www.cnblogs.com/guxiaobei/p/8628657.html
Copyright © 2011-2022 走看看