mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
fix(baremetal): panic occured when fetch powerMetrics
This commit is contained in:
@@ -232,20 +232,26 @@ func (job *SSendMetricsJob) Do(ctx context.Context, now time.Time) error {
|
||||
return nil
|
||||
}
|
||||
powerMetrics, thermalMetrics, err := job.baremetal.fetchPowerThermalMetrics(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "fetchPowerThermalMetrics")
|
||||
}
|
||||
tags := job.baremetal.getTags()
|
||||
metrics := []influxdb.SMetricData{
|
||||
{
|
||||
metrics := []influxdb.SMetricData{}
|
||||
if len(powerMetrics) > 0 {
|
||||
metrics = append(metrics, influxdb.SMetricData{
|
||||
Name: "power",
|
||||
Tags: tags,
|
||||
Metrics: powerMetrics,
|
||||
Timestamp: now,
|
||||
},
|
||||
{
|
||||
})
|
||||
}
|
||||
if len(thermalMetrics) > 0 {
|
||||
metrics = append(metrics, influxdb.SMetricData{
|
||||
Name: "thermal",
|
||||
Tags: tags,
|
||||
Metrics: thermalMetrics,
|
||||
Timestamp: now,
|
||||
},
|
||||
})
|
||||
}
|
||||
err = influxdb.SendMetrics(urls, "telegraf", metrics, false)
|
||||
if err != nil {
|
||||
|
||||
@@ -2382,7 +2382,11 @@ func (b *SBaremetalInstance) fetchPowerThermalMetrics(ctx context.Context) ([]in
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "redfishApi.Thermal")
|
||||
}
|
||||
powerMetrics := powers[0].ToMetrics()
|
||||
|
||||
var powerMetrics []influxdb.SKeyValue
|
||||
if len(powers) > 0 {
|
||||
powerMetrics = powers[0].ToMetrics()
|
||||
}
|
||||
thermalMetrics := make([]influxdb.SKeyValue, 0)
|
||||
for _, t := range thermals {
|
||||
thermalMetrics = append(thermalMetrics, t.ToMetric())
|
||||
|
||||
Reference in New Issue
Block a user