• Stars
    star
    686
  • Rank 65,892 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 5 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

User-friendly Go library for building Grafana dashboards

Grabana

Go Report Card CI codecov GoDoc

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

Whether you prefer writing code or YAML, 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

Note: Grafana 8+ is required, with unified alerting enabled.

Dashboard as code

Dashboard configuration:

builder := dashboard.New(
    "Awesome dashboard",
    dashboard.AutoRefresh("5s"),
    dashboard.Tags([]string{"generated"}),
    dashboard.VariableAsInterval(
        "interval",
        interval.Values([]string{"30s", "1m", "5m", "10m", "30m", "1h", "6h", "12h"}),
    ),
    dashboard.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{}, grafanaHost, grabana.WithAPIToken("such secret, much wow"))

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

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

For a more complete example, see the example directory.

Dashboard as YAML

Dashboard configuration:

# dashboard.yaml
title: Awesome dashboard

editable: true
tags: [generated]
auto_refresh: 5s

variables:
  - interval:
      name: interval
      label: Interval
      values: ["30s", "1m", "5m", "10m", "30m", "1h", "6h", "12h"]

rows:
  - name: Prometheus
    panels:
      - graph:
          title: HTTP Rate
          height: 400px
          datasource: prometheus-default
          targets:
            - prometheus:
                query: "rate(promhttp_metric_handler_requests_total[$interval])"
                legend: "{{handler}} - {{ code }}"

Dashboard creation (or automatically as a Kubernetes Resource, using DARK):

content, err := os.ReadFile("dashboard.yaml")
if err != nil {
    fmt.Fprintf(os.Stderr, "Could not read file: %s\n", err)
    os.Exit(1)
}

dashboard, err := decoder.UnmarshalYAML(bytes.NewBuffer(content))
if err != nil {
    fmt.Fprintf(os.Stderr, "Could not parse file: %s\n", err)
    os.Exit(1)
}

ctx := context.Background()
client := grabana.NewClient(&http.Client{}, grafanaHost, grabana.WithAPIToken("such secret, much wow"))

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

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

Going further

Check out the documentation to discover what Grabana can do for you.

License

This library is under the MIT license.

More Repositories

1

rulerz

Powerful implementation of the Specification pattern in PHP
PHP
872
star
2

dark

(grafana) Dashboards As Resources in Kubernetes
Go
428
star
3

semver-release-action

GitHub Action to automatically create SemVer compliant releases based on PR labels.
Go
85
star
4

backstage-plugin-confluence

Confluence plugins for backstage
TypeScript
58
star
5

backstage-plugin-grafana

Grafana plugin for Backstage
TypeScript
57
star
6

backstage-plugin-announcements

Announcements plugin for Backstage
TypeScript
52
star
7

Rusty

Documentation as tests "à la" Rust for PHP.
PHP
48
star
8

DoctrineStateMachineBundle

[DEPRECATED] Doctrine2 behavior adding a finite state machine in your entities
PHP
46
star
9

RulerZBundle

Symfony Bundle for RulerZ
PHP
38
star
10

backstage-plugin-opsgenie

OpsGenie plugin for Backstage
TypeScript
35
star
11

Vich-Uploader-Sandbox

VichUploaderBundle sandbox
PHP
26
star
12

Vex

[DEPRECATED] Extract videos from any URL
PHP
24
star
13

DoctrineStateMachineBehavior

[DEPRECATED] Doctrine2 behavior adding a finite state machine in your entities
PHP
14
star
14

KPhoenSmsSenderBundle

[DEPRECATED] Integration of the SmsSender library into Symfony2.
PHP
14
star
15

rulerz-spec-builder

Specification builder for RulerZ
PHP
11
star
16

regis

PHP
9
star
17

gaufrette-extras

[DEPRECATED] PHP library providing extra features to the awesome Gaufrette
PHP
8
star
18

KPhoenContactBundle

Yet another contact bundle
PHP
7
star
19

boucle

Boucle is a static travel map and albums generator.
PHP
6
star
20

php-sql-parser

SQL parser implemented in pure PHP
Pascal
6
star
21

NegotiationServiceProvider

[DEPRECATED] Negotiation Service Provider for Silex
PHP
5
star
22

runner

Set of tools to work with .FIT, .TCX and .GPX files.
Python
5
star
23

travelr

Travelr is another static gallery generator, made for travelers.
PHP
5
star
24

gaufrette-extras-bundle

[DEPRECATED] Symfony2 bundle integrating the Gaufrette Extras library
PHP
3
star
25

mon-appart

La recherche d'appart pour ceux qui n'ont pas envie de chercher.
PHP
3
star
26

Config

My configuration files
Ruby
3
star
27

docker-sabre-katana

Docker image for the sabre/katana server
Makefile
3
star
28

k-phoen.github.io

My blog – generated by https://github.com/K-Phoen/blog
HTML
2
star
29

sfTaskExtraPlugin

PHP
2
star
30

silex-rulerz-provider

Silex provider for RulerZ
PHP
2
star
31

Python-REPL

Online Python Read-Eval-Print Loop (REPL)
JavaScript
2
star
32

rulerz-bridge

Symfony Bridge for RulerZ
PHP
2
star
33

negotiation

[DEPRECATED] Content Negotiation tools for Go
Go
2
star
34

node-simple-xlsx

Simple XLSX writer for Node.js.
JavaScript
2
star
35

Random-Stuff-Generator

API providing randomly generated entities (users, locations, events, ...)
PHP
2
star
36

docker-symfony

A Symfony Docker container
PHP
1
star
37

gostore

Gostore is a distributed hash table implementation based on the SWIM protocol and rendezvous hashing.
Go
1
star
38

HoaRouterBundle

[EXPERIMENT] Integrates Hoa/Router in Symfony
PHP
1
star
39

gaas

Geocoder As A Service
PHP
1
star
40

vagrant-dev-box

Vagrant and Puppet powered development box (for PHP and nodejs projects)
Puppet
1
star
41

myVagrant

My vagrant configuration
Ruby
1
star
42

backstage-plugin-codemods

TypeScript
1
star
43

advent_of_code_2018

Go
1
star
44

docker-nginx-php

1
star
45

negotiate

[DEPRECATED] Martini handler providing content negotiation to requests
Go
1
star
46

blog

My blog.
HTML
1
star
47

Wlppr

A small Python script to use wlppr.com and wallbase.cc for your wallpapers
Python
1
star
48

docker-sickbeard

This is a Dockerfile to set up "Sickbeard" on a Raspberry Pi
Shell
1
star
49

Pong

Un semblant de jeu de Ping-Pong réalisé en tant que TP/mini-projet de réseaux.
Java
1
star
50

Form-Class

A form creation & validation class
PHP
1
star