LoginSignup
0
0

More than 5 years have passed since last update.

Grafana で設定されているグラフのクエリ式をさっと確認する

Last updated at Posted at 2017-03-08

grafana-print-expr.sh

#!/bin/bash

set -eu

for dashboard in "$@"; do
  curl -s \
    -H "Authorization: Bearer $GRAFANA_KEY" \
    -H "Content-type: application/json" \
    "http://$GRAFANA_HOST/api/dashboards/db/$dashboard" |
    jq -r --arg dashboard "$dashboard" '
      .dashboard.rows[].panels[] |
      select(has("targets")) |
      ["[" + $dashboard + "::" + .title + "]", (.targets[].expr | . + "\n")][]
    ' |
    sed 's/^\[/\x1b[0;32m[/' |
    sed 's/\]$/]\x1b[m/'
done

例えばこんな感じの出力が得られる。

./grafana-print-expr.sh prometheus-stats
[prometheus-stats::Uptime]
(time() - process_start_time_seconds{job="prometheus"})

[prometheus-stats::Local Storage Memory Series]
prometheus_local_storage_memory_series

[prometheus-stats::Interal Storage Queue Length]
prometheus_local_storage_indexing_queue_length

[prometheus-stats::Samples ingested (rate-5m)]
rate(prometheus_local_storage_ingested_samples_total[5m])

[prometheus-stats::Target Scrapes (last 5m)]
rate(prometheus_target_interval_length_seconds_count[5m])

[prometheus-stats::Scrape Duration]
prometheus_target_interval_length_seconds{quantile!="0.01", quantile!="0.05"}

[prometheus-stats::Rule Eval Duration]
prometheus_evaluator_duration_seconds{quantile!="0.01", quantile!="0.05"}
0
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
0
0