[BUGFIX] Fixed Graphite naming (#72)
* Bugfix: Graphite compatibility with meshviewer * Bugfix: Bad message: Router type not sanitized * Refactoring: Implemented replaceInvalidChars function for Graphite
This commit is contained in:
parent
2148a7de28
commit
b5a694a7a4
|
@ -27,7 +27,7 @@ func GlobalStatsFields(stats *runtime.GlobalStats) []graphigo.Metric {
|
|||
func (c *Connection) addCounterMap(name string, m runtime.CounterMap, t time.Time) {
|
||||
var fields []graphigo.Metric
|
||||
for key, count := range m {
|
||||
fields = append(fields, graphigo.Metric{Name: name + `.` + key + `.count`, Value: count, Timestamp: t})
|
||||
fields = append(fields, graphigo.Metric{Name: name + `.` + replaceInvalidChars(key) + `.count`, Value: count, Timestamp: t})
|
||||
}
|
||||
c.addPoint(fields)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package graphite
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/FreifunkBremen/yanic/runtime"
|
||||
|
@ -25,7 +24,7 @@ func (c *Connection) InsertNode(node *runtime.Node) {
|
|||
return
|
||||
}
|
||||
|
||||
node_prefix := MeasurementNode + `.` + stats.NodeID + `.` + strings.Replace(nodeinfo.Hostname, ".", "__", -1)
|
||||
node_prefix := MeasurementNode + `.` + stats.NodeID + `.` + replaceInvalidChars(nodeinfo.Hostname)
|
||||
|
||||
addField := func(name string, value interface{}) {
|
||||
fields = append(fields, graphigo.Metric{Name: node_prefix + "." + name, Value: value})
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package graphite
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var reInvalidChars = regexp.MustCompile("(?i)[^a-z0-9\\-]")
|
||||
|
||||
func replaceInvalidChars(name string) string {
|
||||
return reInvalidChars.ReplaceAllString(name, "_")
|
||||
}
|
Loading…
Reference in New Issue