mirror of
https://github.com/nshttpd/mikrotik-exporter.git
synced 2024-11-16 10:25:12 +01:00
9ceb56fdbf
Thanks. I could have sworn I went through already and done this at one point in time, but I guess not.
48 lines
1019 B
Go
48 lines
1019 B
Go
package collector
|
|
|
|
import (
|
|
"math"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
func metricStringCleanup(in string) string {
|
|
return strings.Replace(in, "-", "_", -1)
|
|
}
|
|
|
|
func descriptionForPropertyName(prefix, property string, labelNames []string) *prometheus.Desc {
|
|
return prometheus.NewDesc(
|
|
prometheus.BuildFQName(namespace, prefix, metricStringCleanup(property)),
|
|
property,
|
|
labelNames,
|
|
nil,
|
|
)
|
|
}
|
|
|
|
func description(prefix, name, helpText string, labelNames []string) *prometheus.Desc {
|
|
return prometheus.NewDesc(
|
|
prometheus.BuildFQName(namespace, prefix, name),
|
|
helpText,
|
|
labelNames,
|
|
nil,
|
|
)
|
|
}
|
|
|
|
func splitStringToFloats(metric string) (float64, float64, error) {
|
|
strs := strings.Split(metric, ",")
|
|
if len(strs) == 0 {
|
|
return 0, 0, nil
|
|
}
|
|
m1, err := strconv.ParseFloat(strs[0], 64)
|
|
if err != nil {
|
|
return math.NaN(), math.NaN(), err
|
|
}
|
|
m2, err := strconv.ParseFloat(strs[1], 64)
|
|
if err != nil {
|
|
return math.NaN(), math.NaN(), err
|
|
}
|
|
return m1, m2, nil
|
|
}
|