统一监控平台

# 1. 安装方法

# 1.1 上传并解压

上传monitors.tar.gz到目标服务器,并解压。 (scp monitors.tar.gz 用户@主机地址:目标目录)

scp monitors.tar.gz root@172.18.1.248:/opt

cd /opt

tar -xvf monitors.tar.gz

# 1.2 安装

进入monitors目录,执行install-all.sh脚本。

cd /opt/monitors

sh install-all.sh

# 1.3 验证

# 1.3.1 验证Prometheus

打开浏览器访问http://安装主机IP:9080,如 Prometheus (opens new window)

# 1.3.1 验证Grafana

打开浏览器访问http://安装主机IP:3003,如 Grafana (opens new window)

# 1.3.1 验证AlertManager

打开浏览器访问http://安装主机IP:3003,如 AlertManager (opens new window)

# 2. Prometheus

# 2.1 Job配置

编辑/opt/monitors/prometheus/prometheus.yml文件,在scrape_configs节点下加入job信息。(prometheus.yml文件路径根据实际情况调整)

/opt/monitors/prometheus/prometheus.yml

  # 操作系统Job
  - job_name: '操作系统'
    static_configs:
      - targets: ['127.0.0.1:9003']
  
  # 微服务Job
  - job_name: '微服务-注册中心'
    # 微服务支持actuator prometheus监控数据采集,并将状态数据转发到/actuator/prometheus路径下
    metrics_path: /actuator/prometheus
    static_configs:
      # 根据实际业务调整
      - targets: ['172.18.1.248:8000']

  # 其他Job
  - job_name: '端口存活状态'
    metrics_path: /probe
    params:
      module: [tcp_connect]
    # 检测端口存活
    static_configs:
      - targets: ['172.18.1.248:20001', '172.18.1.248:50200']
        labels:
          instance: '端口存活状态'
          group: 'tcp'
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 172.18.1.248:9115
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

# 2.2 规则配置

规则文件位于prometheus目录下的rules子目录,默认情况下会加载该目录下的所有规则文件。(通过prometheus.yml配置,指定规则文件)

rule_files:
  - "rules/*.yml"
1
2

默认支持icmp、linux、port、url检测规则, 可根据实际业务需要调整。当被监控目标触发规则告警时可通过Prometheus查看,如 Alert (opens new window)

# 2.3 AlertManager配置

当被监控对象触发rules后,会产生告警数据,可通过配置AlertManager接收Prometheus发出的告警数据。

alerting:
  alertmanagers:
    - static_configs:
        # 指定AlertManager服务地址
        - targets: ['localhost:9095']
1
2
3
4
5

# 3. Grafana

Grafana用于通过可视化图表呈现监控及告警信息。