Prometheus+grafana+alertmanager告警平台搭建

一:基本组件理解

node_exporter:采集节点的cpu,内存,磁盘等基本信息

prometheus: 收集node_exporter,redis_exporter等数据。

Grafana:  从prometheus,mysql,es中拿到采集的数据进行图形展示。

alertmanager: 报警管理器。可以与钉钉结合将报警发给钉钉机器人。

 

流程:
prometheus采集数据并编写告警规则,告警规则发给alertmanager 之后,alertmanager 作进一步作告警处理。并将告警消息转发给钉钉机器人。

二:告警平台架构图

在这里插入图片描述

三:prometheus部署

3.1: 创建用户

useradd -M -s /sbin/nologin prometheus -g prometheus

3.2: 下载安装包

wget https://github.com/prometheus/prometheus/releases/download/v2.22.2/prometheus-2.22.2.linux-amd64.tar.gz

3.3:解压

tar zxf prometheus-2.22.2.linux-amd64.tar.gz 
mv prometheus-2.22.2.linux-amd64 /usr/local/prometheus
cd /usr/local/prometheus
mkdir  relus data target

3.4:设置prometheus.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: ['172.24.65.155:9090']
  # 设置自动发现监控主机
  - job_name: 'hosts-status'
    file_sd_configs:
    - files:
      - "/usr/local/prometheus/target/host_status.json"
      refresh_interval: 6s

[root@localhost prometheus]# cat target/host_status.json
[
{
   
        "targets": ["172.24.65.107:9100"],
        "labels": {
   
                        "job": "hosts-status",
                        "service": "master107"
                }
},
{
   
        "targets": ["172.24.65.108:9100"],
        "labels": {
   
                        "job": "hosts-status",
                        "service": "master108"
                }
}
]

3.5:将prometheus设置为系统服务

[root@localhost prometheus]# cat /usr/lib/systemd/system/prometheus.service
[Unit]
Description=prometheus-server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.enable-lifecycle --storage.tsdb.path=/usr/local/prometheus/data --storage.tsdb.retention.time=7d --web.max-connections=512 --web.read-timeout=3m --query.max-concurrency=
  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
好的,以下是一个基于Docker Compose的搭建PrometheusGrafanaAlertmanager、Blackbox Exporter和Node Exporter的示例: ```yaml version: "3" services: prometheus: image: prom/prometheus container_name: prometheus ports: - "9090:9090" volumes: - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml command: - '--config.file=/etc/prometheus/prometheus.yml' - '--web.enable-admin-api' restart: always grafana: image: grafana/grafana container_name: grafana ports: - "3000:3000" volumes: - ./grafana:/var/lib/grafana restart: always alertmanager: image: prom/alertmanager container_name: alertmanager ports: - "9093:9093" volumes: - ./alertmanager/config.yml:/etc/alertmanager/config.yml command: - '--config.file=/etc/alertmanager/config.yml' restart: always blackbox-exporter: image: prom/blackbox-exporter container_name: blackbox-exporter ports: - "9115:9115" volumes: - ./blackbox-exporter/config.yml:/etc/blackbox-exporter/config.yml command: - '--config.file=/etc/blackbox-exporter/config.yml' restart: always node-exporter: image: prom/node-exporter container_name: node-exporter ports: - "9100:9100" restart: always ``` 需要注意的是,这里的配置文件都需要自己创建并且挂载到对应的容器中。例如,prometheus.yml、config.yml和config.yml分别对应PrometheusAlertmanager和Blackbox Exporter的配置文件。同时,Grafana的数据目录也需要挂载到主机上以便数据持久化。 另外,需要注意的是这只是一个示例,具体的配置文件需要根据实际情况进行修改。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值