Prometheus监控-BlackExporter部署

2021-06-0913:54:51
评论
3,627 3116字

黑盒检测就是监测应用程序的外部,可以查询应用程序的外部特征,比如是否相应开放端口上的轮询并返回正确的数据或响应代码,探测监视的一个实例是执行icmp或者echo检查并确认收到响应,这种类型的探测也称为黑盒监视

prometheus探测工具是通过运行一个blackbox exporter来探测远程目标,并公开在本地端点上手机的任何时间序列

监视探测的三个限制

  1. 我们需要能够到达探测的资源地
  2. 需要测试到资源的正确路径
  3. 探测的位置能够被prometheus

 

blackbox_exporter是一个二进制Go应用程序,默认监听端口9115。exporter允许通过HTTP、HTTPS、DNS、TCP和ICMP探测端点。在exporter中,我们定义一系列执行特定检查的模块,例:检查正在运行的web服务器,或者DNS解析记录。当exporter运行时,它会在URL上公开这些模块和API。

## 下载

wget https://oss.pealog.com/env/prometheus/blackbox_exporter/blackbox_exporter-0.19.0.linux-amd64.tar.gz
tar -zxvf blackbox_exporter-0.19.0.linux-amd64.tar.gz -C /usr/local/
mv /usr/local/blackbox_exporter-0.19.0.linux-amd64/ /usr/local/blackbox_exporter

## 添加到启动项

cat > /usr/lib/systemd/system/blackbox_exporter.service<<EOF

[Unit]
Description=blackbox_exporter
After=network.target
[Service]
WorkingDirectory=/usr/local/blackbox_exporter
ExecStart=/usr/local/blackbox_exporter/blackbox_exporter \
         --config.file=/usr/local/blackbox_exporter/blackbox.yml
[Install]
WantedBy=multi-user.target
EOF

## 现在使用下面的systemctl命令重新加载systemd系统,并查看服务是否启动

systemctl daemon-reload
systemctl enable blackbox_exporter
systemctl start blackbox_exporter
systemctl status blackbox_exporter

systemctl restart blackbox_exporter
systemctl status blackbox_exporter

## 确认端口(9115)

ss -anltp | grep 9115
netstat -tnlp | grep blackbox

## 配置Prometheus,收集node exporter的数据

mkdir -pv /usr/local/prometheus/blackbox_rules/
vim /usr/local/prometheus/prometheus.yml
   - job_name: 'icmp_ping' # 检测是否可以ping通某些机器
    scrape_interval: 30s
    metrics_path: /probe
    params:
      module: [icmp]
    static_configs:
      - targets:
        - 127.0.0.1
      - targets: ['220.181.38.150','14.215.177.39','180.101.49.12','14.215.177.39','180.101.49.11','14.215.177.38','14.215.177.38']
        labels:
          group: '一线城市-电信网络监控'
      - targets: ['112.80.248.75','163.177.151.109','61.135.169.125','163.177.151.110','180.101.49.11','61.135.169.121','180.101.49.11']
        labels:
          group: '一线城市-联通网络监控'
      - targets: ['183.232.231.172','36.152.44.95','182.61.200.6','36.152.44.96','220.181.38.149']
        labels:
          group: '一线城市-移动网络监控' 
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9115 # black_exporter 这里和Prometheus在一台机器上
		

  - job_name: "blackbox_http_2xx"
    metrics_path: /probe
    params:
      module: [http_2xx]  #使用http模块
    static_configs:
    - targets:
      - https://pealog.com
      - https://www.google.com
    relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: 127.0.0.1:9115

  - job_name: 'port_status'
    metrics_path: /probe
    params:
      module: [tcp_connect]  #使用tcp模块
    static_configs:
      - targets: ['127.0.0.1:22','127.0.0.1:66']  #对应主机接口
        labels:
          instance: 'port_status'
          group: 'tcp'
    relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target 
    - target_label: __address__
      replacement: 127.0.0.1:9115

# 重启

检查配置文件是否书写正确

/usr/local/prometheus/promtool  check config /usr/local/prometheus/prometheus.yml

 

重新加载prometheus的配置

#systemctl reload prometheus

curl -XPOST http://127.0.0.1:9090/-/reload

 

检查prometheus状态

systemctl status  prometheus

 

## Grafana ID

9965

基本翻译
abbr. 超文本传输协议安全(Hyper Text Transfer Protocol)
网络释义
HTTPS: 安全超文本传输协议(Hypertext Transfer Protocol Secure)
android https: 通信安全
豌豆日志
  • 本文由 发表于 2021-06-0913:54:51
  • 转载请务必保留本文链接:https://pealog.com/502.html
Prometheus监控-AlertManager部署 系统运维

Prometheus监控-AlertManager部署

Alertmanager是一个独立的告警模块,接收Prometheus等客户端发来的警报,之后通过分组、删除重复等处理,并将它们通过路由发送给正确的接收器;告警方式可以按照不同的规则发送给不同的模块负...
Prometheus监控-NodeExporter部署 系统运维

Prometheus监控-NodeExporter部署

与传统的监控zabbix来对比的话,prometheus-server就像是mysql,负责存储数据。只不过这是时序数据库而不是关系型的数据库。数据的收集还需要其他的客户端,在prometheus中叫...
CentOS6更换有效源 系统运维

CentOS6更换有效源

前言 CentOS6官方在2020/11/30已停止维护,yum的Base源已失效 操作   YUM源 备份文件 cp CentOS-Base.repo CentOS-Base.repo.b...
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: