mirror of
https://github.com/prometheus-community/postgres_exporter
synced 2025-04-22 23:15:26 +00:00
fix bug with multiple columns in same metric (only the last one was being used because the map was being overwritten each time); add -dumpmaps option for debugging
This commit is contained in:
parent
895166bbbb
commit
fc3a14f645
@ -10,10 +10,10 @@ import (
|
|||||||
//"regexp"
|
//"regexp"
|
||||||
//"strconv"
|
//"strconv"
|
||||||
//"strings"
|
//"strings"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
"io/ioutil"
|
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
|
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
@ -36,6 +36,10 @@ var (
|
|||||||
"extend.query-path", "",
|
"extend.query-path", "",
|
||||||
"Path to custom queries to run.",
|
"Path to custom queries to run.",
|
||||||
)
|
)
|
||||||
|
onlyDumpMaps = flag.Bool(
|
||||||
|
"dumpmaps", false,
|
||||||
|
"Do not run, simply dump the maps.",
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Metric name parts.
|
// Metric name parts.
|
||||||
@ -111,6 +115,21 @@ var variableMaps = map[string]map[string]ColumnMapping{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func dumpMaps() {
|
||||||
|
for name, cmap := range metricMaps {
|
||||||
|
query, ok := queryOverrides[name]
|
||||||
|
if ok {
|
||||||
|
fmt.Printf("%s: %s\n", name, query)
|
||||||
|
} else {
|
||||||
|
fmt.Println(name)
|
||||||
|
}
|
||||||
|
for column, details := range cmap {
|
||||||
|
fmt.Printf(" %-40s %v\n", column, details)
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var metricMaps = map[string]map[string]ColumnMapping{
|
var metricMaps = map[string]map[string]ColumnMapping{
|
||||||
"pg_stat_bgwriter": map[string]ColumnMapping{
|
"pg_stat_bgwriter": map[string]ColumnMapping{
|
||||||
"checkpoints_timed": {COUNTER, "Number of scheduled checkpoints that have been performed", nil},
|
"checkpoints_timed": {COUNTER, "Number of scheduled checkpoints that have been performed", nil},
|
||||||
@ -235,7 +254,6 @@ func addQueries(queriesPath string) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for metric, specs := range extra {
|
for metric, specs := range extra {
|
||||||
for key, value := range specs.(map[interface{}]interface{}) {
|
for key, value := range specs.(map[interface{}]interface{}) {
|
||||||
switch key.(string) {
|
switch key.(string) {
|
||||||
@ -249,14 +267,16 @@ func addQueries(queriesPath string) (err error) {
|
|||||||
|
|
||||||
for n, a := range column {
|
for n, a := range column {
|
||||||
var cmap ColumnMapping
|
var cmap ColumnMapping
|
||||||
var metric_map map[string]ColumnMapping
|
|
||||||
|
|
||||||
metric_map = make(map[string]ColumnMapping)
|
metric_map, ok := metricMaps[metric]
|
||||||
|
if !ok {
|
||||||
|
metric_map = make(map[string]ColumnMapping)
|
||||||
|
}
|
||||||
|
|
||||||
name := n.(string)
|
name := n.(string)
|
||||||
|
|
||||||
for attr_key, attr_val := range a.(map[interface{}]interface{}) {
|
for attr_key, attr_val := range a.(map[interface{}]interface{}) {
|
||||||
switch(attr_key.(string)) {
|
switch attr_key.(string) {
|
||||||
case "usage":
|
case "usage":
|
||||||
usage, err := stringToColumnUsage(attr_val.(string))
|
usage, err := stringToColumnUsage(attr_val.(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -374,7 +394,7 @@ func makeDescMap(metricMaps map[string]map[string]ColumnMapping) map[string]Metr
|
|||||||
|
|
||||||
// convert a string to the corresponding ColumnUsage
|
// convert a string to the corresponding ColumnUsage
|
||||||
func stringToColumnUsage(s string) (u ColumnUsage, err error) {
|
func stringToColumnUsage(s string) (u ColumnUsage, err error) {
|
||||||
switch(s) {
|
switch s {
|
||||||
case "DISCARD":
|
case "DISCARD":
|
||||||
u = DISCARD
|
u = DISCARD
|
||||||
|
|
||||||
@ -666,11 +686,6 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) {
|
|||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
dsn := os.Getenv("DATA_SOURCE_NAME")
|
|
||||||
if len(dsn) == 0 {
|
|
||||||
log.Fatal("couldn't find environment variable DATA_SOURCE_NAME")
|
|
||||||
}
|
|
||||||
|
|
||||||
if *queriesPath != "" {
|
if *queriesPath != "" {
|
||||||
err := addQueries(*queriesPath)
|
err := addQueries(*queriesPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -678,6 +693,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *onlyDumpMaps {
|
||||||
|
dumpMaps()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dsn := os.Getenv("DATA_SOURCE_NAME")
|
||||||
|
if len(dsn) == 0 {
|
||||||
|
log.Fatal("couldn't find environment variable DATA_SOURCE_NAME")
|
||||||
|
}
|
||||||
|
|
||||||
exporter := NewExporter(dsn)
|
exporter := NewExporter(dsn)
|
||||||
prometheus.MustRegister(exporter)
|
prometheus.MustRegister(exporter)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user