Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to enable caching in ipmitool #8335

Merged
merged 7 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions plugins/inputs/ipmi_sensor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ Any of the following parameters will be added to the aformentioned query if they

## Optionally provide the hex key for the IMPI connection.
# hex_key = ""

## If ipmitool should use a cache
## for me ipmitool runs about 2 to 10 times faster with cache enabled on HP G10 servers (when using ubuntu20.04)
## the cache file may not work well for you if some sensors come up late
# use_cache = false

## Path to the ipmitools cache file (defaults to OS temp dir)
## The provided path must exist and must be writable
# cache_path = ""
```

### Measurements
Expand Down
38 changes: 38 additions & 0 deletions plugins/inputs/ipmi_sensor/ipmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"bytes"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -34,6 +36,8 @@ type Ipmi struct {
Timeout internal.Duration
MetricVersion int
UseSudo bool
UseCache bool
CachePath string
}

var sampleConfig = `
Expand Down Expand Up @@ -69,6 +73,15 @@ var sampleConfig = `
## Optionally provide the hex key for the IMPI connection.
# hex_key = ""
## If ipmitool should use a cache
## for me ipmitool runs about 2 to 10 times faster with cache enabled on HP G10 servers (when using ubuntu20.04)
## the cache file may not work well for you if some sensors come up late
# use_cache = false
## Path to the ipmitools cache file (defaults to OS temp dir)
## The provided path must exist and must be writable
# cache_path = ""
DEvil0000 marked this conversation as resolved.
Show resolved Hide resolved
`

// SampleConfig returns the documentation about the sample configuration
Expand Down Expand Up @@ -119,6 +132,29 @@ func (m *Ipmi) parse(acc telegraf.Accumulator, server string) error {
opts = conn.options()
}
opts = append(opts, "sdr")
if m.UseCache {
cacheFile := filepath.Join(m.CachePath, server+"_ipmi_cache")
DEvil0000 marked this conversation as resolved.
Show resolved Hide resolved
_, err := os.Stat(cacheFile)
if os.IsNotExist(err) {
dumpOpts := opts
// init cache file
dumpOpts = append(dumpOpts, "dump")
dumpOpts = append(dumpOpts, cacheFile)
name := m.Path
if m.UseSudo {
// -n - avoid prompting the user for input of any kind
dumpOpts = append([]string{"-n", name}, dumpOpts...)
name = "sudo"
}
cmd := execCommand(name, dumpOpts...)
out, err := internal.CombinedOutputTimeout(cmd, m.Timeout.Duration)
if err != nil {
return fmt.Errorf("failed to run command %s: %s - %s", strings.Join(cmd.Args, " "), err, string(out))
}
}
opts = append(opts, "-S")
opts = append(opts, cacheFile)
}
if m.MetricVersion == 2 {
opts = append(opts, "elist")
}
Expand Down Expand Up @@ -294,6 +330,8 @@ func init() {
m.Path = path
}
m.Timeout = internal.Duration{Duration: time.Second * 20}
m.UseCache = false
m.CachePath = os.TempDir()
inputs.Add("ipmi_sensor", func() telegraf.Input {
m := m
return &m
Expand Down