This commit is contained in:
committed by
Daniel Nelson
parent
1d6db08dc8
commit
9a637eda05
@@ -12,7 +12,9 @@ import (
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
)
|
||||
|
||||
type Interrupts struct{}
|
||||
type Interrupts struct {
|
||||
CpuAsTags bool
|
||||
}
|
||||
|
||||
type IRQ struct {
|
||||
ID string
|
||||
@@ -27,6 +29,9 @@ func NewIRQ(id string) *IRQ {
|
||||
}
|
||||
|
||||
const sampleConfig = `
|
||||
## To report cpus as tags instead of fields use cpu_as_tags
|
||||
# cpu_as_tags = false
|
||||
#
|
||||
## To filter which IRQs to collect, make use of tagpass / tagdrop, i.e.
|
||||
# [inputs.interrupts.tagdrop]
|
||||
# irq = [ "NET_RX", "TASKLET" ]
|
||||
@@ -92,7 +97,7 @@ func gatherTagsFields(irq IRQ) (map[string]string, map[string]interface{}) {
|
||||
tags := map[string]string{"irq": irq.ID, "type": irq.Type, "device": irq.Device}
|
||||
fields := map[string]interface{}{"total": irq.Total}
|
||||
for i := 0; i < len(irq.Cpus); i++ {
|
||||
cpu := fmt.Sprintf("CPU%d", i)
|
||||
cpu := fmt.Sprintf("cpu%d", i)
|
||||
fields[cpu] = irq.Cpus[i]
|
||||
}
|
||||
return tags, fields
|
||||
@@ -111,12 +116,26 @@ func (s *Interrupts) Gather(acc telegraf.Accumulator) error {
|
||||
acc.AddError(fmt.Errorf("Parsing %s: %s", file, err))
|
||||
continue
|
||||
}
|
||||
for _, irq := range irqs {
|
||||
tags, fields := gatherTagsFields(irq)
|
||||
reportMetrics(measurement, irqs, acc, s.CpuAsTags)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func reportMetrics(measurement string, irqs []IRQ, acc telegraf.Accumulator, cpusAsTags bool) {
|
||||
for _, irq := range irqs {
|
||||
tags, fields := gatherTagsFields(irq)
|
||||
if cpusAsTags {
|
||||
for cpu, count := range irq.Cpus {
|
||||
cpuTags := map[string]string{"cpu": fmt.Sprintf("cpu%d", cpu)}
|
||||
for k, v := range tags {
|
||||
cpuTags[k] = v
|
||||
}
|
||||
acc.AddFields(measurement, map[string]interface{}{"count": count}, cpuTags)
|
||||
}
|
||||
} else {
|
||||
acc.AddFields(measurement, fields, tags)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
Reference in New Issue
Block a user