observability-lib

command module
v0.0.0-...-3fbd98c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2025 License: MIT Imports: 1 Imported by: 0

README

Observability-lib

This library enables creating Grafana dashboards and alerts with go code.

It provides abstractions to create grafana resources :

Folder Structure

The observability-lib is structured as follows:

observability-lib/
    api/ # Grafana HTTP API Client to interact with resources
    cmd/ # CLI
    grafana/ # grafana-foundations-sdk abstraction to manipulate grafana resources

Documentation

Godoc generated documentation is available here

Quickstart

Creating a dashboard
main.go
package main

import (
	"fmt"
	"github.com/grafana/grafana-foundation-sdk/go/common"
	"github.com/smartcontractkit/chainlink-common/observability-lib/grafana"
)

func main() {
	builder := grafana.NewBuilder(&grafana.BuilderOptions{
		Name:     "Dashboard Name",
		Tags:     []string{"tags1", "tags2"},
		Refresh:  "30s",
		TimeFrom: "now-30m",
		TimeTo:   "now",
	})

	builder.AddVars(grafana.NewQueryVariable(&grafana.QueryVariableOptions{
		VariableOption: &grafana.VariableOption{
			Label: "Environment",
			Name:  "env",
		},
		Datasource: "Prometheus",
		Query:      `label_values(up, env)`,
	}))

	builder.AddRow("Summary")

	builder.AddPanel(grafana.NewStatPanel(&grafana.StatPanelOptions{
		PanelOptions: &grafana.PanelOptions{
			Datasource:  "Prometheus",
			Title:       grafana.Pointer("Uptime"),
			Description: "instance uptime",
			Span:        12,
			Height:      4,
			Decimals:    grafana.Pointer(2.),
			Unit:        "s",
			Query: []grafana.Query{
				{
					Expr:   `uptime_seconds`,
					Legend: `{{ pod }}`,
				},
			},
		},
		ColorMode:   common.BigValueColorModeNone,
		TextMode:    common.BigValueTextModeValueAndName,
		Orientation: common.VizOrientationHorizontal,
	}))

	db, err := builder.Build()
	if err != nil {
		return
	}
	json, err := db.GenerateJSON()
	if err != nil {
		return
	}
	fmt.Println(string(json))
}

Cmd Usage

CLI to manipulate grafana resources

Contact Point
List
./observability-lib api contact-point list \
  --grafana-url http://localhost:3000 \
  --grafana-token <token>
Delete
./observability-lib api contact-point delete <name> \
  --grafana-url http://localhost:3000 \
  --grafana-token <token>
Dashboard
Delete
./observability-lib api dashboard delete <name> \
  --grafana-url http://localhost:3000 \
  --grafana-token <token>
Notification Policy
List
./observability-lib api notification-policy list \
  --grafana-url http://localhost:3000 \
  --grafana-token <token>
Delete
./observability-lib api notification-policy delete <receiverName> \ 
  --grafana-url http://localhost:3000 \
  --grafana-token <token> \
  --matchers key,=,value \
  --matchers key2,=,value2

Makefile Usage

To build the observability library, run the following command:

make build

To run the tests, run the following command:

make test

To run the linter, run the following command:

make lint

To run the CLI

make run

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL