Skip to content
User-friendly Go library for building Grafana dashboards
Go Makefile
Branch: master
Clone or download
Latest commit 9102e1f Feb 9, 2020
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows Do not fail CI builds if codecov fails Feb 7, 2020
alert Little code cleaning Feb 6, 2020
axis Yet some more docs Feb 2, 2020
cmd/example Fix variables definition Feb 9, 2020
graph Little code cleaning Feb 6, 2020
row Add a few unit tests Feb 6, 2020
singlestat Fix a few docs Feb 6, 2020
table Little code cleaning Feb 6, 2020
target/prometheus Yet some more docs Feb 2, 2020
testdata Add a way to setup and teardown grafana & prometheus instances in dev Feb 2, 2020
text Add some documentation for the public functions Feb 2, 2020
variable Fix variables definition Feb 9, 2020
vendor Commit vendors Jan 31, 2020
.golangci.yaml Add a few unit tests for the client Feb 1, 2020
LICENSE
Makefile Add a way to setup and teardown grafana & prometheus instances in dev Feb 2, 2020
README.md Add go report card Feb 2, 2020
client.go Moar docs Feb 2, 2020
client_test.go Add a few unit tests for the client Feb 1, 2020
codecov.yml Ignore cmd/ in codecov reports Feb 1, 2020
dashboard.go implement json.Marshaler interface on DashboardBuilder Feb 7, 2020
dashboard_test.go
doc.go Add doc.go file Feb 6, 2020
go.mod Write a few tests for the text panel Jan 31, 2020
go.sum Write a few tests for the text panel Jan 31, 2020

README.md

Grabana

CI Go Report Card codecov GoDoc

Grabana provides a developer-friendly way of creating Grafana dashboards.

If you are looking for a way to version your dashboards configuration or automate tedious and error-prone creation of dashboards, this library is meant for you.

Design goals

  • provide an understandable abstraction over dashboards configuration
  • expose a developer-friendly API
  • allow IDE assistance and auto-completion

Example

Dashboard configuration:

dashboard := grabana.NewDashboardBuilder(
    "Awesome dashboard",
    grabana.AutoRefresh("5s"),
    grabana.Tags([]string{"generated"}),
    grabana.VariableAsInterval(
        "interval",
        interval.Values([]string{"30s", "1m", "5m", "10m", "30m", "1h", "6h", "12h"}),
    ),
    grabana.Row(
        "Prometheus",
        row.WithGraph(
            "HTTP Rate",
            graph.DataSource("prometheus-default"),
            graph.WithPrometheusTarget(
                "rate(prometheus_http_requests_total[30s])",
                prometheus.Legend("{{handler}} - {{ code }}"),
            ),
        ),
    ),
)

Dashboard creation:

ctx := context.Background()
client := grabana.NewClient(&http.Client{}, os.Args[1], os.Args[2])

// create the folder holding the dashboard for the service
folder, err := client.GetFolderByTitle(ctx, "Test Folder")
if err != nil && err != grabana.ErrFolderNotFound {
    fmt.Printf("Could not create folder: %s\n", err)
    os.Exit(1)
}
if folder == nil {
    folder, err = client.CreateFolder(ctx, "Test Folder")
    if err != nil {
        fmt.Printf("Could not create folder: %s\n", err)
        os.Exit(1)
    }

    fmt.Printf("Folder created (id: %d, uid: %s)\n", folder.ID, folder.UID)
}

if _, err := client.UpsertDashboard(ctx, folder, dashboard); err != nil {
    fmt.Printf("Could not create dashboard: %s\n", err)
    os.Exit(1)
}

For a more complete example, see the example directory.

License

This library is under the MIT license.

You can’t perform that action at this time.