Skip to content

Commit 9a637ed

Browse files
bitcharmerdanielnelson
authored andcommitted
Switch CPU from field to tag in interrupts input plugin (influxdata#4999) (influxdata#5024)
1 parent 1d6db08 commit 9a637ed

File tree

3 files changed

+184
-184
lines changed

3 files changed

+184
-184
lines changed

plugins/inputs/interrupts/README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The interrupts plugin gathers metrics about IRQs from `/proc/interrupts` and `/p
55
### Configuration
66
```
77
[[inputs.interrupts]]
8+
# To report cpus as tags instead of fields use cpu_as_tags
9+
# cpu_as_tags = false
10+
#
811
## To filter which IRQs to collect, make use of tagpass / tagdrop, i.e.
912
# [inputs.interrupts.tagdrop]
1013
# irq = [ "NET_RX", "TASKLET" ]
@@ -16,20 +19,32 @@ There are two measurements reported by this plugin.
1619
- `soft_interrupts` gathers metrics from the `/proc/softirqs` file
1720

1821
### Fields
19-
- CPUx: the amount of interrupts for the IRQ handled by that CPU
20-
- total: total amount of interrupts for all CPUs
22+
For cpu_as_tags=false (default):
23+
- CPUx: the amount of interrupts for the IRQ handled by the CPU
24+
- Total: sum of interrupts for the IRS for all CPUs
25+
For cpu_as_tags=true ():
26+
- Count: the amount of interrupts for the IRQ handled by CPU described in CPU tag
2127

2228
### Tags
2329
- irq: the IRQ
2430
- type: the type of interrupt
2531
- device: the name of the device that is located at that IRQ
32+
- cpu: the CPU (when cpus_as_tags=true)
2633

2734
### Example Output
2835
```
2936
./telegraf --config ~/interrupts_config.conf --test
37+
For cpus_as_tags=false (default):
3038
* Plugin: inputs.interrupts, Collection 1
31-
> interrupts,irq=0,type=IO-APIC,device=2-edge\ timer,host=hostname CPU0=23i,total=23i 1489346531000000000
32-
> interrupts,irq=1,host=hostname,type=IO-APIC,device=1-edge\ i8042 CPU0=9i,total=9i 1489346531000000000
33-
> interrupts,irq=30,type=PCI-MSI,device=65537-edge\ virtio1-input.0,host=hostname CPU0=1i,total=1i 1489346531000000000
34-
> soft_interrupts,irq=NET_RX,host=hostname CPU0=280879i,total=280879i 1489346531000000000
39+
> interrupts,irq=0,type=IO-APIC,device=2-edge\ timer,host=hostname,cpu=cpu0 count=23i 1489346531000000000
40+
> interrupts,irq=1,host=hostname,type=IO-APIC,device=1-edge\ i8042,cpu=cpu0 count=9i 1489346531000000000
41+
> interrupts,irq=30,type=PCI-MSI,device=65537-edge\ virtio1-input.0,host=hostname,cpu=cpu1 count=1i 1489346531000000000
42+
> soft_interrupts,irq=NET_RX,host=hostname,cpu=cpu0 count=280879i 1489346531000000000
43+
44+
For cpus_as_tags=true:
45+
> interrupts,cpu=cpu6,host=hostname,irq=PIW,type=Posted-interrupt\ wakeup\ event count=0i 1543539773000000000
46+
> interrupts,cpu=cpu7,host=hostname,irq=PIW,type=Posted-interrupt\ wakeup\ event count=0i 1543539773000000000
47+
> soft_interrupts,cpu=cpu0,host=hostname,irq=HI count=246441i 1543539773000000000
48+
> soft_interrupts,cpu=cpu1,host=hostname,irq=HI count=159154i 1543539773000000000
49+
3550
```

plugins/inputs/interrupts/interrupts.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import (
1212
"github.com/influxdata/telegraf/plugins/inputs"
1313
)
1414

15-
type Interrupts struct{}
15+
type Interrupts struct {
16+
CpuAsTags bool
17+
}
1618

1719
type IRQ struct {
1820
ID string
@@ -27,6 +29,9 @@ func NewIRQ(id string) *IRQ {
2729
}
2830

2931
const sampleConfig = `
32+
## To report cpus as tags instead of fields use cpu_as_tags
33+
# cpu_as_tags = false
34+
#
3035
## To filter which IRQs to collect, make use of tagpass / tagdrop, i.e.
3136
# [inputs.interrupts.tagdrop]
3237
# irq = [ "NET_RX", "TASKLET" ]
@@ -92,7 +97,7 @@ func gatherTagsFields(irq IRQ) (map[string]string, map[string]interface{}) {
9297
tags := map[string]string{"irq": irq.ID, "type": irq.Type, "device": irq.Device}
9398
fields := map[string]interface{}{"total": irq.Total}
9499
for i := 0; i < len(irq.Cpus); i++ {
95-
cpu := fmt.Sprintf("CPU%d", i)
100+
cpu := fmt.Sprintf("cpu%d", i)
96101
fields[cpu] = irq.Cpus[i]
97102
}
98103
return tags, fields
@@ -111,12 +116,26 @@ func (s *Interrupts) Gather(acc telegraf.Accumulator) error {
111116
acc.AddError(fmt.Errorf("Parsing %s: %s", file, err))
112117
continue
113118
}
114-
for _, irq := range irqs {
115-
tags, fields := gatherTagsFields(irq)
119+
reportMetrics(measurement, irqs, acc, s.CpuAsTags)
120+
}
121+
return nil
122+
}
123+
124+
func reportMetrics(measurement string, irqs []IRQ, acc telegraf.Accumulator, cpusAsTags bool) {
125+
for _, irq := range irqs {
126+
tags, fields := gatherTagsFields(irq)
127+
if cpusAsTags {
128+
for cpu, count := range irq.Cpus {
129+
cpuTags := map[string]string{"cpu": fmt.Sprintf("cpu%d", cpu)}
130+
for k, v := range tags {
131+
cpuTags[k] = v
132+
}
133+
acc.AddFields(measurement, map[string]interface{}{"count": count}, cpuTags)
134+
}
135+
} else {
116136
acc.AddFields(measurement, fields, tags)
117137
}
118138
}
119-
return nil
120139
}
121140

122141
func init() {

0 commit comments

Comments
 (0)