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)

  • 相关阅读:
    git命令设置
    spring boot之常用注解(二)
    spring boot之入门配置(一)
    Java核心技术第四章——2.final 和 static
    Java核心技术第四章——1.封装性
    Flutter学习笔记(1)--环境安装
    Android 遍历手机应用,跳转应用市场详情页面
    Android 布局渲染流程与卡顿优化
    weex 数据绑定,动态控制组件的显示内容及样式
    weex常用属性梳理
  • 原文地址:https://www.cnblogs.com/guxiaobei/p/8628657.html
Copyright © 2011-2022 走看看