prometheus+grafana+alertmanager监控部署

耀阳居士 耀阳居士     2022-12-02     533

关键词:

Prometheus+Grafana+Alertmanager监控部署
1、环境准备
Prometheus部署
node-export 部署
编辑Prometheus.yml
Grafana 安装部署
部署Alertmanger 告警
1、环境准备
阿里云ECS实例*1 4C 8G 系统盘100G 数据盘 300G

Prometheus+Grafana+Alermanager

开启防火墙对应端口 :

systemctl start firewalld
firewall-cmd --zone=pubic --add-port=9090/tcp --premanent #Prometheus端口
firewall-cmd --zone=pubic --add-port=3000/tcp --premanent #grafana看板端口
firewall-cmd --zone=pubic --add-port=9100/tcp --premanent #node-export 端口
firewall-cmd --zone=pubic --add-port=9093/tcp --premanent # Alermanager 端口
firewall-cmd --zone=pubic --add-port=9094/tcp --premanent # Alermanager 端口
firewall-cmd --reload #重载防火墙,生效
1
2
3
4
5
6
7
Prometheus部署
下载Prometheus次新稳定版本 : https://prometheus.io/download/
Prometheus基础环境配置
1、 yum -y install golang nodejs yarn

yum -y install golang nodejs yarn ## yum安装golang不需要可以不需要再/etc/profile配置环境变量,
1
如果使用编译安装,则需要再/etc/profile 设置环境变量,示例:

export GOROOT=/usr/lib/golang
export GOPATH=/root/Work/programmer/go/gopath/
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
1
2
3
2、解压Prometheus的tar包,我这里下载的是2.26

tar -zxvf prometheus-2.26.0.linux-amd64.tar.gz
mv prometheus-2.26.0.linux-amd64 /usr/local/
1
2
3、运行Prometheus有两种方式
1)使用nohup ./prometheus >> out.log &
但是使用nohup 如果需要关闭或重启Prometheus,需要ps -aux | grep prometheus 查询Prometheus进程的PID ,手动kill -9 进行关闭进程

2)编写system文件

vim /usr/lib/systemd/system/prometheus.service

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/prometheus-2.26.0.linux-amd64/prometheus --config.file=/usr/local/prometheus-2.26.0.linux-amd64/prometheus.yml --storage.tsdb.path=/var/lib/prometheus --storage.tsdb.retention=180d --web.enable-admin-api
# storage.tsdb.path手动指定Prometheus的存储位置 config.file指定Prometheus的配置文件 ExecStart指定Prometheus运行文件
Restart=on-failure

[Install]
WantedBy=multi-user.target


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
配置完system文件之后
systemctl start prometheus
systemctl enable prometheus

node-export 部署
开启Prometheus node端
下载 node_exporter-1.1.2.linux-amd64.tar.gz Linux监控node端
下载地址: https://github.com/prometheus/node_exporter

tar -zxvf node_exporter-1.1.2.linux-amd64.tar.gz
mv /usr/local/node_exporter-1.1.2.linux-amd64
cd /usr/local/node_exporter-1.1.2.linux-amd64
nohup ./node_exporter >> out.log &
1
2
3
4
编辑Prometheus.yml
编辑Prometheus.yml 文件

vim /usr/local/prometheus-2.26.0.linux-amd64/prometheus.yml

scrape_configs:
- job_name: \'prometheus\'
static_configs:
- targets: [\'localhost:9090\']
- job_name: Linux_export
static_configs:
- targets: [\'localhost:9100\']

1
2
3
4
5
6
7
8
9
10
之后重启Prometheus

systemctl restart prometheus

访问 localhost:9090 查看Prometheus状态


Grafana 安装部署
下载grafana安装包

https://grafana.com/grafana/dow

yum localinstall grafana-7.3.6-1.x86_64.rpm

systemctl start grafana
systemctl enable grafana
1
2
启动grafana后,访问
localhost:3000 (默认端口3000) 查看grfana面板

grafana默认密码 admin admin 第一次登陆需要修改密码

grafana官网拥有许多模板可以选择,我们这边监控Linux的话,就选择模板编号为 8919


部署Alertmanger 告警
下载alermanager告警组件

https://prometheus.io/docs/alerting/latest/alertmanager/

这边用的是0.20.0版本

tar -zxvf alertmanager-0.20.0.linux-amd64.tar.gz
mv alertmanager-0.20.0.linux-amd64 /usr/local/alertmanager
vim /usr/local/alertmanager/alertmanager.yml

global:
resolve_timeout: 5m
smtp_smarthost: \'smtp.163.com:465\'
smtp_from: \'xxxxxxxxx@163.com\'
smtp_auth_username: \'xxxxxxxx@163.com\'
smtp_auth_password: \'xxxxxxxxxxxxxxx\'
smtp_require_tls: false

templates:
- \'/alertmanager/template/*.tmpl\'

route:
group_by: [\'alertname\']
group_wait: 30s
group_interval: 5m
repeat_interval: 10m
receiver: \'mail\'
receivers:
- name: \'mail\'
email_configs:
- to: \'xxxxxxxxx@xxx.com\'

inhibit_rules:
- source_match:
severity: \'critical\'
target_match:
severity: \'warning\'
equal: [\'alertname\', \'dev\', \'instance\']

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
编辑system文件

vim /usr/lib/systemd/system/alertmanager.service

[Unit]
Description=alertmanager
Documentation=https://github.com/prometheus/alertmanager
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/alertmanager/alertmanager --config.file=/usr/local/alertmanager/alertmanager.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target
1
2
3
4
5
6
7
8
9
10
11
12
13
systemctl start alermanage
systemctl enable alermanage

编辑Prometheus.yml 文件

vim /usr/local/prometheus-2.26.0.linux-amd64/prometheus.yml

alerting:
alertmanagers:
- static_configs:
- targets:
- localhost:9093 #指定本地alermanage端口
\'evaluation_interval\'.
rule_files:
- "/usr/local/prometheus-2.26.0.linux-amd64/rule/*.yml" #在Prometheus下定制的规则将用于告警
1
2
3
4
5
6
7
8
9
10
之后再Prometheus目录下,创建一个rule文件夹,将定义规则的 .yml文件 放入rule文件夹中 实现告警

以下以告警组件状态为例:

cd /usr/local/prometheus-2.26.0.linux-amd64/rule/
vim nodestatus_rule.yml

groups:
- name: alert-rules.yml
rules:
- alert: InstanceStatus
expr: up == 0
for: 10s
labels:
severity: "critical"
annotations:
summary: "主机 $labels.instance 无响应"
description: " $labels.instance 无响应 (当前值: $value ) "


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
之后重启Prometheus,就可以正常告警了

systemctl restart prometheus
1
如果想验证告警是否成功,可以手动关闭 node-export 验证是否有告警邮件发出

ps -aux | grep node

kill -9 PID

1
2
3
4
感谢观看,您的点赞是对我最大的支持
后续会陆续更新如何监控nginx、tomcat、MySQL、Oracle

以后会继续更新ansible相关教程。
————————————————
版权声明:本文为CSDN博主「靠谱的成年男性Zack」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_43476124/article/details/115986124

prometheus+grafana

prometheus集中管理服务搭建#搭建在监控服务主机上,用于收集节点服务器信息下载:https://prometheus.io/download/解压运行:nohup./prometheus--config.file=./prometheus.yml&>>./prometheus.log&访问http://192.168.1.24:9090node-exporter 查看详情

prometheus+grafana服务器监控

普罗米修斯官网https://prometheus.io/download/grafana官网和下载地址https://grafana.com/grafana/download   查看详情

prometheus+grafana部署说明之安装(代码片段)

说明在前面的Prometheus学习系列文章里,大致介绍说明了Prometheus和Grafana的一些使用,现在开始介绍如何从头开始部署Prometheus+Grafana,来监控各个相关的指标数据来进行展示。部署Prometheus基于Golang编写(需要安装),编译后的软... 查看详情

使用一些指标导出器 + Prometheus + Grafana 监控日志文件

】使用一些指标导出器+Prometheus+Grafana监控日志文件【英文标题】:Monitoringlogfilesusingsomemetricsexporter+Prometheus+Grafana【发布时间】:2017-04-3020:41:51【问题描述】:我需要监控非常不同的日志文件中的错误、成功状态等。我需要使用P... 查看详情

prometheus+grafana+alertmanager监控部署

Prometheus+Grafana+Alertmanager监控部署1、环境准备Prometheus部署node-export部署编辑Prometheus.ymlGrafana安装部署部署Alertmanger告警1、环境准备阿里云ECS实例*14C8G系统盘100G数据盘300GPrometheus+Grafana+Alermanager开启防火墙对应端口:systemctlstartfire 查看详情

部署prometheus+grafana监控docker(代码片段)

文章目录部署Prometheus+Grafana监控Docker(1)实验环境(2)实验步骤1、先做基础配置2、在监控端安装服务3、在被监控端安装4、修改prometheus主配置文件5、测试访问prometheus的web界面6、使用Grafana来进行监控部署Prom... 查看详情

prometheus+grafana监控部署实践

参考文档:Prometheusgithub:https://github.com/prometheusgrafanagithub:https://github.com/grafana/grafanaPrometheusgetting_started:https://prometheus.io/docs/prometheus/latest/getting_started/Prometheusnode 查看详情

多值 Prometheus 查询 Grafana

】多值Prometheus查询Grafana【英文标题】:Multi-ValuePrometheusQueryGrafana【发布时间】:2020-08-0300:34:50【问题描述】:我正在使用Grafana和Prometheus查询在Grafana中为Kubernetes创建仪表板。我将节点的名称(在本例中为3个)放入一个变量中... 查看详情

Grafana/Prometheus 节点导出器无数据

】Grafana/Prometheus节点导出器无数据【英文标题】:Grafana/PrometheusNodeexporterNoData【发布时间】:2021-05-0803:06:39【问题描述】:所以我设置了grafana和prometheus来监控我的服务器,但我没有在grafana中获得任何数据(而且我不知道如何检... 查看详情

prometheus(或grafana)查询来评估grafana loki使用的存储?

】prometheus(或grafana)查询来评估grafanaloki使用的存储?【英文标题】:prometheus(orgrafana)querytoevaluatestorageusedbygrafanaloki?【发布时间】:2021-10-1219:13:38【问题描述】:如何通过prometheus查询计算grafanaloki使用的存储空间?是否有特定... 查看详情

如何使用 Grafana 警报显示 Prometheus 标签

】如何使用Grafana警报显示Prometheus标签【英文标题】:HowtodisplayPrometheuslabelswithGrafanaalert【发布时间】:2019-07-1407:42:29【问题描述】:我正在使用带有Prometheus数据源的Grafana警报。一切正常,但我收到这样的通知:[Alerting]DiskUsage%$... 查看详情

Grafana中如何使用Prometheus数据源监控elasticsearch

】Grafana中如何使用Prometheus数据源监控elasticsearch【英文标题】:HowtomonitorelasticsearchwithPrometheusdatasourceinGrafana【发布时间】:2018-03-2110:47:56【问题描述】:我是Prometheus和Grafana的初学者。我在Grafana中创建了新的仪表板,以使用Prome... 查看详情

尽管 Prometheus 数据源已成功验证,但 Grafana 无法获取 Prometheus 指标

】尽管Prometheus数据源已成功验证,但Grafana无法获取Prometheus指标【英文标题】:GrafanaisnotabletogetPrometheusmetricsalthoughPrometheusDatasourceisvalidatedsuccessfully【发布时间】:2017-01-0416:23:35【问题描述】:我正在尝试将Grafana配置为可视化Pro... 查看详情

prometheus安装部署出图(使用grafana)(代码片段)

一、Prometheus安装与部署安装服务端#下载安装包[root@promethus~]#mkdir/prometheus[root@promethus/opt]#cd/prometheus/[root@promethus/prometheus]#wgethttps://github.com/prometheus/prometheus/releases/download/ 查看详情

监控利器prometheus——prometheus+grafana监控springboot项目jvm信息

Prometheus+Grafana监控SpringBoot项目JVM信息1.SpringBoot项目配置JVM采集2.Prometheus配置3.配置grafana4.扩展-通过JMXExporter监控JVM信息1.SpringBoot项目配置JVM采集(1)maven依赖<dependency><groupId>org.spring 查看详情

3.prometheus+grafana实现可视化告警(代码片段)

3.Prometheus+Grafana实现可视化、告警3.1.什么是Grafana3.2.快速入门3.3.Grafana的下载3.4.启动grafana3.5.配置数据源3.6.配置面板3.7.邮件通道配置3.8.指标告警配置3.9.Dashboards模板下载3.Prometheus+Grafana实现可视化、告警转自:https://www.... 查看详情

监控利器prometheus——prometheus+grafana监控服务器资源(代码片段)

Prometheus+Grafana监控服务器资源1.配置NodeExporter采集服务器数据2.Prometheus配置3.在Grafana中创建监控看板在Prometheus的架构设计中,PrometheusServer并不直接服务监控特定的目标,其主要任务负责数据的收集,存储并且对外... 查看详情

如何配置 Grafana 以捕捉 Prometheus 指标的急剧下降?

】如何配置Grafana以捕捉Prometheus指标的急剧下降?【英文标题】:HowcanGrafanabeconfiguredtocatchasteepdropinametricfromPrometheus?【发布时间】:2020-07-1416:32:04【问题描述】:我们正在使用Grafana来监控某些事件和火灾警报。数据存储在Prometheu... 查看详情