Skip to content

Commit

Permalink
refactor(inputs.diskio): Merge guage and counter into counter.(influx…
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangxianfu committed Oct 2, 2024
1 parent c455ac4 commit e3b7c62
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions plugins/inputs/diskio/diskio.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (d *DiskIO) Gather(acc telegraf.Accumulator) error {
}
}

fieldsC := map[string]interface{}{
fields := map[string]interface{}{
"reads": io.ReadCount,
"writes": io.WriteCount,
"read_bytes": io.ReadBytes,
Expand All @@ -135,20 +135,16 @@ func (d *DiskIO) Gather(acc telegraf.Accumulator) error {
deltaRWCount := float64(io.ReadCount + io.WriteCount - lastValue.ReadCount - lastValue.WriteCount)
deltaRWTime := float64(io.ReadTime + io.WriteTime - lastValue.ReadTime - lastValue.WriteTime)
deltaIOTime := float64(io.IoTime - lastValue.IoTime)
fieldsG := make(map[string]interface{})
if deltaRWCount > 0 {
fieldsG["io_await"] = deltaRWTime / deltaRWCount
fieldsG["io_svctm"] = deltaIOTime / deltaRWCount
fields["io_await"] = deltaRWTime / deltaRWCount
fields["io_svctm"] = deltaIOTime / deltaRWCount
}
itv := float64(collectTime.Sub(d.lastCollectTime).Milliseconds())
if itv > 0 {
fieldsG["io_util"] = 100 * deltaIOTime / itv
}
if len(fieldsG) > 0 {
acc.AddGauge("diskio", fieldsG, tags)
fields["io_util"] = 100 * deltaIOTime / itv
}
}
acc.AddCounter("diskio", fieldsC, tags)
acc.AddCounter("diskio", fields, tags)
}
d.lastCollectTime = collectTime
d.lastIOCounterStat = diskio
Expand Down

0 comments on commit e3b7c62

Please sign in to comment.