feat(inputs.redfish): Allow specifying with metrics to collect (#14143)
This commit is contained in:
parent
37ef23fb7f
commit
43ec383fc6
|
|
@ -31,6 +31,10 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
|||
## System Id to collect data for in Redfish APIs.
|
||||
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
|
||||
## For Example.
|
||||
## Thermal data is an OData link with parent Chassis which has a link of Location.
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ type Redfish struct {
|
|||
Username string `toml:"username"`
|
||||
Password string `toml:"password"`
|
||||
ComputerSystemID string `toml:"computer_system_id"`
|
||||
IncludeMetrics []string `toml:"include_metrics"`
|
||||
IncludeTagSets []string `toml:"include_tag_sets"`
|
||||
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")
|
||||
}
|
||||
|
||||
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))
|
||||
for _, setLabel := range r.IncludeTagSets {
|
||||
r.tagSet[setLabel] = true
|
||||
|
|
@ -295,6 +307,25 @@ func (r *Redfish) Gather(acc telegraf.Accumulator) error {
|
|||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -358,6 +389,10 @@ func (r *Redfish) Gather(acc telegraf.Accumulator) error {
|
|||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -448,7 +483,6 @@ func (r *Redfish) Gather(acc telegraf.Accumulator) error {
|
|||
fields["lower_threshold_fatal"] = j.LowerThresholdFatal
|
||||
acc.AddFields("redfish_power_voltages", fields, tags)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -458,6 +492,7 @@ func init() {
|
|||
return &Redfish{
|
||||
// default tag set of chassis.location required for backwards compatibility
|
||||
IncludeTagSets: []string{tagSetChassisLocation},
|
||||
IncludeMetrics: []string{"power", "thermal"},
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -425,6 +425,7 @@ func TestDellApis(t *testing.T) {
|
|||
Username: "test",
|
||||
Password: "test",
|
||||
ComputerSystemID: "System.Embedded.1",
|
||||
IncludeMetrics: []string{"thermal", "power"},
|
||||
}
|
||||
require.NoError(t, plugin.Init())
|
||||
var acc testutil.Accumulator
|
||||
|
|
@ -603,6 +604,7 @@ func TestHPApis(t *testing.T) {
|
|||
Username: "test",
|
||||
Password: "test",
|
||||
ComputerSystemID: "1",
|
||||
IncludeMetrics: []string{"thermal", "power"},
|
||||
}
|
||||
require.NoError(t, hpPlugin.Init())
|
||||
var hpAcc testutil.Accumulator
|
||||
|
|
@ -643,6 +645,7 @@ func TestInvalidUsernameorPassword(t *testing.T) {
|
|||
Username: "test",
|
||||
Password: "test",
|
||||
ComputerSystemID: "System.Embedded.1",
|
||||
IncludeMetrics: []string{"thermal", "power"},
|
||||
}
|
||||
|
||||
var acc testutil.Accumulator
|
||||
|
|
@ -671,6 +674,7 @@ func TestNoUsernameorPasswordConfiguration(t *testing.T) {
|
|||
r := &Redfish{
|
||||
Address: ts.URL,
|
||||
ComputerSystemID: "System.Embedded.1",
|
||||
IncludeMetrics: []string{"thermal", "power"},
|
||||
}
|
||||
|
||||
err := r.Init()
|
||||
|
|
@ -743,6 +747,7 @@ func TestInvalidDellJSON(t *testing.T) {
|
|||
Username: "test",
|
||||
Password: "test",
|
||||
ComputerSystemID: "System.Embedded.1",
|
||||
IncludeMetrics: []string{"thermal", "power"},
|
||||
}
|
||||
|
||||
require.NoError(t, plugin.Init())
|
||||
|
|
@ -813,6 +818,7 @@ func TestInvalidHPJSON(t *testing.T) {
|
|||
Username: "test",
|
||||
Password: "test",
|
||||
ComputerSystemID: "System.Embedded.2",
|
||||
IncludeMetrics: []string{"thermal", "power"},
|
||||
}
|
||||
|
||||
require.NoError(t, plugin.Init())
|
||||
|
|
@ -1097,6 +1103,7 @@ func TestIncludeTagSetsConfiguration(t *testing.T) {
|
|||
Password: "test",
|
||||
ComputerSystemID: "1",
|
||||
IncludeTagSets: []string{"chassis", "chassis.location"},
|
||||
IncludeMetrics: []string{"thermal", "power"},
|
||||
}
|
||||
require.NoError(t, hpPlugin.Init())
|
||||
var hpAcc testutil.Accumulator
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@
|
|||
## System Id to collect data for in Redfish APIs.
|
||||
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
|
||||
## For Example.
|
||||
## Thermal data is an OData link with parent Chassis which has a link of Location.
|
||||
|
|
|
|||
Loading…
Reference in New Issue