feat(inputs.redfish): Allow specifying with metrics to collect (#14143)

This commit is contained in:
Joshua Powers 2023-10-19 04:08:20 -06:00 committed by GitHub
parent 37ef23fb7f
commit 43ec383fc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 187 additions and 137 deletions

View File

@ -31,6 +31,10 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
## System Id to collect data for in Redfish APIs. ## System Id to collect data for in Redfish APIs.
computer_system_id="System.Embedded.1" computer_system_id="System.Embedded.1"
## Metrics to collect
## The metric collects to gather. Choose from "power" and "thermal".
# include_metrics = ["power", "thermal"]
## Tag sets allow you to include redfish OData link parent data ## Tag sets allow you to include redfish OData link parent data
## For Example. ## For Example.
## Thermal data is an OData link with parent Chassis which has a link of Location. ## Thermal data is an OData link with parent Chassis which has a link of Location.

View File

@ -26,6 +26,7 @@ type Redfish struct {
Username string `toml:"username"` Username string `toml:"username"`
Password string `toml:"password"` Password string `toml:"password"`
ComputerSystemID string `toml:"computer_system_id"` ComputerSystemID string `toml:"computer_system_id"`
IncludeMetrics []string `toml:"include_metrics"`
IncludeTagSets []string `toml:"include_tag_sets"` IncludeTagSets []string `toml:"include_tag_sets"`
Timeout config.Duration `toml:"timeout"` Timeout config.Duration `toml:"timeout"`
@ -163,6 +164,17 @@ func (r *Redfish) Init() error {
return fmt.Errorf("did not provide the computer system ID of the resource") return fmt.Errorf("did not provide the computer system ID of the resource")
} }
if len(r.IncludeMetrics) == 0 {
return fmt.Errorf("no metrics specified to collect")
}
for _, metric := range r.IncludeMetrics {
switch metric {
case "thermal", "power":
default:
return fmt.Errorf("unknown metric requested: %s", metric)
}
}
r.tagSet = make(map[string]bool, len(r.IncludeTagSets)) r.tagSet = make(map[string]bool, len(r.IncludeTagSets))
for _, setLabel := range r.IncludeTagSets { for _, setLabel := range r.IncludeTagSets {
r.tagSet[setLabel] = true r.tagSet[setLabel] = true
@ -295,6 +307,25 @@ func (r *Redfish) Gather(acc telegraf.Accumulator) error {
return err return err
} }
for _, metric := range r.IncludeMetrics {
var err error
switch metric {
case "thermal":
err = r.gatherThermal(acc, address, system, chassis)
case "power":
err = r.gatherPower(acc, address, system, chassis)
default:
return fmt.Errorf("unknown metric requested: %s", metric)
}
if err != nil {
return err
}
}
}
return nil
}
func (r *Redfish) gatherThermal(acc telegraf.Accumulator, address string, system *System, chassis *Chassis) error {
thermal, err := r.getThermal(chassis.Thermal.Ref) thermal, err := r.getThermal(chassis.Thermal.Ref)
if err != nil { if err != nil {
return err return err
@ -358,6 +389,10 @@ func (r *Redfish) Gather(acc telegraf.Accumulator) error {
acc.AddFields("redfish_thermal_fans", fields, tags) acc.AddFields("redfish_thermal_fans", fields, tags)
} }
return nil
}
func (r *Redfish) gatherPower(acc telegraf.Accumulator, address string, system *System, chassis *Chassis) error {
power, err := r.getPower(chassis.Power.Ref) power, err := r.getPower(chassis.Power.Ref)
if err != nil { if err != nil {
return err return err
@ -448,7 +483,6 @@ func (r *Redfish) Gather(acc telegraf.Accumulator) error {
fields["lower_threshold_fatal"] = j.LowerThresholdFatal fields["lower_threshold_fatal"] = j.LowerThresholdFatal
acc.AddFields("redfish_power_voltages", fields, tags) acc.AddFields("redfish_power_voltages", fields, tags)
} }
}
return nil return nil
} }
@ -458,6 +492,7 @@ func init() {
return &Redfish{ return &Redfish{
// default tag set of chassis.location required for backwards compatibility // default tag set of chassis.location required for backwards compatibility
IncludeTagSets: []string{tagSetChassisLocation}, IncludeTagSets: []string{tagSetChassisLocation},
IncludeMetrics: []string{"power", "thermal"},
} }
}) })
} }

View File

@ -425,6 +425,7 @@ func TestDellApis(t *testing.T) {
Username: "test", Username: "test",
Password: "test", Password: "test",
ComputerSystemID: "System.Embedded.1", ComputerSystemID: "System.Embedded.1",
IncludeMetrics: []string{"thermal", "power"},
} }
require.NoError(t, plugin.Init()) require.NoError(t, plugin.Init())
var acc testutil.Accumulator var acc testutil.Accumulator
@ -603,6 +604,7 @@ func TestHPApis(t *testing.T) {
Username: "test", Username: "test",
Password: "test", Password: "test",
ComputerSystemID: "1", ComputerSystemID: "1",
IncludeMetrics: []string{"thermal", "power"},
} }
require.NoError(t, hpPlugin.Init()) require.NoError(t, hpPlugin.Init())
var hpAcc testutil.Accumulator var hpAcc testutil.Accumulator
@ -643,6 +645,7 @@ func TestInvalidUsernameorPassword(t *testing.T) {
Username: "test", Username: "test",
Password: "test", Password: "test",
ComputerSystemID: "System.Embedded.1", ComputerSystemID: "System.Embedded.1",
IncludeMetrics: []string{"thermal", "power"},
} }
var acc testutil.Accumulator var acc testutil.Accumulator
@ -671,6 +674,7 @@ func TestNoUsernameorPasswordConfiguration(t *testing.T) {
r := &Redfish{ r := &Redfish{
Address: ts.URL, Address: ts.URL,
ComputerSystemID: "System.Embedded.1", ComputerSystemID: "System.Embedded.1",
IncludeMetrics: []string{"thermal", "power"},
} }
err := r.Init() err := r.Init()
@ -743,6 +747,7 @@ func TestInvalidDellJSON(t *testing.T) {
Username: "test", Username: "test",
Password: "test", Password: "test",
ComputerSystemID: "System.Embedded.1", ComputerSystemID: "System.Embedded.1",
IncludeMetrics: []string{"thermal", "power"},
} }
require.NoError(t, plugin.Init()) require.NoError(t, plugin.Init())
@ -813,6 +818,7 @@ func TestInvalidHPJSON(t *testing.T) {
Username: "test", Username: "test",
Password: "test", Password: "test",
ComputerSystemID: "System.Embedded.2", ComputerSystemID: "System.Embedded.2",
IncludeMetrics: []string{"thermal", "power"},
} }
require.NoError(t, plugin.Init()) require.NoError(t, plugin.Init())
@ -1097,6 +1103,7 @@ func TestIncludeTagSetsConfiguration(t *testing.T) {
Password: "test", Password: "test",
ComputerSystemID: "1", ComputerSystemID: "1",
IncludeTagSets: []string{"chassis", "chassis.location"}, IncludeTagSets: []string{"chassis", "chassis.location"},
IncludeMetrics: []string{"thermal", "power"},
} }
require.NoError(t, hpPlugin.Init()) require.NoError(t, hpPlugin.Init())
var hpAcc testutil.Accumulator var hpAcc testutil.Accumulator

View File

@ -10,6 +10,10 @@
## System Id to collect data for in Redfish APIs. ## System Id to collect data for in Redfish APIs.
computer_system_id="System.Embedded.1" computer_system_id="System.Embedded.1"
## Metrics to collect
## The metric collects to gather. Choose from "power" and "thermal".
# include_metrics = ["power", "thermal"]
## Tag sets allow you to include redfish OData link parent data ## Tag sets allow you to include redfish OData link parent data
## For Example. ## For Example.
## Thermal data is an OData link with parent Chassis which has a link of Location. ## Thermal data is an OData link with parent Chassis which has a link of Location.