生产实操演示-Prometheus静态监控linux主机
测试环境说明
准备用来测试的服务器,信息如下:
| 作用 | ip | 端口 |
|---|---|---|
| Prometheus服务端 数据存储、数据采集、提供webUI | 10.0.0.51 | 9090 |
| grafana | 10.0.0.51 | 3000 |
| Prometheus客户端 被监控主机 | 10.0.0.61 | node61 |
| Prometheus客户端 被监控主机 | 10.0.0.62 | node62 |
前置环境说明:
1.已经安装了prometheus-server
推荐阅读:
二进制部署Prometheus-server及自动化部署讲解(2)-CSDN博客
2.已经安装了grafana
推荐阅读:
1.构建可视化监控系统:Grafana 安装配置、官方 Dashboard 应用与插件扩展-CSDN博客
3.grafana已经导入了prometheus数据源
推荐阅读:
1.构建可视化监控系统:Grafana 安装配置、官方 Dashboard 应用与插件扩展-CSDN博客
一、客户端采集数据
1.被监控客户端安装node-exporter
安装步骤,我已经写在了之前的博客,同时安装步骤已经写成了自动化项目脚本,推荐阅读:
博客:
二进制部署node-exporter及自动化部署讲解(3)-CSDN博客
我的项目地址:
https://gitee.com/jasonchen_code/prometheus_node-exporter/
发行版地址:
2.验证是否可以采集数据
方法一、curl
[root@prometheus-server51 ~]# curl -s http://10.0.0.61:9100/metrics | wc -l
1075
[root@prometheus-server51 ~]#
方法二、浏览器验证
http://ip地址:9100/metrics
二、安装Prometheus-server服务端
1.服务端安装Prometheus-server
安装步骤,我已经写成脚本和博客,推荐阅读:
博客:
二进制部署Prometheus-server及自动化部署讲解(2)-CSDN博客
项目地址:
https://gitee.com/jasonchen_code/prometheus
发行版下载地址:
https://gitee.com/jasonchen_code/prometheus/repository/archive/v2.53.2.tar.gz
三、配置job采集任务
配置文件路径:
$INSTALLDIR/prometheus-2.53.2.linux-amd64/prometheus.yml
1.编辑配置文件
新增一个job任务:
采集客户端的node-exporter的http接口
[root@prometheus-server51 manifests]# vim /prometheus/softwares/prometheus-2.53.2.linux-amd64/prometheus.yml
...
32 #node---exporter
33 - job_name: "node-exporter"
34
35 # metrics_path defaults to '/metrics'
36 # scheme defaults to 'http'.
37
38 static_configs:
39 - targets:
40 - 10.0.0.61:9100
41 - 10.0.0.62:9100
...
2.热加载Prometheus配置
热加载不需要重新启动Prometheus
冷加载是systemctl restart prometheus.service这样
[root@prometheus-server51 ~]# curl -X POST 10.0.0.51:9090/-/reload
[root@prometheus-server51 ~]#
3.验证
3.1打开prome的WebUI,查看job任务是否加载成功
http://10.0.0.51:9090/targets?search=
3.2用proQL语句验证下Prometheus是否采集到了客户端的数据
验证cpu数据是否采集
node_cpu_seconds_total
四、grafana展示监控
一、部署grafana
推荐阅读我之前的博客:
1.构建可视化监控系统:Grafana 安装配置、官方 Dashboard 应用与插件扩展-CSDN博客
二、配置grafana
1.添加Prometheus数据源
推荐阅读:
1.构建可视化监控系统:Grafana 安装配置、官方 Dashboard 应用与插件扩展-CSDN博客
2.新建dashboard
推荐阅读:
1.构建可视化监控系统:Grafana 安装配置、官方 Dashboard 应用与插件扩展-CSDN博客
监控数据展示成功(关于dashboard详细制作后续会加载说明,敬请关注后续prometheus专题博客)
Prometheus监控window主机
测试环境说明
准备用来测试的服务器,信息如下:
| 作用 | ip | 端口 |
|---|---|---|
| Prometheus服务端 数据存储、数据采集、提供webUI | 10.0.0.51 | 9090 |
| grafana | 10.0.0.51 | 3000 |
| windows | 10.0.0.1 | 9182 |
前置环境说明:
1.已经安装了prometheus-server
推荐阅读:
二进制部署Prometheus-server及自动化部署讲解(2)-CSDN博客
2.已经安装了grafana
推荐阅读:
1.构建可视化监控系统:Grafana 安装配置、官方 Dashboard 应用与插件扩展-CSDN博客
3.grafana已经导入了prometheus数据源
推荐阅读:
1.构建可视化监控系统:Grafana 安装配置、官方 Dashboard 应用与插件扩展-CSDN博客
一、客户端采集数据
一、windows上安装exporter
1.下载exporter
Exporters and integrations | Prometheus

2.运行

3.测试

二、prometheus配置静态监控目标
1.编写配置文件
43 #windows---exporter
44 - job_name: "windows-exporter"
45
46 # metrics_path defaults to '/metrics'
47 # scheme defaults to 'http'.
48
49 static_configs:
50 - targets:
51 - 10.0.0.1:9182
2.热加载
[root@prometheus-server51 prometheus-2.53.2.linux-amd64]# curl -X POST 10.0.0.51:9090/-/reload
3.验证

三、grafana展示监控数据
1.grafana导入了数据源
2.新建dashboard

Prometheus监控zookeeper集群
测试环境说明
准备用来测试的服务器,信息如下:
| 作用 | ip | 端口 |
|---|---|---|
| Prometheus服务端 数据存储、数据采集、提供webUI | 10.0.0.51 | 9090 |
| grafana | 10.0.0.51 | 3000 |
| zok-node01 | 10.0.0.66 | 2888:3888 |
| zok-node02 | 10.0.0.67 | 2888:3888 |
| zok-node03 | 10.0.0.68 | 2888:3888 |
前置环境说明:
1.已经安装了prometheus-server
推荐阅读:
二进制部署Prometheus-server及自动化部署讲解(2)-CSDN博客
2.已经安装了grafana
推荐阅读:
1.构建可视化监控系统:Grafana 安装配置、官方 Dashboard 应用与插件扩展-CSDN博客
3.grafana已经导入了prometheus数据源
推荐阅读:
1.构建可视化监控系统:Grafana 安装配置、官方 Dashboard 应用与插件扩展-CSDN博客
4.已经安装了zookeeper集群
一、客户端出采集数据
zookeeper本身自带metrics接口,不需要部署第三方exporter。
1.zookeeper集群开启metrics接口。
[root@es01 apache-zookeeper-3.8.6-bin]# cat /usr/local/apache-zookeeper-3.8.6-bin/conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/var/lib/zookeeper
clientPort=2181
server.11=10.0.0.66:2888:3888
server.22=10.0.0.67:2888:3888
server.33=10.0.0.68:2888:3888
# https://prometheus.io Metrics Exporter
metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
metricsProvider.httpHost=0.0.0.0
metricsProvider.httpPort=7000
metricsProvider.exportJvmInfo=true
[root@es01 apache-zookeeper-3.8.6-bin]#
把配置同步到其他节点
[root@es01 apache-zookeeper-3.8.6-bin]# scp /usr/local/apache-zookeeper-3.8.6-bin/conf/zoo.cfg 10.0.0.67:/usr/local/apache-zookeeper-3.8.6-bin/conf/zoo.cfg
root@10.0.0.67's password:
zoo.cfg 100% 406 94.6KB/s 00:00
[root@es01 apache-zookeeper-3.8.6-bin]# scp /usr/local/apache-zookeeper-3.8.6-bin/conf/zoo.cfg 10.0.0.68:/usr/local/apache-zookeeper-3.8.6-bin/conf/zoo.cfg
root@10.0.0.68's password:
zoo.cfg 100% 406 108.7KB/s 00:00
重启zk集群
zkServer.sh restart
验证metrics接口
[root@es01 apache-zookeeper-3.8.6-bin]# ss -tnulp |grep 7000
tcp LISTEN 0 50 *:7000 *:* users:(("java",pid=1844,fd=45))
[root@es01 apache-zookeeper-3.8.6-bin]#
2.访问zookeeper的metrics接口

二、配置Prometheus的服务发现(静态监控目标)
配置文件路径:
$INSTALLDIR/prometheus-2.53.2.linux-amd64/prometheus.yml
1.编辑配置文件
新增一个job任务:
采集客户端的zookeeper集群的http接口
53 #zookeeper-metrics
54 - job_name: "zookeeper"
55
56 # metrics_path defaults to '/metrics'
57 # scheme defaults to 'http'.
58
59 static_configs:
60 - targets:
61 - 10.0.0.66:7000
62 - 10.0.0.67:7000
63 - 10.0.0.68:7000

检查配置文件
[root@prometheus-server51 prometheus-2.53.2.linux-amd64]# ./promtool check config prometheus.yml
Checking prometheus.yml
SUCCESS: prometheus.yml is valid prometheus config file syntax
[root@prometheus-server51 prometheus-2.53.2.linux-amd64]#
2.热加载生效
[root@prometheus-server51 prometheus]# !curl
curl -X POST 10.0.0.51:9090/-/reload
3.验证
3.1打开prome的WebUI,查看job任务是否加载成功
http://10.0.0.51:9090/targets?search=

三、grafana展示监控
一、部署grafana
二、配置grafana
1.添加Prometheus数据源
2.新建dashboard
