/grafana-dashboard-dsl

DSL for generating Grafana dashboards

Primary LanguageKotlinMIT LicenseMIT

Build Status Build status codecov codebeat badge License: MIT Javadoc Download

Grafana Dashboard DSL

Kotlin DSL for generating Grafana dashboards.

Features

  • Grafana Dashboards as a Code: review and vcs control over dashboards
  • Reusable dashboards, panels, configs, etc
  • Share visualization style across different metrics
  • Easy to keep metrics up-to-date
  • Easy to extend to most features of Grafana
  • Easy to include in CI cycle: dashboard is a JSON-document
  • Power of Kotlin language

Usage with gradle plugin

See documentation at Grafana Dashboard Plugin

Manual usage

build.gradle

sourceSets {
    grafana {
        kotlin
    }
}

dependencies {
    grafanaCompile 'com.yandex.money.tech:grafana-dashboard-dsl:1.0.5'    
}

Code for dashboards generation must be placed in ${projectDir}/src/grafana/kotlin/. Generation performed manually:

import ru.yandex.money.tools.grafana.dsl.dashboard

fun main(args: Array<String>) {
    println(dashboard(title = "My custom dashboard") {
        panels {
            // ...
        }
    })
}

JSON Import

Import

Examples

Examples are in ./src/examples/kotlin/ru/yandex/money/tools/grafana/dsl/examples

Development

To create new dashboards, panels, metrics, and others, create a class (usually with postfix *Configuration or*Builder), mark it with annotation ru.yandex.money.tools.grafana.dsl.DashboardElement, and create data-class for it's contents, that's implements ru.yandex.money.tools.grafana.dsl.json.Json

For example see DashboardBuilder and Dashboard classes

How to contribute?

Just fork the repo and send us a pull request.

Make sure your branch builds without any warnings/issues.

How to build?

See configuration for Travis (.travis.yml) or AppVeyor (appveyor.yml). There are two gradle projects in this repository:

  • Files build.gradle, gradlew, gradle/wrapper is for internal use in Yandex.Money infrastructure
  • Files build-public.gradle, gradlew-public, gradle-public/wrapper are for public use

Importing into IntelliJ IDEA

Unfortunately, at this moment, intellij does not support this build configuration, so you have to change some files before importing:

  • Move gradle-public/wrapper/gradle-wrapper.properties into gradle/wrapper/gradle-wrapper.properties
  • Move build-public.gradle into build.gradle

Vote for this issue IDEA-199116, to make intellij support these types of configuration.

Contributors