in image/resources/knfsd-metrics-agent/internal/mounts/scraper.go [352:401]
func (s *mountScraper) reportDelta(stats nfsStats, now pdata.Timestamp) {
// TODO: Report counters instead of gauges
// This is a direct port of the original script that used
// nfsiostat, so is limited to the data that was output by nfsiostat.
// Now that we have the raw data we can report a lot more metrics.
// We can also use counters instead of calculating the diff for many of
// the metrics and let the monitoring tool calculate the rate.
// This is a new mount, no previous metrics yet so cannot calculate a diff
// on this scrape.
prev, found := s.previous[stats.server]
if !found {
return
}
// if new.age < prev.summary.age, then the counters must have reset
// i.e. the NFS share was re-mounted.
// If the counters have reset then we cannot derive any useful metrics
// on this scrape, so just treat this as if it were a new summary.
if stats.summary.age <= prev.summary.age {
return
}
diff := diffSummary(stats.summary, prev.summary)
delta := diff.age.Seconds()
if delta <= 0 {
// This should not happen, as any summaries that have an age smaller
// than the previous entry are handled as a reset to the counters.
// Just in case, skip reporting this scrape to avoid divide by zero
// errors or spurious values.
return
}
sends := float64(diff.transport.Sends)
var backlog float64
if sends > 0 {
backlog = float64(diff.transport.CumulativeBacklog) / sends
}
read := calc(delta, diff.operations["READ"])
write := calc(delta, diff.operations["WRITE"])
s.mb.RecordNfsMountOpsPerSecondDataPoint(now, sends/delta, stats.server, stats.instance)
s.mb.RecordNfsMountRPCBacklogDataPoint(now, backlog/delta, stats.server, stats.instance)
s.mb.RecordNfsMountReadExeDataPoint(now, read.exePerOp, stats.server, stats.instance)
s.mb.RecordNfsMountReadRttDataPoint(now, read.rttPerOp, stats.server, stats.instance)
s.mb.RecordNfsMountWriteExeDataPoint(now, write.exePerOp, stats.server, stats.instance)
s.mb.RecordNfsMountWriteRttDataPoint(now, write.rttPerOp, stats.server, stats.instance)
}