2022-04-19 12:05:03 +02:00
|
|
|
package receivers
|
|
|
|
|
|
|
|
import (
|
2022-07-22 12:06:02 +02:00
|
|
|
"crypto/tls"
|
2022-04-19 12:05:03 +02:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2022-07-22 12:06:02 +02:00
|
|
|
"net/http"
|
2022-04-19 12:05:03 +02:00
|
|
|
"strconv"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
|
|
|
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
|
|
|
|
|
|
|
// See: https://pkg.go.dev/github.com/stmcginnis/gofish
|
|
|
|
"github.com/stmcginnis/gofish"
|
2022-08-10 10:30:59 +02:00
|
|
|
"github.com/stmcginnis/gofish/common"
|
|
|
|
"github.com/stmcginnis/gofish/redfish"
|
2022-04-19 12:05:03 +02:00
|
|
|
)
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
type RedfishReceiverClientConfig struct {
|
2022-07-22 12:06:02 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Hostname the redfish service belongs to
|
|
|
|
Hostname string
|
2022-08-10 10:30:59 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// is metric excluded globally or per client
|
|
|
|
isExcluded map[string](bool)
|
2022-08-10 16:24:21 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
doPowerMetric bool
|
|
|
|
doProcessorMetrics bool
|
|
|
|
doThermalMetrics bool
|
2022-08-10 16:24:21 +02:00
|
|
|
|
2022-08-17 15:11:21 +02:00
|
|
|
skipProcessorMetricsURL map[string]bool
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
gofish gofish.ClientConfig
|
|
|
|
}
|
2022-08-10 16:24:21 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// RedfishReceiver configuration:
|
|
|
|
type RedfishReceiver struct {
|
|
|
|
receiver
|
2022-08-10 16:24:21 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
config struct {
|
|
|
|
fanout int
|
|
|
|
Interval time.Duration
|
|
|
|
HttpTimeout time.Duration
|
2022-08-10 16:24:21 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Client config for each redfish service
|
|
|
|
ClientConfigs []RedfishReceiverClientConfig
|
2022-04-19 12:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
done chan bool // channel to finish / stop redfish receiver
|
|
|
|
wg sync.WaitGroup // wait group for redfish receiver
|
|
|
|
}
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// readThermalMetrics reads thermal metrics from a redfish device
|
|
|
|
func (r *RedfishReceiver) readThermalMetrics(
|
|
|
|
clientConfig *RedfishReceiverClientConfig,
|
|
|
|
chassis *redfish.Chassis) error {
|
2022-08-10 16:24:21 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Get thermal information for each chassis
|
|
|
|
thermal, err := chassis.Thermal()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("readMetrics: chassis.Thermal() failed: %v", err)
|
|
|
|
}
|
2022-08-10 10:30:59 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Skip empty thermal information
|
|
|
|
if thermal == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2022-08-10 10:30:59 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
timestamp := time.Now()
|
2022-08-10 10:30:59 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
for _, temperature := range thermal.Temperatures {
|
2022-08-10 10:30:59 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Skip, when temperature metric is excluded
|
|
|
|
if clientConfig.isExcluded["temperature"] {
|
|
|
|
break
|
2022-08-10 10:30:59 +02:00
|
|
|
}
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Skip all temperatures which are not in enabled state
|
2022-08-17 17:37:24 +02:00
|
|
|
if temperature.Status.State != "" && temperature.Status.State != common.EnabledState {
|
2022-08-16 15:14:20 +02:00
|
|
|
continue
|
|
|
|
}
|
2022-08-10 16:24:21 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
tags := map[string]string{
|
|
|
|
"hostname": clientConfig.Hostname,
|
|
|
|
"type": "node",
|
|
|
|
// ChassisType shall indicate the physical form factor for the type of chassis
|
|
|
|
"chassis_typ": string(chassis.ChassisType),
|
|
|
|
// Chassis name
|
|
|
|
"chassis_name": chassis.Name,
|
|
|
|
// ID uniquely identifies the resource
|
|
|
|
"temperature_id": temperature.ID,
|
|
|
|
// MemberID shall uniquely identify the member within the collection. For
|
|
|
|
// services supporting Redfish v1.6 or higher, this value shall be the
|
|
|
|
// zero-based array index.
|
|
|
|
"temperature_member_id": temperature.MemberID,
|
|
|
|
// PhysicalContext shall be a description of the affected device or region
|
|
|
|
// within the chassis to which this temperature measurement applies
|
|
|
|
"temperature_physical_context": string(temperature.PhysicalContext),
|
|
|
|
// Name
|
|
|
|
"temperature_name": temperature.Name,
|
|
|
|
}
|
2022-08-10 16:24:21 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Delete empty tags
|
|
|
|
for key, value := range tags {
|
|
|
|
if value == "" {
|
|
|
|
delete(tags, key)
|
2022-08-10 16:24:21 +02:00
|
|
|
}
|
2022-08-16 15:14:20 +02:00
|
|
|
}
|
2022-08-10 16:24:21 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Set meta data tags
|
|
|
|
meta := map[string]string{
|
|
|
|
"source": r.name,
|
|
|
|
"group": "Temperature",
|
|
|
|
"unit": "degC",
|
|
|
|
}
|
2022-08-10 16:24:21 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// ReadingCelsius shall be the current value of the temperature sensor's reading.
|
|
|
|
value := temperature.ReadingCelsius
|
2022-08-10 16:24:21 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
y, err := lp.New("temperature", tags, meta,
|
|
|
|
map[string]interface{}{
|
|
|
|
"value": value,
|
|
|
|
},
|
|
|
|
timestamp)
|
|
|
|
if err == nil {
|
|
|
|
r.sink <- y
|
2022-08-10 16:24:21 +02:00
|
|
|
}
|
2022-08-10 10:30:59 +02:00
|
|
|
}
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
for _, fan := range thermal.Fans {
|
|
|
|
// Skip, when fan_speed metric is excluded
|
|
|
|
if clientConfig.isExcluded["fan_speed"] {
|
|
|
|
break
|
2022-08-10 10:30:59 +02:00
|
|
|
}
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Skip all fans which are not in enabled state
|
|
|
|
if fan.Status.State != common.EnabledState {
|
|
|
|
continue
|
2022-08-10 10:30:59 +02:00
|
|
|
}
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
tags := map[string]string{
|
|
|
|
"hostname": clientConfig.Hostname,
|
|
|
|
"type": "node",
|
|
|
|
// ChassisType shall indicate the physical form factor for the type of chassis
|
|
|
|
"chassis_typ": string(chassis.ChassisType),
|
|
|
|
// Chassis name
|
|
|
|
"chassis_name": chassis.Name,
|
|
|
|
// ID uniquely identifies the resource
|
|
|
|
"fan_id": fan.ID,
|
|
|
|
// MemberID shall uniquely identify the member within the collection. For
|
|
|
|
// services supporting Redfish v1.6 or higher, this value shall be the
|
|
|
|
// zero-based array index.
|
|
|
|
"fan_member_id": fan.MemberID,
|
|
|
|
// PhysicalContext shall be a description of the affected device or region
|
|
|
|
// within the chassis to which this fan is associated
|
|
|
|
"fan_physical_context": string(fan.PhysicalContext),
|
|
|
|
// Name
|
|
|
|
"fan_name": fan.Name,
|
2022-08-10 10:30:59 +02:00
|
|
|
}
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Delete empty tags
|
|
|
|
for key, value := range tags {
|
|
|
|
if value == "" {
|
|
|
|
delete(tags, key)
|
2022-08-10 17:00:47 +02:00
|
|
|
}
|
2022-08-16 15:14:20 +02:00
|
|
|
}
|
2022-08-10 17:00:47 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Set meta data tags
|
|
|
|
meta := map[string]string{
|
|
|
|
"source": r.name,
|
|
|
|
"group": "FanSpeed",
|
|
|
|
"unit": string(fan.ReadingUnits),
|
|
|
|
}
|
2022-08-10 10:30:59 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Reading shall be the current value of the fan sensor's reading
|
|
|
|
value := fan.Reading
|
2022-08-10 10:30:59 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
y, err := lp.New("fan_speed", tags, meta,
|
|
|
|
map[string]interface{}{
|
|
|
|
"value": value,
|
|
|
|
},
|
|
|
|
timestamp)
|
|
|
|
if err == nil {
|
|
|
|
r.sink <- y
|
|
|
|
}
|
|
|
|
}
|
2022-08-10 10:30:59 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
return nil
|
|
|
|
}
|
2022-08-10 10:30:59 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// readPowerMetrics reads power metrics from a redfish device
|
|
|
|
func (r *RedfishReceiver) readPowerMetrics(
|
|
|
|
clientConfig *RedfishReceiverClientConfig,
|
|
|
|
chassis *redfish.Chassis) error {
|
2022-08-10 10:30:59 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Get power information for each chassis
|
|
|
|
power, err := chassis.Power()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("readMetrics: chassis.Power() failed: %v", err)
|
|
|
|
}
|
2022-08-10 10:30:59 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Skip empty power information
|
|
|
|
if power == nil {
|
2022-08-10 10:30:59 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
timestamp := time.Now()
|
2022-08-15 15:11:29 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Read min, max and average consumed watts for each power control
|
|
|
|
for _, pc := range power.PowerControl {
|
|
|
|
|
|
|
|
// Skip all power controls which are not in enabled state
|
2022-08-17 17:37:24 +02:00
|
|
|
if pc.Status.State != "" && pc.Status.State != common.EnabledState {
|
2022-08-16 15:14:20 +02:00
|
|
|
continue
|
2022-08-15 15:11:29 +02:00
|
|
|
}
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Map of collected metrics
|
|
|
|
metrics := make(map[string]float32)
|
2022-08-15 15:11:29 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// PowerConsumedWatts shall represent the actual power being consumed (in
|
|
|
|
// Watts) by the chassis
|
|
|
|
if !clientConfig.isExcluded["consumed_watts"] {
|
|
|
|
metrics["consumed_watts"] = pc.PowerConsumedWatts
|
2022-08-15 15:11:29 +02:00
|
|
|
}
|
2022-08-16 15:14:20 +02:00
|
|
|
// AverageConsumedWatts shall represent the
|
|
|
|
// average power level that occurred averaged over the last IntervalInMin
|
|
|
|
// minutes.
|
|
|
|
if !clientConfig.isExcluded["average_consumed_watts"] {
|
|
|
|
metrics["average_consumed_watts"] = pc.PowerMetrics.AverageConsumedWatts
|
2022-08-15 15:11:29 +02:00
|
|
|
}
|
2022-08-16 15:14:20 +02:00
|
|
|
// MinConsumedWatts shall represent the
|
|
|
|
// minimum power level in watts that occurred within the last
|
|
|
|
// IntervalInMin minutes.
|
|
|
|
if !clientConfig.isExcluded["min_consumed_watts"] {
|
|
|
|
metrics["min_consumed_watts"] = pc.PowerMetrics.MinConsumedWatts
|
2022-08-15 15:11:29 +02:00
|
|
|
}
|
2022-08-16 15:14:20 +02:00
|
|
|
// MaxConsumedWatts shall represent the
|
|
|
|
// maximum power level in watts that occurred within the last
|
|
|
|
// IntervalInMin minutes
|
|
|
|
if !clientConfig.isExcluded["max_consumed_watts"] {
|
|
|
|
metrics["max_consumed_watts"] = pc.PowerMetrics.MaxConsumedWatts
|
|
|
|
}
|
|
|
|
// IntervalInMin shall represent the time interval (or window), in minutes,
|
|
|
|
// in which the PowerMetrics properties are measured over.
|
|
|
|
// Should be an integer, but some Dell implementations return as a float
|
|
|
|
intervalInMin :=
|
|
|
|
strconv.FormatFloat(
|
|
|
|
float64(pc.PowerMetrics.IntervalInMin), 'f', -1, 32)
|
2022-08-15 15:11:29 +02:00
|
|
|
|
|
|
|
// Set tags
|
|
|
|
tags := map[string]string{
|
2022-08-16 15:14:20 +02:00
|
|
|
"hostname": clientConfig.Hostname,
|
|
|
|
"type": "node",
|
|
|
|
// ChassisType shall indicate the physical form factor for the type of chassis
|
|
|
|
"chassis_typ": string(chassis.ChassisType),
|
|
|
|
// Chassis name
|
|
|
|
"chassis_name": chassis.Name,
|
2022-08-15 15:11:29 +02:00
|
|
|
// ID uniquely identifies the resource
|
2022-08-16 15:14:20 +02:00
|
|
|
"power_control_id": pc.ID,
|
|
|
|
// MemberID shall uniquely identify the member within the collection. For
|
|
|
|
// services supporting Redfish v1.6 or higher, this value shall be the
|
|
|
|
// zero-based array index.
|
|
|
|
"power_control_member_id": pc.MemberID,
|
|
|
|
// PhysicalContext shall be a description of the affected device(s) or region
|
|
|
|
// within the chassis to which this power control applies.
|
|
|
|
"power_control_physical_context": string(pc.PhysicalContext),
|
|
|
|
// Name
|
|
|
|
"power_control_name": pc.Name,
|
2022-08-15 15:11:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Delete empty tags
|
|
|
|
for key, value := range tags {
|
|
|
|
if value == "" {
|
|
|
|
delete(tags, key)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set meta data tags
|
2022-08-16 15:14:20 +02:00
|
|
|
meta := map[string]string{
|
|
|
|
"source": r.name,
|
|
|
|
"group": "Energy",
|
|
|
|
"interval_in_minutes": intervalInMin,
|
|
|
|
"unit": "watts",
|
2022-08-15 15:11:29 +02:00
|
|
|
}
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Delete empty meta data tags
|
|
|
|
for key, value := range meta {
|
|
|
|
if value == "" {
|
|
|
|
delete(meta, key)
|
2022-08-15 15:11:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
for name, value := range metrics {
|
2022-08-15 15:11:29 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
y, err := lp.New(name, tags, meta,
|
2022-08-15 15:11:29 +02:00
|
|
|
map[string]interface{}{
|
2022-08-16 15:14:20 +02:00
|
|
|
"value": value,
|
2022-08-15 15:11:29 +02:00
|
|
|
},
|
|
|
|
timestamp)
|
|
|
|
if err == nil {
|
|
|
|
r.sink <- y
|
|
|
|
}
|
|
|
|
}
|
2022-08-16 15:14:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// readProcessorMetrics reads processor metrics from a redfish device
|
|
|
|
// See: https://redfish.dmtf.org/schemas/v1/ProcessorMetrics.json
|
|
|
|
func (r *RedfishReceiver) readProcessorMetrics(
|
|
|
|
clientConfig *RedfishReceiverClientConfig,
|
|
|
|
processor *redfish.Processor) error {
|
|
|
|
|
|
|
|
timestamp := time.Now()
|
|
|
|
|
2022-08-17 15:11:21 +02:00
|
|
|
// URL to processor metrics
|
2022-08-16 15:14:20 +02:00
|
|
|
URL := processor.ODataID + "/ProcessorMetrics"
|
2022-08-17 15:11:21 +02:00
|
|
|
|
|
|
|
// Skip previously detected non existing URLs
|
|
|
|
if clientConfig.skipProcessorMetricsURL[URL] {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
resp, err := processor.Client.Get(URL)
|
|
|
|
if err != nil {
|
|
|
|
// Skip non existing URLs
|
2022-08-17 15:11:21 +02:00
|
|
|
if statusCode := err.(*common.Error).HTTPReturnedStatusCode; statusCode == http.StatusNotFound {
|
|
|
|
clientConfig.skipProcessorMetricsURL[URL] = true
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("processor.Client.Get(%v) failed: %+w", URL, err)
|
2022-08-15 15:11:29 +02:00
|
|
|
}
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
var processorMetrics struct {
|
|
|
|
common.Entity
|
|
|
|
ODataType string `json:"@odata.type"`
|
|
|
|
ODataEtag string `json:"@odata.etag"`
|
|
|
|
Description string `json:"Description"`
|
|
|
|
// This property shall contain the power, in watts, that the processor has consumed.
|
|
|
|
ConsumedPowerWatt float32 `json:"ConsumedPowerWatt"`
|
|
|
|
// This property shall contain the temperature, in Celsius, of the processor.
|
|
|
|
TemperatureCelsius float32 `json:"TemperatureCelsius"`
|
|
|
|
}
|
|
|
|
err = json.NewDecoder(resp.Body).Decode(&processorMetrics)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("unable to decode JSON for processor metrics: %+w", err)
|
|
|
|
}
|
|
|
|
processorMetrics.SetClient(processor.Client)
|
|
|
|
|
|
|
|
// Set tags
|
|
|
|
tags := map[string]string{
|
|
|
|
"hostname": clientConfig.Hostname,
|
|
|
|
"type": "socket",
|
|
|
|
// ProcessorType shall contain the string which identifies the type of processor contained in this Socket
|
|
|
|
"processor_typ": string(processor.ProcessorType),
|
|
|
|
// Processor name
|
|
|
|
"processor_name": processor.Name,
|
|
|
|
// ID uniquely identifies the resource
|
|
|
|
"processor_id": processor.ID,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete empty tags
|
|
|
|
for key, value := range tags {
|
|
|
|
if value == "" {
|
|
|
|
delete(tags, key)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set meta data tags
|
|
|
|
metaPower := map[string]string{
|
|
|
|
"source": r.name,
|
|
|
|
"group": "Energy",
|
|
|
|
"unit": "watts",
|
|
|
|
}
|
|
|
|
|
|
|
|
namePower := "consumed_power"
|
|
|
|
|
|
|
|
if !clientConfig.isExcluded[namePower] {
|
|
|
|
y, err := lp.New(namePower, tags, metaPower,
|
|
|
|
map[string]interface{}{
|
|
|
|
"value": processorMetrics.ConsumedPowerWatt,
|
|
|
|
},
|
|
|
|
timestamp)
|
|
|
|
if err == nil {
|
|
|
|
r.sink <- y
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Set meta data tags
|
|
|
|
metaThermal := map[string]string{
|
|
|
|
"source": r.name,
|
|
|
|
"group": "Temperature",
|
|
|
|
"unit": "degC",
|
|
|
|
}
|
2022-04-19 12:05:03 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
nameThermal := "temperature"
|
|
|
|
|
|
|
|
if !clientConfig.isExcluded[nameThermal] {
|
|
|
|
y, err := lp.New(nameThermal, tags, metaThermal,
|
|
|
|
map[string]interface{}{
|
|
|
|
"value": processorMetrics.TemperatureCelsius,
|
|
|
|
},
|
|
|
|
timestamp)
|
|
|
|
if err == nil {
|
|
|
|
r.sink <- y
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// readMetrics reads redfish thermal, power and processor metrics from the redfish device
|
|
|
|
// configured in clientConfig
|
|
|
|
func (r *RedfishReceiver) readMetrics(clientConfig *RedfishReceiverClientConfig) error {
|
|
|
|
|
|
|
|
// Connect to redfish service
|
|
|
|
c, err := gofish.Connect(clientConfig.gofish)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"readMetrics: gofish.Connect({Username: %v, Endpoint: %v, BasicAuth: %v, HttpTimeout: %v, HttpInsecure: %v}) failed: %v",
|
|
|
|
clientConfig.gofish.Username,
|
|
|
|
clientConfig.gofish.Endpoint,
|
|
|
|
clientConfig.gofish.BasicAuth,
|
|
|
|
clientConfig.gofish.HTTPClient.Timeout,
|
|
|
|
clientConfig.gofish.HTTPClient.Transport.(*http.Transport).TLSClientConfig.InsecureSkipVerify,
|
|
|
|
err)
|
|
|
|
}
|
|
|
|
defer c.Logout()
|
2022-04-19 12:05:03 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Create a session, when required
|
|
|
|
if _, err = c.GetSession(); err != nil {
|
|
|
|
c, err = c.CloneWithSession()
|
2022-04-19 12:05:03 +02:00
|
|
|
if err != nil {
|
2022-08-16 15:14:20 +02:00
|
|
|
return fmt.Errorf("readMetrics: Failed to create a session: %+w", err)
|
2022-08-10 16:24:21 +02:00
|
|
|
}
|
2022-08-16 15:14:20 +02:00
|
|
|
}
|
2022-08-10 16:24:21 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Get all chassis managed by this service
|
|
|
|
isChassisListRequired :=
|
|
|
|
clientConfig.doThermalMetrics ||
|
|
|
|
clientConfig.doPowerMetric
|
|
|
|
var chassisList []*redfish.Chassis
|
|
|
|
if isChassisListRequired {
|
|
|
|
chassisList, err = c.Service.Chassis()
|
2022-04-19 12:05:03 +02:00
|
|
|
if err != nil {
|
2022-08-10 10:30:59 +02:00
|
|
|
return fmt.Errorf("readMetrics: c.Service.Chassis() failed: %v", err)
|
2022-04-19 12:05:03 +02:00
|
|
|
}
|
2022-08-16 15:14:20 +02:00
|
|
|
}
|
2022-04-19 12:05:03 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Get all computer systems managed by this service
|
|
|
|
isComputerSystemListRequired := clientConfig.doProcessorMetrics
|
|
|
|
var computerSystemList []*redfish.ComputerSystem
|
|
|
|
if isComputerSystemListRequired {
|
|
|
|
computerSystemList, err = c.Service.Systems()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("readMetrics: c.Service.Systems() failed: %v", err)
|
|
|
|
}
|
|
|
|
}
|
2022-04-19 12:05:03 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// read thermal metrics
|
|
|
|
if clientConfig.doThermalMetrics {
|
|
|
|
for _, chassis := range chassisList {
|
|
|
|
err := r.readThermalMetrics(clientConfig, chassis)
|
2022-04-19 12:05:03 +02:00
|
|
|
if err != nil {
|
2022-08-10 10:30:59 +02:00
|
|
|
return err
|
2022-04-19 12:05:03 +02:00
|
|
|
}
|
2022-08-16 15:14:20 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-20 14:39:26 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// read power metrics
|
|
|
|
if clientConfig.doPowerMetric {
|
|
|
|
for _, chassis := range chassisList {
|
|
|
|
err = r.readPowerMetrics(clientConfig, chassis)
|
2022-08-10 10:30:59 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2022-04-19 12:05:03 +02:00
|
|
|
}
|
|
|
|
}
|
2022-08-16 15:14:20 +02:00
|
|
|
}
|
2022-04-19 12:05:03 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// read processor metrics
|
|
|
|
if clientConfig.doProcessorMetrics {
|
2022-08-15 15:11:29 +02:00
|
|
|
// loop for all computer systems
|
2022-08-16 15:14:20 +02:00
|
|
|
for _, system := range computerSystemList {
|
2022-08-15 15:11:29 +02:00
|
|
|
|
|
|
|
// loop for all processors
|
|
|
|
processors, err := system.Processors()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("readMetrics: system.Processors() failed: %v", err)
|
|
|
|
}
|
|
|
|
for _, processor := range processors {
|
2022-08-16 15:14:20 +02:00
|
|
|
err := r.readProcessorMetrics(clientConfig, processor)
|
2022-08-15 15:11:29 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-19 12:05:03 +02:00
|
|
|
}
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
return nil
|
|
|
|
}
|
2022-04-19 12:05:03 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// doReadMetrics reads metrics from all configure redfish devices.
|
|
|
|
// To compensate latencies of the Redfish devices a fanout is used.
|
|
|
|
func (r *RedfishReceiver) doReadMetric() {
|
|
|
|
|
|
|
|
// Create wait group and input channel for workers
|
|
|
|
var workerWaitGroup sync.WaitGroup
|
|
|
|
workerInput := make(chan *RedfishReceiverClientConfig, r.config.fanout)
|
|
|
|
|
|
|
|
// Create worker go routines
|
|
|
|
for i := 0; i < r.config.fanout; i++ {
|
|
|
|
// Increment worker wait group counter
|
|
|
|
workerWaitGroup.Add(1)
|
|
|
|
go func() {
|
|
|
|
// Decrement worker wait group counter
|
|
|
|
defer workerWaitGroup.Done()
|
|
|
|
|
|
|
|
// Read power metrics for each client config
|
|
|
|
for clientConfig := range workerInput {
|
|
|
|
err := r.readMetrics(clientConfig)
|
|
|
|
if err != nil {
|
|
|
|
cclog.ComponentError(r.name, err)
|
2022-04-19 12:05:03 +02:00
|
|
|
}
|
2022-08-16 15:14:20 +02:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2022-04-19 12:05:03 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Distribute client configs to workers
|
|
|
|
for i := range r.config.ClientConfigs {
|
|
|
|
|
|
|
|
// Check done channel status
|
|
|
|
select {
|
|
|
|
case workerInput <- &r.config.ClientConfigs[i]:
|
|
|
|
case <-r.done:
|
|
|
|
// process done event
|
|
|
|
// Stop workers, clear channel and wait for all workers to finish
|
|
|
|
close(workerInput)
|
|
|
|
for range workerInput {
|
2022-04-20 09:58:02 +02:00
|
|
|
}
|
2022-08-16 15:14:20 +02:00
|
|
|
workerWaitGroup.Wait()
|
|
|
|
return
|
2022-04-19 12:05:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Stop workers and wait for all workers to finish
|
|
|
|
close(workerInput)
|
|
|
|
workerWaitGroup.Wait()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start starts the redfish receiver
|
|
|
|
func (r *RedfishReceiver) Start() {
|
|
|
|
cclog.ComponentDebug(r.name, "START")
|
|
|
|
|
2022-04-19 12:05:03 +02:00
|
|
|
// Start redfish receiver
|
|
|
|
r.wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer r.wg.Done()
|
|
|
|
|
|
|
|
// Create ticker
|
2022-07-22 17:48:11 +02:00
|
|
|
ticker := time.NewTicker(r.config.Interval)
|
2022-04-19 12:05:03 +02:00
|
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
for {
|
2022-08-16 15:14:20 +02:00
|
|
|
r.doReadMetric()
|
2022-04-19 12:05:03 +02:00
|
|
|
|
|
|
|
select {
|
2022-08-16 15:14:20 +02:00
|
|
|
case tickerTime := <-ticker.C:
|
|
|
|
// Check if we missed the ticker event
|
|
|
|
if since := time.Since(tickerTime); since > 5*time.Second {
|
|
|
|
cclog.ComponentInfo(r.name, "Missed ticker event for more then", since)
|
|
|
|
}
|
|
|
|
|
2022-04-19 12:05:03 +02:00
|
|
|
// process ticker event -> continue
|
|
|
|
continue
|
|
|
|
case <-r.done:
|
|
|
|
// process done event
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
cclog.ComponentDebug(r.name, "STARTED")
|
|
|
|
}
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Close closes the redfish receiver
|
2022-04-19 12:05:03 +02:00
|
|
|
func (r *RedfishReceiver) Close() {
|
|
|
|
cclog.ComponentDebug(r.name, "CLOSE")
|
|
|
|
|
|
|
|
// Send the signal and wait
|
2022-04-19 14:01:23 +02:00
|
|
|
close(r.done)
|
2022-04-19 12:05:03 +02:00
|
|
|
r.wg.Wait()
|
|
|
|
|
|
|
|
cclog.ComponentDebug(r.name, "DONE")
|
|
|
|
}
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// NewRedfishReceiver creates a new instance of the redfish receiver
|
2022-04-19 12:05:03 +02:00
|
|
|
// Initialize the receiver by giving it a name and reading in the config JSON
|
|
|
|
func NewRedfishReceiver(name string, config json.RawMessage) (Receiver, error) {
|
|
|
|
r := new(RedfishReceiver)
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Config options from config file
|
|
|
|
configJSON := struct {
|
|
|
|
Type string `json:"type"`
|
|
|
|
|
|
|
|
// Maximum number of simultaneous redfish connections (default: 64)
|
|
|
|
Fanout int `json:"fanout,omitempty"`
|
|
|
|
// How often the redfish power metrics should be read and send to the sink (default: 30 s)
|
|
|
|
IntervalString string `json:"interval,omitempty"`
|
|
|
|
|
|
|
|
// Control whether a client verifies the server's certificate
|
|
|
|
// (default: true == do not verify server's certificate)
|
|
|
|
HttpInsecure bool `json:"http_insecure,omitempty"`
|
|
|
|
// Time limit for requests made by this HTTP client (default: 10 s)
|
|
|
|
HttpTimeoutString string `json:"http_timeout,omitempty"`
|
|
|
|
|
|
|
|
// Globally disable collection of power, processor or thermal metrics
|
|
|
|
DisablePowerMetrics bool `json:"disable_power_metrics"`
|
|
|
|
DisableProcessorMetrics bool `json:"disable_processor_metrics"`
|
|
|
|
DisableThermalMetrics bool `json:"disable_thermal_metrics"`
|
|
|
|
|
|
|
|
// Globally excluded metrics
|
|
|
|
ExcludeMetrics []string `json:"exclude_metrics,omitempty"`
|
|
|
|
|
|
|
|
ClientConfigs []struct {
|
|
|
|
Hostname *string `json:"hostname"` // Hostname the redfish service belongs to
|
|
|
|
Username *string `json:"username"` // User name to authenticate with
|
|
|
|
Password *string `json:"password"` // Password to use for authentication
|
|
|
|
Endpoint *string `json:"endpoint"` // URL of the redfish service
|
|
|
|
|
|
|
|
// Per client disable collection of power,processor or thermal metrics
|
|
|
|
DisablePowerMetrics bool `json:"disable_power_metrics"`
|
|
|
|
DisableProcessorMetrics bool `json:"disable_processor_metrics"`
|
|
|
|
DisableThermalMetrics bool `json:"disable_thermal_metrics"`
|
|
|
|
|
|
|
|
// Per client excluded metrics
|
|
|
|
ExcludeMetrics []string `json:"exclude_metrics,omitempty"`
|
|
|
|
} `json:"client_config"`
|
|
|
|
}{
|
|
|
|
// Set defaults values
|
|
|
|
// Allow overwriting these defaults by reading config JSON
|
|
|
|
Fanout: 64,
|
|
|
|
IntervalString: "30s",
|
|
|
|
HttpTimeoutString: "10s",
|
|
|
|
HttpInsecure: true,
|
|
|
|
}
|
|
|
|
|
2022-04-19 12:05:03 +02:00
|
|
|
// Set name
|
|
|
|
r.name = fmt.Sprintf("RedfishReceiver(%s)", name)
|
|
|
|
|
|
|
|
// Create done channel
|
|
|
|
r.done = make(chan bool)
|
|
|
|
|
|
|
|
// Read the redfish receiver specific JSON config
|
|
|
|
if len(config) > 0 {
|
2022-08-16 15:14:20 +02:00
|
|
|
err := json.Unmarshal(config, &configJSON)
|
2022-04-19 12:05:03 +02:00
|
|
|
if err != nil {
|
|
|
|
cclog.ComponentError(r.name, "Error reading config:", err.Error())
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-22 17:48:11 +02:00
|
|
|
// interval duration
|
|
|
|
var err error
|
2022-08-16 15:14:20 +02:00
|
|
|
r.config.Interval, err = time.ParseDuration(configJSON.IntervalString)
|
2022-07-22 17:48:11 +02:00
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf(
|
|
|
|
"Failed to parse duration string interval='%s': %w",
|
2022-08-16 15:14:20 +02:00
|
|
|
configJSON.IntervalString,
|
2022-07-22 17:48:11 +02:00
|
|
|
err,
|
|
|
|
)
|
|
|
|
cclog.Error(r.name, err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// HTTP timeout duration
|
2022-08-16 15:14:20 +02:00
|
|
|
r.config.HttpTimeout, err = time.ParseDuration(configJSON.HttpTimeoutString)
|
2022-07-22 17:48:11 +02:00
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf(
|
|
|
|
"Failed to parse duration string http_timeout='%s': %w",
|
2022-08-16 15:14:20 +02:00
|
|
|
configJSON.HttpTimeoutString,
|
2022-07-22 17:48:11 +02:00
|
|
|
err,
|
|
|
|
)
|
|
|
|
cclog.Error(r.name, err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-07-22 12:06:02 +02:00
|
|
|
// Create new http client
|
|
|
|
customTransport := http.DefaultTransport.(*http.Transport).Clone()
|
|
|
|
customTransport.TLSClientConfig = &tls.Config{
|
2022-08-16 15:14:20 +02:00
|
|
|
InsecureSkipVerify: configJSON.HttpInsecure,
|
2022-07-22 12:06:02 +02:00
|
|
|
}
|
|
|
|
httpClient := &http.Client{
|
|
|
|
Timeout: r.config.HttpTimeout,
|
|
|
|
Transport: customTransport,
|
|
|
|
}
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Compute fanout to use
|
|
|
|
numClients := len(configJSON.ClientConfigs)
|
|
|
|
r.config.fanout = configJSON.Fanout
|
|
|
|
if numClients < r.config.fanout {
|
|
|
|
r.config.fanout = numClients
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize derived configuration
|
|
|
|
r.config.ClientConfigs = make([]RedfishReceiverClientConfig, numClients)
|
|
|
|
|
2022-04-19 12:05:03 +02:00
|
|
|
// Create gofish client config
|
2022-08-16 15:14:20 +02:00
|
|
|
for i := 0; i < numClients; i++ {
|
2022-04-19 12:05:03 +02:00
|
|
|
clientConfig := &r.config.ClientConfigs[i]
|
2022-08-16 15:14:20 +02:00
|
|
|
clientConfigJSON := &configJSON.ClientConfigs[i]
|
2022-04-19 12:05:03 +02:00
|
|
|
gofishConfig := &clientConfig.gofish
|
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
if clientConfigJSON.Hostname == nil {
|
2022-04-19 12:05:03 +02:00
|
|
|
err := fmt.Errorf("client config number %v requires hostname", i)
|
|
|
|
cclog.ComponentError(r.name, err)
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-08-16 15:14:20 +02:00
|
|
|
clientConfig.Hostname = *clientConfigJSON.Hostname
|
2022-04-19 12:05:03 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
if clientConfigJSON.Endpoint == nil {
|
2022-04-19 12:05:03 +02:00
|
|
|
err := fmt.Errorf("client config number %v requires endpoint", i)
|
|
|
|
cclog.ComponentError(r.name, err)
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-08-16 15:14:20 +02:00
|
|
|
gofishConfig.Endpoint = *clientConfigJSON.Endpoint
|
2022-04-19 12:05:03 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
if clientConfigJSON.Username == nil {
|
2022-04-19 12:05:03 +02:00
|
|
|
err := fmt.Errorf("client config number %v requires username", i)
|
|
|
|
cclog.ComponentError(r.name, err)
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-08-16 15:14:20 +02:00
|
|
|
gofishConfig.Username = *clientConfigJSON.Username
|
2022-04-19 12:05:03 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
if clientConfigJSON.Password == nil {
|
2022-04-19 12:05:03 +02:00
|
|
|
err := fmt.Errorf("client config number %v requires password", i)
|
|
|
|
cclog.ComponentError(r.name, err)
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-08-16 15:14:20 +02:00
|
|
|
gofishConfig.Password = *clientConfigJSON.Password
|
2022-04-19 12:05:03 +02:00
|
|
|
|
2022-08-10 16:24:21 +02:00
|
|
|
// Reuse existing http client
|
2022-07-22 12:06:02 +02:00
|
|
|
gofishConfig.HTTPClient = httpClient
|
2022-08-10 16:24:21 +02:00
|
|
|
|
2022-08-16 15:14:20 +02:00
|
|
|
// Which metrics should be collected
|
|
|
|
clientConfig.doPowerMetric =
|
|
|
|
!(configJSON.DisablePowerMetrics ||
|
|
|
|
clientConfigJSON.DisablePowerMetrics)
|
|
|
|
clientConfig.doProcessorMetrics =
|
|
|
|
!(configJSON.DisableProcessorMetrics ||
|
|
|
|
clientConfigJSON.DisableProcessorMetrics)
|
|
|
|
clientConfig.doThermalMetrics =
|
|
|
|
!(configJSON.DisableThermalMetrics ||
|
|
|
|
clientConfigJSON.DisableThermalMetrics)
|
|
|
|
|
2022-08-17 15:11:21 +02:00
|
|
|
clientConfig.skipProcessorMetricsURL = make(map[string]bool)
|
|
|
|
|
2022-08-10 16:24:21 +02:00
|
|
|
// Is metrics excluded globally or per client
|
|
|
|
clientConfig.isExcluded = make(map[string]bool)
|
2022-08-16 15:14:20 +02:00
|
|
|
for _, key := range clientConfigJSON.ExcludeMetrics {
|
2022-08-10 16:24:21 +02:00
|
|
|
clientConfig.isExcluded[key] = true
|
|
|
|
}
|
2022-08-16 15:14:20 +02:00
|
|
|
for _, key := range configJSON.ExcludeMetrics {
|
2022-08-10 16:24:21 +02:00
|
|
|
clientConfig.isExcluded[key] = true
|
|
|
|
}
|
2022-04-19 12:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return r, nil
|
|
|
|
}
|