A set of tools, types and libraries for building and manipulating Grafana objects.
See the codeThe Grafana Foundation SDK is a set of types, and builder libraries that let you define Grafana dashboards and other resources using strongly typed code. By writing your resources as code, you can:
The SDK supports multiple programming languages, including Go, TypeScript, Python, PHP, and Java, so you can choose the one that best fits your development environment.
[!NOTE] This SDK is best suited for Grafana >= 12, but will work with Grafana >= 10.
Here's a quick overview of how the SDK works:
DashboardBuilder, then add panels, queries, and other components step by step.For example, here is how a dashboard can be built in Go:
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"
"github.com/grafana/grafana-foundation-sdk/go/units"
)
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(units.BitsPerSecondSI).
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))
}
[!NOTE] More examples can be found in the
./examples/folder.
After you've defined your resource as code, call the build() function (its
actual name might be slightly different depending on language choice) and
output the result as a JSON.
With the JSON payload, you can:
With the basics of using the Grafana Foundation SDK in mind, here are some possible next steps:
Contributions are welcome! See CONTRIBUTING.md for more information.
The code in this repository should be considered as "public preview". While it is used by Grafana Labs in production, it still is under active development.
[!NOTE] Bugs and issues are handled solely by Engineering teams. On-call support or SLAs are not available.
PHP
38.3%
Python
24.1%
Java
21.3%
TypeScript
15.3%
A set of tools, types and libraries for building and manipulating Grafana objects.
See the codeThe Grafana Foundation SDK is a set of types, and builder libraries that let you define Grafana dashboards and other resources using strongly typed code. By writing your resources as code, you can:
The SDK supports multiple programming languages, including Go, TypeScript, Python, PHP, and Java, so you can choose the one that best fits your development environment.
[!NOTE] This SDK is best suited for Grafana >= 12, but will work with Grafana >= 10.
Here's a quick overview of how the SDK works:
DashboardBuilder, then add panels, queries, and other components step by step.For example, here is how a dashboard can be built in Go:
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"
"github.com/grafana/grafana-foundation-sdk/go/units"
)
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(units.BitsPerSecondSI).
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))
}
[!NOTE] More examples can be found in the
./examples/folder.
After you've defined your resource as code, call the build() function (its
actual name might be slightly different depending on language choice) and
output the result as a JSON.
With the JSON payload, you can:
With the basics of using the Grafana Foundation SDK in mind, here are some possible next steps:
Contributions are welcome! See CONTRIBUTING.md for more information.
The code in this repository should be considered as "public preview". While it is used by Grafana Labs in production, it still is under active development.
[!NOTE] Bugs and issues are handled solely by Engineering teams. On-call support or SLAs are not available.
PHP
38.3%
Python
24.1%
Java
21.3%
TypeScript
15.3%