proxy.golang.org : github.com/clambin/grafana-json-server
Package grafana_json_server provides a Go implementation of the JSON API Grafana Datasource, which provides a way of sending JSON-formatted data into Grafana dataframes. A metric is the source of data to be sent to Grafana. In its simplest form, running a JSON API server for a metric requires creating a server for that metric and starting an HTTP listener: This starts a JSON API server for a single metric, called 'metric1' and a query, which implements the Query interface and will generate the data for the metric. To provide more configuration options for the metric, use WithMetric instead: The query function produces the data to be sent to Grafana. Queries can be of one of two types: Time series queries can therefore only return a single set of values. If your query involves returning multiple sets of data, use table queries instead. A time series query returns a TimeSeriesResponse: A table query returns a TableResponse: Note that the table must be 'complete', i.e. each column should have the same number of entries. The JSON API Grafana Datasource allows each metric to have a number of user-selectable options. In the Grafana Edit panel, these are shown in the Payload section of the metric. To add payload options to the metric, configure these when creating the metric: The above example configures a new metric, with one payload option, called "option". The option allows multiple values to be selected. Two possible options are configured: option1 and option2. When performing the query, the query function can check which options are selected by reading the request's payload: The payload Option field will contain all selected options, i.e. option1, option2. If no options are selected, Option will be an empty slice. Note: the payload structure must match the metric's payload definition. Otherwise GetPayload returns an error. With the above metric definition, the following will fail: Since Option is a multi-select option, a slice is expected. In the previous section, we configured a metric with hard-coded options. If we want to have dynamic options, we use the MetricPayloadOption function when creating the metric. Possible use cases for this could be if runtime conditions determine which options you want to present, or if you want to determine valid options based on what other options are selected. This creates a single metric, metric1. The metric has two payload options, option1 and option2. The former has two hardcoded options. The latter has no Options configured. This will cause the data source plugin to call metricPayloadOptionsFunc to determine which options to present. The following is a basic example of such a MetricPayloadOption function: The JSON API datasource supports dashboard variable values to be retrieved from an JSON API server. To configure this, add a dashboard variable with the variable type set to "Query" and the data source to your JSON API server. In the server, create the server with the WithVariable option: In the example, "query0" is the name specified in the Query section of the variable definition. This causes Grafana to call the variableFunc whenever the variable is refreshed. This function returns all possible values for the variable: A Query function can read the value of each variables by examining the ScopedVars in the QueryRequest: Note: in non-Raw JSON mode, GrafanaJSONDatasource stores the Query name in a json payload, with a "target" field holding the Query name. In Raw JSON mode, a user can specify any JSON structure as payload. To route the request to the correct VariableFunc, add a "target" field with the relevant name. If no "target" field is found, the request is routed to a VariableFunc with a blank ("") target: See the Variable example for more.
Registry
-
Source
- Documentation
- JSON
purl: pkg:golang/github.com/clambin/grafana-json-server
License: MIT
Latest release: 6 months ago
First release: almost 2 years ago
Namespace: github.com/clambin
Dependent packages: 2
Stars: 1 on GitHub
Forks: 0 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 20 days ago
github.com/clambin/sciensano/v2 v2.2.1
4 versions - Latest release: over 1 year ago - 0 stars on GitHubgithub.com/clambin/sciensano v1.16.0
39 versions - Latest release: almost 2 years ago - 0 stars on GitHubCheck this option to include packages that no longer depend on this package in their latest version but previously did.