DashboardBuilder🔗
Constructor🔗
Methods🔗
build🔗
Builds the object.
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/
@param \Grafana\Foundation\Cog\Builder<\Grafana\Foundation\Dashboard\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/
@param array<\Grafana\Foundation\Cog\Builder<\Grafana\Foundation\Dashboard\AnnotationQuery>> $annotations
description🔗
Description of dashboard.
editable🔗
Whether a dashboard is editable or not.
fiscalYearStartMonth🔗
The month that the fiscal year starts on. 0 = January, 11 = December
gnetId🔗
ID of a dashboard imported from the https://grafana.com/grafana/dashboards/ portal
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.
link🔗
Links with references to other dashboards or external websites.
@param \Grafana\Foundation\Cog\Builder<\Grafana\Foundation\Dashboard\DashboardLink> $link
links🔗
Links with references to other dashboards or external websites.
@param array<\Grafana\Foundation\Cog\Builder<\Grafana\Foundation\Dashboard\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
preload🔗
When set to true, the dashboard will load all panels in the dashboard when it's loaded.
readonly🔗
Whether a dashboard is editable or not.
refresh🔗
Refresh rate of dashboard. Represented via interval string, e.g. "5s", "1m", "1h", "1d".
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.
snapshot🔗
Snapshot options. They are present only if the dashboard is a snapshot.
@param \Grafana\Foundation\Cog\Builder<\Grafana\Foundation\Dashboard\Snapshot> $snapshot
tags🔗
Tags associated with dashboard.
@param array 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'}. Configuration of the time picker shown at the top of a dashboard. @param \Grafana\Foundation\Cog\Builder<\Grafana\Foundation\Dashboard\TimePickerConfig> $timepicker Timezone of dashboard. Accepted values are IANA TZDB zone ID or "browser" or "utc". Title of dashboard. Configuration of dashboard cursor sync behavior. Accepted values are 0 (sync turned off), 1 (shared crosshair), 2 (shared crosshair and tooltip). Unique dashboard identifier that can be generated by anyone. string (8-40) Configured template variables @param array<\Grafana\Foundation\Cog\Builder<\Grafana\Foundation\Dashboard\VariableModel>> $variables Version of the dashboard, incremented each time the dashboard is updated. Day when the week starts. Expressed by the name of the day in lowercase, e.g. "monday". @param \Grafana\Foundation\Cog\Builder<\Grafana\Foundation\Dashboard\Panel> $panel @param \Grafana\Foundation\Cog\Builder<\Grafana\Foundation\Dashboard\RowPanel> $rowPanel Configured template variables @param \Grafana\Foundation\Cog\Builder<\Grafana\Foundation\Dashboard\VariableModel> $variable time🔗
timepicker🔗
timezone🔗
title🔗
tooltip🔗
uid🔗
variables🔗
version🔗
weekStart🔗
withPanel🔗
withRow🔗
withVariable🔗
Examples🔗
Building a dashboard🔗
use Grafana\Foundation\Common;
use Grafana\Foundation\Dashboard\DashboardBuilder;
use Grafana\Foundation\Dashboard\RowBuilder;
use Grafana\Foundation\Prometheus;
use Grafana\Foundation\Timeseries;
require_once __DIR__.'/vendor/autoload.php';
$builder = (new DashboardBuilder(title: 'Sample dashboard'))
->uid('generated-from-php')
->tags(['generated', 'from', 'php'])
->refresh('1m')
->time('now-30m', 'now')
->timezone(Common\Constants::TIME_ZONE_BROWSER)
->withRow(new RowBuilder('Overview'))
->withPanel(
(new Timeseries\PanelBuilder())
->title('Network received')
->unit('bps')
->min(0)
->withTarget(
(new Prometheus\DataqueryBuilder())
->expr('rate(node_network_receive_bytes_total{job="integrations/raspberrypi-node", device!="lo"}[$__rate_interval]) * 8')
->legendFormat('{{ device }}')
)
)
;
echo(json_encode($builder->build(), JSON_PRETTY_PRINT).PHP_EOL);
See also🔗