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
114
migrations/inputs_procstat/migration.go
Normal file
114
migrations/inputs_procstat/migration.go
Normal file
|
@ -0,0 +1,114 @@
|
|||
package inputs_procstat
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/influxdata/toml"
|
||||
"github.com/influxdata/toml/ast"
|
||||
|
||||
"github.com/influxdata/telegraf/internal/choice"
|
||||
"github.com/influxdata/telegraf/migrations"
|
||||
)
|
||||
|
||||
// Migration function
|
||||
func migrate(tbl *ast.Table) ([]byte, string, error) {
|
||||
// Decode the old data structure
|
||||
var plugin map[string]interface{}
|
||||
if err := toml.UnmarshalTable(tbl, &plugin); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
// Check for deprecated option(s) and migrate them
|
||||
var applied bool
|
||||
if rawOldUnits, found := plugin["supervisor_unit"]; found {
|
||||
applied = true
|
||||
|
||||
// Check if the new option already exists and merge the two
|
||||
var units []string
|
||||
if newUnits, found := plugin["supervisor_units"]; found {
|
||||
var err error
|
||||
units, err = migrations.AsStringSlice(newUnits)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("setting 'supervisor_units': %w", err)
|
||||
}
|
||||
}
|
||||
oldUnits, err := migrations.AsStringSlice(rawOldUnits)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("setting 'supervisor_unit': %w", err)
|
||||
}
|
||||
for _, u := range oldUnits {
|
||||
if !choice.Contains(u, units) {
|
||||
units = append(units, u)
|
||||
}
|
||||
}
|
||||
plugin["supervisor_units"] = units
|
||||
|
||||
// Remove deprecated setting
|
||||
delete(plugin, "supervisor_unit")
|
||||
}
|
||||
|
||||
// The tagging options both need the 'tag_with' setting
|
||||
var tagwith []string
|
||||
if rawNewTagWith, found := plugin["tag_with"]; found {
|
||||
var err error
|
||||
tagwith, err = migrations.AsStringSlice(rawNewTagWith)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("setting 'tag_with': %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Tagging with PID
|
||||
if oldPidTag, found := plugin["pid_tag"]; found {
|
||||
applied = true
|
||||
|
||||
pt, ok := oldPidTag.(bool)
|
||||
if !ok {
|
||||
return nil, "", fmt.Errorf("setting 'pid_tag' has wrong type %T", oldPidTag)
|
||||
}
|
||||
|
||||
// Add the pid-tagging to 'tag_with' if requested
|
||||
if pt && !choice.Contains("pid", tagwith) {
|
||||
tagwith = append(tagwith, "pid")
|
||||
plugin["tag_with"] = tagwith
|
||||
}
|
||||
|
||||
// Remove deprecated setting
|
||||
delete(plugin, "pid_tag")
|
||||
}
|
||||
|
||||
// Tagging with command-line
|
||||
if oldCmdlinedTag, found := plugin["cmdline_tag"]; found {
|
||||
applied = true
|
||||
|
||||
ct, ok := oldCmdlinedTag.(bool)
|
||||
if !ok {
|
||||
return nil, "", fmt.Errorf("setting 'cmdline_tag' has wrong type %T", oldCmdlinedTag)
|
||||
}
|
||||
|
||||
// Add the pid-tagging to 'tag_with' if requested
|
||||
if ct && !choice.Contains("cmdline", tagwith) {
|
||||
tagwith = append(tagwith, "cmdline")
|
||||
plugin["tag_with"] = tagwith
|
||||
}
|
||||
|
||||
// Remove deprecated setting
|
||||
delete(plugin, "cmdline_tag")
|
||||
}
|
||||
|
||||
// No options migrated so we can exit early
|
||||
if !applied {
|
||||
return nil, "", migrations.ErrNotApplicable
|
||||
}
|
||||
|
||||
// Create the corresponding plugin configurations
|
||||
cfg := migrations.CreateTOMLStruct("inputs", "procstat")
|
||||
cfg.Add("inputs", "procstat", plugin)
|
||||
|
||||
output, err := toml.Marshal(cfg)
|
||||
return output, "", err
|
||||
}
|
||||
|
||||
// Register the migration function for the plugin type
|
||||
func init() {
|
||||
migrations.AddPluginOptionMigration("inputs.procstat", migrate)
|
||||
}
|
73
migrations/inputs_procstat/migration_test.go
Normal file
73
migrations/inputs_procstat/migration_test.go
Normal file
|
@ -0,0 +1,73 @@
|
|||
package inputs_procstat_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf/config"
|
||||
_ "github.com/influxdata/telegraf/migrations/inputs_procstat" // register migration
|
||||
"github.com/influxdata/telegraf/plugins/inputs/procstat" // register plugin
|
||||
)
|
||||
|
||||
func TestNoMigration(t *testing.T) {
|
||||
plugin := procstat.Procstat{}
|
||||
defaultCfg := []byte(plugin.SampleConfig())
|
||||
|
||||
// Migrate and check that nothing changed
|
||||
output, n, err := config.ApplyMigrations(defaultCfg)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, output)
|
||||
require.Zero(t, n)
|
||||
require.Equal(t, string(defaultCfg), string(output))
|
||||
}
|
||||
|
||||
func TestCases(t *testing.T) {
|
||||
// Get all directories in testdata
|
||||
folders, err := os.ReadDir("testcases")
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, f := range folders {
|
||||
// Only handle folders
|
||||
if !f.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
t.Run(f.Name(), func(t *testing.T) {
|
||||
testcasePath := filepath.Join("testcases", f.Name())
|
||||
inputFile := filepath.Join(testcasePath, "telegraf.conf")
|
||||
expectedFile := filepath.Join(testcasePath, "expected.conf")
|
||||
|
||||
// Read the expected output
|
||||
expected := config.NewConfig()
|
||||
require.NoError(t, expected.LoadConfig(expectedFile))
|
||||
require.NotEmpty(t, expected.Inputs)
|
||||
|
||||
// Read the input data
|
||||
input, remote, err := config.LoadConfigFile(inputFile)
|
||||
require.NoError(t, err)
|
||||
require.False(t, remote)
|
||||
require.NotEmpty(t, input)
|
||||
|
||||
// Migrate
|
||||
output, n, err := config.ApplyMigrations(input)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, output)
|
||||
require.GreaterOrEqual(t, n, uint64(1))
|
||||
actual := config.NewConfig()
|
||||
require.NoError(t, actual.LoadConfigData(output, config.EmptySourcePath))
|
||||
|
||||
// Test the output
|
||||
require.Len(t, actual.Inputs, len(expected.Inputs))
|
||||
actualIDs := make([]string, 0, len(expected.Inputs))
|
||||
expectedIDs := make([]string, 0, len(expected.Inputs))
|
||||
for i := range actual.Inputs {
|
||||
actualIDs = append(actualIDs, actual.Inputs[i].ID())
|
||||
expectedIDs = append(expectedIDs, expected.Inputs[i].ID())
|
||||
}
|
||||
require.ElementsMatch(t, expectedIDs, actualIDs, string(output))
|
||||
})
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
[[inputs.procstat]]
|
||||
supervisor_units = ["upsd", "webserver", "mail", "proxy"]
|
|
@ -0,0 +1,3 @@
|
|||
[[inputs.procstat]]
|
||||
supervisor_unit = ["webserver", "proxy"]
|
||||
supervisor_units = ["upsd", "webserver", "mail"]
|
|
@ -0,0 +1,3 @@
|
|||
[[inputs.procstat]]
|
||||
pid_file = "/var/run/nginx.pid"
|
||||
supervisor_units = ["webserver", "proxy"]
|
|
@ -0,0 +1,47 @@
|
|||
# Monitor process cpu and memory usage
|
||||
[[inputs.procstat]]
|
||||
## PID file to monitor process
|
||||
pid_file = "/var/run/nginx.pid"
|
||||
## executable name (ie, pgrep <exe>)
|
||||
# exe = "nginx"
|
||||
## pattern as argument for pgrep (ie, pgrep -f <pattern>)
|
||||
# pattern = "nginx"
|
||||
## user as argument for pgrep (ie, pgrep -u <user>)
|
||||
# user = "nginx"
|
||||
## Systemd unit name, supports globs when include_systemd_children is set to true
|
||||
# systemd_unit = "nginx.service"
|
||||
# include_systemd_children = false
|
||||
## CGroup name or path, supports globs
|
||||
# cgroup = "systemd/system.slice/nginx.service"
|
||||
## Supervisor service names of hypervisorctl management
|
||||
supervisor_unit = ["webserver", "proxy"]
|
||||
|
||||
## Windows service name
|
||||
# win_service = ""
|
||||
|
||||
## override for process_name
|
||||
## This is optional; default is sourced from /proc/<pid>/status
|
||||
# process_name = "bar"
|
||||
|
||||
## Field name prefix
|
||||
# prefix = ""
|
||||
|
||||
## When true add the full cmdline as a tag.
|
||||
# cmdline_tag = false
|
||||
|
||||
## Mode to use when calculating CPU usage. Can be one of 'solaris' or 'irix'.
|
||||
# mode = "irix"
|
||||
|
||||
## Add the PID as a tag instead of as a field. When collecting multiple
|
||||
## processes with otherwise matching tags this setting should be enabled to
|
||||
## ensure each process has a unique identity.
|
||||
##
|
||||
## Enabling this option may result in a large number of series, especially
|
||||
## when processes have a short lifetime.
|
||||
# pid_tag = false
|
||||
|
||||
## Method to use when finding process IDs. Can be one of 'pgrep', or
|
||||
## 'native'. The pgrep finder calls the pgrep executable in the PATH while
|
||||
## the native finder performs the search directly in a manor dependent on the
|
||||
## platform. Default is 'pgrep'
|
||||
# pid_finder = "pgrep"
|
|
@ -0,0 +1,3 @@
|
|||
[[inputs.procstat]]
|
||||
pid_file = "/var/run/nginx.pid"
|
||||
supervisor_units = ["webserver", "proxy"]
|
|
@ -0,0 +1,47 @@
|
|||
# Monitor process cpu and memory usage
|
||||
[[inputs.procstat]]
|
||||
## PID file to monitor process
|
||||
pid_file = "/var/run/nginx.pid"
|
||||
## executable name (ie, pgrep <exe>)
|
||||
# exe = "nginx"
|
||||
## pattern as argument for pgrep (ie, pgrep -f <pattern>)
|
||||
# pattern = "nginx"
|
||||
## user as argument for pgrep (ie, pgrep -u <user>)
|
||||
# user = "nginx"
|
||||
## Systemd unit name, supports globs when include_systemd_children is set to true
|
||||
# systemd_unit = "nginx.service"
|
||||
# include_systemd_children = false
|
||||
## CGroup name or path, supports globs
|
||||
# cgroup = "systemd/system.slice/nginx.service"
|
||||
## Supervisor service names of hypervisorctl management
|
||||
supervisor_unit = ["webserver", "proxy"]
|
||||
|
||||
## Windows service name
|
||||
# win_service = ""
|
||||
|
||||
## override for process_name
|
||||
## This is optional; default is sourced from /proc/<pid>/status
|
||||
# process_name = "bar"
|
||||
|
||||
## Field name prefix
|
||||
# prefix = ""
|
||||
|
||||
## When true add the full cmdline as a tag.
|
||||
cmdline_tag = false
|
||||
|
||||
## Mode to use when calculating CPU usage. Can be one of 'solaris' or 'irix'.
|
||||
# mode = "irix"
|
||||
|
||||
## Add the PID as a tag instead of as a field. When collecting multiple
|
||||
## processes with otherwise matching tags this setting should be enabled to
|
||||
## ensure each process has a unique identity.
|
||||
##
|
||||
## Enabling this option may result in a large number of series, especially
|
||||
## when processes have a short lifetime.
|
||||
pid_tag = false
|
||||
|
||||
## Method to use when finding process IDs. Can be one of 'pgrep', or
|
||||
## 'native'. The pgrep finder calls the pgrep executable in the PATH while
|
||||
## the native finder performs the search directly in a manor dependent on the
|
||||
## platform. Default is 'pgrep'
|
||||
# pid_finder = "pgrep"
|
|
@ -0,0 +1,4 @@
|
|||
[[inputs.procstat]]
|
||||
pid_file = "/var/run/nginx.pid"
|
||||
supervisor_units = ["webserver", "proxy"]
|
||||
tag_with = ["pid", "cmdline"]
|
|
@ -0,0 +1,47 @@
|
|||
# Monitor process cpu and memory usage
|
||||
[[inputs.procstat]]
|
||||
## PID file to monitor process
|
||||
pid_file = "/var/run/nginx.pid"
|
||||
## executable name (ie, pgrep <exe>)
|
||||
# exe = "nginx"
|
||||
## pattern as argument for pgrep (ie, pgrep -f <pattern>)
|
||||
# pattern = "nginx"
|
||||
## user as argument for pgrep (ie, pgrep -u <user>)
|
||||
# user = "nginx"
|
||||
## Systemd unit name, supports globs when include_systemd_children is set to true
|
||||
# systemd_unit = "nginx.service"
|
||||
# include_systemd_children = false
|
||||
## CGroup name or path, supports globs
|
||||
# cgroup = "systemd/system.slice/nginx.service"
|
||||
## Supervisor service names of hypervisorctl management
|
||||
supervisor_unit = ["webserver", "proxy"]
|
||||
|
||||
## Windows service name
|
||||
# win_service = ""
|
||||
|
||||
## override for process_name
|
||||
## This is optional; default is sourced from /proc/<pid>/status
|
||||
# process_name = "bar"
|
||||
|
||||
## Field name prefix
|
||||
# prefix = ""
|
||||
|
||||
## When true add the full cmdline as a tag.
|
||||
cmdline_tag = true
|
||||
|
||||
## Mode to use when calculating CPU usage. Can be one of 'solaris' or 'irix'.
|
||||
# mode = "irix"
|
||||
|
||||
## Add the PID as a tag instead of as a field. When collecting multiple
|
||||
## processes with otherwise matching tags this setting should be enabled to
|
||||
## ensure each process has a unique identity.
|
||||
##
|
||||
## Enabling this option may result in a large number of series, especially
|
||||
## when processes have a short lifetime.
|
||||
pid_tag = true
|
||||
|
||||
## Method to use when finding process IDs. Can be one of 'pgrep', or
|
||||
## 'native'. The pgrep finder calls the pgrep executable in the PATH while
|
||||
## the native finder performs the search directly in a manor dependent on the
|
||||
## platform. Default is 'pgrep'
|
||||
# pid_finder = "pgrep"
|
|
@ -0,0 +1,4 @@
|
|||
[[inputs.procstat]]
|
||||
pid_file = "/var/run/nginx.pid"
|
||||
supervisor_units = ["webserver", "proxy"]
|
||||
tag_with = ["ppid", "pid", "cmdline"]
|
|
@ -0,0 +1,49 @@
|
|||
# Monitor process cpu and memory usage
|
||||
[[inputs.procstat]]
|
||||
## PID file to monitor process
|
||||
pid_file = "/var/run/nginx.pid"
|
||||
## executable name (ie, pgrep <exe>)
|
||||
# exe = "nginx"
|
||||
## pattern as argument for pgrep (ie, pgrep -f <pattern>)
|
||||
# pattern = "nginx"
|
||||
## user as argument for pgrep (ie, pgrep -u <user>)
|
||||
# user = "nginx"
|
||||
## Systemd unit name, supports globs when include_systemd_children is set to true
|
||||
# systemd_unit = "nginx.service"
|
||||
# include_systemd_children = false
|
||||
## CGroup name or path, supports globs
|
||||
# cgroup = "systemd/system.slice/nginx.service"
|
||||
## Supervisor service names of hypervisorctl management
|
||||
supervisor_unit = ["webserver", "proxy"]
|
||||
|
||||
## Windows service name
|
||||
# win_service = ""
|
||||
|
||||
## override for process_name
|
||||
## This is optional; default is sourced from /proc/<pid>/status
|
||||
# process_name = "bar"
|
||||
|
||||
## Field name prefix
|
||||
# prefix = ""
|
||||
|
||||
## When true add the full cmdline as a tag.
|
||||
cmdline_tag = true
|
||||
|
||||
## Mode to use when calculating CPU usage. Can be one of 'solaris' or 'irix'.
|
||||
# mode = "irix"
|
||||
|
||||
## Add the PID as a tag instead of as a field. When collecting multiple
|
||||
## processes with otherwise matching tags this setting should be enabled to
|
||||
## ensure each process has a unique identity.
|
||||
##
|
||||
## Enabling this option may result in a large number of series, especially
|
||||
## when processes have a short lifetime.
|
||||
pid_tag = true
|
||||
|
||||
## Method to use when finding process IDs. Can be one of 'pgrep', or
|
||||
## 'native'. The pgrep finder calls the pgrep executable in the PATH while
|
||||
## the native finder performs the search directly in a manor dependent on the
|
||||
## platform. Default is 'pgrep'
|
||||
# pid_finder = "pgrep"
|
||||
|
||||
tag_with = ["ppid"]
|
|
@ -0,0 +1,4 @@
|
|||
[[inputs.procstat]]
|
||||
pid_file = "/var/run/nginx.pid"
|
||||
supervisor_units = ["webserver", "proxy"]
|
||||
tag_with = ["ppid", "cmdline", "pid"]
|
|
@ -0,0 +1,49 @@
|
|||
# Monitor process cpu and memory usage
|
||||
[[inputs.procstat]]
|
||||
## PID file to monitor process
|
||||
pid_file = "/var/run/nginx.pid"
|
||||
## executable name (ie, pgrep <exe>)
|
||||
# exe = "nginx"
|
||||
## pattern as argument for pgrep (ie, pgrep -f <pattern>)
|
||||
# pattern = "nginx"
|
||||
## user as argument for pgrep (ie, pgrep -u <user>)
|
||||
# user = "nginx"
|
||||
## Systemd unit name, supports globs when include_systemd_children is set to true
|
||||
# systemd_unit = "nginx.service"
|
||||
# include_systemd_children = false
|
||||
## CGroup name or path, supports globs
|
||||
# cgroup = "systemd/system.slice/nginx.service"
|
||||
## Supervisor service names of hypervisorctl management
|
||||
supervisor_unit = ["webserver", "proxy"]
|
||||
|
||||
## Windows service name
|
||||
# win_service = ""
|
||||
|
||||
## override for process_name
|
||||
## This is optional; default is sourced from /proc/<pid>/status
|
||||
# process_name = "bar"
|
||||
|
||||
## Field name prefix
|
||||
# prefix = ""
|
||||
|
||||
## When true add the full cmdline as a tag.
|
||||
cmdline_tag = true
|
||||
|
||||
## Mode to use when calculating CPU usage. Can be one of 'solaris' or 'irix'.
|
||||
# mode = "irix"
|
||||
|
||||
## Add the PID as a tag instead of as a field. When collecting multiple
|
||||
## processes with otherwise matching tags this setting should be enabled to
|
||||
## ensure each process has a unique identity.
|
||||
##
|
||||
## Enabling this option may result in a large number of series, especially
|
||||
## when processes have a short lifetime.
|
||||
pid_tag = true
|
||||
|
||||
## Method to use when finding process IDs. Can be one of 'pgrep', or
|
||||
## 'native'. The pgrep finder calls the pgrep executable in the PATH while
|
||||
## the native finder performs the search directly in a manor dependent on the
|
||||
## platform. Default is 'pgrep'
|
||||
# pid_finder = "pgrep"
|
||||
|
||||
tag_with = ["ppid", "cmdline"]
|
Loading…
Add table
Add a link
Reference in a new issue