Documentation ¶
Overview ¶
Package grabana provides a developer-friendly way of creating Grafana dashboards.
Whether you prefer writing **code or YAML**, if you are looking for a way to version your dashboards configuration or automate tedious and error-prone creation of dashboards, this library is meant for you.
builder := dashboard.New( "Awesome dashboard", dashboard.VariableAsInterval( "interval", interval.Values([]string{"30s", "1m", "5m", "10m", "30m", "1h", "6h", "12h"}), ), dashboard.VariableAsQuery( "status", query.DataSource("prometheus-default"), query.Request("label_values(prometheus_http_requests_total, code)"), query.Sort(query.NumericalAsc), ), dashboard.Row( "Prometheus", row.WithTimeSeries( "HTTP Rate", timeseries.WithPrometheusTarget( "rate(promhttp_metric_handler_requests_total[$interval])", prometheus.Legend("{{handler}} - {{ code }}"), ), ), row.WithTable( "Threads", table.WithPrometheusTarget("go_threads"), table.HideColumn("Time"), table.AsTimeSeriesAggregations([]table.Aggregation{ {Label: "AVG", Type: table.AVG}, {Label: "Current", Type: table.Current}, }), ), row.WithStat( "Heap Allocations", stat.Unit("bytes"), stat.WithPrometheusTarget("go_memstats_heap_alloc_bytes"), ), ), dashboard.Row( "Some text, because it might be useful", row.WithText( "Some awesome html?", text.HTML("<b>lalalala</b>"), ), ), )
For a more information visit https://github.com/anil-appface/grabana
Index ¶
- Variables
- type APIKey
- type APIKeyRole
- type Client
- func (client *Client) APIKeys(ctx context.Context) (map[string]APIKey, error)
- func (client *Client) AddAlert(ctx context.Context, namespace string, alertDefinition alert.Alert, ...) error
- func (client *Client) ConfigureAlertManager(ctx context.Context, manager *alertmanager.Manager) error
- func (client *Client) CreateAPIKey(ctx context.Context, request CreateAPIKeyRequest) (string, error)
- func (client *Client) CreateFolder(ctx context.Context, name string) (*Folder, error)
- func (client *Client) DeleteAPIKeyByName(ctx context.Context, name string) error
- func (client *Client) DeleteAlertGroup(ctx context.Context, namespace string, groupName string) error
- func (client *Client) DeleteDashboard(ctx context.Context, uid string) error
- func (client *Client) DeleteDatasource(ctx context.Context, name string) error
- func (client *Client) FindOrCreateFolder(ctx context.Context, name string) (*Folder, error)
- func (client *Client) GetDashboardByTitle(ctx context.Context, title string) (*Dashboard, error)
- func (client *Client) GetDatasourceUIDByName(ctx context.Context, name string) (string, error)
- func (client *Client) GetFolderByTitle(ctx context.Context, title string) (*Folder, error)
- func (client *Client) UpsertDashboard(ctx context.Context, folder *Folder, builder dashboard.Builder) (*Dashboard, error)
- func (client *Client) UpsertDatasource(ctx context.Context, datasource datasource.Datasource) error
- type CreateAPIKeyRequest
- type Dashboard
- type Folder
- type Option
Constants ¶
This section is empty.
Variables ¶
var ErrAPIKeyNotFound = errors.New("API key not found")
ErrAPIKeyNotFound is returned when the given API key can not be found.
var ErrAlertNotFound = errors.New("alert not found")
ErrAlertNotFound is returned when the requested alert can not be found.
var ErrDashboardNotFound = errors.New("dashboard not found")
ErrDashboardNotFound is returned when the given dashboard can not be found.
var ErrDatasourceNotFound = errors.New("datasource not found")
ErrDatasourceNotFound is returned when the given datasource can not be found.
var ErrFolderNotFound = errors.New("folder not found")
ErrFolderNotFound is returned when the given folder can not be found.
Functions ¶
This section is empty.
Types ¶
type APIKeyRole ¶
type APIKeyRole uint8
APIKeyRole represents a role given to an API key.
const ( AdminRole APIKeyRole = iota EditorRole ViewerRole )
func (APIKeyRole) MarshalJSON ¶
func (role APIKeyRole) MarshalJSON() ([]byte, error)
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a Grafana HTTP client.
func (*Client) AddAlert ¶
func (client *Client) AddAlert(ctx context.Context, namespace string, alertDefinition alert.Alert, datasourcesMap map[string]string) error
AddAlert creates an alert group within a given namespace.
func (*Client) ConfigureAlertManager ¶
func (client *Client) ConfigureAlertManager(ctx context.Context, manager *alertmanager.Manager) error
ConfigureAlertManager updates the alert manager configuration.
func (*Client) CreateAPIKey ¶
func (client *Client) CreateAPIKey(ctx context.Context, request CreateAPIKeyRequest) (string, error)
CreateAPIKey creates a new API key.
func (*Client) CreateFolder ¶
CreateFolder creates a dashboard folder. See https://grafana.com/docs/grafana/latest/reference/dashboard_folders/
func (*Client) DeleteAPIKeyByName ¶
DeleteAPIKeyByName deletes an API key given its name.
func (*Client) DeleteAlertGroup ¶
func (client *Client) DeleteAlertGroup(ctx context.Context, namespace string, groupName string) error
DeleteAlertGroup deletes an alert group.
func (*Client) DeleteDashboard ¶
DeleteDashboard deletes a dashboard given its UID.
func (*Client) DeleteDatasource ¶
DeleteDatasource deletes a datasource given its name.
func (*Client) FindOrCreateFolder ¶
FindOrCreateFolder returns the folder by its name or creates it if it doesn't exist.
func (*Client) GetDashboardByTitle ¶
GetDashboardByTitle finds a dashboard, given its title.
func (*Client) GetDatasourceUIDByName ¶
GetDatasourceUIDByName finds a datasource UID given its name.
func (*Client) GetFolderByTitle ¶
GetFolderByTitle finds a folder, given its title.
func (*Client) UpsertDashboard ¶
func (client *Client) UpsertDashboard(ctx context.Context, folder *Folder, builder dashboard.Builder) (*Dashboard, error)
UpsertDashboard creates or replaces a dashboard, in the given folder.
func (*Client) UpsertDatasource ¶
func (client *Client) UpsertDatasource(ctx context.Context, datasource datasource.Datasource) error
UpsertDatasource creates or replaces a datasource.
type CreateAPIKeyRequest ¶
type CreateAPIKeyRequest struct { Name string `json:"name"` Role APIKeyRole `json:"role"` SecondsToLive int `json:"secondsToLive"` }
CreateAPIKeyRequest represents a request made to the API key creation endpoint.
type Dashboard ¶
type Dashboard struct { ID int `json:"id"` UID string `json:"uid"` Title string `json:"title"` URL string `json:"url"` Tags []string `json:"tags"` IsStarred bool `json:"isStarred"` FolderID int `json:"folderId"` FolderUID string `json:"folderUid"` FolderTitle string `json:"folderTitle"` FolderURL string `json:"folderUrl"` }
Dashboard represents a Grafana dashboard.
type Folder ¶
Folder represents a dashboard folder. See https://grafana.com/docs/grafana/latest/reference/dashboard_folders/
type Option ¶
type Option func(client *Client)
Option represents an option that can be used to configure a client.
func WithAPIToken ¶
WithAPIToken sets up the client to use the given token to authenticate.
func WithBasicAuth ¶
WithBasicAuth sets up the client to use the given credentials to authenticate.