This repository has been archived by the owner on Apr 21, 2021. It is now read-only.
forked from grafana/grafonnet-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsinglestat.libsonnet
181 lines (181 loc) · 5.04 KB
/
singlestat.libsonnet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
{
/**
* Creates a singlestat panel.
*
* @name singlestat.new
*
* @param title The title of the singlestat panel.
* @param format (default `'none'`) Unit
* @param description (default `''`)
* @param interval (optional)
* @param height (optional)
* @param datasource (optional)
* @param span (optional)
* @param min_span (optional)
* @param decimals (optional)
* @param valueName (default `'avg'`)
* @param valueFontSize (default `'80%'`)
* @param prefixFontSize (default `'50%'`)
* @param postfixFontSize (default `'50%'`)
* @param mappingType (default `1`)
* @param repeat (optional)
* @param repeatDirection (optional)
* @param prefix (default `''`)
* @param postfix (default `''`)
* @param colors (default `['#299c46','rgba(237, 129, 40, 0.89)','#d44a3a']`)
* @param colorBackground (default `false`)
* @param colorValue (default `false`)
* @param thresholds (default `''`)
* @param valueMaps (default `{value: 'null',op: '=',text: 'N/A'}`)
* @param rangeMaps (default `{value: 'null',op: '=',text: 'N/A'}`)
* @param transparent (optional)
* @param sparklineFillColor (default `'rgba(31, 118, 189, 0.18)'`)
* @param sparklineFull (default `false`)
* @param sparklineLineColor (default `'rgb(31, 120, 193)'`)
* @param sparklineShow (default `false`)
* @param gaugeShow (default `false`)
* @param gaugeMinValue (default `0`)
* @param gaugeMaxValue (default `100`)
* @param gaugeThresholdMarkers (default `true`)
* @param gaugeThresholdLabels (default `false`)
* @param timeFrom (optional)
* @param links (optional)
* @param tableColumn (default `''`)
* @param maxPerRow (optional)
* @param maxDataPoints (default `100`)
*
* @method addTarget(target) Adds a target object.
*/
new(
title,
format='none',
description='',
interval=null,
height=null,
datasource=null,
span=null,
min_span=null,
decimals=null,
valueName='avg',
valueFontSize='80%',
prefixFontSize='50%',
postfixFontSize='50%',
mappingType=1,
repeat=null,
repeatDirection=null,
prefix='',
postfix='',
colors=[
'#299c46',
'rgba(237, 129, 40, 0.89)',
'#d44a3a',
],
colorBackground=false,
colorValue=false,
thresholds='',
valueMaps=[
{
value: 'null',
op: '=',
text: 'N/A',
},
],
rangeMaps=[
{
from: 'null',
to: 'null',
text: 'N/A',
},
],
transparent=null,
sparklineFillColor='rgba(31, 118, 189, 0.18)',
sparklineFull=false,
sparklineLineColor='rgb(31, 120, 193)',
sparklineShow=false,
gaugeShow=false,
gaugeMinValue=0,
gaugeMaxValue=100,
gaugeThresholdMarkers=true,
gaugeThresholdLabels=false,
timeFrom=null,
links=[],
tableColumn='',
maxPerRow=null,
maxDataPoints=100,
)::
{
[if height != null then 'height']: height,
[if description != '' then 'description']: description,
[if repeat != null then 'repeat']: repeat,
[if repeatDirection != null then 'repeatDirection']: repeatDirection,
[if transparent != null then 'transparent']: transparent,
[if min_span != null then 'minSpan']: min_span,
title: title,
[if span != null then 'span']: span,
type: 'singlestat',
datasource: datasource,
targets: [
],
links: links,
[if decimals != null then 'decimals']: decimals,
maxDataPoints: maxDataPoints,
interval: interval,
cacheTimeout: null,
format: format,
prefix: prefix,
postfix: postfix,
nullText: null,
valueMaps: valueMaps,
[if maxPerRow != null then 'maxPerRow']: maxPerRow,
mappingTypes: [
{
name: 'value to text',
value: 1,
},
{
name: 'range to text',
value: 2,
},
],
rangeMaps: rangeMaps,
mappingType:
if mappingType == 'value'
then
1
else if mappingType == 'range'
then
2
else
mappingType,
nullPointMode: 'connected',
valueName: valueName,
prefixFontSize: prefixFontSize,
valueFontSize: valueFontSize,
postfixFontSize: postfixFontSize,
thresholds: thresholds,
[if timeFrom != null then 'timeFrom']: timeFrom,
colorBackground: colorBackground,
colorValue: colorValue,
colors: colors,
gauge: {
show: gaugeShow,
minValue: gaugeMinValue,
maxValue: gaugeMaxValue,
thresholdMarkers: gaugeThresholdMarkers,
thresholdLabels: gaugeThresholdLabels,
},
sparkline: {
fillColor: sparklineFillColor,
full: sparklineFull,
lineColor: sparklineLineColor,
show: sparklineShow,
},
tableColumn: tableColumn,
_nextTarget:: 0,
addTarget(target):: self {
local nextTarget = super._nextTarget,
_nextTarget: nextTarget + 1,
targets+: [target { refId: std.char(std.codepoint('A') + nextTarget) }],
},
},
}