Documentation ¶
Index ¶
- Constants
- func NewDatasource(ctx context.Context, settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error)
- func NicerErrorMessages(err error) error
- type APIRequestFn
- type Datasource
- func (d *Datasource) CallResource(ctx context.Context, req *backend.CallResourceRequest, ...) error
- func (d *Datasource) CheckHealth(ctx context.Context, _ *backend.CheckHealthRequest) (*backend.CheckHealthResult, error)
- func (d *Datasource) GetResourceIDs(ctx context.Context, qm QueryModel) ([]int64, error)
- func (d *Datasource) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
- type FilterMetricsFn
- type GetResourceFn
- type HCloudMetrics
- type HCloudResource
- type IdentifierFn
- type Label
- type MetricsType
- type NameCache
- type Options
- type QueryModel
- type QueryRunner
- type RequestOpts
- type ResourceType
- type SelectBy
- type SelectableValue
Constants ¶
const ( QueryTypeResourceList = "resource-list" QueryTypeMetrics = "metrics" )
const ( LabelID = "id" LabelName = "name" LabelSeriesName = "series_name" LabelSeriesDisplayName = "series_display_name" )
const ( AutoLegendFormat = "{{ series_display_name }} {{ name }}" // DefaultBufferPeriod is the default buffer period for the QueryRunner. DefaultBufferPeriod = 200 * time.Millisecond InvalidAPITokenErrorMessage = "" /* 128-byte string literal not displayed */ )
Variables ¶
This section is empty.
Functions ¶
func NewDatasource ¶
func NewDatasource(ctx context.Context, settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error)
NewDatasource creates a new datasource instance.
func NicerErrorMessages ¶ added in v0.2.0
NicerErrorMessages replaces some error messages from the hetzner cloud API with more user-friendly messages.
Types ¶
type APIRequestFn ¶
type APIRequestFn[M HCloudMetrics] func(ctx context.Context, id int64, opts RequestOpts) (*M, error)
type Datasource ¶
type Datasource struct {
// contains filtered or unexported fields
}
Datasource is an example datasource which can respond to data queries, reports its health and has streaming skills.
func (*Datasource) CallResource ¶
func (d *Datasource) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error
CallResource handles additional API calls. These are used to fill the resource dropdowns in the query editor.
func (*Datasource) CheckHealth ¶
func (d *Datasource) CheckHealth(ctx context.Context, _ *backend.CheckHealthRequest) (*backend.CheckHealthResult, error)
CheckHealth handles health checks sent from Grafana to the plugin. The main use case for these health checks is the test button on the datasource configuration page which allows users to verify that a datasource is working as expected.
func (*Datasource) GetResourceIDs ¶
func (d *Datasource) GetResourceIDs(ctx context.Context, qm QueryModel) ([]int64, error)
func (*Datasource) QueryData ¶
func (d *Datasource) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
QueryData handles multiple queries and returns multiple responses. req contains the queries []DataQuery (where each query contains RefID as a unique identifier). The QueryDataResponse contains a map of RefID to the response for each query, and each response contains Frames ([]*Frame).
type FilterMetricsFn ¶
type FilterMetricsFn[M HCloudMetrics] func(metrics *M, metricsTypes []MetricsType) *M
type GetResourceFn ¶
type GetResourceFn[R HCloudResource] func(ctx context.Context, id int64) (*R, error)
type HCloudMetrics ¶
type HCloudMetrics interface { hcloud.ServerMetrics | hcloud.LoadBalancerMetrics }
type HCloudResource ¶
type HCloudResource interface { hcloud.Server | hcloud.LoadBalancer }
type IdentifierFn ¶
type IdentifierFn[R HCloudResource] func(resource *R) (int64, string)
type MetricsType ¶
type MetricsType string
const ( MetricsTypeServerCPU MetricsType = "cpu" MetricsTypeServerDiskBandwidth MetricsType = "disk-bandwidth" MetricsTypeServerDiskIOPS MetricsType = "disk-iops" MetricsTypeServerNetworkBandwidth MetricsType = "network-bandwidth" MetricsTypeServerNetworkPPS MetricsType = "network-pps" MetricsTypeLoadBalancerOpenConnections MetricsType = "open-connections" MetricsTypeLoadBalancerConnectionsPerSecond MetricsType = "connections-per-second" MetricsTypeLoadBalancerRequestsPerSecond MetricsType = "requests-per-second" MetricsTypeLoadBalancerBandwidth MetricsType = "bandwidth" )
type NameCache ¶
type NameCache[R HCloudResource] struct { sync.Mutex // contains filtered or unexported fields }
NameCache is a cache for resource names. It is used to avoid sending unnecessary API requests. Right now there is no expiry for entries, so if names are changed this is not reflected in queries.
func NewNameCache ¶
func NewNameCache[R HCloudResource](client *hcloud.Client, getFn GetResourceFn[R], identifierFn IdentifierFn[R]) *NameCache[R]
type QueryModel ¶
type QueryModel struct { ResourceType ResourceType `json:"resourceType"` MetricsType MetricsType `json:"metricsType"` SelectBy SelectBy `json:"selectBy"` LabelSelectors []string `json:"labelSelectors"` ResourceIDs []int64 `json:"resourceIds"` LegendFormat string `json:"legendFormat"` }
type QueryRunner ¶
type QueryRunner[M HCloudMetrics] struct { // contains filtered or unexported fields }
QueryRunner is responsible for getting the Metrics from the Hetzner Cloud API.
The Hetzner Cloud API has endpoints that expose all metrics for a single resource (server/load-balancer). This runs counter to the way you would use the metrics in Grafana, where you would like to see a single metrics for multiple resources.
The naive solution to this would send one request per resource per incoming query to the API, but this can easily exhaust the API rate limit. The QueryRunner instead buffers incoming requests and only sends a single request to the API per resource requested during the buffer period. If you show metrics from the same resource in ie. 5 panels, this will only send 1 request to the API instead of 5.
The downside is that responses are slower, because we always wait for the buffer period to end before sending the requests.
func NewQueryRunner ¶
func NewQueryRunner[M HCloudMetrics](bufferPeriod time.Duration, apiRequestFn APIRequestFn[M], filterMetrics FilterMetricsFn[M]) *QueryRunner[M]
func (*QueryRunner[M]) RequestMetrics ¶
func (q *QueryRunner[M]) RequestMetrics(ctx context.Context, ids []int64, opts RequestOpts) (map[int64]*M, error)
RequestMetrics requests metrics matching the arguments given. It will return a slice of metrics for each id in the same order
type RequestOpts ¶
type RequestOpts struct { MetricsTypes []MetricsType TimeRange backend.TimeRange Step int }
type ResourceType ¶
type ResourceType string
const ( ResourceTypeServer ResourceType = "server" ResourceTypeLoadBalancer ResourceType = "load-balancer" )