fix(inputs.lvm): add options to specify path to binaries (#12725)
This commit is contained in:
parent
86eee2848f
commit
e51b3810ab
|
|
@ -19,9 +19,18 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||||
[[inputs.lvm]]
|
[[inputs.lvm]]
|
||||||
## Use sudo to run LVM commands
|
## Use sudo to run LVM commands
|
||||||
use_sudo = false
|
use_sudo = false
|
||||||
|
|
||||||
|
## The default location of the pvs binary can be overridden with:
|
||||||
|
#pvs_binary = "/usr/sbin/pvs"
|
||||||
|
|
||||||
|
## The default location of the vgs binary can be overridden with:
|
||||||
|
#vgs_binary = "/usr/sbin/vgs"
|
||||||
|
|
||||||
|
## The default location of the lvs binary can be overridden with:
|
||||||
|
#lvs_binary = "/usr/sbin/lvs"
|
||||||
```
|
```
|
||||||
|
|
||||||
The `lvm` command requires elevated permissions. If the user has configured sudo
|
The LVM commands requires elevated permissions. If the user has configured sudo
|
||||||
with the ability to run these commands, then set the `use_sudo` to true.
|
with the ability to run these commands, then set the `use_sudo` to true.
|
||||||
|
|
||||||
### Using sudo
|
### Using sudo
|
||||||
|
|
@ -40,6 +49,9 @@ Cmnd_Alias LVM = /usr/sbin/pvs *, /usr/sbin/vgs *, /usr/sbin/lvs *
|
||||||
Defaults!LVM !logfile, !syslog, !pam_session
|
Defaults!LVM !logfile, !syslog, !pam_session
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Path to binaries must match those from config file (pvs_binary, vgs_binary and
|
||||||
|
lvs_binary)
|
||||||
|
|
||||||
## Metrics
|
## Metrics
|
||||||
|
|
||||||
Metrics are broken out by physical volume (pv), volume group (vg), and logical
|
Metrics are broken out by physical volume (pv), volume group (vg), and logical
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,10 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type LVM struct {
|
type LVM struct {
|
||||||
UseSudo bool `toml:"use_sudo"`
|
UseSudo bool `toml:"use_sudo"`
|
||||||
|
PVSBinary string `toml:"pvs_binary"`
|
||||||
|
VGSBinary string `toml:"vgs_binary"`
|
||||||
|
LVSBinary string `toml:"lvs_binary"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*LVM) SampleConfig() string {
|
func (*LVM) SampleConfig() string {
|
||||||
|
|
@ -47,12 +50,11 @@ func (lvm *LVM) Gather(acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lvm *LVM) gatherPhysicalVolumes(acc telegraf.Accumulator) error {
|
func (lvm *LVM) gatherPhysicalVolumes(acc telegraf.Accumulator) error {
|
||||||
pvsCmd := "/usr/sbin/pvs"
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"--reportformat", "json", "--units", "b", "--nosuffix",
|
"--reportformat", "json", "--units", "b", "--nosuffix",
|
||||||
"-o", "pv_name,vg_name,pv_size,pv_free,pv_used",
|
"-o", "pv_name,vg_name,pv_size,pv_free,pv_used",
|
||||||
}
|
}
|
||||||
out, err := lvm.runCmd(pvsCmd, args)
|
out, err := lvm.runCmd(lvm.PVSBinary, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -102,12 +104,11 @@ func (lvm *LVM) gatherPhysicalVolumes(acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lvm *LVM) gatherVolumeGroups(acc telegraf.Accumulator) error {
|
func (lvm *LVM) gatherVolumeGroups(acc telegraf.Accumulator) error {
|
||||||
cmd := "/usr/sbin/vgs"
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"--reportformat", "json", "--units", "b", "--nosuffix",
|
"--reportformat", "json", "--units", "b", "--nosuffix",
|
||||||
"-o", "vg_name,pv_count,lv_count,snap_count,vg_size,vg_free",
|
"-o", "vg_name,pv_count,lv_count,snap_count,vg_size,vg_free",
|
||||||
}
|
}
|
||||||
out, err := lvm.runCmd(cmd, args)
|
out, err := lvm.runCmd(lvm.VGSBinary, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -166,12 +167,11 @@ func (lvm *LVM) gatherVolumeGroups(acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lvm *LVM) gatherLogicalVolumes(acc telegraf.Accumulator) error {
|
func (lvm *LVM) gatherLogicalVolumes(acc telegraf.Accumulator) error {
|
||||||
cmd := "/usr/sbin/lvs"
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"--reportformat", "json", "--units", "b", "--nosuffix",
|
"--reportformat", "json", "--units", "b", "--nosuffix",
|
||||||
"-o", "lv_name,vg_name,lv_size,data_percent,metadata_percent",
|
"-o", "lv_name,vg_name,lv_size,data_percent,metadata_percent",
|
||||||
}
|
}
|
||||||
out, err := lvm.runCmd(cmd, args)
|
out, err := lvm.runCmd(lvm.LVSBinary, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -284,6 +284,10 @@ type lvsReport struct {
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
inputs.Add("lvm", func() telegraf.Input {
|
inputs.Add("lvm", func() telegraf.Input {
|
||||||
return &LVM{}
|
return &LVM{
|
||||||
|
PVSBinary: "/usr/sbin/pvs",
|
||||||
|
VGSBinary: "/usr/sbin/vgs",
|
||||||
|
LVSBinary: "/usr/sbin/lvs",
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,11 @@ import (
|
||||||
func TestGather(t *testing.T) {
|
func TestGather(t *testing.T) {
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
||||||
lvm := LVM{UseSudo: false}
|
lvm := LVM{
|
||||||
|
PVSBinary: "/usr/sbin/pvs",
|
||||||
|
VGSBinary: "/usr/sbin/vgs",
|
||||||
|
LVSBinary: "/usr/sbin/lvs",
|
||||||
|
}
|
||||||
|
|
||||||
// overwriting exec commands with mock commands
|
// overwriting exec commands with mock commands
|
||||||
execCommand = fakeExecCommand
|
execCommand = fakeExecCommand
|
||||||
|
|
@ -128,7 +132,11 @@ func TestHelperProcess(_ *testing.T) {
|
||||||
func TestGatherNoLVM(t *testing.T) {
|
func TestGatherNoLVM(t *testing.T) {
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
||||||
noLVM := LVM{UseSudo: false}
|
noLVM := LVM{
|
||||||
|
PVSBinary: "/usr/sbin/pvs",
|
||||||
|
VGSBinary: "/usr/sbin/vgs",
|
||||||
|
LVSBinary: "/usr/sbin/lvs",
|
||||||
|
}
|
||||||
|
|
||||||
// overwriting exec commands with mock commands
|
// overwriting exec commands with mock commands
|
||||||
execCommand = fakeExecCommandNoLVM
|
execCommand = fakeExecCommandNoLVM
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,12 @@
|
||||||
[[inputs.lvm]]
|
[[inputs.lvm]]
|
||||||
## Use sudo to run LVM commands
|
## Use sudo to run LVM commands
|
||||||
use_sudo = false
|
use_sudo = false
|
||||||
|
|
||||||
|
## The default location of the pvs binary can be overridden with:
|
||||||
|
#pvs_binary = "/usr/sbin/pvs"
|
||||||
|
|
||||||
|
## The default location of the vgs binary can be overridden with:
|
||||||
|
#vgs_binary = "/usr/sbin/vgs"
|
||||||
|
|
||||||
|
## The default location of the lvs binary can be overridden with:
|
||||||
|
#lvs_binary = "/usr/sbin/lvs"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue