使用docker方式构建prometheus监控的学习
一、背景:近期学习部署prometheus监控系统,经研究发现prometheus提供docker运行模式。根据我的经验,能够使用docker模式构建系统一定多快好省。
二、环境:
1、centos7.5虚拟机一台,分配4G内存,拟作prometheus服务器,ip:192.168.0.208
2、centos8.0虚拟机一台,分配2G内存,拟作node-exporter客户机,ip:192.168.0.202
3、两台机器都在不同的实体机上,已安装docker-ce软件
三、部署过程
1、服务器(考虑安装prometheus服务器和node-exporter客户端):
(1)pull服务器镜像:
docker pull prom/prometheus
(2)pull客户端镜像:
docker pull prom/node-exporter
(3)配置prometheus.yml
mkdir -p /root/prometheus/prometheus-data #prometheus的工作目录和数据目录
mkdir -p /root/prometheus/node-exporter-data #node-exporter的数据目录
cd /root/prometheus
vi promethe.yml
内容如下:
...
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: 'prometheus-node-exporter'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['192.168.0.208:9100']
- job_name: 'node-dell5460'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['192.168.0.202:9100']
(4)运行prometheus服务
[root@ELK prometheus]# docker run -d -p 9090:9090 -v $PWD/prometheus.yml:/etc/prometheus/prometheus.yml -v $PWD/prometheus-data:/prometheus --hostname ELK.localdomain --name prometheus prom/prometheus
说明:
-p 9090:9090 #服务端口对应到宿主机的相同端口
-v $PWD/prometheus.yml:/etc/prometheus/prometheus.yml #容器内/etc/prometheus/prometheus.yml配置文件挂载到宿主机/root/prometheus目录下。
-v $PWD/prometheus-data:/prometheus #容器内prometheus工作目录挂载到宿主机的/root/prometheus/prometheus-data目录下。
--hostname ELK.localdomain #容器的主机名称(ELK.localdomain是208机的主机名),若不加这个选项,docker会自动把容器的短id号作为容器主机名,在web页面就会发生无法访问的问题。
测试:curl http://localhost:9090/metrics
(5)运行node-exporter
[root@ELK prometheus]# docker run -d --net="host" --pid="host" -v "/root/prometheus/node-exporter-data:/host:ro,rslave" prom/node-exporter --path.rootfs=/host
测试:curl http://192.168.0.208:9100/metrics
2、node-exporter客户机
(1)pull客户端镜像
docker pull prom/node-exporter
(2)运行node-exporter
[root@ELK prometheus]# docker run -d --net="host" --pid="host" -v "/home/node-exporter-data:/host:ro,rslave" prom/node-exporter --path.rootfs=/host
3、访问测试:
在浏览器中输入网址:http://192.168.0.208:9090
四、使用
1、metric的表现形式是键值对{k,v}
2、metrics的页面说明:
#HELP 关于指标的说明
#TYPE 指标的类型,常见gauge,conter等类型
键 值 以空格隔开
3、把metrics页面存在的键拷贝后粘贴到graph页面的搜索栏中即可看到值或图形。
4、在搜索栏中可灵活应用各类函数,如rate、increase、sum、topk、等等
例:
rate(node_cpu_seconds_total{mode="user"}[1m]) #1分钟内用户态cpu时间每秒增加量
rate(node_cpu_seconds_total{mode="system",instance="192.168.0.208:9100",job="prometheus-node-exporter"}[1m])
(1-(sum(increase(node_cpu_seconds_total{mode="idle"}[1m])) by(instance)) / (sum(increase(node_cpu_seconds_total[1m])) by(instance)))*100 #每台机器1分钟内cpu负荷
topk(3,rate(node_network_receive_bytes_total[5m])) #网络5分钟内平均每秒接收字节数前3位的数据展示
5、关于web页面的时间显示问题,默认页面显示的是UTS时区时间,与本地时间相差8小时。这是因为Prometheus 为避免时区混乱,在所有组件中专门使用 Unix Time 和 Utc 进行显示。不支持在配置文件中设置时区,也不能读取本机 /etc/timezone 时区。prometheus在新版web页面已提供本地时区时间显示功能,可点击web页面右上角“Try experimental React UI”切换到新版页面,在新版页面上部勾选“Use local time”即可。
附:更多的函数参考https://prometheus.io/docs/prometheus/latest/querying/functions/
最新文章
- 原生js实现放大镜效果
- Direct3D 10学习笔记(三)——文本输出
- protostuff简单应用
- 简单几何(推公式) UVA 11646 Athletics Track
- AR增强现实特点、关键技术和应用
- KNN算法的简单实现
- 将js对象转为json对象属性加上引号
- C++的转换构造函数、拷贝构造函数、赋值运算符重载
- JS类型、值和变量 笔记
- Node.js学习(12)----Web应用开发
- I/O重定向与管道
- c#分部类型详解
- Activity not started, its current task has been brought to the front的解决办法
- android-tools adb for ARM Linux
- ABP .Net Core 日志组件集成使用NLog
- mysql自增长主键,删除数据后,将主键顺序重新排序
- gdb remote 使用
- Docker概念学习系列之详谈Docker 的核心组件与概念(5)
- js 图片压缩上传(纯js的质量压缩,非长宽压缩)
- gdb调试:
热门文章
- PUBG 1V3 线段树扫描线
- Uncaught DOMException: Failed to set the &#39;value&#39; property on &#39;HTMLInputElement&#39;: This input element accepts a filename, which may only be programmatically set to the empty string.
- dbcp数据源连接池
- STL下<;algorithm>;下的sort函数
- 【BIM】BIMFACE中实现电梯实时动效
- Day_11【集合】扩展案例3_打印最高分的学员姓名、年龄、成绩,打印10个学生的总成绩和平均分,打印不及格的学员信息及数量
- 【Hadoop离线基础总结】Yarn集群的资源调度
- 风扇转速通过FPGA采样
- [hdu5521 Meeting]最短路
- [hdu4631 Sad Love Story]最近点对,枚举