@@ -34,7 +34,9 @@ const (
34
34
PluginlistType
35
35
AlertlistType
36
36
SinglestatType
37
+ StatType
37
38
RowType
39
+ BarGaugeType
38
40
)
39
41
40
42
const MixedSource = "-- Mixed --"
@@ -49,10 +51,12 @@ type (
49
51
* TablePanel
50
52
* TextPanel
51
53
* SinglestatPanel
54
+ * StatPanel
52
55
* DashlistPanel
53
56
* PluginlistPanel
54
57
* RowPanel
55
58
* AlertlistPanel
59
+ * BarGaugePanel
56
60
* CustomPanel
57
61
}
58
62
panelType int8
82
86
Text string `json:"text"`
83
87
Value string `json:"value"`
84
88
} `json:"scopedVars,omitempty"`
85
- Span float32 `json:"span"` // general
86
- Title string `json:"title"` // general
89
+ Span float32 `json:"span"` // general
90
+ Title string `json:"title"` // general
91
+ Description * string `json:"description,omitempty"` // general
87
92
Transparent bool `json:"transparent"`
88
93
Type string `json:"type"`
89
94
Alert * Alert `json:"alert,omitempty"`
@@ -127,7 +132,6 @@ type (
127
132
DashLength * uint `json:"dashLength,omitempty"`
128
133
Dashes * bool `json:"dashes,omitempty"`
129
134
Decimals * uint `json:"decimals,omitempty"`
130
- Description * string `json:"description,omitempty"`
131
135
Fill int `json:"fill"`
132
136
// Grid grid `json:"grid"` obsoleted in 4.1 by xaxis and yaxis
133
137
@@ -155,6 +159,33 @@ type (
155
159
Xaxis Axis `json:"xaxis"` // was added in Grafana 4.x?
156
160
Yaxes []Axis `json:"yaxes"` // was added in Grafana 4.x?
157
161
}
162
+ FieldConfig struct {
163
+ Defaults struct {
164
+ Unit string `json:"unit"`
165
+ Threshold struct {
166
+ Mode string `json:"mode"`
167
+ Steps []struct {
168
+ Color string `json:"color"`
169
+ Value string `json:"value"`
170
+ } `json:"steps"`
171
+ } `json:"threshold"`
172
+ } `json:"defaults"`
173
+ }
174
+ Options struct {
175
+ Orientation string `json:"orientation"`
176
+ TextMode string `json:"textMode"`
177
+ ColorMode string `json:"colorMode"`
178
+ GraphMode string `json:"graphMode"`
179
+ JustifyMode string `json:"justifyMode"`
180
+ DisplayMode string `json:"displayMode"`
181
+ Content string `json:"content"`
182
+ Mode string `json:"mode"`
183
+ ReduceOptions struct {
184
+ Values bool `json:"values"`
185
+ Fields string `json:"fields"`
186
+ Calcs []string `json:"calcs"`
187
+ } `json:"reduceOptions"`
188
+ }
158
189
Threshold struct {
159
190
// the alert threshold value, we do not omitempty, since 0 is a valid
160
191
// threshold
@@ -188,13 +219,18 @@ type (
188
219
Scroll bool `json:"scroll"` // from grafana 3.x
189
220
}
190
221
TextPanel struct {
191
- Content string `json:"content"`
192
- Mode string `json:"mode"`
193
- PageSize uint `json:"pageSize"`
194
- Scroll bool `json:"scroll"`
195
- ShowHeader bool `json:"showHeader"`
196
- Sort Sort `json:"sort"`
197
- Styles []ColumnStyle `json:"styles"`
222
+ Content string `json:"content"`
223
+ Mode string `json:"mode"`
224
+ PageSize uint `json:"pageSize"`
225
+ Scroll bool `json:"scroll"`
226
+ ShowHeader bool `json:"showHeader"`
227
+ Sort Sort `json:"sort"`
228
+ Styles []ColumnStyle `json:"styles"`
229
+ FieldConfig FieldConfig `json:"fieldConfig"`
230
+ Options struct {
231
+ Content string `json:"content"`
232
+ Mode string `json:"mode"`
233
+ } `json:"options"`
198
234
}
199
235
SinglestatPanel struct {
200
236
Colors []string `json:"colors"`
@@ -219,11 +255,40 @@ type (
219
255
ValueMaps []ValueMap `json:"valueMaps"`
220
256
ValueName string `json:"valueName"`
221
257
}
258
+ StatPanel struct {
259
+ Colors []string `json:"colors"`
260
+ ColorValue bool `json:"colorValue"`
261
+ ColorBackground bool `json:"colorBackground"`
262
+ Decimals int `json:"decimals"`
263
+ Format string `json:"format"`
264
+ Gauge Gauge `json:"gauge,omitempty"`
265
+ MappingType * uint `json:"mappingType,omitempty"`
266
+ MappingTypes []* MapType `json:"mappingTypes,omitempty"`
267
+ MaxDataPoints * IntString `json:"maxDataPoints,omitempty"`
268
+ NullPointMode string `json:"nullPointMode"`
269
+ Postfix * string `json:"postfix,omitempty"`
270
+ PostfixFontSize * string `json:"postfixFontSize,omitempty"`
271
+ Prefix * string `json:"prefix,omitempty"`
272
+ PrefixFontSize * string `json:"prefixFontSize,omitempty"`
273
+ RangeMaps []* RangeMap `json:"rangeMaps,omitempty"`
274
+ SparkLine SparkLine `json:"sparkline,omitempty"`
275
+ Targets []Target `json:"targets,omitempty"`
276
+ Thresholds string `json:"thresholds"`
277
+ ValueFontSize string `json:"valueFontSize"`
278
+ ValueMaps []ValueMap `json:"valueMaps"`
279
+ ValueName string `json:"valueName"`
280
+ Options Options `json:"options"`
281
+ }
222
282
DashlistPanel struct {
223
- Mode string `json:"mode"`
224
- Limit uint `json:"limit"`
225
- Query string `json:"query"`
226
- Tags []string `json:"tags"`
283
+ Mode string `json:"mode"`
284
+ Query string `json:"query"`
285
+ Tags []string `json:"tags"`
286
+ FolderID int `json:"folderId"`
287
+ Limit int `json:"limit"`
288
+ Headings bool `json:"headings"`
289
+ Recent bool `json:"recent"`
290
+ Search bool `json:"search"`
291
+ Starred bool `json:"starred"`
227
292
}
228
293
PluginlistPanel struct {
229
294
Limit int `json:"limit,omitempty"`
@@ -237,6 +302,11 @@ type (
237
302
NameFilter string `json:"nameFilter,omitempty"`
238
303
DashboardTags []string `json:"dashboardTags,omitempty"`
239
304
}
305
+ BarGaugePanel struct {
306
+ Options Options `json:"options"`
307
+ Targets []Target `json:"targets,omitempty"`
308
+ FieldConfig FieldConfig `json:"fieldConfig"`
309
+ }
240
310
RowPanel struct {
241
311
Panels []Panel `json:"panels"`
242
312
Collapsed bool `json:"collapsed"`
@@ -331,7 +401,7 @@ type (
331
401
}
332
402
)
333
403
334
- // for a singlestat
404
+ // for a stat
335
405
type (
336
406
ValueMap struct {
337
407
Op string `json:"op"`
@@ -558,7 +628,23 @@ func NewSinglestat(title string) *Panel {
558
628
SinglestatPanel : & SinglestatPanel {}}
559
629
}
560
630
561
- // NewPluginlist initializes panel with a singlestat panel.
631
+ // NewStat initializes panel with a stat panel.
632
+ func NewStat (title string ) * Panel {
633
+ if title == "" {
634
+ title = "Panel Title"
635
+ }
636
+ render := "flot"
637
+ return & Panel {
638
+ CommonPanel : CommonPanel {
639
+ OfType : StatType ,
640
+ Title : title ,
641
+ Type : "stat" ,
642
+ Renderer : & render ,
643
+ IsNew : true },
644
+ StatPanel : & StatPanel {}}
645
+ }
646
+
647
+ // NewPluginlist initializes panel with a stat panel.
562
648
func NewPluginlist (title string ) * Panel {
563
649
if title == "" {
564
650
title = "Panel Title"
@@ -589,7 +675,7 @@ func NewAlertlist(title string) *Panel {
589
675
AlertlistPanel : & AlertlistPanel {}}
590
676
}
591
677
592
- // NewCustom initializes panel with a singlestat panel.
678
+ // NewCustom initializes panel with a stat panel.
593
679
func NewCustom (title string ) * Panel {
594
680
if title == "" {
595
681
title = "Panel Title"
@@ -612,8 +698,12 @@ func (p *Panel) ResetTargets() {
612
698
p .GraphPanel .Targets = nil
613
699
case SinglestatType :
614
700
p .SinglestatPanel .Targets = nil
701
+ case StatType :
702
+ p .StatPanel .Targets = nil
615
703
case TableType :
616
704
p .TablePanel .Targets = nil
705
+ case BarGaugeType :
706
+ p .BarGaugePanel .Targets = nil
617
707
}
618
708
}
619
709
@@ -627,6 +717,8 @@ func (p *Panel) AddTarget(t *Target) {
627
717
p .GraphPanel .Targets = append (p .GraphPanel .Targets , * t )
628
718
case SinglestatType :
629
719
p .SinglestatPanel .Targets = append (p .SinglestatPanel .Targets , * t )
720
+ case StatType :
721
+ p .StatPanel .Targets = append (p .StatPanel .Targets , * t )
630
722
case TableType :
631
723
p .TablePanel .Targets = append (p .TablePanel .Targets , * t )
632
724
}
@@ -650,6 +742,8 @@ func (p *Panel) SetTarget(t *Target) {
650
742
setTarget (t , & p .GraphPanel .Targets )
651
743
case SinglestatType :
652
744
setTarget (t , & p .SinglestatPanel .Targets )
745
+ case StatType :
746
+ setTarget (t , & p .StatPanel .Targets )
653
747
case TableType :
654
748
setTarget (t , & p .TablePanel .Targets )
655
749
}
@@ -677,6 +771,8 @@ func (p *Panel) RepeatDatasourcesForEachTarget(dsNames ...string) {
677
771
repeatDS (dsNames , & p .GraphPanel .Targets )
678
772
case SinglestatType :
679
773
repeatDS (dsNames , & p .SinglestatPanel .Targets )
774
+ case StatType :
775
+ repeatDS (dsNames , & p .StatPanel .Targets )
680
776
case TableType :
681
777
repeatDS (dsNames , & p .TablePanel .Targets )
682
778
}
@@ -707,6 +803,8 @@ func (p *Panel) RepeatTargetsForDatasources(dsNames ...string) {
707
803
repeatTarget (dsNames , & p .GraphPanel .Targets )
708
804
case SinglestatType :
709
805
repeatTarget (dsNames , & p .SinglestatPanel .Targets )
806
+ case StatType :
807
+ repeatTarget (dsNames , & p .StatPanel .Targets )
710
808
case TableType :
711
809
repeatTarget (dsNames , & p .TablePanel .Targets )
712
810
}
@@ -720,8 +818,12 @@ func (p *Panel) GetTargets() *[]Target {
720
818
return & p .GraphPanel .Targets
721
819
case SinglestatType :
722
820
return & p .SinglestatPanel .Targets
821
+ case StatType :
822
+ return & p .StatPanel .Targets
723
823
case TableType :
724
824
return & p .TablePanel .Targets
825
+ case BarGaugeType :
826
+ return & p .BarGaugePanel .Targets
725
827
default :
726
828
return nil
727
829
}
@@ -761,12 +863,24 @@ func (p *Panel) UnmarshalJSON(b []byte) (err error) {
761
863
if err = json .Unmarshal (b , & singlestat ); err == nil {
762
864
p .SinglestatPanel = & singlestat
763
865
}
866
+ case "stat" :
867
+ var stat StatPanel
868
+ p .OfType = StatType
869
+ if err = json .Unmarshal (b , & stat ); err == nil {
870
+ p .StatPanel = & stat
871
+ }
764
872
case "dashlist" :
765
873
var dashlist DashlistPanel
766
874
p .OfType = DashlistType
767
875
if err = json .Unmarshal (b , & dashlist ); err == nil {
768
876
p .DashlistPanel = & dashlist
769
877
}
878
+ case "bargauge" :
879
+ var bargauge BarGaugePanel
880
+ p .OfType = BarGaugeType
881
+ if err = json .Unmarshal (b , & bargauge ); err == nil {
882
+ p .BarGaugePanel = & bargauge
883
+ }
770
884
case "row" :
771
885
var rowpanel RowPanel
772
886
p .OfType = RowType
@@ -810,12 +924,24 @@ func (p *Panel) MarshalJSON() ([]byte, error) {
810
924
SinglestatPanel
811
925
}{p .CommonPanel , * p .SinglestatPanel }
812
926
return json .Marshal (outSinglestat )
927
+ case StatType :
928
+ var outSinglestat = struct {
929
+ CommonPanel
930
+ StatPanel
931
+ }{p .CommonPanel , * p .StatPanel }
932
+ return json .Marshal (outSinglestat )
813
933
case DashlistType :
814
934
var outDashlist = struct {
815
935
CommonPanel
816
936
DashlistPanel
817
937
}{p .CommonPanel , * p .DashlistPanel }
818
938
return json .Marshal (outDashlist )
939
+ case BarGaugeType :
940
+ var outBarGauge = struct {
941
+ CommonPanel
942
+ BarGaugePanel
943
+ }{p .CommonPanel , * p .BarGaugePanel }
944
+ return json .Marshal (outBarGauge )
819
945
case PluginlistType :
820
946
var outPluginlist = struct {
821
947
CommonPanel
0 commit comments