4

I'm able to generate Panel JSON for provisioning a Grafana dashboard like so:

jsonnet -J ~/grafana/grafonnet-lib mydash.jsonnet > mydash.json

However I like to manipulate and edit the resulting dashboard in Grafana itself.

What I am absolutely puzzled and frustrated by, is once I've made the UI changes in Grafana by tweaking its settings and such... how does one get that back into Jsonnet? Right now for me it's a super awkward development experience. I export the Panel JSON and open the source Jsonnet in a seperate window and earnestly try port my changes across.

This is especially painful when in the JSON you might have:

      "sparkline": {
              "fillColor": "rgba(31, 118, 189, 0.18)",
              "full": true,
              "lineColor": "rgb(31, 120, 193)",
              "show": true
      },

That you would need to manually translate to Jsonnet/Graffonet-lib:

sparklineShow=true,
sparklineFull=true,
colorBackground=true,

Am I missing a trick or work flow?

030
  • 10,842
  • 12
  • 78
  • 123
hendry
  • 9,725
  • 18
  • 81
  • 139

1 Answers1

3

You have to edit mydash.jsonnet and add the needed properties there. There is currently no automated way that I know to translate back from grafana-json to grafonnet. It is a bit of a pain to find the right properties sometimes.

The properties you are looking for are here: https://github.com/grafana/grafonnet-lib/blob/master/grafonnet/singlestat.libsonnet#L44

Something like this should work:

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


grafana.dashboard.new(
  'Sparkline Example'
)
.addPanel(
  grafana.singlestat.new(
    'uptime',
    format='s',
    span=4,
    valueName='current',
    sparklineFillColor='rgba(31, 118, 189, 0.18)',
    sparklineFull=true,
    sparklineLineColor='rgb(31, 120, 193)',
    sparklineShow=true,
  )
  .addTarget(
    grafana.prometheus.target(
      'time()',
    )
  ), gridPos={
    x: 0,
    y: 0,
    w: 24,
    h: 3,
  }
)
Stephan
  • 261
  • 3
  • 8