Skip to content

DashboardBuilder🔗

Constructor🔗

new DashboardBuilder(String title)

Methods🔗

build🔗

Builds the object.

public Dashboard 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/

public DashboardBuilder annotation(com.grafana.foundation.cog.Builder<AnnotationQuery> annotation)

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/

public DashboardBuilder annotations(List<com.grafana.foundation.cog.Builder<AnnotationQuery>> annotations)

description🔗

Description of dashboard.

public DashboardBuilder description(String description)

editable🔗

Whether a dashboard is editable or not.

public DashboardBuilder editable()

fiscalYearStartMonth🔗

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

public DashboardBuilder fiscalYearStartMonth(Integer fiscalYearStartMonth)

gnetId🔗

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

public DashboardBuilder gnetId(String gnetId)

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.

public DashboardBuilder id(Long id)

Links with references to other dashboards or external websites.

public DashboardBuilder link(com.grafana.foundation.cog.Builder<DashboardLink> link)

Links with references to other dashboards or external websites.

public DashboardBuilder links(List<com.grafana.foundation.cog.Builder<DashboardLink>> links)

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

public DashboardBuilder liveNow(Boolean liveNow)

preload🔗

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

public DashboardBuilder preload(Boolean preload)

readonly🔗

Whether a dashboard is editable or not.

public DashboardBuilder readonly()

refresh🔗

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

public DashboardBuilder refresh(String refresh)

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.

public DashboardBuilder revision(Long revision)

snapshot🔗

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

public DashboardBuilder snapshot(com.grafana.foundation.cog.Builder<Snapshot> snapshot)

tags🔗

Tags associated with dashboard.

public DashboardBuilder tags(List<String> tags)

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

public DashboardBuilder time(com.grafana.foundation.cog.Builder<DashboardDashboardTime> time)

timepicker🔗

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

public DashboardBuilder timepicker(com.grafana.foundation.cog.Builder<TimePickerConfig> timepicker)

timezone🔗

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

public DashboardBuilder timezone(String timezone)

title🔗

Title of dashboard.

public DashboardBuilder title(String title)

tooltip🔗

Configuration of dashboard cursor sync behavior.

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

public DashboardBuilder tooltip(DashboardCursorSync graphTooltip)

uid🔗

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

public DashboardBuilder uid(String uid)

variables🔗

Configured template variables

public DashboardBuilder variables(List<com.grafana.foundation.cog.Builder<VariableModel>> variables)

version🔗

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

public DashboardBuilder version(Integer version)

weekStart🔗

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

public DashboardBuilder weekStart(String weekStart)

withPanel🔗

public DashboardBuilder withPanel(com.grafana.foundation.cog.Builder<Panel> panel)

withRow🔗

public DashboardBuilder withRow(com.grafana.foundation.cog.Builder<RowPanel> rowPanel)

withVariable🔗

Configured template variables

public DashboardBuilder withVariable(com.grafana.foundation.cog.Builder<VariableModel> variable)

Examples🔗

Building a dashboard🔗

package example;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.grafana.foundation.dashboard.Dashboard;
import com.grafana.foundation.common.Constants;
import com.grafana.foundation.dashboard.DashboardBuilder;
import com.grafana.foundation.dashboard.DashboardDashboardTimeBuilder;
import com.grafana.foundation.dashboard.RowBuilder;
import com.grafana.foundation.prometheus.DataqueryBuilder;
import com.grafana.foundation.timeseries.PanelBuilder;

import java.util.List;

public class Main {
    public static void main(String[] args) throws JsonProcessingException {
        Dashboard dashboard = new DashboardBuilder("Sample Dashboard").
                uid("generated-from-java").
                tags(List.of("generated", "from", "java")).
                refresh("1m").
                time(new DashboardDashboardTimeBuilder().
                        from("now-30m").
                        to("now")
                ).
                timezone(Constants.TimeZoneBrowser).
                withRow(new RowBuilder("Overview")).
                withPanel(new PanelBuilder().
                        title("Network Received").
                        unit("bps").
                        min(0.0).
                        withTarget(new DataqueryBuilder().
                                expr("rate(node_network_receive_bytes_total{job=\"integrations/raspberrypi-node\", device!=\"lo\"}[$__rate_interval]) * 8").
                                legendFormat("{{ device }}")
                        )
                ).build();

        System.out.println(dashboard.toJSON());
    }
}

See also🔗