You've already forked postgres_exporter
mirror of
https://github.com/prometheus-community/postgres_exporter.git
synced 2025-06-16 04:40:57 +03:00
Made cosmetic changes to fit the Go coding standards
This commit is contained in:
@ -222,7 +222,7 @@ var queryOverrides = map[string]string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add queries to the metricMaps and queryOverrides maps
|
// Add queries to the metricMaps and queryOverrides maps
|
||||||
func add_queries(queriesPath string) (err error) {
|
func addQueries(queriesPath string) (err error) {
|
||||||
var extra map[string]interface{}
|
var extra map[string]interface{}
|
||||||
|
|
||||||
content, err := ioutil.ReadFile(queriesPath)
|
content, err := ioutil.ReadFile(queriesPath)
|
||||||
@ -258,7 +258,7 @@ func add_queries(queriesPath string) (err error) {
|
|||||||
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 := _string_to_columnusage(attr_val.(string))
|
usage, err := stringToColumnUsage(attr_val.(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -282,34 +282,6 @@ func add_queries(queriesPath string) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert a string to the corresponding ColumnUsage
|
|
||||||
func _string_to_columnusage(s string) (u ColumnUsage, err error) {
|
|
||||||
switch(s) {
|
|
||||||
case "DISCARD":
|
|
||||||
u = DISCARD
|
|
||||||
|
|
||||||
case "LABEL":
|
|
||||||
u = LABEL
|
|
||||||
|
|
||||||
case "COUNTER":
|
|
||||||
u = COUNTER
|
|
||||||
|
|
||||||
case "GAUGE":
|
|
||||||
u = GAUGE
|
|
||||||
|
|
||||||
case "MAPPEDMETRIC":
|
|
||||||
u = MAPPEDMETRIC
|
|
||||||
|
|
||||||
case "DURATION":
|
|
||||||
u = DURATION
|
|
||||||
default:
|
|
||||||
err = fmt.Errorf("wrong ColumnUsage given : %s", s)
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Turn the MetricMap column mapping into a prometheus descriptor mapping.
|
// Turn the MetricMap column mapping into a prometheus descriptor mapping.
|
||||||
func makeDescMap(metricMaps map[string]map[string]ColumnMapping) map[string]MetricMapNamespace {
|
func makeDescMap(metricMaps map[string]map[string]ColumnMapping) map[string]MetricMapNamespace {
|
||||||
var metricMap = make(map[string]MetricMapNamespace)
|
var metricMap = make(map[string]MetricMapNamespace)
|
||||||
@ -400,6 +372,34 @@ func makeDescMap(metricMaps map[string]map[string]ColumnMapping) map[string]Metr
|
|||||||
return metricMap
|
return metricMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convert a string to the corresponding ColumnUsage
|
||||||
|
func stringToColumnUsage(s string) (u ColumnUsage, err error) {
|
||||||
|
switch(s) {
|
||||||
|
case "DISCARD":
|
||||||
|
u = DISCARD
|
||||||
|
|
||||||
|
case "LABEL":
|
||||||
|
u = LABEL
|
||||||
|
|
||||||
|
case "COUNTER":
|
||||||
|
u = COUNTER
|
||||||
|
|
||||||
|
case "GAUGE":
|
||||||
|
u = GAUGE
|
||||||
|
|
||||||
|
case "MAPPEDMETRIC":
|
||||||
|
u = MAPPEDMETRIC
|
||||||
|
|
||||||
|
case "DURATION":
|
||||||
|
u = DURATION
|
||||||
|
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("wrong ColumnUsage given : %s", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Convert database.sql types to float64s for Prometheus consumption. Null types are mapped to NaN. string and []byte
|
// Convert database.sql types to float64s for Prometheus consumption. Null types are mapped to NaN. string and []byte
|
||||||
// types are mapped as NaN and !ok
|
// types are mapped as NaN and !ok
|
||||||
func dbToFloat64(t interface{}) (float64, bool) {
|
func dbToFloat64(t interface{}) (float64, bool) {
|
||||||
@ -672,7 +672,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if *queriesPath != "" {
|
if *queriesPath != "" {
|
||||||
err := add_queries(*queriesPath)
|
err := addQueries(*queriesPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnln("Unparseable queries file - discarding merge: ", *queriesPath, err)
|
log.Warnln("Unparseable queries file - discarding merge: ", *queriesPath, err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user