prometheus grafana alertmanager 安装配置

prometheus+grafana+alertmanager 安装配置

服务器监控告警系统搭建,通过 exporter 获取节点信息到 prometheus。prometheus 配置规则,使 garfana 和 alertmanager 能够接受到数据,分别展示数据和发送告警

参数

VM :192.168.99.78

端口服务
9100node_exporter
3000grafana
9090prometheus
9115blackbox_exporter

安装

grafa 安装

  1. docker 安装
1docker run -d -p 3000:3000 \
2--name=grafana \
3-v grafana-storage:/var/lib/grafana \
4grafana/grafana:8.3.3

prometheus 安装

  1. 下载
1wget https://github.com/prometheus/prometheus/releases/download/v2.32.1/prometheus-2.32.1.linux-amd64.tar.gz
2tar -zxvf prometheus-2.32.1.linux-amd64.tar.gz
3cd prometheus-2.32.1.linux-amd64
4mkdir -p file_sd
5mkdir -p rules
  1. 运行 prometheus
1killall prometheus
2nohup ./prometheus --config.file=prometheus.yml &
3# 查看运行状况
4tail -f nohup.out

node_exporter 安装

  1. docker-compose 安装
1version: "3"
2services:
3  node-exporter:
4    image: prom/node-exporter:v1.3.1
5    container_name: node-exporter
6    restart: always
7    ports:
8      - "9100:9100"
1docker-compose up -d
  1. 二进制安装
1wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
2tar -zxvf node_exporter-1.3.1.linux-amd64.tar.gz
3cd node_exporter-1.3.1.linux-amd64
4nohup ./node_exporter &

blackbox_exporter

  1. 二进制安装
1wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.19.0/blackbox_exporter-0.19.0.linux-amd64.tar.gz
2tar -zxvf blackbox_exporter-0.19.0.linux-amd64.tar.gz
3cd blackbox_exporter-0.19.0.linux-amd64
4nohup ./blackbox_exporter &

Alertmanager

  1. 二进制安装
1wget https://github.com/prometheus/alertmanager/releases/download/v0.23.0/alertmanager-0.23.0.linux-amd64.tar.gz
2tar -zxvf alertmanager-0.23.0.linux-amd64.tar.gz
3cd alertmanager-0.23.0.linux-amd64
4nohup ./alertmanager &
  1. docker-compose 安装
 1version: "3"
 2services:
 3  alertmanager:
 4    image: "prom/alertmanager:v0.22.2"
 5    volumes:
 6      - "/etc/localtime:/etc/localtime"
 7      - "./alertmanager.yml:/etc/alertmanager/alertmanager.yml"
 8    ports:
 9      - "9093:9093"
10    restart: "always"
11    container_name: "alertmanager"

prometheus.yml 配置

 1global:
 2  scrape_interval: 15s # By default, scrape targets every 15 seconds.
 3
 4  # Attach these labels to any time series or alerts when communicating with
 5  # external systems (federation, remote storage, Alertmanager).
 6  external_labels:
 7    monitor: "codelab-monitor"
 8
 9# Alertmanager configuration
10# alerting:
11#   alertmanagers:
12#   - static_configs:
13#     - targets:
14#       - 192.168.99.78:9093
15
16# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
17# rule_files:
18#   - "./rules/blackbox.yaml"
19#   - "./rules/node-exporter.yaml"
20
21# A scrape configuration containing exactly one endpoint to scrape:
22# Here it's Prometheus itself.
23scrape_configs:
24  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
25  - job_name: "prometheus"
26    # Override the global default and scrape targets from this job every 5 seconds.
27    scrape_interval: 5s
28    static_configs:
29      - targets: ["localhost:9090"]
30
31  - job_name: "node-exporter"
32    file_sd_configs:
33      - files:
34          - "./file_sd/node-exporter.yaml"
35        refresh_interval: 5s
36
37  - job_name: "blackbox"
38    metrics_path: /probe
39    scrape_interval: 30s
40    scrape_timeout: 30s
41    params:
42      module: [http_2xx] # Look for a HTTP 200 response.
43    file_sd_configs:
44      - files:
45          - "./file_sd/blackbox.yaml"
46        refresh_interval: 5s
47    relabel_configs:
48      - source_labels: [__address__]
49        target_label: __param_target
50      - source_labels: [__param_target]
51        target_label: instance
52      - target_label: __address__
53        replacement: 192.168.99.78:9115

node-exporter.yaml

1- targets: ["192.168.99.78:9100"]
2  labels:
3    instance: <实例名称>
4- targets: ["<IP>:9100"]
5  labels:
6    instance: 实例名称

blackbox.yaml

1- targets:
2    - https://www.jobcher.com
3    - https://<域名>