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)

  • 相关阅读:
    [BOST] 博赞有机的学习技巧
    [BOST] 你的大脑比你想象的更优秀
    Markdown学习笔记
    nodejs原生态模块,写个聊天室
    【2】自定义WindowsForm分页控件使用【共两篇】
    【1】自定义WindowsForm分页控件使用【共两篇】
    《Log4net写出适合自己的日志类》第三篇【终】【怎样让它适合你自己需求】
    《Log4net写出适合自己的日志类》第二篇【没有理论的实践是盲目】
    《Log4net写出适合自己的日志类》第一篇【上来就是干,先实践后理论】
    记忆留住深刻过往,博客写出平淡事迹【博客首篇】
  • 原文地址:https://www.cnblogs.com/guxiaobei/p/8628657.html
Copyright © 2011-2022 走看看