Only compute rates with a valid previous state

This commit is contained in:
Holger Obermaier 2022-03-10 15:28:30 +01:00
parent f8fdc4b377
commit d4df493fba
2 changed files with 34 additions and 27 deletions

View File

@ -17,11 +17,11 @@ import (
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric" lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
) )
const DEFAULT_GPFS_CMD = `mmpmon` const DEFAULT_GPFS_CMD = "mmpmon"
type GpfsCollectorLastValues struct { type GpfsCollectorLastState struct {
read int64 bytesRead int64
write int64 bytesWritten int64
} }
type GpfsCollector struct { type GpfsCollector struct {
@ -34,7 +34,7 @@ type GpfsCollector struct {
} }
skipFS map[string]struct{} skipFS map[string]struct{}
lastTimestamp time.Time // Store time stamp of last tick to derive bandwidths lastTimestamp time.Time // Store time stamp of last tick to derive bandwidths
lastValues map[string]GpfsCollectorLastValues lastState map[string]GpfsCollectorLastState
} }
func (m *GpfsCollector) Init(config json.RawMessage) error { func (m *GpfsCollector) Init(config json.RawMessage) error {
@ -46,10 +46,9 @@ func (m *GpfsCollector) Init(config json.RawMessage) error {
var err error var err error
m.name = "GpfsCollector" m.name = "GpfsCollector"
m.setup() m.setup()
m.lastTimestamp = time.Now()
// Set default mmpmon binary // Set default mmpmon binary
m.config.Mmpmon = string(DEFAULT_GPFS_CMD) m.config.Mmpmon = DEFAULT_GPFS_CMD
// Read JSON configuration // Read JSON configuration
if len(config) > 0 { if len(config) > 0 {
@ -98,9 +97,13 @@ func (m *GpfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
return return
} }
// Current time stamp
now := time.Now() now := time.Now()
tdiff := now.Sub(m.lastTimestamp) // time difference to last time stamp
timeDiff := now.Sub(m.lastTimestamp).Seconds()
// Save current timestamp
m.lastTimestamp = now m.lastTimestamp = now
// mmpmon: // mmpmon:
// -p: generate output that can be parsed // -p: generate output that can be parsed
// -s: suppress the prompt on input // -s: suppress the prompt on input
@ -160,10 +163,10 @@ func (m *GpfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
} }
m.tags["filesystem"] = filesystem m.tags["filesystem"] = filesystem
if _, ok := m.lastValues[filesystem]; !ok { if _, ok := m.lastState[filesystem]; !ok {
m.lastValues[filesystem] = GpfsCollectorLastValues{ m.lastState[filesystem] = GpfsCollectorLastState{
read: 0, bytesRead: -1,
write: 0, bytesWritten: -1,
} }
} }
@ -210,13 +213,12 @@ func (m *GpfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
output <- y output <- y
} }
if m.config.SendBandwidths { if m.config.SendBandwidths {
lastVal := m.lastValues[filesystem] if lastBytesRead := m.lastState[filesystem].bytesRead; lastBytesRead >= 0 {
diff := bytesRead - lastVal.read bwRead := float64(bytesRead-lastBytesRead) / timeDiff
lastVal.read = bytesRead if y, err := lp.New("gpfs_bw_read", m.tags, m.meta, map[string]interface{}{"value": bwRead}, timestamp); err == nil {
if y, err := lp.New("gpfs_bw_read", m.tags, m.meta, map[string]interface{}{"value": float64(diff) / tdiff.Seconds()}, timestamp); err == nil { output <- y
output <- y }
} }
m.lastValues[filesystem] = lastVal
} }
// bytes written // bytes written
@ -231,13 +233,19 @@ func (m *GpfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
output <- y output <- y
} }
if m.config.SendBandwidths { if m.config.SendBandwidths {
lastVal := m.lastValues[filesystem] if lastBytesWritten := m.lastState[filesystem].bytesRead; lastBytesWritten >= 0 {
diff := bytesWritten - lastVal.write bwWrite := float64(bytesWritten-lastBytesWritten) / timeDiff
lastVal.write = bytesWritten if y, err := lp.New("gpfs_bw_write", m.tags, m.meta, map[string]interface{}{"value": bwWrite}, timestamp); err == nil {
if y, err := lp.New("gpfs_bw_write", m.tags, m.meta, map[string]interface{}{"value": float64(diff) / tdiff.Seconds()}, timestamp); err == nil { output <- y
output <- y }
}
}
if m.config.SendBandwidths {
m.lastState[filesystem] = GpfsCollectorLastState{
bytesRead: bytesRead,
bytesWritten: bytesWritten,
} }
m.lastValues[filesystem] = lastVal
} }
// number of opens // number of opens

View File

@ -161,6 +161,8 @@ func (m *InfinibandCollector) Read(interval time.Duration, output chan lp.CCMetr
now := time.Now() now := time.Now()
// time difference to last time stamp // time difference to last time stamp
timeDiff := now.Sub(m.lastTimestamp).Seconds() timeDiff := now.Sub(m.lastTimestamp).Seconds()
// Save current timestamp
m.lastTimestamp = now
for _, info := range m.info { for _, info := range m.info {
for counterName, counterFile := range info.portCounterFiles { for counterName, counterFile := range info.portCounterFiles {
@ -205,9 +207,6 @@ func (m *InfinibandCollector) Read(interval time.Duration, output chan lp.CCMetr
} }
} }
// Save current timestamp
m.lastTimestamp = now
} }
func (m *InfinibandCollector) Close() { func (m *InfinibandCollector) Close() {