Prometheus部署
开源的监控告警系统
- prometheus server 核心组件,收集与存储时间序列数据
- CLient Library 客户端库,为需要监控的服务生成相应的 metrics 并暴露给 Prometheus server
- push gateway 主要用于短期的 jobs。由于这类 jobs 存在时间较短,可能在 Prometheus 来 pull 之前就消失了, 此,这次 jobs 可以直接向 Prometheus server 端推送它们的 metrics
- Exporters 用于暴露已有的第三方服务的 metrics 给 Prometheus。
- Alertmanager 从 Prometheus server 端接收到 alerts 后,会进行去除重复数据,分组,并路由到对收的接受方式,发出报警
- 下载
mkdir /opt/softwarecd /opt/softwarewget https://github.com/prometheus/prometheus/releases/download/v3.1.0-rc.1/prometheus-3.1.0-rc.1.linux-amd64.tar.gztar -zxvf prometheus-3.1.0-rc.1.linux-amd64.tar.gzcd prometheus-3.1.0-rc.1.linux-amd64cp -r prometheus /usr/bin/- 配置
# my global configglobal: 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 configurationalerting: alertmanagers: - static_configs: - targets: # - alertmanager: 9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.rule_files: # - "first_rules.yml" # - "second_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:10090"]- 启动
./prometheus --config.file=prometheus.yml --web.listen-address=:10090# 访问 http://localhost: 10900 查看面板# 访问 http://localhost: 10900/metrics 查看暴露的指标信息- 配置 systemd
[Unit]Description=Prometheus ServerDocumentation=https://prometheus.io/docs/After=network-online.targetWants=network-online.target
[Service]Type=simpleExecStart=/opt/software/prometheus-3.1.0-rc.1.linux-amd64/prometheus \ # Prometheus 二进制文件的路径 --config.file=/opt/software/prometheus-3.1.0-rc.1.linux-amd64/prometheus.yml \ # Prometheus 配置文件的路径 --storage.tsdb.path=/opt/software/prometheus-3.1.0-rc.1.linux-amd64/data \ # Prometheus 数据存储路径 --web.listen-address=:10090 \ # Prometheus 监听地址和端口 --web.enable-lifecycle # 允许通过 API 重载配置Restart=on-failure # 在 Prometheus 崩溃时自动重启RestartSec=5s # 重启间隔时间
[Install]WantedBy=multi-user.target- 管理服务
systemctl restart prometheussystemctl start prometheussystemctl stop prometheussystemctl status prometheus4. Node Exporter 安装
Section titled “4. Node Exporter 安装”- 下载
mkdir /opt/softwarecd /opt/softwarewget https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gztar -zxvf node_exporter-1.8.2.linux-amd64.tar.gzcd node_exporter-1.8.2.linux-amd64cp -r node_exporter /usr/bin/- 配置
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:10090"] - job_name: 'node' static_configs: - targets: ['localhost:9100'] - job_name: 'apisix' scrape_interval: 10s metrics_path: '/apisix/prometheus/metrics' static_configs: - targets: ['localhost:9091']参考:https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md
- 启动
/opt/software/node_exporter-1.8.2.linux-amd64/node_exporter --web.listen-address=:9100- 配置 systemd
[Unit]Description=Prometheus Node Exporter ServerDocumentation=https://prometheus.io/docs/After=network-online.targetWants=network-online.target
[Service]Type=simpleExecStart=/opt/software/node_exporter-1.8.2.linux-amd64/node_exporter \ --web.listen-address=:9100Restart=on-failureRestartSec=5s
[Install]WantedBy=multi-user.target- 管理服务
systemctl restart prometheus-nodesystemctl start prometheus-nodesystemctl stop prometheus-nodesystemctl status prometheus-node5. 拓展信息
Section titled “5. 拓展信息”…