grafana+influxdb+python实现监控cpu、内存
来源:互联网 发布:c语言什么时候用void 编辑:程序博客网 时间:2024/06/02 22:07
grafana和influxdb下载rpm然后yum install *.rpm
influxdb有个web管理界面,不会操作的可以通过这个界面管理数据库,这个web的端口是8083
influxdb:
create database grafana
CREATE USER “grafana” WITH PASSWORD ‘grafana’
grafana:
数据源这部分的配置成功就可以产生图像
数据库地址:http://ip:8086(这个是influxdb的后端端口)
点击panel Title有个Edit可以为这个Panel Title配置一个数据源
数据源可以配置tags和fields,field配置出来显示的就是图形(注意:有些数据要选择合适selectors,不然不显示)
alias是上面线条的名字
python:
安装psutil和influxdb的模块
yum install python-pip -y
yum install gcc python-devel zlib-devel openssl-devel -y#这些安装完了pip install不会报错
pip install psutil
pip install influxdb
python获取信息的脚本
#!/usr/bin/python# -*- coding: UTF-8 -*-import threadimport timeimport socketimport psutilfrom influxdb import InfluxDBClientclient=InfluxDBClient('localhost',8086,'root',',','grafana')#获取本机IPdef get_ip(): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: # doesn't even have to be reachable s.connect(('10.255.255.255', 0)) IP = s.getsockname()[0] except: IP = '127.0.0.1' finally: s.close() return IPip = get_ip()#获取cpu信息def get_cpu(sec): while True: time.sleep(sec) info=psutil.cpu_percent(0) text=[ { "measurement":"cpu_info", "tags":{ "host":ip }, "fields":{ "percent":info } } ] client.write_points(text)def get_memory(sec): while True: time.sleep(sec) info=psutil.virtual_memory() text=[ { "measurement":"memory_info", "tags":{ "host":ip }, "fields":{ "mem_percent":info.percent, "mem_used":info.used, "mem_free":info.free, } } ] client.write_points(text)def get_disk(sec): while True: time.sleep(sec) info=psutil.disk_usage('/') text=[ { "measurement":"disk_info", "tags":{ "host":ip }, "fields":{ "disk_used":info.used, "disk_free":info.free, "disk_percent":info.percent, } } ] client.write_points(text)def get_network(sec): while True: time.sleep(sec) info = psutil.net_io_counters(pernic=True)['ens192'] text=[ { "measurement":"network_info", "tags":{ "host":ip }, "fields":{ "bytes_sent":info.bytes_sent, "bytes_recv":info.bytes_recv, } } ] client.write_points(text) try: thread.start_new_thread( get_cpu,(1,))except: print "ERROR:cpu unable to start thread"try: thread.start_new_thread( get_memory, (1,))except: print "ERROR:mem_ory unable to start thread"try: thread.start_new_thread( get_disk, (1,))except: print "ERROR:disk unable to start thread"try: thread.start_new_thread( get_network,(1,))except: print "ERROR:net unable to start thread"while 1: pass
阅读全文
0 0
- grafana+influxdb+python实现监控cpu、内存
- grafana+influxdb+telegraf监控服务器cpu,内存和硬盘
- grafana+influxdb+telegraf监控服务器cpu,内存和硬盘
- Cadvisor-InfluxDB-Grafana监控实现
- MXtrans + InfluxDB + Grafana实现Kafka性能指标监控
- 监控 Grafana + collectd + InfluxDB
- Kafka+Influxdb+Grafana实现灵活集群服务监控
- ubuntu influxDb + grafana 监控系统
- 开源grafana可视化监控+influxdb
- 利用Metrics+influxdb+grafana构建监控平台
- 使用 Collectd + InfluxDB + Grafana 监控主机
- Influxdb+collectd+grafana搭建现代化监控系统
- grafana 配合influxdb监控的Sql例子
- collectd, influxdb, grafana协同作战,不一样的监控
- 利用Metrics+influxdb+grafana构建监控平台
- 时序数据监控系统Influxdb+Grafana+Fluented
- Docker 集群监控平台---cAdvisor-InfluxDB-Grafana
- 使用InfluxDB+cAdvisor+Grafana配置Docker监控
- Linux Centos7下安装GitLab最详细教程
- mysql中文乱码的解决方法
- MVC模式和三层架构之间的关系
- binbinyang-- Retrofit 2.0的简单使用(入门篇)-GET请求
- JedisCluster源码解读:集群初始化、slot(槽)的分配、值的存取
- grafana+influxdb+python实现监控cpu、内存
- QT HTTP下载网络文件
- 【二叉树】DFS计算路径和,保存路径【113. Path Sum II】【112. Path Sum】
- 记录linux 命令
- MultiValueMap的序列化以及反序列化
- spark架构
- 【编程初学者】创建自己的开源项目5-在主分支上创建新分支(myeclipse+git)
- 基于Hadoop的好友推荐系统项目综述
- 专注服务,而非容器