TargetBase
grafanacode: base class for generating targets and collection class to store targets and datasources
always use DOUBLE QUOTES (NO SINGLE QUOTES) in the grafana sources (queries)
- class grafanacode.plugins.target_base.TargetBag[source]
Bases:
objectclass containing Datasource and Target objects
- param datasources:
read only - default: Factory(factory=<class ‘dict’>, takes_self=False)
- param targets:
read only - default: {0: {}}
- addDatasource(key='', data=None)[source]
Add a Datasource json dict to the collection.
- Parameters:
key (string) – name of the Datasource
data (object) – Datasource json or object
- addTarget(group=0, key=None, target=None)[source]
Add a Target json dict to the collection. The collection consists of a number of groups. the group <0> is created by default, but if the group does not exists if gets created.
- Parameters:
group (string, int) – name or number defining the Target collection group
key (string) – name of the Target (in the group)
data (object) – Target json or object
- getDatasource(key='')[source]
Get a Datasource json dict from the collection.
- Parameters:
key (string) – name of the Datasource
- Returns:
object – Datasource json or object
- getTarget(group=0, key=0)[source]
Get a Target json dict from the collection.
- Parameters:
group (string, int) – name or number defining the Target collection group
key (string) – name of the Target (in the group)
- Returns:
object – Target json or object
- loglevel: int = 5
- class grafanacode.plugins.target_base.TargetBase(q=None, t=None)[source]
Bases:
objectDataclass encapsulating one target mappinsitem. This class can be subclassed to hold specific targets, e.g. InfluxDB, Prometheus, …
- param q:
default: None - optional - type: str
- param t:
default: None - optional - type: object
- loglevel: int = 50
TargetInfluxdb
grafanacode: class for generating InfluxDB Flux targets
always use DOUBLE QUOTES (NO SINGLE QUOTES) in the grafana (flux) sources
- class grafanacode.plugins.target_influxdb.TargetInfluxDB(q=None, t=None, tz=None, b=None, h=None, c=None, r=None, a=_Nothing.NOTHING, datasource=_Nothing.NOTHING, hide=None, query=None, refid=None)[source]
Bases:
TargetBaseDataclass encapsulating one InfluxDB target mappingsitem.
h: additional headers c: additional calculations b: bucketname r: range = 'default' |> range(start: v.timeRangeStart, stop: v.timeRangeStop) = '<hstart>' |> range(start: v.timeRangeStop-hstart, stop: v.timeRangeStop) = ['<hstart>','<hstop>'] |> range(start: <hstart>, stop: <hstop>) if hstart = start then hstart = v.timeRangeStart if hstop = stop then hstop = v.timeRangeStop = {'t': '<optional trunc>', 's': '<start>', 'd': '<duration>|stop'} if 'd' = stop then stop = v.timeRangeStop htrunc = date.truncate(t: v.timeRangeStop, unit: {t}) hstart = experimental.subDuration(d: {s}, from: htrunc) hstop = experimental.addDuration(d: {d}, to: hstart) |> range(start: hstart, stop: hstop) OR |> range(start: hstart, stop: v.timeRangeStop) a: aggregations at the end (in order of list) = ['last', ...] |> last() = [{'w':}, ...] |> aggregateWindow(every: $__interval, fn: <w>) = [{'w':, 'i':}, ...] |> aggregateWindow(every: <i>, fn: <w>) = [{'w':, 'i':, 'e': True}, ...] |> aggregateWindow(every: <i>, fn: <w>) = [{'d':[..]}, ...] |> drop(columns: [..])- param q:
default: None - optional - type: str
- param t:
default: None - optional - type: object
- param tz:
default: None - optional - type: str
- param b:
default: None - optional - type: str
- param h:
default: None - optional - type: str
- param c:
default: None - optional - type: str
- param r:
default: None - optional - type: str
- param a:
default: Factory(factory=<class ‘list’>, takes_self=False) - optional - type: list
- param datasource:
default: Factory(factory=<class ‘dict’>, takes_self=False) - optional - type: dict
- param hide:
default: None - optional - type: bool
- param query:
default: None - optional - type: str
- param refid:
default: None - optional - type: str
- getJson(dashboard=None, panel=None)[source]
Create the json to pack this target.
- Returns:
dict – target json code
- loglevel: int = 51
TargetPrometheus
grafanacode: class for generating Prometheus targets
always use DOUBLE QUOTES (NO SINGLE QUOTES) in the grafana (flux) sources
- class grafanacode.plugins.target_prometheus.TargetPrometheus(q=None, t=None, datasource=_Nothing.NOTHING, exemplar=False, expr=None, format='time_series', hide=None, instant=True, interval='', legendformat='', refid=None)[source]
Bases:
TargetBaseDataclass encapsulating one InfluxDB target mappinsitem.
- param q:
default: None - optional - type: str
- param t:
default: None - optional - type: object
- param datasource:
default: Factory(factory=<class ‘dict’>, takes_self=False) - optional - type: dict
- param exemplar:
optional - type: bool
- param expr:
default: None - optional - type: str
- param format:
default: time_series - optional - in: (‘time_series’, ‘table’, ‘heatmap’)
- param hide:
default: None - optional - type: bool
- param instant:
default: True - optional - type: bool
- param interval:
optional - type: str
- param legendformat:
optional - type: str
- param refid:
default: None - optional - type: str
- getJson(dashboard=None, panel=None)[source]
Create the json to pack this target.
- Returns:
dict – target json code
- loglevel: int = 51