Skip to content

Commit

Permalink
Make the sensor id an argument for the exporter
Browse files Browse the repository at this point in the history
Modify the collector structure to include a senorID field
  • Loading branch information
operator committed Sep 16, 2024
1 parent 3cb0973 commit 56b8abf
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 25 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ jobs:
run: |
go get .
- name: Build for "System Temp" sensor
run: env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-X 'main.iPMI_TEMP_SENSOR=System Temp'" -o ipmitool_exporter ./main.go

- name: Build for "Inlet Temp" sensor (ekhi)
run: env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-X 'main.iPMI_TEMP_SENSOR=Inlet Temp'" -o ipmitool_exporter-ekhi ./main.go
- name: Build the executable
run: env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o ipmitool_exporter ./main.go

- name: Create a release
uses: softprops/action-gh-release@v2
Expand All @@ -39,4 +36,3 @@ jobs:
prerelease: false
files: |
ipmitool_exporter
ipmitool_exporter-ekhi
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.swp
ipmitool_exporter
binaries/*
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
sensor = System Temp

ipmitool_exporter:
go build -ldflags="-X 'main.iPMI_TEMP_SENSOR=$(sensor)'" -o ipmitool_exporter main.go
go build -o ipmitool_exporter main.go
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ Prometheus exporter to collect the inlet temperature of the server using the `ip

## Build the exporter

By default, the ipmisensor to read the temperature from is `System Temp`. If you need to change it, you can override the `sensor` variable in the Makefile with the option `-e`. E.g:
Compile the exporter:

```bash
[root@dave ipmitool_exporter] make -e sensor="Inlet Temp"
[root@dave ipmitool_exporter] make
```

## Run the exporter

Run the binary in the host you want to monitor. You can cofigure a system service for this.

```bash
[root@dave ipmitool_exporter] ./ipmitool_exporter -address=:5000 -path=/metrics
[root@dave ipmitool_exporter] ./ipmitool_exporter -sensor "Inlet Temp" -address=":5000" -path="/metrics"
```

## View the metrics
Expand Down Expand Up @@ -75,9 +75,3 @@ process_max_fds 262144

- Import the dashboard (`grafana/inlet-temperature.json`) into Grafana:
`Dashboards`->`New`->`Import`->`Upload JSON file`

# Releases

There are two binaries for every release:
- `ipmitool_exporter` compiled for the "System Temp" sensor.
- `ipmitool_exporter-ekhi` compiled for the "Inlet Temp" sensor.
16 changes: 9 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
)

var iPMI_TEMP_SENSOR string = "System Temp"

func fetch() float64 {
func fetch(sensor_id string) float64 {

/* Fetch the inlet temperature running shell commands */

sensor := exec.Command("/usr/bin/ipmitool", "sdr", "get", iPMI_TEMP_SENSOR)
sensor := exec.Command("/usr/bin/ipmitool", "sdr", "get", sensor_id)
output,_ := sensor.Output()

// regex to match
Expand All @@ -37,6 +35,7 @@ type tempCollector struct {

/* Define a structure for the collector */

sensorID string
tempMetric *prometheus.Desc
}

Expand All @@ -54,18 +53,19 @@ func (collector *tempCollector) Collect(ch chan <- prometheus.Metric) {
which runs the logic to determine the value of the metric */

// fetch the metric
metric := fetch()
metric := fetch(collector.sensorID)

// write the latest value for the metric in the metric channel
metric_latest := prometheus.MustNewConstMetric(collector.tempMetric, prometheus.GaugeValue, metric)
ch <- metric_latest
}

func newTempCollector() *tempCollector{
func newTempCollector(sensorID string) *tempCollector{

/* Initialize the descriptor and return a pointer to the collector */

return &tempCollector{
sensorID: sensorID,
tempMetric: prometheus.NewDesc("ipmitool_temp", "Inlet Temperature", nil, nil),
}
}
Expand All @@ -76,6 +76,8 @@ func main() {

// command line arguments
var (
sensorID = flag.String("sensor", "System Temp",
"Sensor ID to fetch the Inlet Temperature with ipmitool")
listenAddress = flag.String("address", ":8000",
"Address to listen on for this exporter")
metricsPath = flag.String("path", "/metrics",
Expand All @@ -84,7 +86,7 @@ func main() {
flag.Parse()

// create and register the metric
inlet_temperature := newTempCollector()
inlet_temperature := newTempCollector(*sensorID)
prometheus.MustRegister(inlet_temperature)

// expose the metric
Expand Down

0 comments on commit 56b8abf

Please sign in to comment.