add total power factor
This commit is contained in:
parent
3fdf996a93
commit
cbfaa2f2da
2 changed files with 46 additions and 21 deletions
|
@ -6,11 +6,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Exporter struct {
|
type Exporter struct {
|
||||||
Voltage *prometheus.GaugeVec
|
Voltage *prometheus.GaugeVec
|
||||||
Current *prometheus.GaugeVec
|
Current *prometheus.GaugeVec
|
||||||
ApparantPower *prometheus.GaugeVec
|
ApparantPower *prometheus.GaugeVec
|
||||||
ActivePower *prometheus.GaugeVec
|
ActivePower *prometheus.GaugeVec
|
||||||
Frequency *prometheus.GaugeVec
|
Frequency *prometheus.GaugeVec
|
||||||
|
TotalPowerFactor *prometheus.GaugeVec
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() Exporter {
|
func New() Exporter {
|
||||||
|
@ -51,11 +52,19 @@ func New() Exporter {
|
||||||
Help: "Frequency in Hz",
|
Help: "Frequency in Hz",
|
||||||
}, []string{"device"})
|
}, []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.Voltage)
|
||||||
prometheus.MustRegister(exporter.Current)
|
prometheus.MustRegister(exporter.Current)
|
||||||
prometheus.MustRegister(exporter.ApparantPower)
|
prometheus.MustRegister(exporter.ApparantPower)
|
||||||
prometheus.MustRegister(exporter.ActivePower)
|
prometheus.MustRegister(exporter.ActivePower)
|
||||||
prometheus.MustRegister(exporter.Frequency)
|
prometheus.MustRegister(exporter.Frequency)
|
||||||
|
prometheus.MustRegister(exporter.TotalPowerFactor)
|
||||||
|
|
||||||
return exporter
|
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.ActivePower.WithLabelValues(deviceName, "C").Set(float64(measurement.ActivePowerC))
|
||||||
|
|
||||||
e.Frequency.WithLabelValues(deviceName).Set(float64(measurement.Frequency))
|
e.Frequency.WithLabelValues(deviceName).Set(float64(measurement.Frequency))
|
||||||
|
e.TotalPowerFactor.WithLabelValues(deviceName).Set(float64(measurement.TotalPowerFactor))
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,22 +15,23 @@ type Scraper struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Measurements struct {
|
type Measurements struct {
|
||||||
VoltageAN float32
|
VoltageAN float32
|
||||||
VoltageBN float32
|
VoltageBN float32
|
||||||
VoltageCN float32
|
VoltageCN float32
|
||||||
VoltageAB float32
|
VoltageAB float32
|
||||||
VoltageBC float32
|
VoltageBC float32
|
||||||
VoltageCA float32
|
VoltageCA float32
|
||||||
CurrentA float32
|
CurrentA float32
|
||||||
CurrentB float32
|
CurrentB float32
|
||||||
CurrentC float32
|
CurrentC float32
|
||||||
ApparantPowerA float32
|
ApparantPowerA float32
|
||||||
ApparantPowerB float32
|
ApparantPowerB float32
|
||||||
ApparantPowerC float32
|
ApparantPowerC float32
|
||||||
ActivePowerA float32
|
ActivePowerA float32
|
||||||
ActivePowerB float32
|
ActivePowerB float32
|
||||||
ActivePowerC float32
|
ActivePowerC float32
|
||||||
Frequency float32
|
Frequency float32
|
||||||
|
TotalPowerFactor float32
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(address string, logger zerolog.Logger) (*Scraper, error) {
|
func New(address string, logger zerolog.Logger) (*Scraper, error) {
|
||||||
|
@ -139,6 +140,11 @@ func (s *Scraper) GetMeasurments() (Measurements, error) {
|
||||||
s.logger.Err(err)
|
s.logger.Err(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
measurement.TotalPowerFactor, err = s.GetTotalPowerFactor()
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Err(err)
|
||||||
|
}
|
||||||
|
|
||||||
return measurement, nil
|
return measurement, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,6 +292,15 @@ func (s *Scraper) GetFrequency() (float32, error) {
|
||||||
return Float32fromBytes(results), nil
|
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 {
|
func Float32fromBytes(bytes []byte) float32 {
|
||||||
bits := binary.BigEndian.Uint32(bytes)
|
bits := binary.BigEndian.Uint32(bytes)
|
||||||
float := math.Float32frombits(bits)
|
float := math.Float32frombits(bits)
|
||||||
|
|
Loading…
Reference in a new issue