mirror of
https://github.com/prometheus-community/ipmi_exporter
synced 2025-03-11 06:07:58 +00:00
These are for now considered slightly experimental. They can be enabled by `--native-ipmi`. The implementation is backed by go-ipmi [1]. For the time being, this will be a purely optional thing. There are some caveats (which will be documented), but mostly this should be a fully functional replacement. It may in some aspects even be superior (or at least become so in the future), as the exporter has much better control over the IPMI communication. [1] https://github.com/bougou/go-ipmi Signed-off-by: Conrad Hoffmann <ch@bitfehler.net>
68 lines
1.8 KiB
Go
68 lines
1.8 KiB
Go
// Copyright 2025 The Prometheus Authors
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus-community/ipmi_exporter/freeipmi"
|
|
)
|
|
|
|
var (
|
|
powerConsumptionNativeDesc = prometheus.NewDesc(
|
|
prometheus.BuildFQName(namespace, "dcmi", "power_consumption_watts"),
|
|
"Current power consumption in Watts.",
|
|
[]string{},
|
|
nil,
|
|
)
|
|
)
|
|
|
|
type DCMINativeCollector struct{}
|
|
|
|
func (c DCMINativeCollector) Name() CollectorName {
|
|
// The name is intentionally the same as the non-native collector
|
|
return DCMICollectorName
|
|
}
|
|
|
|
func (c DCMINativeCollector) Cmd() string {
|
|
return ""
|
|
}
|
|
|
|
func (c DCMINativeCollector) Args() []string {
|
|
return []string{}
|
|
}
|
|
|
|
func (c DCMINativeCollector) Collect(_ freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
|
|
client, err := NewNativeClient(target)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
res, err := client.GetDCMIPowerReading(context.TODO())
|
|
if err != nil {
|
|
logger.Error("Failed to collect DCMI data", "target", targetName(target.host), "error", err)
|
|
return 0, err
|
|
}
|
|
|
|
if res.PowerMeasurementActive {
|
|
ch <- prometheus.MustNewConstMetric(
|
|
powerConsumptionNativeDesc,
|
|
prometheus.GaugeValue,
|
|
float64(res.CurrentPower),
|
|
)
|
|
}
|
|
return 1, nil
|
|
}
|