grafanasdkclistarter

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2025 License: MIT Imports: 30 Imported by: 0

README

GrafanaSdkCliStarter

GrafanaSdkCliStarter is a CLI helper for working with Go-written dashboards using the grafana-foundation-sdk.

Features

  • Uses urfave/cli to enable automatic deployment and destruction of dashboards.
  • Easily extendable to add more commands.
  • Provides development commands to start a local Grafana and Prometheus instance for testing new metrics.

Development Commands

  • go run . dev init

    • Generates a prometheus.yml file where you can attach your application (via your computer's IP address).
  • go run . dev run

Example Usage

Here’s an example main.go implementation:

package main

import (
	"os"

	g "github.com/fasibio/grafanaSdkCliStarter"
	"github.com/grafana/grafana-foundation-sdk/go/dashboard"
	"github.com/urfave/cli/v2"
)

func main() {
	defaultDataSourceName := "datasource"

	app, err := g.NewCli("your-app-name",
		g.DashboardBuilder(
			func(folderName string, c *cli.Context) ([]dashboard.Dashboard, error) {
        
				o := NewGrafanaFoundationSDKDashboard("some-datasource")
				d, err := o.Build(string(folderName), "overview")
				return []dashboard.Dashboard{d}, err // attach here your builded Dashboards 
			},
		),
		g.DefaultDashboardCliFlagValue(g.CliServer, "your-grafana-server"),
		g.DefaultDashboardCliFlagValue(g.CliFolderName, "test_cli_starter"),
		g.DefaultDevRunDataSource(defaultDataSourceName),
	)
	if err != nil {
		panic(err)
	}
	if err := app.Run(os.Args); err != nil {
		panic("Error: " + err.Error())
	}
}

Building Dashboards

How to build Dashboards you can find at Grafana Foundation SDK Examples

Contributing

Feel free to fork this repository and submit pull requests for improvements.

License

This project is licensed under the MIT License.

Documentation

Index

Constants

View Source
const (
	CliServer            CliValues = "server"
	CliApiKey            CliValues = "apikey"
	CliApiBasePath       CliValues = "apibasepath"
	CliFolderName        CliValues = "foldername"
	CliYamlTargetFile    CliValues = "file"
	CliDevDatasourceName string    = "datasource_name"
	CliDevSubnet         string    = "subnet"
	CliDevGateway                  = "gateway"
)

Variables

This section is empty.

Functions

func DirExist

func DirExist(dir string) bool

DirExist checks if directory exist

func EnsureDir

func EnsureDir(dir string) error

EnsureDir checks if given directory exist, creates if not

func GetFlagEnvByFlagName

func GetFlagEnvByFlagName(flagName, appName string) string

func NewCli

func NewCli(appName string, options ...Option) (*cli.App, error)

Types

type APIKeyReader

type APIKeyReader struct{}

func (APIKeyReader) ReadResponse

func (APIKeyReader) ReadResponse(cr runtime.ClientResponse, c runtime.Consumer) (interface{}, error)

type CliValues

type CliValues = string

type DashboardCreator

type DashboardCreator func(folderName string, c *cli.Context) ([]dashboard.Dashboard, error)

type Option

type Option func(runner *Runner, app *cli.App) error

func DashboardBuilder

func DashboardBuilder(d DashboardCreator) Option

func DefaultDashboardCliFlagValue

func DefaultDashboardCliFlagValue(key CliValues, value string) Option

func DefaultDevRunDataSource

func DefaultDevRunDataSource(value string) Option

type Runner

type Runner struct {
	Dashboard DashboardCreator
	// contains filtered or unexported fields
}

func (*Runner) Apply

func (r *Runner) Apply(c *cli.Context) error

func (*Runner) Before

func (r *Runner) Before(c *cli.Context) error

func (*Runner) BeforeDev

func (r *Runner) BeforeDev(c *cli.Context) error

func (*Runner) Destroy

func (r *Runner) Destroy(c *cli.Context) error

func (*Runner) InitDev

func (r *Runner) InitDev(c *cli.Context) error

func (*Runner) Plan

func (r *Runner) Plan(c *cli.Context) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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