2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GCEでprometheusを使ってみた

2
Posted at

GCE上にインスタンスをいくつか作って、役割などに応じて、 api , web , db , staging , production などのタグを雑につけて運用しています。

その状況で、prometheus を導入していろいろメトリクスを取りたくなりました。

ということで、以下のようなことをやりました。

credeitial の生成

https://developers.google.com/identity/protocols/application-default-credentials
この辺を参照して、credential の json を取得し、prometheus を実行するホストの ~/.config/gcloud/application_default_credentials.json に配置します。

gce_sd_config

__meta_gce_tags は、例えば foo と bar というタグが付いていたら、 ,foo,bar, という値を返すようです。

redis_exporter について

redis_exporter は、起動時の引数として対象となるredis server のアドレスをいくつも並べる形になっています。
が、それではちょっと管理しにくいので、redis の各インスタンスでそれぞれ localhost を向けた redis_exporter を動かすことにしました。

最終的な prometheus.yml

最終的にはこんな感じになりました。

  - job_name: 'node'
    gce_sd_configs:
    - project: XXXXXXXXX
      zone: asia-east1-c
      port: 9100
    relabel_configs:
    - source_labels: [__meta_gce_instance_name]
      target_label: instance
      regex: (.*)
      replacement: $1
    - source_labels: [__meta_gce_tags]
      target_label: stage
      regex: ".*,(staging|production),.*"
      replacement: $1
    - source_labels: [__meta_gce_tags]
      target_label: role
      regex: ".*,(api|web|db|redis),.*"
      replacement: $1

  - job_name: 'redis_exporter'
    gce_sd_configs:
    - project: XXXXXXXXX
      zone: asia-east1-c
      port: 9121
    relabel_configs:
    - source_labels: [__meta_gce_instance_name]
      target_label: instance
      regex: (.*)
      replacement: $1
    - source_labels: [__meta_gce_tags]
      target_label: stage
      regex: ".*,(staging|production),.*"
      replacement: $1
    - source_labels: [__meta_gce_tags]
      target_label: role
      regex: ".*,redis,.*"
      action: keep

もう少し、regexのあたりとかうまくやれそうに見えますが…
とりあえずいい感じに動いたので良しとします。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?