基于Prometheus搭建监控平台
前言
准备软件包:
- prometheus:prometheus-2.22.2.linux-amd64.tar.gz
- grafana安装包:grafana-enterprise-7.3.4-1.x86_64.rpm
- node_report:node_exporter-1.0.1.linux-amd64.tar.gz
- mysqld-exporter:mysqld_exporter-0.12.1.linux-amd64.tar.gz
- alertmanager:alertmanager-0.21.0.linux-amd64.tar.gz
- 钉钉告警插件:prometheus-webhook-dingtalk-1.4.0.linux-amd64.tar.gz
可以使用kill -HUP <prometheus's pid>的方式热加载prometheus的配置。
本文档只是简单的初步配置,不涉及高可用和微服务、容器云、日志监控。
配置server单节点
- server节点:172.50.13.101
- 部署位置:/usr/local/prometheus/(建议部署在/usr/local/prometheus/prometheus/目录下)
- 配置文件:/usr/local/prometheus/prometheus.yml(建议放在/usr/local/prometheus/prometheus/目录下)
- 监听端口:19090
- 数据存储位置:/home/prometheus/data/(建议存放于/home/data/prometheus/目录下)
- 数据保留时间:15天
下载prometheus压缩包并解压,二进制文件可直接运行。
prometheus.service
将prometheus设置为service,并开机自启
vim /usr/lib/systemd/system/prometheus.service- 文件内容见本文底部 -> 附录代码 -> prometheus.service
- 加载service:
systemctl daemon-reload - 启动:
systemctl start prometheus - 设置自启:
systemctl enable prometheus
配置node节点
- node节点:需要被监控的服务器
- 部署位置:/usr/local/prometheus/node_exporter/
- 监听端口:18080
- 下载node_exporter压缩包到目标服务器的部署位置
vim /usr/lib/systemd/system/node_exporter.service- 文件内容见本文底部 -> 附录代码 -> node_exporter.service
- 加载service文件:
systemctl daemon-reload - 启动:
systemctl start node_exporter - 设置自启:
systemctl enable node_exporter
配置mysql监控
在数据库中添加exporter账户
- 登录需要被监控的数据库
- 创建用户exporter:
CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'XXXXXXXX' WITH MAX_USER_CONNECTIONS 3; - 授权:
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost'; - 刷新:
flush privileges;
修改mysql_exporter的配置
添加/usr/local/prometheus/mysql_exporter/.my.cnf文件
[client]
user=exporter
password=xxxxxxxx
添加service
见附录代码中的mysql_exporter.service
相关参考资料
配置grafana
安装grafana
下载rpm安装包后直接yum安装。
添加prometheus数据源
进入grafana的web界面,添加prometheus的数据源。
导入模板
mysql主题的ID:7362
node主题ID:13105
踩坑
- 问题1:添加mysql的exporter后,prometheus的web页面能看到mysql的监控数据,但是grafana里面添加不了prometheus的数据源
- 解决:
- 试试其它mysql dashboard的ID
- 自己创建panel。
- 原因:并没有适配Prometheus
- 解决:
- 问题2:grafana中的MySQL仪表盘有部分没有数据:
- 解决:更改node_exporter和mysql_exporter的instance为一致
官方Dashboard资源
监控告警
- 告警服务在172.50.13.102
- 部署位置:
/usr/local/prometheus/alertmanager/ - 数据存储路径:
/home/data/prometheus/alertmanager/ - 监听端口:18081
配置alertmanager
./alertmanager --storage.path=/home/data/prometheus/alertmanager/ --web.listen-address=:18081 --config.file=/usr/local/prometheus/alertmanager/alertmanager.yml --data.retention=120h --web.external-url=http://172.50.13.102:18081 &
- storage.path:数据存储路径
- web.listen-address:监听端口
- config.file:配置文件路径
- data.retention:数据存储保留时长
- web.external-url:web访问的url
配置prometheus告警规则
- 关联alertmanager:见prometheus.yml中的alerting
- 指定告警规则文件的路径:见prometheus.yml中的rule_files
配置钉钉告警机器人
/usr/local/prometheus/prometheus-webhook-dingtalk/prometheus-webhook-dingtalk --ding.profile=webhook1=https://oapi.dingtalk.com/robot/send?access_token=钉钉token &
附录代码
prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets: ['172.50.13.102:18081']
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
- "alertrules/*_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
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:19090']
- job_name: '非生产'
file_sd_configs:
- files: ['/usr/local/prometheus/sd_configs/noGroup*.yml']
refresh_interval: 10s
- job_name: '生产mysql'
file_sd_configs:
- files: ['/usr/local/prometheus/sd_configs/mysql/product*.yml']
refresh_interval: 10s
- job_name: '非生产mysql'
file_sd_configs:
- files: ['/usr/local/prometheus/sd_configs/mysql/noproduct*.yml']
refresh_interval: 10s
- job_name: '生产服务器'
file_sd_configs:
- files: ['/usr/local/prometheus/sd_configs/product*.yml']
refresh_interval: 10s
- job_name: '物理机'
file_sd_configs:
- files: ['/usr/local/prometheus/sd_configs/wuli*.yml']
refresh_interval: 10s
alertmanager.yml
global:
resolve_timeout: 5m
route:
group_by: [alertname]
group_wait: 10s
group_interval: 10s
repeat_interval: 1h
receiver: webhook
receivers:
- name: webhook
webhook_configs:
- url: 'http://172.50.13.102:8060/dingtalk/webhook1/send'
send_resolved: true
prometheus.service
[Unit]
Description=https://prometheus.io
Documentation=https://prometheus.io
[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus/ \
--storage.tsdb.path=/home/prometheus/data/ \
--config.file=/usr/local/prometheus/prometheus.yml \
--web.listen-address=:19090 \
--storage.tsdb.retention=15d
[Install]
WantedBy=multi-user.target
node_exporter.service
[Unit]
Description=https://prometheus.io
[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/node_exporter/node_exporter --web.listen-address 0.0.0.0:18080
[Install]
WantedBy=multi-user.target
mysql_exporter.service
[Unit]
Description=https://prometheus.io
[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/mysqld_exporter/mysqld_exporter \
--web.listen-address 0.0.0.0:9104 \
--config.my-cnf=/usr/local/prometheus/mysqld_exporter/.my.cnf
[Install]
WantedBy=multi-user.target
alertmanager.service
告警规则-内存、硬盘、CPU
groups:
- name: mem
rules:
- alert : mem
expr: (1 - (node_memory_MemAvailable_bytes / (node_memory_MemTotal_bytes)))* 100 > 95
for: 5m
labels:
severity: critical
annotations:
description: "{{ $labels.job }} {{ $labels.instance }} 节点的内存使用率超过95%已持续5分钟!"
summary: "{{ $labels.instance }} 内存使用率超标! "
- name: disk
rules:
- alert : disk
expr: (node_filesystem_size_bytes{fstype=~"ext.*|xfs",mountpoint !~".*pod.*"}-node_filesystem_free_bytes{fstype=~"ext.*|xfs",mountpoint !~".*pod.*"}) *100/(node_filesystem_avail_bytes {fstype=~"ext.*|xfs",mountpoint !~".*pod.*"}+(node_filesystem_size_bytes{fstype=~"ext.*|xfs",mountpoint !~".*pod.*"}-node_filesystem_free_bytes{fstype=~"ext.*|xfs",mountpoint !~".*pod.*"})) > 95
for: 5m
labels:
severity: warning
annotations:
description: "{{ $labels.job }} {{ $labels.instance }} 节点的硬盘使用率超过95%已持续5分钟!"
summary: "{{ $labels.instance }} 硬盘空间使用率已超过95%! "
- name: cpu
rules:
- alert : cpu
expr: ((1- sum(increase(node_cpu_seconds_total{mode="idle"}[5m])) by (instance)/sum(increase(node_cpu_seconds_total[5m])) by (instance)) * 100) > 70
for: 5m
labels:
severity: warning
annotations:
description: "{{ $labels.job }} {{ $labels.instance }} 节点的CPU使用率超过70%已持续5分钟!"
summary: "{{ $labels.instance }} CPU使用率已超过70! "
告警规则-主机存活
groups:
- name: UP
rules:
- alert : node
expr: up == 0
for: 1m
labels:
severity: critical
annotations:
description: "{{ $labels.job }} {{ $labels.instance }} 节点断联已超过1分钟!"
summary: "{{ $labels.instance }} down "
基于Prometheus搭建监控平台的更多相关文章
- 实战 Prometheus 搭建监控系统
实战 Prometheus 搭建监控系统 Prometheus 是一款基于时序数据库的开源监控告警系统,说起 Prometheus 则不得不提 SoundCloud,这是一个在线音乐分享的平台,类似于 ...
- 自动化运维:使用flask+mysql+highcharts搭建监控平台
1.前言 本来想做一个比较完善的监控平台,只需要做少许改动就可以直接拿来用,但是在做的过程中发现要实现这个目标所需的工作量太大,而当前的工作中对其需求又不是特别明显.所以就退而求其次,做了一个类似教程 ...
- 记录一次基于docker搭建jira平台
背景:项目需要选择不同测试平台,筛选一个最佳平台 现状:一台机器安装多套环境,虚拟机太繁琐 解决方案:通过Docker模拟安装测环境 1.pull docker 镜像: jira:7.11.1(目前的 ...
- SpringBoot整合SpringAdmin搭建监控平台
在SpringBoot整合Actuator进行健康监控中,胜金讲述了通过Actuator进行健康监控,但是学习API并根据API开发前端需要花费相当大的精力,本次胜金就写一下通过SpringAdmin ...
- 基于Prometheus搭建SpringCloud全方位立体监控体系
前提 最近公司在联合运维做一套全方位监控的系统,应用集群的技术栈是SpringCloud体系.虽然本人没有参与具体基础架构的研发,但是从应用引入的包和一些资料的查阅大致推算出具体的实现方案,这里做一次 ...
- 基于Prometheus和Grafana的监控平台 - 环境搭建
相关概念 微服务中的监控分根据作用领域分为三大类,Logging,Tracing,Metrics. Logging - 用于记录离散的事件.例如,应用程序的调试信息或错误信息.它是我们诊断问题的依据. ...
- 理解OpenShift(7):基于 Prometheus 的集群监控
理解OpenShift(1):网络之 Router 和 Route 理解OpenShift(2):网络之 DNS(域名服务) 理解OpenShift(3):网络之 SDN 理解OpenShift(4) ...
- inux监控平台搭建-监控项
linux监控平台搭建-监控项 本人运维某生态互联网监控平台服务.过程中遇见了很多问题.目前互联网有很多的开源监控工具:nagios.zabbix.falcon.cacti...各有优点.这里不讲解监 ...
- JMeter+Grafana+Influxdb搭建可视化性能测试监控平台(使用了docker)
[运行自定义镜像搭建监控平台] 继上一篇的帖子 ,上一篇已经展示了如何自定义docker镜像,大家操作就行 或者 用我已经自定义好了的镜像,直接pull就行 下面我简单介绍pull下来后如何使用 拉取 ...
- Prometheus + Grafana 监控系统搭
本文主要介绍基于Prometheus + Grafana 监控Linux服务器. 一.Prometheus 概述(略) 与其他监控系统对比 1 Prometheus vs. Zabbix Zabbix ...
随机推荐
- spring事务传播的Propagation.REQUIRES_NEW以及NEVER MANDATORY验证,及其失效的诡异问题
NEVER 不使用事务,如果当前事务存在,则抛出异常 验证: @Service public class PrService { @Autowired PrDao dao; @Transactiona ...
- 2022-09-29:在第 1 天,有一个人发现了一个秘密。 给你一个整数 delay ,表示每个人会在发现秘密后的 delay 天之后, 每天 给一个新的人 分享 秘密。 同时给你一个整数 forg
2022-09-29:在第 1 天,有一个人发现了一个秘密. 给你一个整数 delay ,表示每个人会在发现秘密后的 delay 天之后, 每天 给一个新的人 分享 秘密. 同时给你一个整数 forg ...
- 2022-09-01:字符串的 波动 定义为子字符串中出现次数 最多 的字符次数与出现次数 最少 的字符次数之差。 给你一个字符串 s ,它只包含小写英文字母。请你返回 s 里所有 子字符串的 最大波
2022-09-01:字符串的 波动 定义为子字符串中出现次数 最多 的字符次数与出现次数 最少 的字符次数之差. 给你一个字符串 s ,它只包含小写英文字母.请你返回 s 里所有 子字符串的 最大波 ...
- 2022-04-11:给定一个正数数组arr,其中每个值代表砖块长度, 所有砖块等高等宽,只有长度有区别, 每一层可以用1块或者2块砖来摆, 要求每一层的长度一样, 要求必须使用所有的砖块, 请问最多
2022-04-11:给定一个正数数组arr,其中每个值代表砖块长度, 所有砖块等高等宽,只有长度有区别, 每一层可以用1块或者2块砖来摆, 要求每一层的长度一样, 要求必须使用所有的砖块, 请问最多 ...
- C# 实现 Linux 视频会议(源码,支持信创环境,银河麒麟,统信UOS)
信创是现阶段国家发展的重要战略之一,面对这一趋势,所有的软件应用只有支持信创国产化的基础软硬件设施,在未来才不会被淘汰.那么,如何可以使用C#来实现支持信创环境的视频会议系统吗?答案是肯定的. 本文讲 ...
- 在使用abaqus时可能会遇到的一些问题
我收集了一些网友及客户在使用abaqus软件时遇到的一些问题,下面来看看是如何解决的~ (1)Linux平台使用Abaqus子程序的免费方案 gcc+gfortran 本方法在centos7和cen ...
- 小程序打印饼图报错VM6541:1 thirdScriptError Converting circular structure to JSON;
今日使用小程序开发饼图页面,由于一个页面需要打印多个饼图,所以需要将echarts对象进行缓存,于是出现了如下js报错问题 一. 错误代码 VM6541:1 thirdScriptError Conv ...
- 多线程合集(三)---异步的那些事之自定义AsyncTaskMethodBuilder
引言 之前在上一篇文章中多线程合集(二)---异步的那些事,async和await原理抛析,我们从源码去分析了async和await如何运行,以及将编译后的IL代码写成了c#代码,以及实现自定义的Aw ...
- 如何开启Apache SkyWalking的自监控?
1. 开启Prometheus遥测数据 默认情况下, 遥测功能(telemetry)是关闭的(selector 为 none),像这样: telemetry: selector: ${SW_TELEM ...
- 浅聊一下 C#程序的 内存映射文件 玩法
一:背景 1. 讲故事 前段时间训练营里有朋友问 内存映射文件 是怎么玩的?说实话这东西理论我相信很多朋友都知道,就是将文件映射到进程的虚拟地址,说起来很容易,那如何让大家眼见为实呢?可能会难倒很多人 ...