一,Prometheus
1.什么是Prometheus?
Prometheus
是 Cloud Native Computing Foundation
的一个监控系统项目, 集采集、监控、报警等特点于一体。
Prometheus
主要受启发于Google
的Brogmon
监控系统, 从2012
年开始由前Google
工程师在Soundcloud
以开源软件的形式进行研发,2017
年底发布了基于全新存储层的2.0
版本,当前最新版本是2.44.0
版本。
2.Prometheus架构

3.prometheus具有那些特点?
- 多维数据模型(由指标名称、键/值组合的时间序列);
- 提供了一种强大而灵活的查询语言
promsql
;
- 没有对分布式存储的依赖,单个服务器节点是自主的;
- 主要支持时间序列集合的HTTP拉模模型,同时也提供
PushGateway
来满足;
- 服务发现;
- 自带
UI
,支持丰富多种图形和仪表板,还能与其他;
- 支持分层和水平联合;
二,Prometheus搭建
IP |
角色 |
|
192.168.2.4 |
prometheus服务器端 |
|
192.168.2.3 |
node_exporter客户端 |
1.二进制安装Prometheus
[root@server ~]
[root@server ~]
[root@server ~]
1.查看版本号
[root@server ~]
[root@server prometheus]
prometheus, version 2.44.0 (branch: HEAD, revision: 1ac5131f698ebc60f13fe2727f89b115a41f6558)
build user: root@739e8181c5db
build date: 20230514-06:18:11
go version: go1.20.4
platform: linux/amd64
tags: netgo,builtinassets,stringlabels
2.查看帮助文档
[root@server prometheus]
2.prometheus.yml配置解释
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
rule_files:
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
3.升级为系统服务
cd /usr/lib/systemd/system
vi prometheus.service
[Unit]
Description=https://prometheus.io
[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.listen-address=:9090
[Install]
WantedBy=multi-user.target
其他选项解释:
常用选项解释:
--config.file="prometheus.yml"
--web.listen-address="0.0.0.0:9090"
--web.max-connections=512
--storage.tsdb.path="data/"
--storage.tsdb.retention=15d
--web.enable-lifecycle
--web.config.file=""
启动选项了解:./prometheus --help
4.刷新system文件,启动
systemctl daemon-reload
systemctl start prometheus
5.访问测试
IP:9090

三,客户端node_exporter搭建
1.监控目的Linux安装node_exporter
[root@server ~]
[root@server ~]
[root@server ~]
[root@server ~]
2.添加为系统服务
[root@server ~]
[Unit]
Description=node_exporter
After=network.target
[Service]
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start node_exporter
3.prometheus服务器端添加监控项
[root@server prometheus]
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
rule_files:
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['192.168.2.4:9090']
- job_name: 'linux'
static_configs:
- targets: ['192.168.2.4:9100','192.168.2.3:9100']
4.重启系统普罗米修斯
[root@server ~]
5.监控界面

四,监控MySQL
1.安装mysqld-exporter
[root@VM_2-44 ~]
[root@VM_2-44 ~]
[root@VM_2-44 /usr/local]
[root@VM_2-44 /usr/local/mysqld_exporter]
[client]
host=192.168.2.3
user=root
password=123456
port=3306
2.启动mysqld-exporter服务
[root@VM_2-44 /usr/local/mysqld_exporter]
[root@VM_2-44 /usr/local/mysqld_exporter]
root 3447 3398 0 01:31 pts/1 00:00:02 ./node_exporter
root 4647 3398 0 02:13 pts/1 00:00:00 ./mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf
root 4654 3398 0 02:13 pts/1 00:00:00 grep --color=auto exporter
[root@VM_2-44 /usr/local/mysqld_exporter]
LISTEN 0 128 :::9104 :::* users:(("mysqld_exporter",pid=4647,fd=3))
[root@VM_2-44 /usr/local/mysqld_exporter]
3.普罗米修斯配置文件添加监控项
[root@VM_2-45 /usr/local/prometheus]
- job_name: 'mysql'
static_configs:
- targets: ['192.168.2.3:9104']
4.重启普罗米修斯
[root@VM_2-45 /usr/local/prometheus]
5.查看状态

五,grafana展示prometheus数据
1.在prometheus安装grafana
wget https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/Packages/grafana-7.4.3-1.x86_64.rpm
[root@VM_2-45 ~]
[root@VM_2-45 ~]
[root@VM_2-45 ~]
2.访问grafana
启动后访问地址:ip:3000
初始用户名和密码都是admin

3.添加Prometheus数据源
Configuration -> Data Sources ->add data source -> Prometheus

添加prometheus服务器

4.添加dashboard Linux基础数据展示

导入模板8919

选择数据源

5.查看dashboard
Dashboards ->Manage

六,grafana展示MySQL信息
1.设置数据源
Configuration -> Data Sources ->add data source -> MySQL

2.数据库上授权用户

3.导入下载的dashboard,数据源现在刚刚创建的
https://pan.baidu.com/s/1GBzogDLsYS3IvwH4WbdPLw 提取码:ef6e

4.查看效果
