fix(inputs.upsd): Handle float battery.runtime value (#13412)
This commit is contained in:
parent
cba7369903
commit
037eb2f545
|
|
@ -30,8 +30,6 @@ type Upsd struct {
|
|||
ForceFloat bool `toml:"force_float"`
|
||||
|
||||
Log telegraf.Logger `toml:"-"`
|
||||
|
||||
batteryRuntimeTypeWarningIssued bool
|
||||
}
|
||||
|
||||
func (*Upsd) SampleConfig() string {
|
||||
|
|
@ -67,10 +65,14 @@ func (u *Upsd) gatherUps(acc telegraf.Accumulator, name string, variables []nut.
|
|||
// For compatibility with the apcupsd plugin's output we map the status string status into a bit-format
|
||||
status := u.mapStatus(metrics, tags)
|
||||
|
||||
timeLeftS, ok := metrics["battery.runtime"].(int64)
|
||||
if !ok && !u.batteryRuntimeTypeWarningIssued {
|
||||
u.Log.Warnf("'battery.runtime' type is not int64")
|
||||
u.batteryRuntimeTypeWarningIssued = true
|
||||
timeLeftS, err := internal.ToFloat64(metrics["battery.runtime"])
|
||||
if err != nil {
|
||||
u.Log.Warnf("'battery.runtime' type is not supported: %w", err)
|
||||
}
|
||||
|
||||
timeLeftNS, err := internal.ToInt64(timeLeftS * 1_000_000_000)
|
||||
if err != nil {
|
||||
u.Log.Warnf("converting 'battery.runtime' to 'time_left_ns' failed: %w", err)
|
||||
}
|
||||
|
||||
fields := map[string]interface{}{
|
||||
|
|
@ -80,7 +82,7 @@ func (u *Upsd) gatherUps(acc telegraf.Accumulator, name string, variables []nut.
|
|||
"ups_status": metrics["ups.status"],
|
||||
|
||||
//Compatibility with apcupsd metrics format
|
||||
"time_left_ns": timeLeftS * 1_000_000_000,
|
||||
"time_left_ns": timeLeftNS,
|
||||
}
|
||||
|
||||
floatValues := map[string]string{
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ VAR fake device.model "Model 12345"
|
|||
VAR fake input.voltage "242.0"
|
||||
VAR fake ups.load "23.0"
|
||||
VAR fake battery.charge "100.0"
|
||||
VAR fake battery.runtime "600"
|
||||
VAR fake battery.runtime "600.00"
|
||||
VAR fake output.voltage "230.0"
|
||||
VAR fake battery.voltage "13.4"
|
||||
VAR fake input.voltage.nominal "230.0"
|
||||
|
|
|
|||
Loading…
Reference in New Issue