Skip to content

DashboardBuilder🔗

Constructor🔗

new DashboardBuilder(title: string)

Methods🔗

build🔗

Builds the object.

build()

annotation🔗

Contains the list of annotations that are associated with the dashboard.

Annotations are used to overlay event markers and overlay event tags on graphs.

Grafana comes with a native annotation store and the ability to add annotation events directly from the graph panel or via the HTTP API.

See https://grafana.com/docs/grafana/latest/dashboards/build-dashboards/annotate-visualizations/

annotation(annotation: cog.Builder<dashboard.AnnotationQuery>)

annotations🔗

Contains the list of annotations that are associated with the dashboard.

Annotations are used to overlay event markers and overlay event tags on graphs.

Grafana comes with a native annotation store and the ability to add annotation events directly from the graph panel or via the HTTP API.

See https://grafana.com/docs/grafana/latest/dashboards/build-dashboards/annotate-visualizations/

annotations(annotations: cog.Builder<dashboard.AnnotationQuery>[])

description🔗

Description of dashboard.

description(description: string)

editable🔗

Whether a dashboard is editable or not.

editable()

fiscalYearStartMonth🔗

The month that the fiscal year starts on. 0 = January, 11 = December

fiscalYearStartMonth(fiscalYearStartMonth: number)

gnetId🔗

ID of a dashboard imported from the https://grafana.com/grafana/dashboards/ portal

gnetId(gnetId: string)

id🔗

Unique numeric identifier for the dashboard.

id is internal to a specific Grafana instance. uid should be used to identify a dashboard across Grafana instances.

id(id: number | null)

Links with references to other dashboards or external websites.

link(link: cog.Builder<dashboard.DashboardLink>)

Links with references to other dashboards or external websites.

links(links: cog.Builder<dashboard.DashboardLink>[])

liveNow🔗

When set to true, the dashboard will redraw panels at an interval matching the pixel width.

This will keep data "moving left" regardless of the query refresh rate. This setting helps

avoid dashboards presenting stale live data

liveNow(liveNow: boolean)

preload🔗

When set to true, the dashboard will load all panels in the dashboard when it's loaded.

preload(preload: boolean)

readonly🔗

Whether a dashboard is editable or not.

readonly()

refresh🔗

Refresh rate of dashboard. Represented via interval string, e.g. "5s", "1m", "1h", "1d".

refresh(refresh: string)

revision🔗

This property should only be used in dashboards defined by plugins. It is a quick check

to see if the version has changed since the last time.

revision(revision: number)

snapshot🔗

Snapshot options. They are present only if the dashboard is a snapshot.

snapshot(snapshot: cog.Builder<dashboard.Snapshot>)

tags🔗

Tags associated with dashboard.

tags(tags: string[])

time🔗

Time range for dashboard.

Accepted values are relative time strings like {from: 'now-6h', to: 'now'} or absolute time strings like {from: '2020-07-10T08:00:00.000Z', to: '2020-07-10T14:00:00.000Z'}.

time(time: {
    from: string;
    to: string;
})

timepicker🔗

Configuration of the time picker shown at the top of a dashboard.

timepicker(timepicker: cog.Builder<dashboard.TimePickerConfig>)

timezone🔗

Timezone of dashboard. Accepted values are IANA TZDB zone ID or "browser" or "utc".

timezone(timezone: string)

title🔗

Title of dashboard.

title(title: string)

tooltip🔗

Configuration of dashboard cursor sync behavior.

Accepted values are 0 (sync turned off), 1 (shared crosshair), 2 (shared crosshair and tooltip).

tooltip(graphTooltip: dashboard.DashboardCursorSync)

uid🔗

Unique dashboard identifier that can be generated by anyone. string (8-40)

uid(uid: string)

variables🔗

Configured template variables

variables(variables: cog.Builder<dashboard.VariableModel>[])

version🔗

Version of the dashboard, incremented each time the dashboard is updated.

version(version: number)

weekStart🔗

Day when the week starts. Expressed by the name of the day in lowercase, e.g. "monday".

weekStart(weekStart: string)

withPanel🔗

withPanel(panel: cog.Builder<dashboard.Panel>)

withRow🔗

withRow(rowPanel: cog.Builder<dashboard.RowPanel>)

withVariable🔗

Configured template variables

withVariable(variable: cog.Builder<dashboard.VariableModel>)

Examples🔗

Building a dashboard🔗

import { DashboardBuilder, RowBuilder } from '@grafana/grafana-foundation-sdk/dashboard';
import { DataqueryBuilder } from '@grafana/grafana-foundation-sdk/prometheus';
import { PanelBuilder } from '@grafana/grafana-foundation-sdk/timeseries';

const builder = new DashboardBuilder('[TEST] Node Exporter / Raspberry')
  .uid('test-dashboard-raspberry')
  .tags(['generated', 'raspberrypi-node-integration'])

  .refresh('1m')
  .time({from: 'now-30m', to: 'now'})
  .timezone('browser')

  .withRow(new RowBuilder('Overview'))
  .withPanel(
    new PanelBuilder()
      .title('Network Received')
      .unit('bps')
      .min(0)
      .withTarget(
        new DataqueryBuilder()
          .expr('rate(node_network_receive_bytes_total{job="integrations/raspberrypi-node", device!="lo"}[$__rate_interval]) * 8')
          .legendFormat("{{ device }}")
      )
  )
;

console.log(JSON.stringify(builder.build(), null, 2));

See also🔗