Skip to content

DashboardBuilder🔗

Constructor🔗

func NewDashboardBuilder(title string) *DashboardBuilder

Methods🔗

Build🔗

Builds the object.

func (builder *DashboardBuilder) Build() (Dashboard, error)

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/

func (builder *DashboardBuilder) Annotation(annotation cog.Builder[dashboard.AnnotationQuery]) *DashboardBuilder

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/

func (builder *DashboardBuilder) Annotations(annotations []cog.Builder[dashboard.AnnotationQuery]) *DashboardBuilder

Description🔗

Description of dashboard.

func (builder *DashboardBuilder) Description(description string) *DashboardBuilder

Editable🔗

Whether a dashboard is editable or not.

func (builder *DashboardBuilder) Editable() *DashboardBuilder

FiscalYearStartMonth🔗

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

func (builder *DashboardBuilder) FiscalYearStartMonth(fiscalYearStartMonth uint8) *DashboardBuilder

GnetId🔗

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

func (builder *DashboardBuilder) GnetId(gnetId string) *DashboardBuilder

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.

func (builder *DashboardBuilder) Id(id int64) *DashboardBuilder

Links with references to other dashboards or external websites.

func (builder *DashboardBuilder) Link(link cog.Builder[dashboard.DashboardLink]) *DashboardBuilder

Links with references to other dashboards or external websites.

func (builder *DashboardBuilder) Links(links []cog.Builder[dashboard.DashboardLink]) *DashboardBuilder

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

func (builder *DashboardBuilder) LiveNow(liveNow bool) *DashboardBuilder

Preload🔗

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

func (builder *DashboardBuilder) Preload(preload bool) *DashboardBuilder

Readonly🔗

Whether a dashboard is editable or not.

func (builder *DashboardBuilder) Readonly() *DashboardBuilder

Refresh🔗

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

func (builder *DashboardBuilder) Refresh(refresh string) *DashboardBuilder

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.

func (builder *DashboardBuilder) Revision(revision int64) *DashboardBuilder

Snapshot🔗

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

func (builder *DashboardBuilder) Snapshot(snapshot cog.Builder[dashboard.Snapshot]) *DashboardBuilder

Tags🔗

Tags associated with dashboard.

func (builder *DashboardBuilder) Tags(tags []string) *DashboardBuilder

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'}.

func (builder *DashboardBuilder) Time(from string, to string) *DashboardBuilder

Timepicker🔗

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

func (builder *DashboardBuilder) Timepicker(timepicker cog.Builder[dashboard.TimePickerConfig]) *DashboardBuilder

Timezone🔗

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

func (builder *DashboardBuilder) Timezone(timezone string) *DashboardBuilder

Title🔗

Title of dashboard.

func (builder *DashboardBuilder) Title(title string) *DashboardBuilder

Tooltip🔗

Configuration of dashboard cursor sync behavior.

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

func (builder *DashboardBuilder) Tooltip(graphTooltip dashboard.DashboardCursorSync) *DashboardBuilder

Uid🔗

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

func (builder *DashboardBuilder) Uid(uid string) *DashboardBuilder

Variables🔗

Configured template variables

func (builder *DashboardBuilder) Variables(variables []cog.Builder[dashboard.VariableModel]) *DashboardBuilder

Version🔗

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

func (builder *DashboardBuilder) Version(version uint32) *DashboardBuilder

WeekStart🔗

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

func (builder *DashboardBuilder) WeekStart(weekStart string) *DashboardBuilder

WithPanel🔗

func (builder *DashboardBuilder) WithPanel(panel cog.Builder[dashboard.Panel]) *DashboardBuilder

WithRow🔗

func (builder *DashboardBuilder) WithRow(rowPanel cog.Builder[dashboard.RowPanel]) *DashboardBuilder

WithVariable🔗

Configured template variables

func (builder *DashboardBuilder) WithVariable(variable cog.Builder[dashboard.VariableModel]) *DashboardBuilder

Examples🔗

Building a dashboard🔗

package main

import (
    "encoding/json"
    "fmt"

    "github.com/grafana/grafana-foundation-sdk/go/common"
    "github.com/grafana/grafana-foundation-sdk/go/dashboard"
    "github.com/grafana/grafana-foundation-sdk/go/prometheus"
    "github.com/grafana/grafana-foundation-sdk/go/timeseries"
)

func main() {
    builder := dashboard.NewDashboardBuilder("Sample dashboard").
        Uid("generated-from-go").
        Tags([]string{"generated", "from", "go"}).
        Refresh("1m").
        Time("now-30m", "now").
        Timezone(common.TimeZoneBrowser).
        WithRow(dashboard.NewRowBuilder("Overview")).
        WithPanel(
            timeseries.NewPanelBuilder().
                Title("Network Received").
                Unit("bps").
                Min(0).
                WithTarget(
                    prometheus.NewDataqueryBuilder().
                        Expr(`rate(node_network_receive_bytes_total{job="integrations/raspberrypi-node", device!="lo"}[$__rate_interval]) * 8`).
                        LegendFormat("{{ device }}"),
                ),
        )

    sampleDashboard, err := builder.Build()
    if err != nil {
        panic(err)
    }
    dashboardJson, err := json.MarshalIndent(sampleDashboard, "", "  ")
    if err != nil {
        panic(err)
    }

    fmt.Println(string(dashboardJson))
}

See also🔗