关于运维:利用-blackboxexporter-对网站运行状态进行监测

58次阅读

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

装置 blackbox_exporter

下载安装包

[root@local ~]# wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.18.0/blackbox_exporter-0.18.0.linux-amd64.tar.gz

将安装包解压

[root@local ~]# tar -xf blackbox_exporter-0.18.0.linux-amd64.tar.gz

进入解压目录并启动服务

[root@local ~]# cd blackbox_exporter-0.18.0.linux-amd64/
[root@local ~]#  nohup ./blackbox_exporter &

查看服务运行状态

[root@local ~]#  nohup ./blackbox_exporter &^C
[root@local ~]# ss -ntulp | grep 9115
tcp    LISTEN     0      128    [::]:9115               [::]:*                   users:(("blackbox_export",pid=3143,fd=3))

自定义 Prometheus 配置文件

写入一个文件 prometheus-additional.yaml

vim prometheus-additional.yaml
- job_name: 'blackbox-http'
  metrics_path: /probe
  params:
    modelue: [http_2xx]
  static_configs:
  - targets:
    - https://12bit.cn  #须要监控的 url
    - http://els-prod.yiyiny.com
    - http://wanjia-nfcp.yiyiny.com
    - http://pqlp.yiyiny.com
  relabel_configs:
    - source_labels: [__address__]
      target_label: __param_target
    - source_labels: [__param_target]
      target_label: instance
    - target_label: __address__
      replacement: 47.116.130.219:9115  #部署 blackbox_exporter 主机 ip

把这个文件创建为一个 secret 对象

kubectl create secret generic additional-configs --from-file=prometheus-additional.yaml -n monitoring
secret "additional-configs" created

批改 prometheus-prometheus.yaml

[root@kube-node01 manifests]# vim prometheus-prometheus.yaml

securityContext:
    fsGroup: 2000
    runAsNonRoot: true
    runAsUser: 1000
  additionalScrapeConfigs:  #新增
    name: additional-configs    #新增
    key: prometheus-additional.yaml #新增
  serviceAccountName: prometheus-k8s
  serviceMonitorNamespaceSelector: {}

增加实现后,apply 下这个文件

[root@kube-node01 manifests]# kubectl apply -f prometheus-prometheus.yaml
prometheus.monitoring.coreos.com“k8s”configured

验证

拜访 http://192.168.1.10:8002/targets 进行验证

效果图展现:

正文完
 0