Adding upstream version 1.34.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e393c3af3f
commit
4978089aab
4963 changed files with 677545 additions and 0 deletions
101
plugins/inputs/interrupts/README.md
Normal file
101
plugins/inputs/interrupts/README.md
Normal file
|
@ -0,0 +1,101 @@
|
|||
# Interrupts Input Plugin
|
||||
|
||||
This plugin gathers metrics about IRQs from interrupts (`/proc/interrupts`) and
|
||||
soft-interrupts (`/proc/softirqs`).
|
||||
|
||||
⭐ Telegraf v1.3.0
|
||||
🏷️ system
|
||||
💻 all
|
||||
|
||||
## Global configuration options <!-- @/docs/includes/plugin_config.md -->
|
||||
|
||||
In addition to the plugin-specific configuration settings, plugins support
|
||||
additional global and plugin configuration settings. These settings are used to
|
||||
modify metrics, tags, and field or create aliases and configure ordering, etc.
|
||||
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||
|
||||
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins
|
||||
|
||||
## Configuration
|
||||
|
||||
```toml @sample.conf
|
||||
# This plugin gathers interrupts data from /proc/interrupts and /proc/softirqs.
|
||||
[[inputs.interrupts]]
|
||||
## When set to true, cpu metrics are tagged with the cpu. Otherwise cpu is
|
||||
## stored as a field.
|
||||
##
|
||||
## The default is false for backwards compatibility, and will be changed to
|
||||
## true in a future version. It is recommended to set to true on new
|
||||
## deployments.
|
||||
# cpu_as_tag = false
|
||||
|
||||
## To filter which IRQs to collect, make use of tagpass / tagdrop, i.e.
|
||||
# [inputs.interrupts.tagdrop]
|
||||
# irq = [ "NET_RX", "TASKLET" ]
|
||||
```
|
||||
|
||||
## Metrics
|
||||
|
||||
There are two styles depending on the value of `cpu_as_tag`.
|
||||
|
||||
With `cpu_as_tag = false`:
|
||||
|
||||
- interrupts
|
||||
- tags:
|
||||
- irq (IRQ name)
|
||||
- type
|
||||
- device (name of the device that is located at the IRQ)
|
||||
- cpu
|
||||
- fields:
|
||||
- cpu (int, number of interrupts per cpu)
|
||||
- total (int, total number of interrupts)
|
||||
|
||||
- soft_interrupts
|
||||
- tags:
|
||||
- irq (IRQ name)
|
||||
- type
|
||||
- device (name of the device that is located at the IRQ)
|
||||
- cpu
|
||||
- fields:
|
||||
- cpu (int, number of interrupts per cpu)
|
||||
- total (int, total number of interrupts)
|
||||
|
||||
With `cpu_as_tag = true`:
|
||||
|
||||
- interrupts
|
||||
- tags:
|
||||
- irq (IRQ name)
|
||||
- type
|
||||
- device (name of the device that is located at the IRQ)
|
||||
- cpu
|
||||
- fields:
|
||||
- count (int, number of interrupts)
|
||||
|
||||
- soft_interrupts
|
||||
- tags:
|
||||
- irq (IRQ name)
|
||||
- type
|
||||
- device (name of the device that is located at the IRQ)
|
||||
- cpu
|
||||
- fields:
|
||||
- count (int, number of interrupts)
|
||||
|
||||
## Example Output
|
||||
|
||||
With `cpu_as_tag = false`:
|
||||
|
||||
```text
|
||||
interrupts,irq=0,type=IO-APIC,device=2-edge\ timer,cpu=cpu0 count=23i 1489346531000000000
|
||||
interrupts,irq=1,type=IO-APIC,device=1-edge\ i8042,cpu=cpu0 count=9i 1489346531000000000
|
||||
interrupts,irq=30,type=PCI-MSI,device=65537-edge\ virtio1-input.0,cpu=cpu1 count=1i 1489346531000000000
|
||||
soft_interrupts,irq=NET_RX,cpu=cpu0 count=280879i 1489346531000000000
|
||||
```
|
||||
|
||||
With `cpu_as_tag = true`:
|
||||
|
||||
```text
|
||||
interrupts,cpu=cpu6,irq=PIW,type=Posted-interrupt\ wakeup\ event count=0i 1543539773000000000
|
||||
interrupts,cpu=cpu7,irq=PIW,type=Posted-interrupt\ wakeup\ event count=0i 1543539773000000000
|
||||
soft_interrupts,cpu=cpu0,irq=HI count=246441i 1543539773000000000
|
||||
soft_interrupts,cpu=cpu1,irq=HI count=159154i 1543539773000000000
|
||||
```
|
145
plugins/inputs/interrupts/interrupts.go
Normal file
145
plugins/inputs/interrupts/interrupts.go
Normal file
|
@ -0,0 +1,145 @@
|
|||
//go:generate ../../../tools/readme_config_includer/generator
|
||||
package interrupts
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
)
|
||||
|
||||
//go:embed sample.conf
|
||||
var sampleConfig string
|
||||
|
||||
type Interrupts struct {
|
||||
CPUAsTag bool `toml:"cpu_as_tag"`
|
||||
}
|
||||
|
||||
type irq struct {
|
||||
id string
|
||||
typ string
|
||||
device string
|
||||
total int64
|
||||
cpus []int64
|
||||
}
|
||||
|
||||
func (*Interrupts) SampleConfig() string {
|
||||
return sampleConfig
|
||||
}
|
||||
|
||||
func (s *Interrupts) Gather(acc telegraf.Accumulator) error {
|
||||
for measurement, file := range map[string]string{"interrupts": "/proc/interrupts", "soft_interrupts": "/proc/softirqs"} {
|
||||
irqs, err := parseFile(file)
|
||||
if err != nil {
|
||||
acc.AddError(err)
|
||||
continue
|
||||
}
|
||||
reportMetrics(measurement, irqs, acc, s.CPUAsTag)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseInterrupts(r io.Reader) ([]irq, error) {
|
||||
var irqs []irq
|
||||
var cpucount int
|
||||
scanner := bufio.NewScanner(r)
|
||||
if scanner.Scan() {
|
||||
cpus := strings.Fields(scanner.Text())
|
||||
if cpus[0] != "CPU0" {
|
||||
return nil, fmt.Errorf("expected first line to start with CPU0, but was %s", scanner.Text())
|
||||
}
|
||||
cpucount = len(cpus)
|
||||
}
|
||||
|
||||
scan:
|
||||
for scanner.Scan() {
|
||||
fields := strings.Fields(scanner.Text())
|
||||
if !strings.HasSuffix(fields[0], ":") {
|
||||
continue
|
||||
}
|
||||
irqid := strings.TrimRight(fields[0], ":")
|
||||
irq := newIRQ(irqid)
|
||||
irqvals := fields[1:]
|
||||
for i := 0; i < cpucount; i++ {
|
||||
if i < len(irqvals) {
|
||||
irqval, err := strconv.ParseInt(irqvals[i], 10, 64)
|
||||
if err != nil {
|
||||
continue scan
|
||||
}
|
||||
irq.cpus = append(irq.cpus, irqval)
|
||||
}
|
||||
}
|
||||
for _, irqval := range irq.cpus {
|
||||
irq.total += irqval
|
||||
}
|
||||
_, err := strconv.ParseInt(irqid, 10, 64)
|
||||
if err == nil && len(fields) >= cpucount+2 {
|
||||
irq.typ = fields[cpucount+1]
|
||||
irq.device = strings.Join(fields[cpucount+2:], " ")
|
||||
} else if len(fields) > cpucount {
|
||||
irq.typ = strings.Join(fields[cpucount+1:], " ")
|
||||
}
|
||||
irqs = append(irqs, *irq)
|
||||
}
|
||||
if scanner.Err() != nil {
|
||||
return nil, fmt.Errorf("error scanning file: %w", scanner.Err())
|
||||
}
|
||||
return irqs, nil
|
||||
}
|
||||
|
||||
func gatherTagsFields(irq irq) (map[string]string, map[string]interface{}) {
|
||||
tags := map[string]string{"irq": irq.id, "type": irq.typ, "device": irq.device}
|
||||
fields := map[string]interface{}{"total": irq.total}
|
||||
for i := 0; i < len(irq.cpus); i++ {
|
||||
cpu := fmt.Sprintf("CPU%d", i)
|
||||
fields[cpu] = irq.cpus[i]
|
||||
}
|
||||
return tags, fields
|
||||
}
|
||||
|
||||
func parseFile(file string) ([]irq, error) {
|
||||
f, err := os.Open(file)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not open file: %s", file)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
irqs, err := parseInterrupts(f)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parsing %q: %w", file, err)
|
||||
}
|
||||
return irqs, 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func newIRQ(id string) *irq {
|
||||
return &irq{id: id}
|
||||
}
|
||||
|
||||
func init() {
|
||||
inputs.Add("interrupts", func() telegraf.Input {
|
||||
return &Interrupts{}
|
||||
})
|
||||
}
|
160
plugins/inputs/interrupts/interrupts_test.go
Normal file
160
plugins/inputs/interrupts/interrupts_test.go
Normal file
|
@ -0,0 +1,160 @@
|
|||
package interrupts
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
)
|
||||
|
||||
// =====================================================================================
|
||||
// Setup and helper functions
|
||||
// =====================================================================================
|
||||
|
||||
func expectCPUAsTags(m *testutil.Accumulator, t *testing.T, measurement string, irq irq) {
|
||||
for idx, value := range irq.cpus {
|
||||
m.AssertContainsTaggedFields(t, measurement,
|
||||
map[string]interface{}{"count": value},
|
||||
map[string]string{"irq": irq.id, "type": irq.typ, "device": irq.device, "cpu": fmt.Sprintf("cpu%d", idx)},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func expectCPUAsFields(m *testutil.Accumulator, t *testing.T, measurement string, irq irq) {
|
||||
fields := map[string]interface{}{}
|
||||
total := int64(0)
|
||||
for idx, count := range irq.cpus {
|
||||
fields[fmt.Sprintf("CPU%d", idx)] = count
|
||||
total += count
|
||||
}
|
||||
fields["total"] = total
|
||||
|
||||
m.AssertContainsTaggedFields(t, measurement, fields, map[string]string{"irq": irq.id, "type": irq.typ, "device": irq.device})
|
||||
}
|
||||
|
||||
func setup(t *testing.T, irqString string, cpuAsTags bool) (*testutil.Accumulator, []irq) {
|
||||
f := bytes.NewBufferString(irqString)
|
||||
irqs, err := parseInterrupts(f)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, irqs)
|
||||
|
||||
acc := new(testutil.Accumulator)
|
||||
reportMetrics("soft_interrupts", irqs, acc, cpuAsTags)
|
||||
|
||||
return acc, irqs
|
||||
}
|
||||
|
||||
// =====================================================================================
|
||||
// Soft interrupts
|
||||
// =====================================================================================
|
||||
|
||||
const softIrqsString = ` CPU0 CPU1
|
||||
0: 134 0 IO-APIC-edge timer
|
||||
1: 7 3 IO-APIC-edge i8042
|
||||
NMI: 0 0 Non-maskable interrupts
|
||||
LOC: 2338608687 2334309625 Local timer interrupts
|
||||
MIS: 0
|
||||
NET_RX: 867028 225
|
||||
TASKLET: 205 0`
|
||||
|
||||
var softIrqsExpectedArgs = []irq{
|
||||
{id: "0", typ: "IO-APIC-edge", device: "timer", cpus: []int64{134, 0}},
|
||||
{id: "1", typ: "IO-APIC-edge", device: "i8042", cpus: []int64{7, 3}},
|
||||
{id: "NMI", typ: "Non-maskable interrupts", cpus: []int64{0, 0}},
|
||||
{id: "MIS", cpus: []int64{0}},
|
||||
{id: "NET_RX", cpus: []int64{867028, 225}},
|
||||
{id: "TASKLET", cpus: []int64{205, 0}},
|
||||
}
|
||||
|
||||
func TestCpuAsTagsSoftIrqs(t *testing.T) {
|
||||
acc, irqs := setup(t, softIrqsString, true)
|
||||
reportMetrics("soft_interrupts", irqs, acc, true)
|
||||
|
||||
for _, irq := range softIrqsExpectedArgs {
|
||||
expectCPUAsTags(acc, t, "soft_interrupts", irq)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCpuAsFieldsSoftIrqs(t *testing.T) {
|
||||
acc, irqs := setup(t, softIrqsString, false)
|
||||
reportMetrics("soft_interrupts", irqs, acc, false)
|
||||
|
||||
for _, irq := range softIrqsExpectedArgs {
|
||||
expectCPUAsFields(acc, t, "soft_interrupts", irq)
|
||||
}
|
||||
}
|
||||
|
||||
// =====================================================================================
|
||||
// HW interrupts, tests #4470
|
||||
// =====================================================================================
|
||||
|
||||
const hwIrqsString = ` CPU0 CPU1 CPU2 CPU3
|
||||
16: 0 0 0 0 bcm2836-timer 0 Edge arch_timer
|
||||
17: 127224250 118424219 127224437 117885416 bcm2836-timer 1 Edge arch_timer
|
||||
21: 0 0 0 0 bcm2836-pmu 9 Edge arm-pmu
|
||||
23: 1549514 0 0 0 ARMCTRL-level 1 Edge 3f00b880.mailbox
|
||||
24: 2 0 0 0 ARMCTRL-level 2 Edge VCHIQ doorbell
|
||||
46: 0 0 0 0 ARMCTRL-level 48 Edge bcm2708_fb dma
|
||||
48: 0 0 0 0 ARMCTRL-level 50 Edge DMA IRQ
|
||||
50: 0 0 0 0 ARMCTRL-level 52 Edge DMA IRQ
|
||||
51: 208 0 0 0 ARMCTRL-level 53 Edge DMA IRQ
|
||||
54: 883002 0 0 0 ARMCTRL-level 56 Edge DMA IRQ
|
||||
59: 0 0 0 0 ARMCTRL-level 61 Edge bcm2835-auxirq
|
||||
62: 521451447 0 0 0 ARMCTRL-level 64 Edge dwc_otg, dwc_otg_pcd, dwc_otg_hcd:usb1
|
||||
86: 857597 0 0 0 ARMCTRL-level 88 Edge mmc0
|
||||
87: 4938 0 0 0 ARMCTRL-level 89 Edge uart-pl011
|
||||
92: 5669 0 0 0 ARMCTRL-level 94 Edge mmc1
|
||||
FIQ: usb_fiq
|
||||
IPI0: 0 0 0 0 CPU wakeup interrupts
|
||||
IPI1: 0 0 0 0 Timer broadcast interrupts
|
||||
IPI2: 23564958 23464876 23531165 23040826 Rescheduling interrupts
|
||||
IPI3: 148438 639704 644266 588150 Function call interrupts
|
||||
IPI4: 0 0 0 0 CPU stop interrupts
|
||||
IPI5: 4348149 1843985 3819457 1822877 IRQ work interrupts
|
||||
IPI6: 0 0 0 0 completion interrupts`
|
||||
|
||||
var hwIrqsExpectedArgs = []irq{
|
||||
{id: "16", typ: "bcm2836-timer", device: "0 Edge arch_timer", cpus: []int64{0, 0, 0, 0}},
|
||||
{id: "17", typ: "bcm2836-timer", device: "1 Edge arch_timer", cpus: []int64{127224250, 118424219, 127224437, 117885416}},
|
||||
{id: "21", typ: "bcm2836-pmu", device: "9 Edge arm-pmu", cpus: []int64{0, 0, 0, 0}},
|
||||
{id: "23", typ: "ARMCTRL-level", device: "1 Edge 3f00b880.mailbox", cpus: []int64{1549514, 0, 0, 0}},
|
||||
{id: "24", typ: "ARMCTRL-level", device: "2 Edge VCHIQ doorbell", cpus: []int64{2, 0, 0, 0}},
|
||||
{id: "46", typ: "ARMCTRL-level", device: "48 Edge bcm2708_fb dma", cpus: []int64{0, 0, 0, 0}},
|
||||
{id: "48", typ: "ARMCTRL-level", device: "50 Edge DMA IRQ", cpus: []int64{0, 0, 0, 0}},
|
||||
{id: "50", typ: "ARMCTRL-level", device: "52 Edge DMA IRQ", cpus: []int64{0, 0, 0, 0}},
|
||||
{id: "51", typ: "ARMCTRL-level", device: "53 Edge DMA IRQ", cpus: []int64{208, 0, 0, 0}},
|
||||
{id: "54", typ: "ARMCTRL-level", device: "56 Edge DMA IRQ", cpus: []int64{883002, 0, 0, 0}},
|
||||
{id: "59", typ: "ARMCTRL-level", device: "61 Edge bcm2835-auxirq", cpus: []int64{0, 0, 0, 0}},
|
||||
{id: "62", typ: "ARMCTRL-level", device: "64 Edge dwc_otg, dwc_otg_pcd, dwc_otg_hcd:usb1", cpus: []int64{521451447, 0, 0, 0}},
|
||||
{id: "86", typ: "ARMCTRL-level", device: "88 Edge mmc0", cpus: []int64{857597, 0, 0, 0}},
|
||||
{id: "87", typ: "ARMCTRL-level", device: "89 Edge uart-pl011", cpus: []int64{4938, 0, 0, 0}},
|
||||
{id: "92", typ: "ARMCTRL-level", device: "94 Edge mmc1", cpus: []int64{5669, 0, 0, 0}},
|
||||
{id: "IPI0", typ: "CPU wakeup interrupts", cpus: []int64{0, 0, 0, 0}},
|
||||
{id: "IPI1", typ: "Timer broadcast interrupts", cpus: []int64{0, 0, 0, 0}},
|
||||
{id: "IPI2", typ: "Rescheduling interrupts", cpus: []int64{23564958, 23464876, 23531165, 23040826}},
|
||||
{id: "IPI3", typ: "Function call interrupts", cpus: []int64{148438, 639704, 644266, 588150}},
|
||||
{id: "IPI4", typ: "CPU stop interrupts", cpus: []int64{0, 0, 0, 0}},
|
||||
{id: "IPI5", typ: "IRQ work interrupts", cpus: []int64{4348149, 1843985, 3819457, 1822877}},
|
||||
{id: "IPI6", typ: "completion interrupts", cpus: []int64{0, 0, 0, 0}},
|
||||
}
|
||||
|
||||
func TestCpuAsTagsHwIrqs(t *testing.T) {
|
||||
acc, irqs := setup(t, hwIrqsString, true)
|
||||
reportMetrics("interrupts", irqs, acc, true)
|
||||
|
||||
for _, irq := range hwIrqsExpectedArgs {
|
||||
expectCPUAsTags(acc, t, "interrupts", irq)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCpuAsFieldsHwIrqs(t *testing.T) {
|
||||
acc, irqs := setup(t, hwIrqsString, false)
|
||||
reportMetrics("interrupts", irqs, acc, false)
|
||||
|
||||
for _, irq := range hwIrqsExpectedArgs {
|
||||
expectCPUAsFields(acc, t, "interrupts", irq)
|
||||
}
|
||||
}
|
13
plugins/inputs/interrupts/sample.conf
Normal file
13
plugins/inputs/interrupts/sample.conf
Normal file
|
@ -0,0 +1,13 @@
|
|||
# This plugin gathers interrupts data from /proc/interrupts and /proc/softirqs.
|
||||
[[inputs.interrupts]]
|
||||
## When set to true, cpu metrics are tagged with the cpu. Otherwise cpu is
|
||||
## stored as a field.
|
||||
##
|
||||
## The default is false for backwards compatibility, and will be changed to
|
||||
## true in a future version. It is recommended to set to true on new
|
||||
## deployments.
|
||||
# cpu_as_tag = false
|
||||
|
||||
## To filter which IRQs to collect, make use of tagpass / tagdrop, i.e.
|
||||
# [inputs.interrupts.tagdrop]
|
||||
# irq = [ "NET_RX", "TASKLET" ]
|
Loading…
Add table
Add a link
Reference in a new issue