This commit is contained in:
@@ -8,9 +8,17 @@ import (
|
||||
|
||||
"github.com/dnaeon/go-ucs/api"
|
||||
"github.com/dnaeon/go-ucs/mo"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
// Define the fields we will send back to the collector
|
||||
type UcsmTemperatures struct {
|
||||
Server string
|
||||
Component string
|
||||
Description string
|
||||
Value float64
|
||||
}
|
||||
|
||||
/*
|
||||
type UcsmTemperaturesCollector struct {
|
||||
ucsClient *api.Client
|
||||
ctx context.Context
|
||||
@@ -18,6 +26,7 @@ type UcsmTemperaturesCollector struct {
|
||||
}
|
||||
|
||||
var metrics []prometheus.Desc
|
||||
*/
|
||||
|
||||
//var ucsClient *api.Client
|
||||
//var ctx context.Context
|
||||
@@ -30,64 +39,44 @@ var metrics []prometheus.Desc
|
||||
FmTempSenRear string `xml:"fmTempSenRear,attr,omitempty"`
|
||||
}
|
||||
*/
|
||||
func NewUcsmTemperatureCollector(client *api.Client, ctx context.Context) *UcsmTemperaturesCollector {
|
||||
/*
|
||||
func NewUcsmTemperatureCollector(client *api.Client, ctx context.Context) *UcsExporters {
|
||||
|
||||
/*
|
||||
ucsClient = client
|
||||
ctx = ctx
|
||||
*/
|
||||
/*
|
||||
return &main.Collector{
|
||||
UcsmTemperature: prometheus.NewDesc("ucsm_temperature_sensor",
|
||||
"UCSM temperature sensor for motherboard/cpu/psu",
|
||||
[]string{"server", "component", "description"}, nil,
|
||||
),
|
||||
}
|
||||
*/
|
||||
|
||||
return &UcsmTemperaturesCollector{
|
||||
return &UcsExporters{
|
||||
ucsClient: client,
|
||||
ctx: ctx,
|
||||
metrics: []*prometheus.Desc{
|
||||
prometheus.NewDesc(
|
||||
"ucsm_temperature_sensor",
|
||||
"UCSM temperature sensor for motherboard/cpu/psu",
|
||||
[]string{"server", "component", "description"}, nil,
|
||||
),
|
||||
},
|
||||
UcsmTemperatures: prometheus.NewDesc("ucsm_temperature_sensor",
|
||||
"UCSM temperature sensor for motherboard/cpu/psu",
|
||||
[]string{"server", "component", "description"}, nil,
|
||||
),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Describe prometheus describe
|
||||
func (u *UcsmTemperaturesCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
func (u *UcsExporters) Describe(ch chan<- *prometheus.Desc) {
|
||||
log.Printf("Running Describe for UcsmTemperaturesCollector\n")
|
||||
|
||||
// Describe the metrics and send them on the channel
|
||||
for _, desc := range u.metrics {
|
||||
ch <- desc
|
||||
}
|
||||
|
||||
/*
|
||||
metricDesc := prometheus.NewDesc("ucsm_temperature_sensor",
|
||||
"UCSM temperature sensor for motherboard/cpu/psu",
|
||||
[]string{"server", "component", "description"}, nil)
|
||||
|
||||
fmt.Printf("metricDesc: %v\n", *metricDesc)
|
||||
|
||||
metrics = append(metrics, *metricDesc)
|
||||
ch <- metricDesc
|
||||
*/
|
||||
ch <- u.UcsmTemperatures
|
||||
}
|
||||
*/
|
||||
|
||||
// Collect prometheus collect
|
||||
func (u *UcsmTemperaturesCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
func (u *UcsExporters) GetUcsmTemperatures(ctx context.Context, ucsmTempsChannel chan []UcsmTemperatures) {
|
||||
/*
|
||||
wg.Add(1)
|
||||
defer wg.Done()
|
||||
defer close(ucsmTempsChannel)
|
||||
*/
|
||||
temperatureResults := make([]UcsmTemperatures, 0)
|
||||
|
||||
// The type into which we unmarshal the result data
|
||||
type temps struct {
|
||||
XMLName xml.Name
|
||||
Temperatures []mo.ComputeMbTempStats `xml:"computeMbTempStats"`
|
||||
}
|
||||
|
||||
// Define the request we are making to UCS Manager
|
||||
tempRequest := api.ConfigResolveClassRequest{
|
||||
Cookie: u.ucsClient.Cookie,
|
||||
ClassId: "computeMbTempStats",
|
||||
@@ -96,6 +85,7 @@ func (u *UcsmTemperaturesCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
|
||||
var boardTempList temps
|
||||
|
||||
//cswg := new(sync.WaitGroup)
|
||||
log.Println("Retrieving managed objects with class `computeMbTempStats`")
|
||||
|
||||
if err := u.ucsClient.ConfigResolveClass(u.ctx, tempRequest, &boardTempList); err != nil {
|
||||
@@ -111,28 +101,41 @@ func (u *UcsmTemperaturesCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
log.Printf("Front Temperature: %v\n", temps.FmTempSenIo)
|
||||
log.Printf("Rear Temperature: %v\n", temps.FmTempSenRear)
|
||||
|
||||
// TODO - work out a better way of running this twice, once for each temperature sensor
|
||||
boardTempFront := UcsmTemperatures{
|
||||
Server: bladeDn,
|
||||
Component: temps.Dn,
|
||||
Description: "motherboard_front_temperature",
|
||||
Value: temps.FmTempSenIo,
|
||||
}
|
||||
|
||||
// Collect the actual metric values and send them on the channel
|
||||
for _, desc := range u.metrics {
|
||||
boardTempRear := UcsmTemperatures{
|
||||
Server: bladeDn,
|
||||
Component: temps.Dn,
|
||||
Description: "motherboard_rear_temperature",
|
||||
Value: temps.FmTempSenRear,
|
||||
}
|
||||
|
||||
// populate the labels array
|
||||
//labelValues := []string{bladeDn, temps.Dn, "motherboard_rear_temperature"}
|
||||
temperatureResults = append(temperatureResults, boardTempFront)
|
||||
temperatureResults = append(temperatureResults, boardTempRear)
|
||||
|
||||
// generate the metric
|
||||
metric1 := prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, temps.FmTempSenIo, bladeDn, temps.Dn, "motherboard_rear_temperature")
|
||||
/*
|
||||
// TODO - work out a better way of running this twice, once for each temperature sensor
|
||||
|
||||
metric1 := prometheus.MustNewConstMetric(u.UcsmTemperatures, prometheus.GaugeValue, temps.FmTempSenIo, bladeDn, temps.Dn, "motherboard_rear_temperature")
|
||||
// send the data
|
||||
ch <- metric1
|
||||
|
||||
// generate the metric
|
||||
metric2 := prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, temps.FmTempSenRear, bladeDn, temps.Dn, "motherboard_front_temperature")
|
||||
metric2 := prometheus.MustNewConstMetric(u.UcsmTemperatures, prometheus.GaugeValue, temps.FmTempSenRear, bladeDn, temps.Dn, "motherboard_front_temperature")
|
||||
// send the data
|
||||
ch <- metric2
|
||||
}
|
||||
|
||||
//ch <- prometheus.MustNewConstMetric()
|
||||
*/
|
||||
}
|
||||
//cswg.Wait()
|
||||
|
||||
log.Printf("GetUcsmTemperatures sending results to channel\n")
|
||||
ucsmTempsChannel <- temperatureResults
|
||||
//return
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user