Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Refactoring Redfish exporter to gofish library
Browse files Browse the repository at this point in the history
  • Loading branch information
BirknerAlex committed Mar 25, 2024
1 parent 0edf416 commit b57bb5c
Show file tree
Hide file tree
Showing 25 changed files with 539 additions and 600 deletions.
23 changes: 2 additions & 21 deletions .github/workflows/pm_exporter.yml → .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,6 @@ on:
branches:
- main
jobs:
binary:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Build
run: go build -o pm_exporter cmd/main.go
- name: Upload pm_exporter
uses: actions/upload-artifact@v2
with:
name: pm_exporter
path: pm_exporter
build-docker-image:
runs-on: ubuntu-latest
needs: binary
Expand All @@ -33,15 +18,11 @@ jobs:
registry: 'https://index.docker.io/v1/'
username: '${{ secrets.DOCKER_USERNAME }}'
password: '${{ secrets.DOCKER_PASSWORD }}'
- name: Download a Build Artifact
uses: actions/download-artifact@v2.0.9
with:
name: pm_exporter
- name: Build and push container image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
gportal/pm_exporter:${{ github.sha }}
gportal/pm_exporter:latest
gportal/redfish_exporter:${{ github.sha }}
gportal/redfish_exporter:latest
23 changes: 19 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
FROM fedora:34
FROM gportal/golang:latest

COPY pm_exporter /usr/local/bin/pm_exporter
RUN chmod +x /usr/local/bin/pm_exporter
# Import application source
COPY ./ /opt/app-root/src

ENTRYPOINT [ "/usr/local/bin/pm_exporter" ]
# Change working directory
WORKDIR /opt/app-root/src

# Build binary for Latency Service
RUN go build -v -o "${APP_ROOT}/redfish_exporter" cmd/main.go && \
setcap cap_net_bind_service+ep "${APP_ROOT}/redfish_exporter"

# Finally delete application source
RUN rm -rf /opt/app-root/src/*

EXPOSE 9096

RUN /usr/bin/fix-permissions ${APP_ROOT} && \
/usr/bin/fix-permissions /data/

CMD ["/opt/app-root/redfish_exporter"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Ociris GmbH
Copyright (c) 2024 Ociris GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
78 changes: 10 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,71 +1,13 @@
# pm_exporter
# Redfish Prometheus Exporter

[![Build](https://github.com/GPORTALcloud/pm_exporter/actions/workflows/pm_exporter.yml/badge.svg?branch=main)](https://github.com/GPORTALcloud/pm_exporter/actions/workflows/pm_exporter.yml)
### This is WIP.

!!! STILL UNDER DEVELOPMENT !!!
Redfish Exporter is providing generic metrics fetched from Redfish endpoints.

pm_exporter is providing metrics fetched from platform management endpoints (such as iDRAC or ILO) and exposing those through HTTP for making those readable for prometheus.

For fetching those details the platform management specific API's are used (such as Redfish for iDRAC).
Those metrics are getting persisted within the runtime for the duration specified through command line arguments.

The list of platform managements to fetch details from is stored within a yaml file, each platform management needs to be defined there,
including their credentials, address and types. In addition, this config file allows adding
custom labels to the metrics which can be used for example for passing the id of the server within your
own inventory system or the switch the platform management is connected to.

Metrics which are getting collected:

| metric | Type | description |
| ------------------------------ |:-------:| :-----------------------------------------------|
| pm_platform_management_up | gauge | Defines if the platform management is reachable |
| pm_powersupply_health | gauge | Indicates the health status of the Power Supply |
| pm_battery_health | gauge | Indicates the health status of the Battery |
| pm_cpu_health | gauge | Indicates the health status of the CPU |
| pm_fan_health | gauge | Indicates the health status of the Fan |
| pm_storage_health | gauge | Indicates the health status of the Storage |
| pm_temperature_health | gauge | Indicates the health status of the Temperature |
| pm_intrusion_health | gauge | Indicates if the chassis is closed or not |
| pm_license_health | gauge | Indicates if the license is still valid |
| pm_memory_health | gauge | Indicates the health status of the Memory |
| pm_overall_health | gauge | Indicates if any of the health metrics are bad |

Platform Managements are getting implemented once there is a host needs to get monitored, this list will grow with time.

Currently supported:
* iDRAC (redfish)


## Install
There are different ways of running the pm_exporter.

### Precompiled binaries
Precompiled binaries are getting created with each workflow run. Just download the artifact below "Actions" and
place them wherever you want.

### Docker images
pm_exporter is getting build and published to the Docker and Github registry.

You can just launch your own pm_exporter instance using the following command (arguments you're fine with the default you can just omit)

```
docker run -d --name pm_exporter --rm \
-v /local/config.yml:/etc/pm_exporter.yml \
msniveau/pm_exporter \
--config.file=/etc/pm_exporter.yml \
--web.listen-address=0.0.0.0:9096 \
--web.enable-lifecycle \
--metrics.persist_duration=5m \
--metrics.refresh_interval=1m \
--worker.count=5
```

## Command line arguments
| argument | default | description |
| ------------------------- |:----------------------:| :------------------------------------------------------|
| --config.file | /etc/pm_exporter.yml | Config file location |
| -metric.persist_duration | 1m30s | Duration metrics are getting persisted |
| -metric.refresh_interval | 1m | Interval metrics are getting fetched |
| -web.enable-lifecycle | false | Adds the /-/reload endpoint for config reload |
| -web.listen-address | 0.0.0.0:9096 | Listen address the HTTP server runs on |
| -worker.count | 10 | The amount of workers used for fetching the metrics |
Tested with:
* HPE ILO4
* HPE ILO5
* Dell iDRAC 8
* Dell iDRAC 9
* AsRockRack
* SuperMicro SuperServer
39 changes: 11 additions & 28 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,31 @@ package main

import (
"flag"
"github.com/g-portal/redfish_exporter/pkg/config"
"github.com/g-portal/redfish_exporter/pkg/metric"
"github.com/gin-gonic/gin"
"log"
"net/http"
"time"

"github.com/GPORTALcloud/pm_exporter/pkg/config"
"github.com/GPORTALcloud/pm_exporter/pkg/metric"
"github.com/GPORTALcloud/pm_exporter/pkg/updater"
)

var (
workerCount int
refreshInterval time.Duration
persistDuration time.Duration
listenAddr string
enableLifecycle bool
configPath string
listenAddr string
configPath string
)

func init() {
flag.StringVar(&configPath, "config.file", "/etc/pm_exporter.yml", "Defines the path to the platform management config")
flag.StringVar(&configPath, "config.file", "/etc/redfish_exporter/config.yml", "Defines the path to the platform management config")
flag.StringVar(&listenAddr, "web.listen-address", "0.0.0.0:9096", "Address the exporter listens on")
flag.BoolVar(&enableLifecycle, "web.enable-lifecycle", false, "With this parameter set calls to /-/reload are reloading the config")
flag.IntVar(&workerCount, "worker.count", 10, "Worker processes for calling platform management API's")
flag.DurationVar(&refreshInterval, "metric.refresh_interval", time.Second*60, "Interval the exporter refresh the metrics")
flag.DurationVar(&persistDuration, "metric.persist_duration", time.Second*90, "Duration collected metrics persist before being invalidated")
flag.Parse()
config.Prepare(configPath)

config.SetPath(configPath)
}

func main() {
r := gin.Default()

metric.SetPersistDuration(persistDuration)

go updater.Run(workerCount, refreshInterval)
http.HandleFunc("/metrics", metric.MetricHttpHandler)

if enableLifecycle {
http.HandleFunc("/-/reload", config.ReloadConfigHandler)
}

r.GET("/metrics", metric.Handle)
log.Println("Starting listening on: " + listenAddr)
err := http.ListenAndServe(listenAddr, nil)
err := r.Run(listenAddr)
if err != nil {
log.Printf("Error starting http server: %v", err)
}
Expand Down
23 changes: 4 additions & 19 deletions config.example.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
---

platform_managements:
- host: https://192.168.0.1
username: root
password: toor
type: IDRAC
labels:
funny: labels
- host: https://192.168.0.2
username: root
password: toor
type: IDRAC
labels:
customer: 1337
- host: https://192.168.0.3
username: root
password: toor
type: IDRAC
labels:
internal_name: host00123
# Redfish Default Credentials
redfish:
username: root
password: toor
42 changes: 39 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
module github.com/GPORTALcloud/pm_exporter
module github.com/g-portal/redfish_exporter

go 1.16
go 1.22

require (
github.com/fsnotify/fsnotify v1.4.9
github.com/gin-gonic/gin v1.9.1
github.com/prometheus/client_golang v1.19.0
github.com/stmcginnis/gofish v0.15.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.11.3 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.51.1 // indirect
github.com/prometheus/procfs v0.13.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit b57bb5c

Please sign in to comment.