Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch CPU from field to tag in Interrupts input plugin (#4999) #5024

Merged
merged 4 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions plugins/inputs/interrupts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The interrupts plugin gathers metrics about IRQs from `/proc/interrupts` and `/p
### Configuration
```
[[inputs.interrupts]]
# 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" ]
Expand All @@ -16,20 +19,32 @@ There are two measurements reported by this plugin.
- `soft_interrupts` gathers metrics from the `/proc/softirqs` file

### Fields
- CPUx: the amount of interrupts for the IRQ handled by that CPU
- total: total amount of interrupts for all CPUs
For cpu_as_tags=false (default):
- CPUx: the amount of interrupts for the IRQ handled by the CPU
- Total: sum of interrupts for the IRS for all CPUs
For cpu_as_tags=true ():
- Count: the amount of interrupts for the IRQ handled by CPU described in CPU tag

### Tags
- irq: the IRQ
- type: the type of interrupt
- device: the name of the device that is located at that IRQ
- cpu: the CPU (when cpus_as_tags=true)

### Example Output
```
./telegraf --config ~/interrupts_config.conf --test
For cpus_as_tags=false (default):
* Plugin: inputs.interrupts, Collection 1
> interrupts,irq=0,type=IO-APIC,device=2-edge\ timer,host=hostname CPU0=23i,total=23i 1489346531000000000
> interrupts,irq=1,host=hostname,type=IO-APIC,device=1-edge\ i8042 CPU0=9i,total=9i 1489346531000000000
> interrupts,irq=30,type=PCI-MSI,device=65537-edge\ virtio1-input.0,host=hostname CPU0=1i,total=1i 1489346531000000000
> soft_interrupts,irq=NET_RX,host=hostname CPU0=280879i,total=280879i 1489346531000000000
> interrupts,irq=0,type=IO-APIC,device=2-edge\ timer,host=hostname,cpu=cpu0 count=23i 1489346531000000000
> interrupts,irq=1,host=hostname,type=IO-APIC,device=1-edge\ i8042,cpu=cpu0 count=9i 1489346531000000000
> interrupts,irq=30,type=PCI-MSI,device=65537-edge\ virtio1-input.0,host=hostname,cpu=cpu1 count=1i 1489346531000000000
> soft_interrupts,irq=NET_RX,host=hostname,cpu=cpu0 count=280879i 1489346531000000000
For cpus_as_tags=true:
> interrupts,cpu=cpu6,host=hostname,irq=PIW,type=Posted-interrupt\ wakeup\ event count=0i 1543539773000000000
> interrupts,cpu=cpu7,host=hostname,irq=PIW,type=Posted-interrupt\ wakeup\ event count=0i 1543539773000000000
> soft_interrupts,cpu=cpu0,host=hostname,irq=HI count=246441i 1543539773000000000
> soft_interrupts,cpu=cpu1,host=hostname,irq=HI count=159154i 1543539773000000000
```
29 changes: 24 additions & 5 deletions plugins/inputs/interrupts/interrupts.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
"github.com/influxdata/telegraf/plugins/inputs"
)

type Interrupts struct{}
type Interrupts struct {
CpuAsTags bool
}

type IRQ struct {
ID string
Expand All @@ -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" ]
Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand Down
Loading