mirror of
https://github.com/nshttpd/mikrotik-exporter.git
synced 2025-01-04 18:07:50 +01:00
25911b4e60
* Fix newlines. * Added wlan metrics. * Fix WlanSTA collector - return on errors.
46 lines
986 B
Go
46 lines
986 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) {
|
|
strings := strings.Split(metric, ",")
|
|
|
|
m1, err := strconv.ParseFloat(strings[0], 64)
|
|
if err != nil {
|
|
return math.NaN(), math.NaN(), err
|
|
}
|
|
m2, err := strconv.ParseFloat(strings[1], 64)
|
|
if err != nil {
|
|
return math.NaN(), math.NaN(), err
|
|
}
|
|
return m1, m2, nil
|
|
}
|