PromEx.GrafanaClient (PromEx v1.12.0)

Copy Markdown View Source

This module is used by the Mix tasks that are available in PromEx to update dashboards in Grafana and also by the PromEx.DashboardUpdater to update dashboards automatically on application initialization.

Dashboard models: https://grafana.com/docs/grafana/latest/dashboards/json-model/

Summary

Functions

Build a grafana client connection.

Used to create annotations on dashboard panels.

Used to create a new folder in Grafana

Get all of the folder that exist in Grafana

Used to get the dashboard definition currently in Grafana for the provided dashboard file. If the ID does not exist in Grafana an error tuple will be returned.

Used to fetch the details regarding a particular folder on Grafana

Used to create a new dashboard or update an existing dashboard.

Functions

build_conn(prom_ex_module)

@spec build_conn(prom_ex_module :: module()) :: PromEx.GrafanaClient.Connection.t()

Build a grafana client connection.

create_annotation(grafana_conn, tags, message, opts \\ [])

@spec create_annotation(
  grafana_conn :: PromEx.GrafanaClient.Connection.t(),
  tags :: [String.t()],
  message :: String.t(),
  opts :: keyword()
) :: handler_response()

Used to create annotations on dashboard panels.

Option Details

  • :dashboard_id - Create a dashboard specific annotation. Optional
  • :panel_id - Create a panel specific annotation. Optional
  • :time - Specify the time of the annotation. When non is supplied the annotation is inferred by grafana. Optional
  • :time_end - Specify to great a region annotation. Optional

create_folder(grafana_conn, folder_uid, title)

@spec create_folder(
  grafana_conn :: PromEx.GrafanaClient.Connection.t(),
  folder_uid :: String.t(),
  title :: String.t()
) :: handler_response()

Used to create a new folder in Grafana

get_all_folders(grafana_conn)

@spec get_all_folders(grafana_conn :: PromEx.GrafanaClient.Connection.t()) ::
  handler_response()

Get all of the folder that exist in Grafana

get_dashboard(grafana_conn, dashboard_contents)

@spec get_dashboard(
  grafana_conn :: PromEx.GrafanaClient.Connection.t(),
  dashboard_file_path :: String.t()
) :: handler_response()

Used to get the dashboard definition currently in Grafana for the provided dashboard file. If the ID does not exist in Grafana an error tuple will be returned.

get_folder(grafana_conn, folder_id)

@spec get_folder(
  grafana_conn :: PromEx.GrafanaClient.Connection.t(),
  folder_uid :: String.t()
) ::
  handler_response()

Used to fetch the details regarding a particular folder on Grafana

update_folder(grafana_conn, folder_uid, new_title, attrs \\ %{})

@spec update_folder(
  grafana_conn :: PromEx.GrafanaClient.Connection.t(),
  folder_uid :: String.t(),
  new_title :: String.t(),
  attrs :: map()
) :: handler_response()

Update an existing folder in Grafana

upload_dashboard(grafana_conn, dashboard_contents, opts \\ [])

@spec upload_dashboard(
  grafana_conn :: PromEx.GrafanaClient.Connection.t(),
  dashboard_file_path :: String.t(),
  opts :: keyword()
) :: handler_response()

Used to create a new dashboard or update an existing dashboard.