tjtjtjのメモ

自分のためのメモです

Prometheus を試した

Prometheus 導入

Prometheus の監視の仕組み

scrape_configs:
- job_name: prometheus
  honor_timestamps: true
  scrape_interval: 15s
  scrape_timeout: 10s
  metrics_path: /metrics    <---
  scheme: http              <---
  static_configs:
  - targets:
    - localhost:9090        <--- 
  • scheme + targets + metrics_path を組み合わせる。 http://localhost:9090/metrics
  • これをブラウザ等で確認。リロードすると数字が変化するのがわかる
# HELP go_gc_duration_seconds A summary of the GC invocation durations.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0
go_gc_duration_seconds{quantile="0.25"} 0
go_gc_duration_seconds{quantile="0.5"} 0
go_gc_duration_seconds{quantile="0.75"} 0
go_gc_duration_seconds{quantile="1"} 0.001997
go_gc_duration_seconds_sum 0.0029972
go_gc_duration_seconds_count 15
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 42

というわけでPrometheusは設定scrape_configsの監視対象をプル(scrape)していることがわかる。

expoter 追加

# HELP blackbox_exporter_build_info A metric with a constant '1' value labeled by version, revision, branch, and goversion from which blackbox_exporter was built.
# TYPE blackbox_exporter_build_info gauge
blackbox_exporter_build_info{branch="HEAD",goversion="go1.11.5",revision="bba7ef76193948a333a5868a1ab38b864f7d968a",version="0.14.0"} 1
# HELP blackbox_exporter_config_last_reload_success_timestamp_seconds Timestamp of the last successful configuration reload.
# TYPE blackbox_exporter_config_last_reload_success_timestamp_seconds gauge
blackbox_exporter_config_last_reload_success_timestamp_seconds 1.564051261737019e+09
# HELP blackbox_exporter_config_last_reload_successful Blackbox exporter config loaded successfully.
# TYPE blackbox_exporter_config_last_reload_successful gauge
blackbox_exporter_config_last_reload_successful 1
  • ↑を監視対象(scrape)に追加。prometheus.yml を編集する
- job_name: 'blackbox'
  metrics_path: /metrics
  static_configs:
  - targets: ['localhost:9115']
  • prometheus 再起動
  • blackbox_exporter_build_info を execulte

まったく面白くないが監視対象は追加できた。

ここ http://localhost:9090/targets にも、balckbox が追加されている。

f:id:tjtjtjofthedead:20190725203039p:plain

prometheus architecture

今回試したのはこのあたり f:id:tjtjtjofthedead:20190725203849p:plain

参考

tech-lab.sios.jp