码迷,mamicode.com
首页 > Web开发 > 详细

Prometheus使用blackbox_exporter监控端口及网站状态(六)

时间:2020-05-12 17:02:10      阅读:311      评论:0      收藏:0      [点我收藏+]

标签:app   时间   one   install   usr   linux   https   service   nec   

一、blackbox_exporter应用场景

HTTP 测试: 定义 Request Header 信息、判断 Http status / Http Respones Header / Http Body 内容
TCP 测试:   业务组件端口状态监听、应用层协议定义与监听
ICMP 测试: 主机探活机制
POST 测试: 接口联通性
SSL证书过期时间

二、blackbox_exporter安装

# wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.16.0/blackbox_exporter-0.16.0.linux-amd64.tar.gz

# tar xf blackbox_exporter-0.16.0.linux-amd64.tar.gz -C /usr/local/
# ln -s /usr/local/blackbox_exporter-0.16.0.linux-amd64/ /usr/local/blackbox_exporter

# 使用systemd进行管理blackbox_exporter服务
# vim /usr/lib/systemd/system/blackbox_exporter.service
[Unit]
Description=blackbox_exporter
After=network.target

[Service]
User=root
Type=simple
ExecStart=/usr/local/blackbox_exporter/blackbox_exporter --config.file=/usr/local/blackbox_exporter/blackbox.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target

# systemctl daemon-reload
# systemctl start blackbox_exporter.service 
# systemctl enable blackbox_exporter.service 

三、配置prometheus采集数据

# cd /usr/local/prometheus
# vim prometheus.yml
# my global config
global:
  scrape_interval:     15s
  evaluation_interval: 15s
alerting:
  alertmanagers:
  - static_configs:
    - targets:
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"
scrape_configs:
  - job_name: prometheus

    static_configs:
    - targets: [192.168.5.237:9090]

  - job_name: node
    file_sd_configs:
    - refresh_interval: 30s
      files: 
      - "/usr/local/prometheus/sd_config/node*.yml"

  - job_name: docker
    static_configs:
    - targets: [192.168.5.85:8080]

  - job_name: mysql
    static_configs:
    - targets: [192.168.5.237:9104]
      labels:
        app: zabbix-server-mysql
# 网站监控
- job_name: http_status metrics_path: /probe params: module: [http_2xx] static_configs: - targets: [http://www.lzfn.com, wiki.lzfn.com] labels: instance: http_status group: web relabel_configs: - source_labels: [__address__] target_label: __param_target - target_label: __address__ replacement: 192.168.5.85:9115 # ping 检测 - job_name: ping_status metrics_path: /probe params: module: [icmp] static_configs: - targets: [192.168.5.85] labels: instance: ping_status group: icmp relabel_configs: - source_labels: [__address__] target_label: __param_target - target_label: __address__ replacement: 192.168.5.85:9115 # 端口监控 - job_name: port_status metrics_path: /probe params: module: [tcp_connect] static_configs: - targets: [192.168.5.85:80, 192.168.5.85:9000, 192.168.5.85:8080] labels: instance: port_status group: port relabel_configs: - source_labels: [__address__] target_label: __param_target - target_label: __address__ replacement: 192.168.5.85:9115
# 检查配置文件并重启服务 # .
/promtool check config prometheus.yml Checking prometheus.yml SUCCESS: 0 rule files found # systemctl restart prometheus.service

四、配置Grafana展示数据

使用9965模板,需要安装饼状态图插件,安装后重启grafana

grafana-cli plugins install grafana-piechart-panel
systemctl restart grafana-server.service 

技术图片

技术图片

 

Prometheus使用blackbox_exporter监控端口及网站状态(六)

标签:app   时间   one   install   usr   linux   https   service   nec   

原文地址:https://www.cnblogs.com/cyleon/p/12876897.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!