1
0
Fork 0

Adding upstream version 1.34.4.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-24 07:26:29 +02:00
parent e393c3af3f
commit 4978089aab
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
4963 changed files with 677545 additions and 0 deletions

View file

@ -0,0 +1,51 @@
# Wireless Input Plugin
The wireless plugin gathers metrics about wireless link quality by reading the
`/proc/net/wireless` file. This plugin currently supports linux only.
## 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
# Monitor wifi signal strength and quality
# This plugin ONLY supports Linux
[[inputs.wireless]]
## Sets 'proc' directory path
## If not specified, then default is /proc
# host_proc = "/proc"
```
## Metrics
- metric
- tags:
- interface (wireless interface)
- fields:
- status (int64, gauge) - Its current state. This is a device dependent
information
- link (int64, percentage, gauge) - general quality of the reception
- level (int64, dBm, gauge) - signal strength at the receiver
- noise (int64, dBm, gauge) - silence level (no packet) at the receiver
- nwid (int64, packets, counter) - number of discarded packets due to
invalid network id
- crypt (int64, packets, counter) - number of packet unable to decrypt
- frag (int64, packets, counter) - fragmented packets
- retry (int64, packets, counter) - cumulative retry counts
- misc (int64, packets, counter) - dropped for un-specified reason
- missed_beacon (int64, packets, counter) - missed beacon packets
## Example Output
This section shows example output in Line Protocol format.
```text
wireless,host=example.localdomain,interface=wlan0 misc=0i,frag=0i,link=60i,level=-50i,noise=-256i,nwid=0i,crypt=0i,retry=1525i,missed_beacon=0i,status=0i 1519843022000000000
```

View file

@ -0,0 +1,6 @@
# Monitor wifi signal strength and quality
# This plugin ONLY supports Linux
[[inputs.wireless]]
## Sets 'proc' directory path
## If not specified, then default is /proc
# host_proc = "/proc"

View file

@ -0,0 +1,27 @@
//go:generate ../../../tools/readme_config_includer/generator
package wireless
import (
_ "embed"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"
)
//go:embed sample.conf
var sampleConfig string
type Wireless struct {
HostProc string `toml:"host_proc"`
Log telegraf.Logger `toml:"-"`
}
func (*Wireless) SampleConfig() string {
return sampleConfig
}
func init() {
inputs.Add("wireless", func() telegraf.Input {
return &Wireless{}
})
}

View file

@ -0,0 +1,120 @@
//go:build linux
package wireless
import (
"bytes"
"os"
"path"
"strconv"
"strings"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/plugins/inputs"
)
var newLineByte = []byte("\n")
// length of wireless interface fields
const interfaceFieldLength = 10
type wirelessInterface struct {
Interface string
Status int64
Link int64
Level int64
Noise int64
Nwid int64
Crypt int64
Frag int64
Retry int64
Misc int64
Beacon int64
}
func (w *Wireless) Gather(acc telegraf.Accumulator) error {
// load proc path, get default value if config value and env variable are empty
if w.HostProc == "" {
w.HostProc = internal.GetProcPath()
}
wirelessPath := path.Join(w.HostProc, "net", "wireless")
table, err := os.ReadFile(wirelessPath)
if err != nil {
return err
}
interfaces, err := w.loadWirelessTable(table)
if err != nil {
return err
}
for _, w := range interfaces {
tags := map[string]string{
"interface": w.Interface,
}
fieldsG := map[string]interface{}{
"status": w.Status,
"link": w.Link,
"level": w.Level,
"noise": w.Noise,
}
fieldsC := map[string]interface{}{
"nwid": w.Nwid,
"crypt": w.Crypt,
"frag": w.Frag,
"retry": w.Retry,
"misc": w.Misc,
"beacon": w.Beacon,
}
acc.AddGauge("wireless", fieldsG, tags)
acc.AddCounter("wireless", fieldsC, tags)
}
return nil
}
func (w *Wireless) loadWirelessTable(table []byte) ([]*wirelessInterface, error) {
var wi []*wirelessInterface
lines := bytes.Split(table, newLineByte)
// iterate over interfaces
for i := 2; i < len(lines); i = i + 1 {
if len(lines[i]) == 0 {
continue
}
values := make([]int64, 0, interfaceFieldLength)
fields := strings.Fields(string(lines[i]))
for j := 1; j < len(fields); j = j + 1 {
v, err := strconv.ParseInt(strings.Trim(fields[j], "."), 10, 64)
if err != nil {
return nil, err
}
values = append(values, v)
}
if len(values) != interfaceFieldLength {
w.Log.Error("invalid length of interface values")
continue
}
wi = append(wi, &wirelessInterface{
Interface: strings.Trim(fields[0], ":"),
Status: values[0],
Link: values[1],
Level: values[2],
Noise: values[3],
Nwid: values[4],
Crypt: values[5],
Frag: values[6],
Retry: values[7],
Misc: values[8],
Beacon: values[9],
})
}
return wi, nil
}
func init() {
inputs.Add("wireless", func() telegraf.Input {
return &Wireless{}
})
}

View file

@ -0,0 +1,23 @@
//go:build !linux
package wireless
import (
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"
)
func (w *Wireless) Init() error {
w.Log.Warn("Current platform is not supported")
return nil
}
func (*Wireless) Gather(telegraf.Accumulator) error {
return nil
}
func init() {
inputs.Add("wireless", func() telegraf.Input {
return &Wireless{}
})
}

View file

@ -0,0 +1,56 @@
//go:build linux
package wireless
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/influxdata/telegraf/testutil"
)
var testInput = []byte(`Inter-| sta-| Quality | Discarded packets | Missed | WE
face | tus | link level noise | nwid crypt frag retry misc | beacon | 22
wlan0: 0000 60. -50. -256 0 0 0 1525 0 0
wlan1: 0000 70. -39. -256 0 0 0 12096 191188 0`)
func TestLoadWirelessTable(t *testing.T) {
expectedMetrics := []*wirelessInterface{
{
Interface: "wlan0",
Status: int64(0000),
Link: int64(60),
Level: int64(-50),
Noise: int64(-256),
Nwid: int64(0),
Crypt: int64(0),
Frag: int64(0),
Retry: int64(1525),
Misc: int64(0),
Beacon: int64(0),
},
{
Interface: "wlan1",
Status: int64(0000),
Link: int64(70),
Level: int64(-39),
Noise: int64(-256),
Nwid: int64(0),
Crypt: int64(0),
Frag: int64(0),
Retry: int64(12096),
Misc: int64(191188),
Beacon: int64(0),
},
}
w := Wireless{
Log: testutil.Logger{},
}
metrics, err := w.loadWirelessTable(testInput)
require.NoError(t, err)
as := require.New(t)
as.Equal(expectedMetrics, metrics)
}