Blackbox ExporterのメトリクスをPrometheusを介さず、直接Wavefrontに送る


TL;DR

Blackboxエクスポーターに限らず、Prometheus式のメトリクスを吐くエンドポイントであれば、Prometheusを介さずに直接Wavefrontに送れます。

始めに

Wavefront(正規名称Tanzu Observability)とは、SaaSベースの監視基盤であり、Kubernetesなどの環境にインストールすると、監視をするためのメトリクス収集を行ってくれます。

本来はPrometheusが不要なソリューションなのですが、Prometheusを使い込んでいるユーザーが既存の資産を使い続けたい場合、それの取り込み方法が課題となります。

その場合、連携方法として2つあり、1つがこの記事で紹介したようPrometheusをRelayのように扱いメトリクスを送信する方法、もうひとつが個々のエンドポイントをWavefront Collector経由でScrapeして転送する方法です。

この例では、URL監視に使うBlackbox Exporterを環境に追加して、Prometheusを無しに直接Wavefrontに転送する方法を紹介します。

事前準備

以下を準備してください。

  • WavefrontのアカウントとAPIキー
  • Kubernetes環境
  • Helm(v3) cliのインストール

Blackbox Exporterのインストール

まずはURL監視コンポーネントのBlackbox Exporterをインストールします。

kubectl create ns blackbox
helm install prom-black stable/prometheus-blackbox-exporter --namespace blackbox

稼働しているか確認します。今回は同じnamespaceにalpine podを起動して、そこからcurlを行います。

kubectl run -i --tty --image=alpine alpine -n blackbox -- sh

プロンプトが起動したら以下のコマンドでcurlを実行します。

apk add curl
curl 'prom-black-prometheus-blackbox-exporter:9115/probe?target=http://google.com&module=http_2xx'

以下のような出力が買ってくればOKです。

# HELP probe_dns_lookup_time_seconds Returns the time taken for probe dns lookup in seconds
# TYPE probe_dns_lookup_time_seconds gauge
probe_dns_lookup_time_seconds 0.004944754
# HELP probe_duration_seconds Returns how long the probe took to complete in seconds
# TYPE probe_duration_seconds gauge
probe_duration_seconds 0.099084546
# HELP probe_failed_due_to_regex Indicates if probe failed due to regex
# TYPE probe_failed_due_to_regex gauge
probe_failed_due_to_regex 0
# HELP probe_http_content_length Length of http content response
# TYPE probe_http_content_length gauge
probe_http_content_length -1
# HELP probe_http_duration_seconds Duration of http request by phase, summed over all redirects
# TYPE probe_http_duration_seconds gauge
probe_http_duration_seconds{phase="connect"} 0.0049864620000000005
probe_http_duration_seconds{phase="processing"} 0.083818997
probe_http_duration_seconds{phase="resolve"} 0.009260726
probe_http_duration_seconds{phase="tls"} 0
probe_http_duration_seconds{phase="transfer"} 0.000294504
# HELP probe_http_redirects The number of redirects
# TYPE probe_http_redirects gauge
probe_http_redirects 1
# HELP probe_http_ssl Indicates if SSL was used for the final redirect
# TYPE probe_http_ssl gauge
probe_http_ssl 0
# HELP probe_http_status_code Response HTTP status code
# TYPE probe_http_status_code gauge
probe_http_status_code 200
# HELP probe_http_uncompressed_body_length Length of uncompressed response body
# TYPE probe_http_uncompressed_body_length gauge
probe_http_uncompressed_body_length 13392
# HELP probe_http_version Returns the version of HTTP of the probe response
# TYPE probe_http_version gauge
probe_http_version 1.1
# HELP probe_ip_protocol Specifies whether probe ip protocol is IP4 or IP6
# TYPE probe_ip_protocol gauge
probe_ip_protocol 4
# HELP probe_success Displays whether or not the probe was a success
# TYPE probe_success gauge
probe_success 1

なお、上記コマンドですが、http://google.comへリクエストを送った際のメトリクスを出力するコマンドです。本来は、監視したいアプリのURLなどを指定しますが、今回はテストなので、googleを使います。

Wavefrontのインストール

まず、WavefrontのhelmチャートのRepositoryを追加します。

helm repo add wavefront https://wavefronthq.github.io/helm/
helm repo update

次に以下のようなファイルをmyvalues.ymlとして保存します。
なお、XXXXには、Wavefrontのアカウントに対応した値を入れてください。

clusterName: mhoshi-test

wavefront:
  url: https://XXXX.wavefront.com
  token: XXXXXXXXXX

collector:
  discovery:
    enabled: true
    config:
    - name: blackbox-exporter-google
      type: prometheus
      port: 9115
      path: '/probe?target=http://google.com&module=http_2xx'
      selectors:
        labels:
          app.kubernetes.io/instance:
          - prom-black
      prefix: blackbox.google.

Wavefrontをインストールします。

kubectrl create ns wavefront
helm install -f myvalues.yml wavefront wavefront/wavefront --namespace wavefront

PODを確認して起動しているか確認します。

mhoshino@mhoshino ~ % kubectl get po -n wavefront
NAME                              READY   STATUS    RESTARTS   AGE
wavefront-collector-49rrh         1/1     Running   0          52s
wavefront-collector-8h86x         1/1     Running   0          52s
wavefront-collector-j5qhx         1/1     Running   0          52s
wavefront-collector-rwxd7         1/1     Running   0          52s
wavefront-proxy-5db9d8c45-46n7f   1/1     Running   0          52s

ここまでで、起動は完了です。

もし、のちの手順で問題がある場合、いずれかのwavefront-collector-*に以下のようにエンドポイントがディスカバーされたログが出力されるているか確認します。

time="2020-08-05T06:12:49Z" level=info msg="Adding provider" collection_interval=0s name="prometheus_metrics_provider: blackbox-pod-prom-black-prometheus-blackbox-exporter-7dbf585f57-624m4:9115" timeout=30s
time="2020-08-05T06:12:49Z" level=info msg="Using default collection interval" collection_interval=1m0s provider="prometheus_metrics_provider: blackbox-pod-prom-black-prometheus-blackbox-exporter-7dbf585f57-624m4:9115"

Wavefront側の確認

Wavefrontからはmyvalues.yml内のprefixで始まるメトリクスが表示されるようになるはずです。
Browse > Metricsからblackbox.google.の内容を検索します。
するとメトリクスが収集されていることがわかります。

さらに、blackbox.google.probe.duration.seconds.gaugeなどをみると、収集されたメトリクスの詳細を確認できます。

まとめ

今回はBlackbox Exporterを使った例を紹介しましたが、テクニカルにはいかなるエンドポイントもつなげることができるはずです。

PrometheusからWavefrontの移行には使える機能と思います。