From da0773151b970a342e1b2a84dab52a1ca20b669a Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Fri, 21 Apr 2017 10:55:54 -0700 Subject: [PATCH] Use C locale when running sadf (#2690) fixes #1911 --- CHANGELOG.md | 1 + plugins/inputs/sysstat/sysstat.go | 26 +++++++++++++++++++ .../inputs/sysstat/sysstat_interval_test.go | 3 +++ 3 files changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 626a9ef93..c2ddc9d27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -110,6 +110,7 @@ be deprecated eventually. - [#2671](https://github.com/influxdata/telegraf/issues/2671): The internal input plugin uses the wrong units for `heap_objects` - [#2684](https://github.com/influxdata/telegraf/pull/2684): Fix ipmi_sensor config is shared between all plugin instances - [#2450](https://github.com/influxdata/telegraf/issues/2450): Network statistics not collected when system has alias interfaces +- [#1911](https://github.com/influxdata/telegraf/issues/1911): Sysstat plugin needs LANG=C or similar locale ## v1.2.1 [2017-02-01] diff --git a/plugins/inputs/sysstat/sysstat.go b/plugins/inputs/sysstat/sysstat.go index 9c9ef6b05..27e181002 100644 --- a/plugins/inputs/sysstat/sysstat.go +++ b/plugins/inputs/sysstat/sysstat.go @@ -210,11 +210,37 @@ func (s *Sysstat) collect() error { return nil } +func filterEnviron(env []string, prefix string) []string { + newenv := env[:0] + for _, envvar := range env { + if !strings.HasPrefix(envvar, prefix) { + newenv = append(newenv, envvar) + } + } + return newenv +} + +// Return the Cmd with its environment configured to use the C locale +func withCLocale(cmd *exec.Cmd) *exec.Cmd { + var env []string + if cmd.Env != nil { + env = cmd.Env + } else { + env = os.Environ() + } + env = filterEnviron(env, "LANG") + env = filterEnviron(env, "LC_") + env = append(env, "LANG=C") + cmd.Env = env + return cmd +} + // parse runs Sadf on the previously saved tmpFile: // Sadf -p -- -p