关于prometheus:prometheus-简单例子

57次阅读

共计 1518 个字符,预计需要花费 4 分钟才能阅读完成。

1.node_exporter 用户明码验证拜访

yum install httpd-tools

htpasswd -nB "prometheus"

[root@node3 node_exporter]# htpasswd -nB "prometheus"
New password: 
Re-type new password: 
prometheus:$2y$05$TsMfhNUmHVD8PYmrAvWcNO5lisOfL25.5ybV0Z7t4NF43Aq1IennO

node_exporter web.config.yaml

basic_auth_users:
   prometheus: $2y$05$TsMfhNUmHVD8PYmrAvWcNxO5OxfL25x.5ybV0Z7t4NF43Aq1IennO

启动 node_exporter

./node_exporter --web.config=web.config.yaml

设置 node_exporter.service

[Unit]
Descriptiong=node_exporter
Documentation=
After=network.target

[Service]
WorkingDirectory=/opt/node_exporter/
ExecStart=/opt/node_exporter/node_exporter --web.config=/opt/node_exporter/web.config.yaml
ExecStop=/bin/kill -KILL $MAINPID
Type=simple
KillMode=control-group
RestartSec=3s

[Install]
WantedBy=multi-user.target

从新加载 systemd

systemctl daemon-reload

2. 将 node_exporter 退出到 prometheus

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: ['localhost:9090']
  
 - job_name: 'node'
    basic_auth:
      username: prometheus
      password: 123456
    static_configs:
    - targets: ['localhost:9100']

查看配置文件是否正确

./promtool check config prometheus.yml

退出胜利

alertmanager

定义 prometheus 规定

prometheus.yml

rule_files:
   - "rules/*.yml"

rules/target.yml

groups:
    - name: targetdown
      rules:
        - alert: target is down
          expr: up == 0
          for: 1m

查看 rules/target.yml

./promtool check rules rulues/target.yml

[root@node3 prometheus]# ./promtool check rules rule/target.yml 
Checking rule/target.yml
  SUCCESS: 1 rules found

prometheus 具体配置地址

https://prometheus.io/docs/pr…

正文完
 0