diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index cfbd182..2260fac 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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 @@ -39,4 +36,3 @@ jobs: prerelease: false files: | ipmitool_exporter - ipmitool_exporter-ekhi diff --git a/.gitignore b/.gitignore index 861fd19..27bd022 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ +*.swp +ipmitool_exporter binaries/* diff --git a/Makefile b/Makefile index 36d3ded..6fb1af4 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index d4de129..7c76a00 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,10 @@ 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 @@ -29,7 +29,7 @@ By default, the ipmisensor to read the temperature from is `System Temp`. If you 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 @@ -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. diff --git a/main.go b/main.go index 5c89e07..618dda0 100644 --- a/main.go +++ b/main.go @@ -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 @@ -37,6 +35,7 @@ type tempCollector struct { /* Define a structure for the collector */ + sensorID string tempMetric *prometheus.Desc } @@ -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), } } @@ -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", @@ -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