diff --git a/examples/plugins/traffic-control/report.go b/examples/plugins/traffic-control/report.go index 3ea8dab4d..e1e0d3023 100644 --- a/examples/plugins/traffic-control/report.go +++ b/examples/plugins/traffic-control/report.go @@ -146,6 +146,7 @@ func (r *Reporter) getContainerNodes() map[string]node { case Running: nodeID := containerIDToNodeID(containerID) latency, _ := getLatency(container.PID) + pktLoss, _ := getPktLoss(container.PID) nodes[nodeID] = node{ LatestControls: getTrafficNodeControls(timestamp, dead), Latest: map[string]stringEntry{ @@ -153,10 +154,18 @@ func (r *Reporter) getContainerNodes() map[string]node { Timestamp: timestamp, Value: latency, }, + "traffic-control-pktloss": { + Timestamp: timestamp, + Value: pktLoss, + }, "traffic-control-table-latency": { Timestamp: timestamp, Value: latency, }, + "traffic-control-table-pktloss": { + Timestamp: timestamp, + Value: pktLoss, + }, }, } } @@ -174,6 +183,14 @@ func getMetadataTemplate() map[string]metadataTemplate { Priority: 13.5, From: "latest", }, + "traffic-control-pktloss": metadataTemplate{ + ID: "traffic-control-pktloss", + Label: "Packet Loss", + Truncate: 0, + Datatype: "", + Priority: 13.6, + From: "latest", + }, } } diff --git a/examples/plugins/traffic-control/tc.go b/examples/plugins/traffic-control/tc.go index 4c2d8dd84..b66d2ec69 100644 --- a/examples/plugins/traffic-control/tc.go +++ b/examples/plugins/traffic-control/tc.go @@ -51,7 +51,7 @@ func DoTrafficControl(pid int, latency string) error { } else { trafficControlStatusCache[netNSID] = trafficControlStatus{ latency: latency, - pktLoss: "0.0%", + pktLoss: "-", } } return nil @@ -106,10 +106,11 @@ func getStatus(pid int) (*trafficControlStatus, error) { log.Error(netNSID) return &emptyTrafficControlStatus, fmt.Errorf("failed to get network namespace ID: %v", err) } else { - l, _ := parseLatency(output) + lat, _ := parseLatency(output) + pktL, _ := parsePktLoss(output) trafficControlStatusCache[netNSID] = trafficControlStatus{ - latency: l, - pktLoss: "0.0%", + latency: lat, + pktLoss: pktL, } } status, _ := trafficControlStatusCache[netNSID] @@ -134,7 +135,7 @@ func parseAttribute(statusString string, attribute string) (string, error) { } } } - return "N/A", fmt.Errorf("%s not found", attribute) + return "-", fmt.Errorf("%s not found", attribute) } func getNSID(nsPath string) (string, error) {