View Source PromEx.DashboardRenderer (PromEx v1.11.0)

This module is used to read dashboard definitions, render EEx dashboards, and ensure that requested files actually exist

Summary

Functions

This function will execute a provided function on the rendered dashboard to give the user a chance to adjust the dashboard definition.

Read the contents of a dashboard file entry. If an EEx version of the file exists, read that, else fallback to the provided file name. For example, if the requested dashboard file is ecto.json, if ecto.json.eex exists, then that will be returned. This is more so for convenience so that you don't need to write out .eex everywhere given that all PromEx 1st party dashboards are EEx templates.

This function will decode the JSON dashboard using Jason. If any errors occur during the decoding process, the struct will be marked as having invalid JSON.

This function will merge in the provided assigns to the struct's assigns. These assigns will then be used during the render_dashboard/1 call to render any EEx template statements.

Renders the dashboard. If it is an EEx file then the PromEx module assigns are passed. Else if it is a raw json file then it is passed through untouched.

Types

@type t() :: %PromEx.DashboardRenderer{
  assigns: keyword() | nil,
  decoded_dashboard: map() | nil,
  error: tuple() | nil,
  file_contents: String.t(),
  file_type: :eex | :json | nil,
  full_path: term(),
  otp_app: term(),
  relative_path: String.t(),
  rendered_file: String.t() | nil,
  valid_file?: boolean(),
  valid_json?: boolean() | nil
}

Functions

Link to this function

apply_dashboard_function(dashboard_render, apply_function)

View Source
@spec apply_dashboard_function(t(), (map() -> map())) :: t()

This function will execute a provided function on the rendered dashboard to give the user a chance to adjust the dashboard definition.

Link to this function

build(dashboard_otp_app, dashboard_relative_path, metrics_otp_app)

View Source
@spec build(
  dashboard_otp_app :: atom(),
  dashboard_relative_path :: String.t(),
  metrics_otp_app :: atom()
) :: t()

Read the contents of a dashboard file entry. If an EEx version of the file exists, read that, else fallback to the provided file name. For example, if the requested dashboard file is ecto.json, if ecto.json.eex exists, then that will be returned. This is more so for convenience so that you don't need to write out .eex everywhere given that all PromEx 1st party dashboards are EEx templates.

Link to this function

decode_dashboard(dashboard_render)

View Source
@spec decode_dashboard(t()) :: t()

This function will decode the JSON dashboard using Jason. If any errors occur during the decoding process, the struct will be marked as having invalid JSON.

Link to this function

merge_assigns(dashboard_render, additional_assigns)

View Source
@spec merge_assigns(
  t(),
  keyword()
) :: t()

This function will merge in the provided assigns to the struct's assigns. These assigns will then be used during the render_dashboard/1 call to render any EEx template statements.

Link to this function

render_dashboard(dashboard_render, prom_ex_module)

View Source
@spec render_dashboard(t(), prom_ex_module :: module()) :: t()

Renders the dashboard. If it is an EEx file then the PromEx module assigns are passed. Else if it is a raw json file then it is passed through untouched.