LoginSignup
6
3

More than 5 years have passed since last update.

GrafanaでPrometheusのクエリで「変数と文字列」を結合して使用する方法

Posted at

概要

  • GrafanaのTemplatingのVariablesを使用する
  • 変数はロール名$role=(web|DB|batch)が選択できる
  • 実際には、web-blueやweb-greenがあるので、クエリでは$role-blueみたいに指定したい

説明

  • 画面上で複数選択すると発行されるクエリは、{instance=~"$role"}{instance=~"web|db|batch"}と展開される
  • なのでクエリを{instance=~"($role)-blue"}と記述してあげれば、{instance=~"(web|db|batch)-blue"}と展開される
    • 結果、正規表現として正しい形でクエリが展開される

デバッグ方法

  • グラフ定義画面で、「Link to Graph in Prometheus」をクリックする

image

  • Prometheusの画面が開いてGrafanaが実際に発行しているクエリが代入されている。

image

6
3
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
6
3