Giter VIP home page Giter VIP logo

sdk's Introduction

Grafana SDK Go Report Card

SDK for Go language offers a library for interacting with Grafana server from Go applications. It realizes many of HTTP REST API calls for administration, client, organizations. Beside of them it allows creating of Grafana objects (dashboards, panels, datasources) locally and manipulating them for constructing dashboards programmatically. It would be helpful for massive operations on a large set of dashboards for example.

It was made foremost for autograf project but later separated from it and moved to this new repository because the library is useful per se.

Grafana operates with Javascript objects on client side so on first view Go language looks alien thing here. And Grafana has GUI with detailed options for panel customization so in many cases you don't need additional automatization. But in situations when you operates on hundreds of dashboards programming generation of them become not bad idea. And SDK that allow you import/export, create, modify and validate Grafana structures is very helpful. Golang is good enough choice for operations with JSON though it may be subject of discuss. Positives of this choice is strong typization in Go that help validate objects alongside with high speed of execution and nice concurrency patterns. Negative aspect the same: the strong typization that add more verbosity to JSON parsing in comparing with Javascript or for an example with scripting languages like Python. But with SDK you already have ready for use structures and methods so generation of JSONs become simple. Anyway Grafana server made in Golang that prove concept for applicability of Go for that kind of tasks.

And of course if you write applications in Golang and integrate them with Grafana then client SDK for Go will be uniquely useful.

Library design principles

  1. SDK offers client functionality so it covers Grafana REST API with its requests and responses as close as possible.
  2. SDK maps Grafana objects (dashboard, row, panel, datasource) to similar Go structures but not follows exactly all Grafana abstractions.
  3. It doesn't use logging, instead API functions can return errors where it need.
  4. No external deps except Go stdlib. Another exception is URL slugify, SDK uses external lib "slug" for algorithm compatibility — that is the same package that Grafana server uses.

Examples GoDoc

	board := sdk.NewBoard("Sample dashboard title")
	board.ID = 1
	row1 := board.AddRow("Sample row title")
	row1.Add(sdk.NewGraph("Sample graph"))
	graph := sdk.NewGraph("Sample graph 2")
	target := sdk.Target{
		RefID:      "A",
		Datasource: "Sample Source 1",
		Expr:       "sample request 1"}
	graph.AddTarget(&target)
	row1.Add(graph)
	c := sdk.NewClient("http://grafana.host", "grafana-api-key", sdk.DefaultHTTPClient)	
	if err = c.SetDashboard(board, false); err != nil {
		fmt.Printf("error on uploading dashboard %s", board.Title)
	}

The library includes several demo apps for showing API usage:

You need Grafana API key with admin rights for using these utilities.

Installation Build Status

Of course Go development environment should be set up first. Then:

go get github.com/grafana-tools/sdk

Single external dependency required:

go get github.com/gosimple/slug

The "slugify" for URLs is a simple task but this package used in Grafana server so it used here for compatibility reasons.

Grafana server compability

Made mostly for Grafana 3.x, works with Grafana 4.x but need more tests. Full support for Grafana 4.x is on the way.

Status of REST API realization Coverage Status

Work on full API implementation still in progress. Currently implemented only create/update/delete operations for dashboards and datasources. State of support for misc API parts noted below.

API Status
Authorization only API tokens
Dashboards partially
Datasources +
Organization (current) partially
Organizations -
Users partially
User (actual) partially
Snapshots -
Frontend settings -
Admin -

Roadmap

  • [DONE] Realize data structures used in a default Grafana installation for data visualizing (dashboards, datasources, panels, variables, annotations).
  • [PROGRESS] Support all functions of Grafana REST API for manipulating dashboards and datasources.
  • Support functions of Grafana REST API for manipulating users and organizations.

Collection of Grafana tools in Golang

sdk's People

Contributors

grafov avatar

Watchers

James Cloos avatar  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.