This commit is contained in:
77
internal/exporters/UcsmBlade.go
Normal file
77
internal/exporters/UcsmBlade.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package exporters
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"log"
|
||||
|
||||
"github.com/dnaeon/go-ucs/api"
|
||||
"github.com/dnaeon/go-ucs/mo"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
type UcsmBladeCollector struct {
|
||||
ucsClient *api.Client
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
/*
|
||||
type ComputeMbTempStats struct {
|
||||
XMLName xml.Name `xml:"computeMbTempStats"`
|
||||
Dn string `xml:"dn,attr,omitempty"`
|
||||
FmTempSenIo string `xml:"fmTempSenIo,attr,omitempty"`
|
||||
FmTempSenRear string `xml:"fmTempSenRear,attr,omitempty"`
|
||||
}
|
||||
*/
|
||||
func NewUcsmBladeCollector(client *api.Client, ctx context.Context) *UcsmTemperaturesCollector {
|
||||
return &UcsmTemperaturesCollector{
|
||||
ucsClient: client,
|
||||
ctx: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// Describe prometheus describe
|
||||
func (u *UcsmBladeCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
log.Printf("Running Describe for UcsmTemperaturesCollector\n")
|
||||
ch <- prometheus.NewDesc("ucsm_temperature_sensor",
|
||||
"UCSM temperature sensor for motherboard/cpu/psu",
|
||||
[]string{"server", "component", "description"}, nil,
|
||||
)
|
||||
ch <- prometheus.NewDesc("ucsm_temperature_sensor",
|
||||
"UCSM temperature sensor for motherboard/cpu/psu",
|
||||
[]string{"server", "component", "description"}, nil,
|
||||
)
|
||||
}
|
||||
|
||||
// Collect prometheus collect
|
||||
func (u *UcsmBladeCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
// The type into which we unmarshal the result data
|
||||
type blades struct {
|
||||
XMLName xml.Name
|
||||
Blades []mo.ComputeBlade `xml:"computeBlade"`
|
||||
}
|
||||
|
||||
bladeRequest := api.ConfigResolveClassRequest{
|
||||
Cookie: u.ucsClient.Cookie,
|
||||
ClassId: "computeBlade",
|
||||
InHierarchical: "false",
|
||||
}
|
||||
|
||||
var bladeList blades
|
||||
|
||||
log.Println("Retrieving managed objects with class `computeBlade`")
|
||||
|
||||
if err := u.ucsClient.ConfigResolveClass(u.ctx, bladeRequest, &bladeList); err != nil {
|
||||
log.Fatalf("Unable to retrieve `computeBlade` managed object: %s", err)
|
||||
}
|
||||
|
||||
log.Printf("Retrieved %d compute blades\n", len(bladeList.Blades))
|
||||
for _, blade := range bladeList.Blades {
|
||||
log.Printf("%s:\n", blade.Dn)
|
||||
log.Printf("\tNumber of CPUs: %d\n", blade.NumOfCpus)
|
||||
log.Printf("\tTotal Memory: %d\n", blade.TotalMemory)
|
||||
log.Printf("\tModel: %s\n", blade.Model)
|
||||
log.Printf("\tVendor: %s\n", blade.Vendor)
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user