prometheus

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatLabelsTable

func FormatLabelsTable(w io.Writer, resp *LabelsResponse) error

FormatLabelsTable formats a LabelsResponse as a table.

func FormatMetadataTable

func FormatMetadataTable(w io.Writer, resp *MetadataResponse) error

FormatMetadataTable formats a MetadataResponse as a table.

func FormatTable

func FormatTable(w io.Writer, resp *QueryResponse) error

FormatTable formats a QueryResponse as a table.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a client for executing Prometheus queries via Grafana's datasource API.

func NewClient

func NewClient(cfg config.NamespacedRESTConfig) (*Client, error)

NewClient creates a new Prometheus query client.

func (*Client) LabelValues

func (c *Client) LabelValues(ctx context.Context, datasourceUID, labelName string) (*LabelsResponse, error)

LabelValues returns values for a specific label.

func (*Client) Labels

func (c *Client) Labels(ctx context.Context, datasourceUID string) (*LabelsResponse, error)

Labels returns all label names.

func (*Client) Metadata

func (c *Client) Metadata(ctx context.Context, datasourceUID string, metric string) (*MetadataResponse, error)

Metadata returns metric metadata.

func (*Client) Query

func (c *Client) Query(ctx context.Context, datasourceUID string, req QueryRequest) (*QueryResponse, error)

Query executes a Prometheus query against the specified datasource.

type DataFrame

type DataFrame struct {
	Schema DataFrameSchema `json:"schema"`
	Data   DataFrameData   `json:"data"`
}

DataFrame represents a Grafana data frame.

type DataFrameData

type DataFrameData struct {
	Values [][]any `json:"values,omitempty"`
}

DataFrameData contains the actual data values.

type DataFrameSchema

type DataFrameSchema struct {
	Name   string  `json:"name,omitempty"`
	Fields []Field `json:"fields,omitempty"`
}

DataFrameSchema describes the structure of a data frame.

type Field

type Field struct {
	Name   string            `json:"name,omitempty"`
	Type   string            `json:"type,omitempty"`
	Labels map[string]string `json:"labels,omitempty"`
}

Field describes a field in a data frame.

type GrafanaQueryResponse

type GrafanaQueryResponse struct {
	Results map[string]GrafanaResult `json:"results"`
}

GrafanaQueryResponse represents the response from Grafana's datasource query API.

type GrafanaResult

type GrafanaResult struct {
	Frames      []DataFrame `json:"frames,omitempty"`
	Error       string      `json:"error,omitempty"`
	ErrorSource string      `json:"errorSource,omitempty"`
	Status      int         `json:"status,omitempty"`
}

GrafanaResult represents a single result from a Grafana query.

type LabelsResponse

type LabelsResponse struct {
	Status string   `json:"status"`
	Data   []string `json:"data"`
}

LabelsResponse represents the response from a labels query.

type MetadataEntry

type MetadataEntry struct {
	Type string `json:"type"`
	Help string `json:"help"`
	Unit string `json:"unit,omitempty"`
}

MetadataEntry represents metadata for a single metric.

type MetadataResponse

type MetadataResponse struct {
	Status string                     `json:"status"`
	Data   map[string][]MetadataEntry `json:"data"`
}

MetadataResponse represents the response from a metadata query.

type QueryRequest

type QueryRequest struct {
	Query string
	Start time.Time
	End   time.Time
	Step  time.Duration
}

QueryRequest represents a Prometheus query request.

func (QueryRequest) IsRange

func (r QueryRequest) IsRange() bool

IsRange returns true if this is a range query.

type QueryResponse

type QueryResponse struct {
	Status    string     `json:"status"`
	Data      ResultData `json:"data"`
	ErrorType string     `json:"errorType,omitempty"`
	Error     string     `json:"error,omitempty"`
}

QueryResponse represents the response from a Prometheus query.

type ResultData

type ResultData struct {
	ResultType string   `json:"resultType"`
	Result     []Sample `json:"result"`
}

ResultData holds the query result data.

type Sample

type Sample struct {
	Metric map[string]string `json:"metric"`
	Value  []any             `json:"value,omitempty"`  // [timestamp, value] for instant queries
	Values [][]any           `json:"values,omitempty"` // [[timestamp, value], ...] for range queries
}

Sample represents a single sample from the query result.

Jump to

Keyboard shortcuts

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