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
56
plugins/inputs/linux_sysctl_fs/README.md
Normal file
56
plugins/inputs/linux_sysctl_fs/README.md
Normal file
|
@ -0,0 +1,56 @@
|
|||
# Linux Sysctl Filesystem Input Plugin
|
||||
|
||||
This plugin gathers metrics by reading the [system filesystem][sysfs] files on
|
||||
[Linux][kernel] systems.
|
||||
|
||||
⭐ Telegraf v1.24.0
|
||||
🏷️ system
|
||||
💻 linux
|
||||
|
||||
[kernel]: https://kernel.org/
|
||||
[sysfs]: https://www.kernel.org/doc/Documentation/sysctl/fs.txt
|
||||
|
||||
## 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
|
||||
# Provides Linux sysctl fs metrics
|
||||
[[inputs.linux_sysctl_fs]]
|
||||
# no configuration
|
||||
```
|
||||
|
||||
## Metrics
|
||||
|
||||
`linux_sysctl_fs` metric:
|
||||
|
||||
- tags: _none_
|
||||
- fields:
|
||||
- `aio-max-nr` (unsigned integer)
|
||||
- `aio-nr` (unsigned integer)
|
||||
- `dentry-age-limit` (unsigned integer)
|
||||
- `dentry-nr` (unsigned integer)
|
||||
- `dentry-unused-nr` (unsigned integer)
|
||||
- `dentry-want-pages` (unsigned integer)
|
||||
- `dquot-max` (unsigned integer)
|
||||
- `dquot-nr` (unsigned integer)
|
||||
- `inode-free-nr` (unsigned integer)
|
||||
- `inode-nr` (unsigned integer)
|
||||
- `inode-preshrink-nr` (unsigned integer)
|
||||
- `super-max` (unsigned integer)
|
||||
- `super-nr` (unsigned integer)
|
||||
- `file-max` (unsigned integer)
|
||||
- `file-nr` (unsigned integer)
|
||||
|
||||
## Example Output
|
||||
|
||||
```text
|
||||
> linux_sysctl_fs,host=foo dentry-want-pages=0i,file-max=44222i,aio-max-nr=65536i,inode-preshrink-nr=0i,dentry-nr=64340i,dentry-unused-nr=55274i,file-nr=1568i,aio-nr=0i,inode-nr=35952i,inode-free-nr=12957i,dentry-age-limit=45i 1490982022000000000
|
||||
```
|
109
plugins/inputs/linux_sysctl_fs/linux_sysctl_fs.go
Normal file
109
plugins/inputs/linux_sysctl_fs/linux_sysctl_fs.go
Normal file
|
@ -0,0 +1,109 @@
|
|||
//go:generate ../../../tools/readme_config_includer/generator
|
||||
package linux_sysctl_fs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"errors"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/internal"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
)
|
||||
|
||||
//go:embed sample.conf
|
||||
var sampleConfig string
|
||||
|
||||
// https://www.kernel.org/doc/Documentation/sysctl/fs.txt
|
||||
type SysctlFS struct {
|
||||
path string
|
||||
}
|
||||
|
||||
func (*SysctlFS) SampleConfig() string {
|
||||
return sampleConfig
|
||||
}
|
||||
|
||||
func (sfs *SysctlFS) Gather(acc telegraf.Accumulator) error {
|
||||
fields := make(map[string]interface{})
|
||||
|
||||
for _, n := range []string{"aio-nr", "aio-max-nr", "dquot-nr", "dquot-max", "super-nr", "super-max"} {
|
||||
if err := sfs.gatherOne(n, fields); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err := sfs.gatherList("inode-state", fields, "inode-nr", "inode-free-nr", "inode-preshrink-nr")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = sfs.gatherList("dentry-state", fields, "dentry-nr", "dentry-unused-nr", "dentry-age-limit", "dentry-want-pages")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = sfs.gatherList("file-nr", fields, "file-nr", "", "file-max")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
acc.AddFields("linux_sysctl_fs", fields, nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sfs *SysctlFS) gatherList(file string, fields map[string]interface{}, fieldNames ...string) error {
|
||||
bs, err := os.ReadFile(sfs.path + "/" + file)
|
||||
if err != nil {
|
||||
// Ignore non-existing entries
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
bsplit := bytes.Split(bytes.TrimRight(bs, "\n"), []byte{'\t'})
|
||||
for i, name := range fieldNames {
|
||||
if i >= len(bsplit) {
|
||||
break
|
||||
}
|
||||
if name == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
v, err := strconv.ParseUint(string(bsplit[i]), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fields[name] = v
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sfs *SysctlFS) gatherOne(name string, fields map[string]interface{}) error {
|
||||
bs, err := os.ReadFile(sfs.path + "/" + name)
|
||||
if err != nil {
|
||||
// Ignore non-existing entries
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
v, err := strconv.ParseUint(string(bytes.TrimRight(bs, "\n")), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fields[name] = v
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
inputs.Add("linux_sysctl_fs", func() telegraf.Input {
|
||||
return &SysctlFS{
|
||||
path: path.Join(internal.GetProcPath(), "/sys/fs"),
|
||||
}
|
||||
})
|
||||
}
|
39
plugins/inputs/linux_sysctl_fs/linux_sysctl_fs_test.go
Normal file
39
plugins/inputs/linux_sysctl_fs/linux_sysctl_fs_test.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package linux_sysctl_fs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
)
|
||||
|
||||
func TestSysctlFSGather(t *testing.T) {
|
||||
td := t.TempDir()
|
||||
|
||||
require.NoError(t, os.WriteFile(td+"/aio-nr", []byte("100\n"), 0640))
|
||||
require.NoError(t, os.WriteFile(td+"/aio-max-nr", []byte("101\n"), 0640))
|
||||
require.NoError(t, os.WriteFile(td+"/super-nr", []byte("102\n"), 0640))
|
||||
require.NoError(t, os.WriteFile(td+"/super-max", []byte("103\n"), 0640))
|
||||
require.NoError(t, os.WriteFile(td+"/file-nr", []byte("104\t0\t106\n"), 0640))
|
||||
require.NoError(t, os.WriteFile(td+"/inode-state", []byte("107\t108\t109\t0\t0\t0\t0\n"), 0640))
|
||||
|
||||
sfs := &SysctlFS{
|
||||
path: td,
|
||||
}
|
||||
var acc testutil.Accumulator
|
||||
require.NoError(t, sfs.Gather(&acc))
|
||||
|
||||
acc.AssertContainsFields(t, "linux_sysctl_fs", map[string]interface{}{
|
||||
"aio-nr": uint64(100),
|
||||
"aio-max-nr": uint64(101),
|
||||
"super-nr": uint64(102),
|
||||
"super-max": uint64(103),
|
||||
"file-nr": uint64(104),
|
||||
"file-max": uint64(106),
|
||||
"inode-nr": uint64(107),
|
||||
"inode-free-nr": uint64(108),
|
||||
"inode-preshrink-nr": uint64(109),
|
||||
})
|
||||
}
|
3
plugins/inputs/linux_sysctl_fs/sample.conf
Normal file
3
plugins/inputs/linux_sysctl_fs/sample.conf
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Provides Linux sysctl fs metrics
|
||||
[[inputs.linux_sysctl_fs]]
|
||||
# no configuration
|
Loading…
Add table
Add a link
Reference in a new issue