IBM Cloud Docs
使用 Prometheus Blackbox 匯出器收集可用性度量值

使用 Prometheus Blackbox 匯出器收集可用性度量值

Prometheus Blackbox Exporter 允許透過 HTTP、HTTPS、DNS、TCP 和 ICMP 對端點進行黑盒探測。 監視代理程式可以與 Blackbox 匯出器一起使用,以收集可用性度量值。 可用性指標可在 IBM Cloud Monitoring 中發出警示,提醒使用者端點的可用性。

完成下列步驟,以配置 Prometheus Blackbox Exporter:

配置監視代理程式以收集度量值

若要監視一或多個主機,您必須配置監視代理程式。 代理程式會自動收集一組您可以透過監視使用者介面監視的度量值。

請參閱 依基礎結構選擇代理程式類型,然後選擇要設定為監控主機的監控代理程式。

安裝 Prometheus Blackbox 匯出器

請完成下列步驟,以 Docker 儲存器形式執行 Blackbox 匯出器:

  1. 從 Github 下載 blackbox.yml 檔案

    將檔案儲存至 /config/prometheus/blackbox/ 目錄。

  2. 將 Blackbox 匯出器作為 Docker 儲存器執行:

    docker run --rm -d -p 9115:9115 -l io.prometheus.scrape=true -l io.prometheus.port=9115 -l io.prometheus.path=/probe --name blackbox_exporter -v `pwd`:/config/prometheus/blackbox prom/blackbox-exporter:master --config.file=/config/prometheus/blackbox/blackbox.yml
    
  3. 請檢查匯出器是否已啟動。 執行下列指令:

    docker container ls
    

    您可以看到類似於下列輸出的輸出:

    CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS              PORTS                    NAMES
    2480a0034bb4        prom/blackbox-exporter:master   "/bin/blackbox_expor…"   36 minutes ago      Up 36 minutes       0.0.0.0:9115->9115/tcp   blackbox_exporter
    

    若要停止 blackbox 儲存器,請執行下列指令: docker container stop 2480a0034bb4

配置網路設定

如果您想要從遠端伺服器收集度量值,請完成下列步驟:

  1. 啟用防火牆以容許存取 blackbox_exporter

  2. [選用] 更新 VPC 規則

    如果您使用專用端點,請使用 source type = Security Group 將入埠規則新增至埠 9115 的安全群組,並選擇伺服器的安全群組。

更新在伺服器中執行的監視代理程式

執行下列指令,以編輯 configmap 並新增您要使用 Kubernetes 監視代理程式監視之 Blackbox 目標的相關資訊:

kubectl edit configmap sysdig-agent -n ibm-observe
log:
  file_priority: error
configmap: true
### Agent tags
# tags: linux:ubuntu,dept:dev,local:nyc

#### Monitoring Software related config ####

# Monitoring collector address
# collector: 192.168.1.1

# Collector TCP port
# collector_port: 6666

# Whether collector accepts ssl
# ssl: true

# collector certificate validation
# ssl_verify_certificate: true

#######################################
# new_k8s: true
# k8s_cluster_name: production
security:
  k8s_audit_server_url: 0.0.0.0
  k8s_audit_server_port: 7765
k8s_cluster_name: <CLUSTER_NAME>/<CLUSTER_ID>
tags: ibm.containers-kubernetes.cluster.id:<CLUSTER_ID>
collector: <INGESTION_ENDPOINT>
collector_port: 6443
ssl: true
ssl_verify_certificate: true
sysdig_capture_enabled: false
promscrape_fastproto: true
use_promscrape: true
prometheus:
  enabled: true
  prom_service_discovery: true
  log_errors: true
  max_metrics: 200000
  max_metrics_per_process: 200000
  max_tags_per_metric: 100
  ingest_raw: true
  ingest_calculated: false
prometheus.yaml:
----
global:
  scrape_interval: 10s
scrape_configs:
- job_name: blackbox
  metrics_path: /probe
  params:
    module: [http_2xx]
  static_configs:
  - targets:
    - https://prometheus.io/
    - https://www.google.com/search?q=promcat
    - https://www.ibm.com/software/passportadvantage
  relabel_configs:
  - source_labels: [__address__]
    target_label: __param_target
  - source_labels: [__param_target]
    target_label: instance
  - source_labels: [__param_target]
    target_label: blackbox_instance
  - target_label: __address__
    replacement: blackbox-exporter.ibm-observe:9115

其中

  • <IP_ADDRESS_OF_REMOTE_SERVER> 是您要監控的伺服器的 IP 位址。
  • <INGESTION_ENDPOINT> 是 IBM Cloud Monitoring 實例汲取端點,例如 ingest.us-south.monitoring.cloud.ibm.com。 請參閱 收集器端點

當您儲存檔案時,會套用變更。

配置預設儀表板及警示以分析伺服器的 Blackbox 狀態

請完成下列步驟:

  1. 啟動監視使用者介面

  2. 建立儀表板。

  3. 為下列每一個查詢新增一個畫面:

Blackbox 匯出器範例查詢
度量 查詢 選項
依實例的狀態碼 probe_http_status_code{instance=$instance} number (auto)
SSL 憑證期限 (以天數為單位) probe_ssl_earliest_cert_expiry{instance=$instance}-time() time (auto)
DNS 查閱 probe_dns_lookup_time_seconds{instance=$instance} time (auto)
探測持續時間 probe_duration_seconds{instance=$instance} time (auto)

例如,您可以建立如下所示的儀表板:

Blackbox 儀表板範例
Blackbox 儀表板範例