Giter Site home page Giter Site 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 Grafana objects.

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.

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 any logger, instead API functions could return errors where it need.
  4. Prefere no external deps except Go stdlib.
  5. Cover SDK calls with unit tests.

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)
	grafanaURL := "http://grafana.host"
	c := sdk.NewClient(grafanaURL, "grafana-api-key", sdk.DefaultHTTPClient)
	response, err := c.SetDashboard(context.TODO() ,*board, sdk.SetDashboardParams{
		Overwrite: false,
	})
	if err != nil {
		fmt.Printf("error on uploading dashboard %s", board.Title)
	} else {
		fmt.Printf("dashboard URL: %v", grafanaURL+*response.URL)
	}

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 git.xiaojukeji.com/datasre/grafana-sdk

Dependency packages have included into distro. govendor utility used for vendoring. The single dependency now is:

go get github.com/gosimple/slug

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

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 API tokens and Basic Auth
Annotations partially
Dashboards partially
Datasources +
Alert notification channels +
Organization (current) partially
Organizations partially
Users partially
User (actual) partially
Snapshots -
Frontend settings -
Admin partially

There is no exact roadmap. The integration tests are being run against the following Grafana versions:

With the following Go versions:

  • 1.14.x
  • 1.13.x
  • 1.12.x
  • 1.11.x

I still have interest to this library development but not always have time for it. So I gladly accept new contributions. Drop an issue or contact me.

Licence

Distributed under Apache v2.0. All rights belong to the SDK authors. There is no authors list yet, you can see the full list of the contributors in the git history. Official repository is https://git.xiaojukeji.com/datasre/grafana-sdk

Collection of Grafana tools in Golang

sdk's People

Contributors

bigkraig avatar bradbeam avatar curtisallen avatar d-ulyanov avatar detailyang avatar edwardishaq avatar fredwangwang avatar giedriuss avatar grafov avatar gustavjaner avatar haseth avatar indragunawan avatar jasonatran avatar jlhags avatar jmccann avatar k-phoen avatar krya-kryak avatar kuri-su avatar masudur-rahman avatar matt-deboer avatar mcristina422 avatar mlclmj avatar ntindall avatar pmenglund avatar raffaelschmid avatar tdabasinskas avatar thevan4 avatar y3llowcake avatar yasumoto avatar zibuyu28 avatar

Watchers

 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.