@@ -10,10 +10,10 @@ import (
10
10
//"regexp"
11
11
//"strconv"
12
12
//"strings"
13
+ "gopkg.in/yaml.v2"
14
+ "io/ioutil"
13
15
"math"
14
16
"time"
15
- "io/ioutil"
16
- "gopkg.in/yaml.v2"
17
17
18
18
_ "github.com/lib/pq"
19
19
"github.com/prometheus/client_golang/prometheus"
36
36
"extend.query-path" , "" ,
37
37
"Path to custom queries to run." ,
38
38
)
39
+ onlyDumpMaps = flag .Bool (
40
+ "dumpmaps" , false ,
41
+ "Do not run, simply dump the maps." ,
42
+ )
39
43
)
40
44
41
45
// Metric name parts.
@@ -111,6 +115,21 @@ var variableMaps = map[string]map[string]ColumnMapping{
111
115
},
112
116
}
113
117
118
+ func dumpMaps () {
119
+ for name , cmap := range metricMaps {
120
+ query , ok := queryOverrides [name ]
121
+ if ok {
122
+ fmt .Printf ("%s: %s\n " , name , query )
123
+ } else {
124
+ fmt .Println (name )
125
+ }
126
+ for column , details := range cmap {
127
+ fmt .Printf (" %-40s %v\n " , column , details )
128
+ }
129
+ fmt .Println ()
130
+ }
131
+ }
132
+
114
133
var metricMaps = map [string ]map [string ]ColumnMapping {
115
134
"pg_stat_bgwriter" : map [string ]ColumnMapping {
116
135
"checkpoints_timed" : {COUNTER , "Number of scheduled checkpoints that have been performed" , nil },
@@ -235,7 +254,6 @@ func addQueries(queriesPath string) (err error) {
235
254
return err
236
255
}
237
256
238
-
239
257
for metric , specs := range extra {
240
258
for key , value := range specs .(map [interface {}]interface {}) {
241
259
switch key .(string ) {
@@ -249,14 +267,16 @@ func addQueries(queriesPath string) (err error) {
249
267
250
268
for n , a := range column {
251
269
var cmap ColumnMapping
252
- var metric_map map [string ]ColumnMapping
253
270
254
- metric_map = make (map [string ]ColumnMapping )
271
+ metric_map , ok := metricMaps [metric ]
272
+ if ! ok {
273
+ metric_map = make (map [string ]ColumnMapping )
274
+ }
255
275
256
276
name := n .(string )
257
277
258
278
for attr_key , attr_val := range a .(map [interface {}]interface {}) {
259
- switch ( attr_key .(string ) ) {
279
+ switch attr_key .(string ) {
260
280
case "usage" :
261
281
usage , err := stringToColumnUsage (attr_val .(string ))
262
282
if err != nil {
@@ -374,7 +394,7 @@ func makeDescMap(metricMaps map[string]map[string]ColumnMapping) map[string]Metr
374
394
375
395
// convert a string to the corresponding ColumnUsage
376
396
func stringToColumnUsage (s string ) (u ColumnUsage , err error ) {
377
- switch ( s ) {
397
+ switch s {
378
398
case "DISCARD" :
379
399
u = DISCARD
380
400
@@ -666,18 +686,23 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) {
666
686
func main () {
667
687
flag .Parse ()
668
688
669
- dsn := os .Getenv ("DATA_SOURCE_NAME" )
670
- if len (dsn ) == 0 {
671
- log .Fatal ("couldn't find environment variable DATA_SOURCE_NAME" )
672
- }
673
-
674
689
if * queriesPath != "" {
675
690
err := addQueries (* queriesPath )
676
691
if err != nil {
677
692
log .Warnln ("Unparseable queries file - discarding merge: " , * queriesPath , err )
678
693
}
679
694
}
680
695
696
+ if * onlyDumpMaps {
697
+ dumpMaps ()
698
+ return
699
+ }
700
+
701
+ dsn := os .Getenv ("DATA_SOURCE_NAME" )
702
+ if len (dsn ) == 0 {
703
+ log .Fatal ("couldn't find environment variable DATA_SOURCE_NAME" )
704
+ }
705
+
681
706
exporter := NewExporter (dsn )
682
707
prometheus .MustRegister (exporter )
683
708
0 commit comments