diff --git a/collectors/infinibandMetric.go b/collectors/infinibandMetric.go index 7560af9..615d68f 100644 --- a/collectors/infinibandMetric.go +++ b/collectors/infinibandMetric.go @@ -37,6 +37,7 @@ type InfinibandCollector struct { config struct { ExcludeDevices []string `json:"exclude_devices,omitempty"` // IB device to exclude e.g. mlx5_0 SendAbsoluteValues bool `json:"send_abs_values"` // Send absolut values as read from sys filesystem + SendTotalValues bool `json:"send_total_values"` // Send computed total values SendDerivedValues bool `json:"send_derived_values"` // Send derived values e.g. rates } info []*InfinibandCollectorInfo @@ -171,6 +172,9 @@ func (m *InfinibandCollector) Read(interval time.Duration, output chan lp.CCMetr m.lastTimestamp = now for _, info := range m.info { + + currentState := make(map[string]int64) + for counterName, counterDef := range info.portCounterFiles { // Read counter file @@ -211,11 +215,52 @@ func (m *InfinibandCollector) Read(interval time.Duration, output chan lp.CCMetr output <- y } } - // Save current state - info.lastState[counterName] = v } + + // Save current state + currentState[counterName] = v + } + // Save current state for use as last state + if m.config.SendDerivedValues { + info.lastState = currentState + } + + if m.config.SendAbsoluteValues { + recv, recv_ok := currentState["ib_recv"] + xmit, xmit_ok := currentState["ib_xmit"] + recv_pkts, recv_pkts_ok := currentState["ib_recv_pkts"] + xmit_pkts, xmit_pkts_ok := currentState["ib_xmit_pkts"] + if recv_ok && xmit_ok { + if y, err := + lp.New( + "ib_total", + info.tagSet, + m.meta, + map[string]interface{}{ + "value": recv + xmit, + }, + now); err == nil { + y.AddMeta("unit", "bytes") + output <- y + } + } + if recv_pkts_ok && xmit_pkts_ok { + if y, err := + lp.New( + "ib_total_pkts", + info.tagSet, + m.meta, + map[string]interface{}{ + "value": recv_pkts + xmit_pkts, + }, + now); err == nil { + y.AddMeta("unit", "packets") + output <- y + } + } + } } } diff --git a/collectors/infinibandMetric.md b/collectors/infinibandMetric.md index f129aad..c965ea8 100644 --- a/collectors/infinibandMetric.md +++ b/collectors/infinibandMetric.md @@ -17,13 +17,16 @@ LID file (`/sys/class/infiniband//ports//lid`) The devices can be filtered with the `exclude_devices` option in the configuration. -For each found LID the collector reads data through the sysfs files below `/sys/class/infiniband/`. +For each found LID the collector reads data through the sysfs files below `/sys/class/infiniband/`. (See: ) Metrics: + * `ib_recv` * `ib_xmit` * `ib_recv_pkts` * `ib_xmit_pkts` +* `ib_total = ib_recv + ib_xmit` (if `send_total_values == true`) +* `ib_total_pkts = ib_recv_pkts + ib_xmit_pkts` (if `send_total_values == true`) * `ib_recv_bw` (if `send_derived_values == true`) * `ib_xmit_bw` (if `send_derived_values == true`) * `ib_recv_pkts_bw` (if `send_derived_values == true`)