Skip to content

Commit

Permalink
refactor: replace namespace to flxpeters
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Peters committed Apr 20, 2024
1 parent aed55c9 commit 798e0f7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
6 changes: 4 additions & 2 deletions collector/chassis_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
type ChassisCollector struct {
redfishClient *gofish.APIClient
metrics map[string]Metric
logger *slog.Logger
collectorScrapeStatus *prometheus.GaugeVec
}

Expand Down Expand Up @@ -87,12 +88,13 @@ func createChassisMetricMap() map[string]Metric {
}

// NewChassisCollector returns a collector that collecting chassis statistics
func NewChassisCollector(redfishClient *gofish.APIClient) *ChassisCollector {
func NewChassisCollector(redfishClient *gofish.APIClient, logger *slog.Logger) *ChassisCollector {
// get service from redfish client

return &ChassisCollector{
redfishClient: redfishClient,
metrics: chassisMetrics,
logger: logger,
collectorScrapeStatus: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Expand All @@ -116,7 +118,7 @@ func (c *ChassisCollector) Describe(ch chan<- *prometheus.Desc) {
// Collect implemented prometheus.Collector
func (c *ChassisCollector) Collect(ch chan<- prometheus.Metric) {

logger := slog.Default().With(slog.String("collector", "ChassisCollector"))
logger := c.logger.With(slog.String("collector", "ChassisCollector"))
service := c.redfishClient.Service

// get a list of chassis from service
Expand Down
6 changes: 4 additions & 2 deletions collector/manager_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
type ManagerCollector struct {
redfishClient *gofish.APIClient
metrics map[string]Metric
logger *slog.Logger
collectorScrapeStatus *prometheus.GaugeVec
}

Expand All @@ -39,10 +40,11 @@ func createManagerMetricMap() map[string]Metric {
}

// NewManagerCollector returns a collector that collecting memory statistics
func NewManagerCollector(redfishClient *gofish.APIClient) *ManagerCollector {
func NewManagerCollector(redfishClient *gofish.APIClient, logger *slog.Logger) *ManagerCollector {
return &ManagerCollector{
redfishClient: redfishClient,
metrics: managerMetrics,
logger: logger,
collectorScrapeStatus: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Expand All @@ -66,7 +68,7 @@ func (m *ManagerCollector) Describe(ch chan<- *prometheus.Desc) {
// Collect implemented prometheus.Collector
func (m *ManagerCollector) Collect(ch chan<- prometheus.Metric) {

logger := slog.Default().With(slog.String("collector", "ManagerCollector"))
logger := m.logger.With(slog.String("collector", "ManagerCollector"))
service := m.redfishClient.Service

// get a list of managers from service
Expand Down
8 changes: 5 additions & 3 deletions collector/redfish_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ type RedfishCollector struct {
func NewRedfishCollector(host string, username string, password string) *RedfishCollector {
var collectors map[string]prometheus.Collector

targetLogger := slog.Default().With(slog.String("target", host))

redfishClient, err := newRedfishClient(host, username, password)
if err != nil {
slog.Error("error creating redfish client", slog.Any("error", err))
} else {
chassisCollector := NewChassisCollector(redfishClient)
systemCollector := NewSystemCollector(redfishClient)
managerCollector := NewManagerCollector(redfishClient)
chassisCollector := NewChassisCollector(redfishClient, targetLogger)
systemCollector := NewSystemCollector(redfishClient, targetLogger)
managerCollector := NewManagerCollector(redfishClient, targetLogger)

collectors = map[string]prometheus.Collector{
"chassis": chassisCollector,
Expand Down
6 changes: 4 additions & 2 deletions collector/system_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
type SystemCollector struct {
redfishClient *gofish.APIClient
metrics map[string]Metric
logger *slog.Logger
prometheus.Collector
collectorScrapeStatus *prometheus.GaugeVec
}
Expand Down Expand Up @@ -93,10 +94,11 @@ func createSystemMetricMap() map[string]Metric {
}

// NewSystemCollector returns a collector that collecting memory statistics
func NewSystemCollector(redfishClient *gofish.APIClient) *SystemCollector {
func NewSystemCollector(redfishClient *gofish.APIClient, logger *slog.Logger) *SystemCollector {
return &SystemCollector{
redfishClient: redfishClient,
metrics: systemMetrics,
logger: logger,
collectorScrapeStatus: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Expand All @@ -119,7 +121,7 @@ func (s *SystemCollector) Describe(ch chan<- *prometheus.Desc) {
// Collect implements prometheus.Collector.
func (s *SystemCollector) Collect(ch chan<- prometheus.Metric) {

logger := slog.Default().With(slog.String("collector", "SystemCollector"))
logger := s.logger.With(slog.String("collector", "SystemCollector"))
service := s.redfishClient.Service

// get a list of systems from service
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/jenningsloy318/redfish_exporter
module github.com/flxpeters/redfish_exporter

go 1.21

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

"log/slog"

"github.com/flxpeters/redfish_exporter/collector"
kitlog "github.com/go-kit/log"
"github.com/jenningsloy318/redfish_exporter/collector"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"

Expand Down

0 comments on commit 798e0f7

Please sign in to comment.