add total power factor
This commit is contained in:
parent
3fdf996a93
commit
cbfaa2f2da
2 changed files with 46 additions and 21 deletions
|
@ -11,6 +11,7 @@ type Exporter struct {
|
|||
ApparantPower *prometheus.GaugeVec
|
||||
ActivePower *prometheus.GaugeVec
|
||||
Frequency *prometheus.GaugeVec
|
||||
TotalPowerFactor *prometheus.GaugeVec
|
||||
}
|
||||
|
||||
func New() Exporter {
|
||||
|
@ -51,11 +52,19 @@ func New() Exporter {
|
|||
Help: "Frequency in Hz",
|
||||
}, []string{"device"})
|
||||
|
||||
exporter.TotalPowerFactor = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: "siemens",
|
||||
Subsystem: "pac3100",
|
||||
Name: "total_power_factor",
|
||||
Help: "Total Power Factor",
|
||||
}, []string{"device"})
|
||||
|
||||
prometheus.MustRegister(exporter.Voltage)
|
||||
prometheus.MustRegister(exporter.Current)
|
||||
prometheus.MustRegister(exporter.ApparantPower)
|
||||
prometheus.MustRegister(exporter.ActivePower)
|
||||
prometheus.MustRegister(exporter.Frequency)
|
||||
prometheus.MustRegister(exporter.TotalPowerFactor)
|
||||
|
||||
return exporter
|
||||
}
|
||||
|
@ -82,4 +91,5 @@ func (e Exporter) SetMeasurements(measurement scraper.Measurements, deviceName s
|
|||
e.ActivePower.WithLabelValues(deviceName, "C").Set(float64(measurement.ActivePowerC))
|
||||
|
||||
e.Frequency.WithLabelValues(deviceName).Set(float64(measurement.Frequency))
|
||||
e.TotalPowerFactor.WithLabelValues(deviceName).Set(float64(measurement.TotalPowerFactor))
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ type Measurements struct {
|
|||
ActivePowerB float32
|
||||
ActivePowerC float32
|
||||
Frequency float32
|
||||
TotalPowerFactor float32
|
||||
}
|
||||
|
||||
func New(address string, logger zerolog.Logger) (*Scraper, error) {
|
||||
|
@ -139,6 +140,11 @@ func (s *Scraper) GetMeasurments() (Measurements, error) {
|
|||
s.logger.Err(err)
|
||||
}
|
||||
|
||||
measurement.TotalPowerFactor, err = s.GetTotalPowerFactor()
|
||||
if err != nil {
|
||||
s.logger.Err(err)
|
||||
}
|
||||
|
||||
return measurement, nil
|
||||
}
|
||||
|
||||
|
@ -286,6 +292,15 @@ func (s *Scraper) GetFrequency() (float32, error) {
|
|||
return Float32fromBytes(results), nil
|
||||
}
|
||||
|
||||
// no Unit
|
||||
func (s *Scraper) GetTotalPowerFactor() (float32, error) {
|
||||
results, err := s.modbus.ReadInputRegistersBytes(126, 53, 2)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("reading Total Power Factor: %w", err)
|
||||
}
|
||||
return Float32fromBytes(results), nil
|
||||
}
|
||||
|
||||
func Float32fromBytes(bytes []byte) float32 {
|
||||
bits := binary.BigEndian.Uint32(bytes)
|
||||
float := math.Float32frombits(bits)
|
||||
|
|
Loading…
Reference in a new issue