Skip to content

Commit

Permalink
When exporting node specific statistics to prometheus we now include …
Browse files Browse the repository at this point in the history
…the hostname of the node to the labels of the metric
  • Loading branch information
dereulenspiegel committed Dec 21, 2015
1 parent b931111 commit 1d3c8b3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,31 @@ func (t *TrafficCountPipe) Process(in chan data.ParsedResponse) chan data.Parsed
}

// NodeMetricCollector updates per node metrics based on received statistics responses.
type NodeMetricCollector struct{}
type NodeMetricCollector struct {
Store data.Nodeinfostore
}

func (n *NodeMetricCollector) Process(in chan data.ParsedResponse) chan data.ParsedResponse {
out := make(chan data.ParsedResponse)
go func() {
for response := range in {
if response.Type() == "statistics" {
stats := response.ParsedData().(*data.StatisticsStruct)
NodesClients.WithLabelValues(response.NodeId()).Set(float64(stats.Clients.Total))
NodesUptime.WithLabelValues(response.NodeId()).Set(stats.Uptime)
if stats.Traffic != nil {
NodesTrafficRx.WithLabelValues(response.NodeId(), "traffic").Set(float64(stats.Traffic.Rx.Bytes))
NodesTrafficTx.WithLabelValues(response.NodeId(), "traffic").Set(float64(stats.Traffic.Tx.Bytes))
NodesTrafficRx.WithLabelValues(response.NodeId(), "mgmt_traffic").Set(float64(stats.Traffic.MgmtRx.Bytes))
NodesTrafficTx.WithLabelValues(response.NodeId(), "mgmt_traffic").Set(float64(stats.Traffic.MgmtTx.Bytes))
nodeinfo, err := n.Store.GetNodeInfo(response.NodeId())
if err != nil {
log.WithFields(log.Fields{
"nodeid": response.NodeId(),
}).Errorf("Can't retrieve node infos to get the hostname")
} else {
name := nodeinfo.Hostname
NodesClients.WithLabelValues(response.NodeId(), name).Set(float64(stats.Clients.Total))
NodesUptime.WithLabelValues(response.NodeId(), name).Set(stats.Uptime)
if stats.Traffic != nil {
NodesTrafficRx.WithLabelValues(response.NodeId(), name, "traffic").Set(float64(stats.Traffic.Rx.Bytes))
NodesTrafficTx.WithLabelValues(response.NodeId(), name, "traffic").Set(float64(stats.Traffic.Tx.Bytes))
NodesTrafficRx.WithLabelValues(response.NodeId(), name, "mgmt_traffic").Set(float64(stats.Traffic.MgmtRx.Bytes))
NodesTrafficTx.WithLabelValues(response.NodeId(), name, "mgmt_traffic").Set(float64(stats.Traffic.MgmtTx.Bytes))
}
}
}
out <- response
Expand All @@ -160,6 +170,6 @@ func GetPrometheusProcessPipes(store data.Nodeinfostore) []pipeline.ProcessPipe
//out = append(out, &ReturnedNodeDetector{Store: store})
out = append(out, &ClientCountPipe{Store: store})
out = append(out, &TrafficCountPipe{Store: store})
out = append(out, &NodeMetricCollector{})
out = append(out, &NodeMetricCollector{Store: store})
return out
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ var (
NodesTrafficRx = stat.NewCounterVec(stat.CounterOpts{
Name: "meshnode_traffic_rx",
Help: "Transmitted traffic from nodes",
}, []string{"nodeid", "type"})
}, []string{"nodeid", "name", "type"})

NodesTrafficTx = stat.NewCounterVec(stat.CounterOpts{
Name: "meshnode_traffic_tx",
Help: "Received traffic on nodes",
}, []string{"nodeid", "type"})
}, []string{"nodeid", "name", "type"})

NodesUptime = stat.NewCounterVec(stat.CounterOpts{
Name: "meshnode_uptime",
Help: "Uptime of meshnodes",
}, []string{"nodeid"})
}, []string{"nodeid", "name"})

NodesClients = stat.NewGaugeVec(stat.GaugeOpts{
Name: "meshnode_clients",
Help: "Clients on single meshnodes",
}, []string{"nodeid"})
}, []string{"nodeid", "name"})

NodeMetricsMap = make(map[string]*NodeMetrics)
)
Expand Down

0 comments on commit 1d3c8b3

Please sign in to comment.