grafana

package
v1.0.43 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultEvaluationFrequency = "1m"
	DefaultDecisionWindow      = "0s"
)
View Source
const (
	ErrOK          ExecErrState = "OK"
	ErrError       ExecErrState = "Error"
	ErrAlerting    ExecErrState = "Alerting"
	NoDataOk       NoDataState  = "OK"
	NoData         NoDataState  = "NoData"
	NoDataAlerting NoDataState  = "Alerting"
)
View Source
const (
	TagCreated = "create"
	TagDeleted = "delete"
	TagFailed  = "failed"
	TagChaos   = "chaos"
)

Variables

View Source
var DefaultVariableEvaluation = map[string]string{
	"Instance": ".+",
	"Node":     ".+",
}

DefaultVariableEvaluation contains the default replacement of environment variables in Grafana expressions.

View Source
var Timeout = 2 * time.Minute

Functions

func AnnotatePointInTime added in v1.0.40

func AnnotatePointInTime(obj client.Object, ts time.Time, tags []Tag)

func AnnotateTimerange added in v1.0.40

func AnnotateTimerange(obj client.Object, tsStart time.Time, tsEnd time.Time, tags []Tag)

func BuildURL added in v1.0.37

func BuildURL(grafanaEndpoint string, dashboard string, from int64, to int64, postfix string) string

func ConvertEvaluatorAlias

func ConvertEvaluatorAlias(alias string) string

func DeleteClientFor

func DeleteClientFor(obj metav1.Object)

DeleteClientFor removes the client registered for the given object.

func HasClientFor added in v1.0.38

func HasClientFor(obj metav1.Object) bool

HasClientFor returns whether there is a non-nil grafana client is registered for the given object.

func SetClientFor

func SetClientFor(obj metav1.Object, client *Client)

SetClientFor creates a new client for the given object. It panics if it cannot parse the object's metadata, or if another client is already registers.

Types

type AlertRule added in v1.0.37

type AlertRule struct {
	Metric

	Query

	// FromTime indicate a relative duration accounted for the alerting. e.g, 15m ago
	FromTime string

	// ToTime indicate a point of reference accounted for the alerting. e.g, now
	ToTime string

	// Frequency specifies how frequently an alert rule is evaluated Must be a multiple of 10 seconds. For examples, 1m, 30s.
	Frequency string

	// Duration, when configured, specifies the duration for which the condition must be true before an alert fires.
	Duration string
}

AlertRule is a set of evaluation criteria that determines whether an alert will fire. The alert rule consists of one or more queries and expressions, a condition, the frequency of evaluation, and optionally, the duration over which the condition is met.

func ParseAlertExpr

func ParseAlertExpr(query v1alpha1.ExprMetrics) (*AlertRule, error)

type Annotation

type Annotation interface {
	// Add  pushes an annotation to grafana indicating that a new component has joined the experiment.
	Add(obj client.Object)

	// Delete pushes an annotation to grafana indicating that a new component has left the experiment.
	Delete(obj client.Object)
}

Annotation provides a way to mark points on the graph with rich events.

type Client

type Client struct {
	Conn *sdk.Client

	GapiClient *gapi.Client

	BaseURL string
	// contains filtered or unexported fields
}

func GetClientFor

func GetClientFor(obj metav1.Object) *Client

GetClientFor returns the client with the given name. It panics if it cannot parse the object's metadata, if the client does not exist, or if the client is empty.

func New

func New(parentCtx context.Context, setters ...Option) (*Client, error)

func (*Client) AddAnnotation added in v1.0.40

func (c *Client) AddAnnotation(annotationRequest sdk.CreateAnnotationRequest) (reqID uint)

AddAnnotation inserts a new annotation to Grafana.

func (*Client) DownloadData added in v1.0.37

func (c *Client) DownloadData(ctx context.Context, url *URL, destDir string) error

DownloadData returns data for the given panel.

func (*Client) ListPanels added in v1.0.37

func (c *Client) ListPanels(ctx context.Context, dashboardUID string) ([]PanelRef, error)

ListPanels returns a list of Panels ID with a Grafana dashboard.

func (*Client) PatchAnnotation

func (c *Client) PatchAnnotation(reqID uint, annotationRequest sdk.PatchAnnotationRequest)

PatchAnnotation updates an existing annotation to Grafana.

func (*Client) SetAlert

func (c *Client) SetAlert(ctx context.Context, alert *AlertRule, name string, msg string) error

SetAlert adds a new alert to Grafana using the Legacy API.

func (*Client) SetNotificationChannel

func (c *Client) SetNotificationChannel(parentCtx context.Context, webhookURL string) error

func (*Client) UnsetAlert

func (c *Client) UnsetAlert(alertID string)

UnsetAlert removes an alert from Grafana.

type DataRequest added in v1.0.37

type DataRequest struct {
	Queries []interface{} `json:"queries"`

	Range TimeRange `json:"range"`
	From  string    `json:"from"`
	To    string    `json:"to"`
}

DataRequest is used to ask DataFrame from Grafana.

type ExecErrState added in v1.0.41

type ExecErrState string

type Metric

type Metric struct {
	DashboardUID string

	PanelID uint

	MetricName string
}

Metric points to the Grafana metric we are interested in. The location can be retrieved from the Grafana URL. Example: URL: http://grafana.platform.science-hangar.eu/d/wpFnYRwGk/iperf?orgId=1&viewPanel=2 Metric: wpFnYRwGk/2/bitrate.

type NoDataState added in v1.0.41

type NoDataState string

type Option

type Option func(*Options)

func WithHTTP

func WithHTTP(endpoint string) Option

WithHTTP will use HTTP for connection with Grafana.

func WithLogger

func WithLogger(logger logr.Logger) Option

WithLogger will use the given logger for printing info.

func WithNotifications

func WithNotifications(webhookURL string) Option

WithNotifications will update the object's annotations if a Grafana alert is triggered.

func WithRegisterFor

func WithRegisterFor(obj metav1.Object) Option

WithRegisterFor will register the client with the given name. Registered clients are retrievable by GetFrisbeeClient().

type Options

type Options struct {
	WebhookURL *string

	EventDispatcher func(b *notifier.Body)

	RegisterFor metav1.Object

	Logger logr.Logger

	HTTPEndpoint *string
}

type PanelRef added in v1.0.37

type PanelRef struct {
	Title string
	ID    uint
}

type Query

type Query struct {
	/* == Evaluator
	* below
	* above
	* within_range
	* outside_range
	* empty
	 */
	Evaluator sdk.AlertEvaluator

	/* == Reducers
	* avg
	* min
	* max
	* sum
	* count
	* last
	* median
	* diff
	* diff_abs
	* percent_diff
	* percent_diff_abs
	* count_non_null
	 */
	Reducer sdk.AlertReducer
}

type RawTimeRange added in v1.0.37

type RawTimeRange struct {
	From time.Time `json:"from"`
	To   time.Time `json:"to"`
}

type Tag

type Tag = string

Tag is used as tag for Grafana Annotations

type TimeRange

type TimeRange struct {
	From time.Time     `json:"from"`
	To   time.Time     `json:"to"`
	Raw  *RawTimeRange `json:"raw"`
}

type URL added in v1.0.37

type URL struct {
	Endpoint     string
	DashboardUID *string
	FromTS       *time.Time
	ToTS         *time.Time
	PanelID      *uint
	Kiosk        bool
}

func NewURL added in v1.0.37

func NewURL(endpoint string) *URL

NewURL access an endpoint at the form: grafana-fedbed-48.knot-platform.eu

func (*URL) AnnotationsQuery added in v1.0.38

func (url *URL) AnnotationsQuery() string

func (*URL) DataSourceQuery added in v1.0.38

func (url *URL) DataSourceQuery() string

func (*URL) WithDashboard added in v1.0.37

func (url *URL) WithDashboard(dashboardUID string) *URL

func (*URL) WithFromTS added in v1.0.37

func (url *URL) WithFromTS(ts time.Time) *URL

func (*URL) WithKiosk added in v1.0.37

func (url *URL) WithKiosk() *URL

func (*URL) WithPanel added in v1.0.37

func (url *URL) WithPanel(panelID uint) *URL

func (*URL) WithToTS added in v1.0.37

func (url *URL) WithToTS(ts time.Time) *URL

Jump to

Keyboard shortcuts

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