Documentation
¶
Index ¶
- func FormatLabelsTable(w io.Writer, resp *LabelsResponse) error
- func FormatMetadataTable(w io.Writer, resp *MetadataResponse) error
- func FormatSeriesTable(w io.Writer, resp *SeriesResponse) error
- func FormatTable(w io.Writer, resp *QueryResponse) error
- func FormatWideTable(w io.Writer, resp *QueryResponse) error
- type Client
- func (c *Client) LabelValues(ctx context.Context, datasourceUID, labelName string) (*LabelsResponse, error)
- func (c *Client) Labels(ctx context.Context, datasourceUID string) (*LabelsResponse, error)
- func (c *Client) Metadata(ctx context.Context, datasourceUID string, metric string) (*MetadataResponse, error)
- func (c *Client) Query(ctx context.Context, datasourceUID string, req QueryRequest) (*QueryResponse, error)
- func (c *Client) Series(ctx context.Context, datasourceUID string, match []string, ...) (*SeriesResponse, error)
- type DataFrame
- type DataFrameData
- type DataFrameSchema
- type Field
- type GrafanaQueryResponse
- type GrafanaResult
- type LabelsResponse
- type MetadataEntry
- type MetadataResponse
- type QueryRequest
- type QueryResponse
- type ResultData
- type Sample
- type SeriesResponse
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 FormatSeriesTable ¶ added in v0.2.8
func FormatSeriesTable(w io.Writer, resp *SeriesResponse) error
FormatSeriesTable formats a SeriesResponse as a table. Each row is a single series rendered in Prometheus selector syntax ({k="v",k2="v2"}) with labels sorted for stability.
func FormatTable ¶
func FormatTable(w io.Writer, resp *QueryResponse) error
FormatTable formats a QueryResponse as a compact, human-readable table. Labels are collapsed into a single SERIES column by default. Use FormatWideTable to explode labels into individual columns.
func FormatWideTable ¶ added in v0.2.11
func FormatWideTable(w io.Writer, resp *QueryResponse) error
FormatWideTable formats a QueryResponse as a wide table with one column per label. This is useful for inspection but is too verbose for the default human-readable view.
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) 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 ¶
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 ¶
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 ¶
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.
type SeriesResponse ¶ added in v0.2.8
SeriesResponse represents the response from a /api/v1/series query.