Skip to content

Commit

Permalink
Add setting to enable caching in ipmitool (influxdata#8335)
Browse files Browse the repository at this point in the history
  • Loading branch information
DEvil0000 authored Jan 21, 2021
1 parent b5215d7 commit 65a12e9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
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 = ""
`

// 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")
_, 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

0 comments on commit 65a12e9

Please sign in to comment.