From 0325aad24e1cd762c8e7204fa016d4d007a4419d Mon Sep 17 00:00:00 2001 From: lemoer Date: Fri, 26 Mar 2021 10:18:29 +0100 Subject: [PATCH] Add hostnames to database-output of link Grafana is currently not able to resolve the target.id or source.id into a human readable hostname. Therefore reading the neighbour graphs is quite difficult for humans. To resolve this, we add the additional tags source.hostname and target.hostname to the influx link measurements. In PR #197 --- database/influxdb/link.go | 6 ++++++ runtime/node.go | 2 ++ runtime/nodes.go | 15 +++++++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/database/influxdb/link.go b/database/influxdb/link.go index 1d642ba..37c2bd9 100644 --- a/database/influxdb/link.go +++ b/database/influxdb/link.go @@ -14,6 +14,12 @@ func (conn *Connection) InsertLink(link *runtime.Link, t time.Time) { tags.SetString("source.addr", link.SourceAddress) tags.SetString("target.id", link.TargetID) tags.SetString("target.addr", link.TargetAddress) + if link.SourceHostname != "" { + tags.SetString("source.hostname", link.SourceHostname) + } + if link.TargetHostname != "" { + tags.SetString("target.hostname", link.TargetHostname) + } conn.addPoint(MeasurementLink, tags, models.Fields{"tq": link.TQ * 100}, t) } diff --git a/runtime/node.go b/runtime/node.go index cb55738..d048639 100644 --- a/runtime/node.go +++ b/runtime/node.go @@ -22,9 +22,11 @@ type Node struct { // Link represents a link between two nodes type Link struct { SourceID string + SourceHostname string SourceAddress string TargetID string TargetAddress string + TargetHostname string TQ float32 } diff --git a/runtime/nodes.go b/runtime/nodes.go index 3dae12d..069e804 100644 --- a/runtime/nodes.go +++ b/runtime/nodes.go @@ -117,13 +117,24 @@ func (nodes *Nodes) NodeLinks(node *Node) (result []Link) { for sourceMAC, batadv := range neighbours.Batadv { for neighbourMAC, link := range batadv.Neighbours { if neighbourID := nodes.ifaceToNodeID[neighbourMAC]; neighbourID != "" { - result = append(result, Link{ + neighbour := nodes.List[neighbours.NodeID] + + link := Link{ SourceID: neighbours.NodeID, SourceAddress: sourceMAC, TargetID: neighbourID, TargetAddress: neighbourMAC, TQ: float32(link.Tq) / 255.0, - }) + } + + if neighbour.Nodeinfo != nil { + link.SourceHostname = neighbour.Nodeinfo.Hostname + } + if node.Nodeinfo != nil { + link.TargetHostname = node.Nodeinfo.Hostname + } + + result = append(result, link) } } }