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

  • 相关阅读:
    Wireshark抓包工具使用教程以及常用抓包规则
    linux自带抓包工具tcpdump使用说明
    利用mmap /dev/mem 读写Linux内存
    使用mii-tool设置网卡速率
    LINUX命令之ETHTOOL用法详解
    ethtool 在 Linux 中的实现框架和应用
    IDEA 上传更新的代码到码云上
    如何选择开源许可证
    IDEA 安装完码云插件,运行报“Cannot run program "xxx":CreateProcess error=2,系统找不到指定的文件”
    beans.factory.BeanCreationException beans.factory.annotation.Autowired(required=true)
  • 原文地址:https://www.cnblogs.com/guxiaobei/p/8628657.html
Copyright © 2020-2023  润新知