Giter Site home page Giter Site logo

grafonnet-lib's Introduction

Grafonnet, a Jsonnet library for generating Grafana dashboards

CircleCI

Grafonnet provides a simple way of writing Grafana dashboards. It leverages the data templating language Jsonnet. It enables you to write reusable components that you can use and reuse for multiple dashboards.

screenshot

Getting started

Prerequisites

Grafonnet requires Jsonnet.

Linux

You must build the binary. For details, see the GitHub repository.

Mac OS X

Jsonnet is available in Homebrew. If you do not have Homebrew installed, install it.

Then run:

brew install jsonnet

Install grafonnet

Clone this git repository:

git clone [email protected]:grafana/grafonnet-lib.git

Then import the grafonnet in your jsonnet code:

local grafana = import 'grafonnet/grafana.libsonnet';

To be able to find the grafonnet library, you must pass the root of the git repository to grafonnet using the -J option:

jsonnet -J <path> dashboard.jsonnet

As you build your own mixins/dashboards, you should add additional -J paths.

Examples

Simple Grafana 5.x dashboard:

Please note that the layout has changed, no row objects and new possible nesting of panel objects. You need to set schemaVersion parameter on dashboard object to at least 16.

local grafana = import 'grafonnet/grafana.libsonnet';
local dashboard = grafana.dashboard;
local row = grafana.row;
local singlestat = grafana.singlestat;
local prometheus = grafana.prometheus;
local template = grafana.template;

dashboard.new(
  'JVM',
  schemaVersion=16,
  tags=['java'],
)
.addTemplate(
  grafana.template.datasource(
    'PROMETHEUS_DS',
    'prometheus',
    'Prometheus',
    hide='label',
  )
)
.addTemplate(
  template.new(
    'env',
    '$PROMETHEUS_DS',
    'label_values(jvm_threads_current, env)',
    label='Environment',
    refresh='time',
  )
)
.addTemplate(
  template.new(
    'job',
    '$PROMETHEUS_DS',
    'label_values(jvm_threads_current{env="$env"}, job)',
    label='Job',
    refresh='time',
  )
)
.addTemplate(
  template.new(
    'instance',
    '$PROMETHEUS_DS',
    'label_values(jvm_threads_current{env="$env",job="$job"}, instance)',
    label='Instance',
    refresh='time',
  )
)
.addPanel(
  singlestat.new(
    'uptime',
    format='s',
    datasource='Prometheus',
    span=2,
    valueName='current',
  )
  .addTarget(
    prometheus.target(
      'time() - process_start_time_seconds{env="$env", job="$job", instance="$instance"}',
    )
  ), gridPos={
    x: 0,
    y: 0,
    w: 24,
    h: 3,
  }
)

Simple Grafana 4.x dashboard:

local grafana = import 'grafonnet/grafana.libsonnet';
local dashboard = grafana.dashboard;
local row = grafana.row;
local singlestat = grafana.singlestat;
local prometheus = grafana.prometheus;
local template = grafana.template;

dashboard.new(
  'JVM',
  tags=['java'],
)
.addTemplate(
  grafana.template.datasource(
    'PROMETHEUS_DS',
    'prometheus',
    'Prometheus',
    hide='label',
  )
)
.addTemplate(
  template.new(
    'env',
    '$PROMETHEUS_DS',
    'label_values(jvm_threads_current, env)',
    label='Environment',
    refresh='time',
  )
)
.addTemplate(
  template.new(
    'job',
    '$PROMETHEUS_DS',
    'label_values(jvm_threads_current{env="$env"}, job)',
    label='Job',
    refresh='time',
  )
)
.addTemplate(
  template.new(
    'instance',
    '$PROMETHEUS_DS',
    'label_values(jvm_threads_current{env="$env",job="$job"}, instance)',
    label='Instance',
    refresh='time',
  )
)
.addRow(
  row.new()
  .addPanel(
    singlestat.new(
      'uptime',
      format='s',
      datasource='Prometheus',
      span=2,
      valueName='current',
    )
    .addTarget(
      prometheus.target(
        'time() - process_start_time_seconds{env="$env", job="$job", instance="$instance"}',
      )
    )
  )
)

Find more examples in the examples directory.

grafonnet-lib's People

Contributors

asiekkowa avatar caarlos0 avatar cznewt avatar daniellee avatar efritz avatar hex2dec avatar jecnua avatar jtlisi avatar kobtea avatar lukaf avatar mlushpenko avatar mtanda avatar pborzenkov avatar prabdeb avatar roidelapluie avatar simonpasquier avatar stephen-soltesz avatar svenklemm avatar tomwilkie avatar voronenko avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.