prometheus 简单例子

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

prometheus 简单例子_第1张图片

设置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=` 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

加入成功
prometheus 简单例子_第2张图片

alertmanager

prometheus 简单例子_第3张图片

定义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...

你可能感兴趣的:(prometheus)