@@ -46,54 +46,49 @@ var (
46
46
}
47
47
48
48
// prometheus metrics
49
- labelNames = []string {"model" , "serial" }
50
- gridExportWatts = promauto .NewGaugeVec (prometheus.GaugeOpts {
51
- Name : "grid_export_watts" ,
52
- Help : "Power exported to the grid. " +
53
- "Negative values indicate power is being drawn from the grid." ,
54
- }, labelNames )
55
- pvGenerationWatts = promauto .NewGaugeVec (prometheus.GaugeOpts {
56
- Name : "pv_generation_watts" ,
49
+ labelNames = []string {"model" , "serial" }
50
+ // headline metrics
51
+ powerGenerationWatts = promauto .NewGaugeVec (prometheus.GaugeOpts {
52
+ Name : "power_generation_watts" ,
57
53
Help : "Power generated by PV array. " +
58
54
"Small negative values are a measurement error. This value is [0,Inf.)." ,
59
55
}, labelNames )
60
- sumOfGridAndPVWatts = promauto .NewGaugeVec (prometheus.GaugeOpts {
61
- Name : "sum_of_grid_and_pv_watts" ,
62
- Help : "Sum of Grid and PV watts. (sometimes slightly inaccurate?)" ,
63
- }, labelNames )
64
- timeSyncPacketsTotal = promauto .NewCounterVec (prometheus.CounterOpts {
65
- Name : "time_sync_packets_total" ,
66
- Help : "Count of outbound time sync packets." ,
67
- }, labelNames )
68
- timeSyncAckPacketsTotal = promauto .NewCounterVec (prometheus.CounterOpts {
69
- Name : "time_sync_ack_packets_total" ,
70
- Help : "Count of outbound time sync acknowledgement packets." ,
71
- }, labelNames )
72
- metricsPacketsTotal = promauto .NewCounterVec (prometheus.CounterOpts {
73
- Name : "metrics_packets_total" ,
74
- Help : "Count of outbound metrics packets." ,
56
+ powerExportWatts = promauto .NewGaugeVec (prometheus.GaugeOpts {
57
+ Name : "power_export_watts" ,
58
+ Help : "Power exported to the grid. " +
59
+ "Negative values indicate power is being imported." ,
75
60
}, labelNames )
76
- unknownPacketsTotal = promauto .NewCounterVec (prometheus.CounterOpts {
77
- Name : "outbound_unknown_packets_total" ,
78
- Help : "Count of outbound unknown packets." ,
61
+ // other useful metrics
62
+ energyGenerationDecawattHoursTotal = promauto .NewGaugeVec (prometheus.GaugeOpts {
63
+ Name : "energy_generation_decawatt_hours_total" ,
64
+ Help : "Cumulative energy generated." ,
79
65
}, labelNames )
80
- // prometheus metrics debug
81
- gridExportDecawattHoursTotal = promauto .NewGaugeVec (prometheus.GaugeOpts {
82
- Name : "grid_export_decawatt_hours_total" ,
66
+ energyExportDecawattHoursTotal = promauto .NewGaugeVec (prometheus.GaugeOpts {
67
+ Name : "energy_export_decawatt_hours_total" ,
68
+ Help : "Cumulative energy exported. " +
69
+ "When energy is imported, this value is static." ,
83
70
}, labelNames )
84
- pvGenerationDecawattHoursTotal = promauto .NewGaugeVec (prometheus.GaugeOpts {
85
- Name : "pv_generation_decawatt_hours_total" ,
71
+ energyImportDecawattHoursTotal = promauto .NewGaugeVec (prometheus.GaugeOpts {
72
+ Name : "energy_import_decawatt_hours_total" ,
73
+ Help : "Cumulative energy imported. " +
74
+ "When energy is exported, this value is static." ,
86
75
}, labelNames )
87
- sumOfGridExportAndPVDecawattHoursTotal = promauto .NewGaugeVec (
76
+ sumOfEnergyGenerationAndImportDecawattHoursTotal = promauto .NewGaugeVec (
88
77
prometheus.GaugeOpts {
89
- Name : "sum_of_grid_export_and_pv_decawatt_hours_total" ,
78
+ Name : "sum_of_energy_generation_and_import_decawatt_hours_total" ,
79
+ Help : "Sum of energy generation and import." ,
90
80
}, labelNames )
91
- gridImportDecawattHoursTotal = promauto .NewGaugeVec (prometheus.GaugeOpts {
92
- Name : "grid_import_decawatt_hours_total" ,
81
+ // less useful and unknown metrics
82
+ sumOfPowerGenerationAndExportWatts = promauto .NewGaugeVec (prometheus.GaugeOpts {
83
+ Name : "sum_of_power_generation_and_export_watts" ,
84
+ Help : "Sum of power generation and export. " +
85
+ "Not particularly useful since it can double-count generated power." ,
93
86
}, labelNames )
94
- sumOfGridImportAndPVDecawattHoursTotal = promauto .NewGaugeVec (
87
+ sumOfEnergyGenerationAndExportDecawattHoursTotal = promauto .NewGaugeVec (
95
88
prometheus.GaugeOpts {
96
- Name : "sum_of_grid_import_and_pv_decawatt_hours_total" ,
89
+ Name : "sum_of_energy_generation_and_export_decawatt_hours_total" ,
90
+ Help : "Sum of energy generation and export. " +
91
+ "Not particularly useful since it can double-count generated energy." ,
97
92
}, labelNames )
98
93
unknownInt5 = promauto .NewGaugeVec (prometheus.GaugeOpts {
99
94
Name : "unknown_int_5" ,
@@ -119,6 +114,23 @@ var (
119
114
unknownInt12 = promauto .NewGaugeVec (prometheus.GaugeOpts {
120
115
Name : "unknown_int_12" ,
121
116
}, labelNames )
117
+ // expoerter internal metrics
118
+ timeSyncPacketsTotal = promauto .NewCounterVec (prometheus.CounterOpts {
119
+ Name : "time_sync_packets_total" ,
120
+ Help : "Count of outbound time sync packets." ,
121
+ }, labelNames )
122
+ timeSyncAckPacketsTotal = promauto .NewCounterVec (prometheus.CounterOpts {
123
+ Name : "time_sync_ack_packets_total" ,
124
+ Help : "Count of outbound time sync acknowledgement packets." ,
125
+ }, labelNames )
126
+ metricsPacketsTotal = promauto .NewCounterVec (prometheus.CounterOpts {
127
+ Name : "metrics_packets_total" ,
128
+ Help : "Count of outbound metrics packets." ,
129
+ }, labelNames )
130
+ unknownPacketsTotal = promauto .NewCounterVec (prometheus.CounterOpts {
131
+ Name : "outbound_unknown_packets_total" ,
132
+ Help : "Count of outbound unknown packets." ,
133
+ }, labelNames )
122
134
)
123
135
124
136
// OutboundHeader represents the header of an outbound packet.
@@ -158,28 +170,28 @@ type OutboundTimeSync struct {
158
170
159
171
// OutboundMetrics is the cleartext body of an outbound metrics packet.
160
172
type OutboundMetrics struct {
161
- PacketType [7 ]byte // 0x00-0x06 Packet type?
162
- GridExportDecawattHoursTotal int32 // 0x07-0x0a Units of 10 watt-hours
163
- UnknownBytes1 [2 ]byte // 0x0b-0x0c Fixed null?
164
- PVGenerationDecawattHoursTotal int32 // 0x0d-0x10 Units of 10 watt-hours
165
- UnknownBytes2 [8 ]byte // 0x11-0x18 Fixed null?
166
- SumOfGridExportAndPVDecawattHoursTotal int32 // 0x19-0x1c Units of 10 watt-hours
167
- UnknownBytes3 [2 ]byte // 0x1d-0x1e Fixed null?
168
- GridImportDecawattHoursTotal int32 // 0x1f-0x22 Units of 10 watt-hours
169
- UnknownBytes4 [16 ]byte // 0x23-0x32 Fixed bytes?
170
- SumOfGridImportAndPVDecawattHoursTotal int16 // 0x33-0x34 Units of 10 watt-hours
171
- UnknownInt5 int32 // 0x35-0x38 Fixed int value?
172
- UnknownInt6 int16 // 0x39-0x3a Gauge?
173
- UnknownInt7 int16 // 0x3b-0x3c Gauge?
174
- UnknownInt8 int16 // 0x3d-0x3e Incrementing counter?
175
- UnknownInt9 int32 // 0x3f-0x42 Gauge?
176
- UnknownInt10 int32 // 0x43-0x46 Gauge?
177
- UnknownInt11 int32 // 0x47-0x4a Fixed int zero?
178
- GridWatts int32 // 0x4b-0x4e
179
- PVWatts int32 // 0x4f-0x52
180
- UnknownInt12 int32 // 0x53-0x56 Fixed int zero?
181
- SumOfGridAndPVWatts int32 // 0x57-0x5a Sum of GridWatts and PVWatts (sometimes slightly inaccurate?)
182
- UnknownBytes5 [21 ]byte // 0x5b-0x6f Fixed bytes?
173
+ PacketType [7 ]byte // 0x00-0x06 Packet type?
174
+ EnergyExportDecawattHoursTotal int32 // 0x07-0x0a Units of 10 watt-hours
175
+ UnknownBytes1 [2 ]byte // 0x0b-0x0c Fixed null?
176
+ EnergyGenerationDecawattHoursTotal int32 // 0x0d-0x10 Units of 10 watt-hours
177
+ UnknownBytes2 [8 ]byte // 0x11-0x18 Fixed null?
178
+ SumOfEnergyGenerationAndExportDecawattHoursTotal int32 // 0x19-0x1c Units of 10 watt-hours
179
+ UnknownBytes3 [2 ]byte // 0x1d-0x1e Fixed null?
180
+ EnergyImportDecawattHoursTotal int32 // 0x1f-0x22 Units of 10 watt-hours
181
+ UnknownBytes4 [16 ]byte // 0x23-0x32 Fixed bytes?
182
+ SumOfEnergyGenerationAndImportDecawattHoursTotal int16 // 0x33-0x34 Units of 10 watt-hours
183
+ UnknownInt5 int32 // 0x35-0x38 Fixed int value?
184
+ UnknownInt6 int16 // 0x39-0x3a Gauge?
185
+ UnknownInt7 int16 // 0x3b-0x3c Gauge?
186
+ UnknownInt8 int16 // 0x3d-0x3e Incrementing counter?
187
+ UnknownInt9 int32 // 0x3f-0x42 Gauge?
188
+ UnknownInt10 int32 // 0x43-0x46 Gauge?
189
+ UnknownInt11 int32 // 0x47-0x4a Fixed int zero?
190
+ PowerExportWatts int32 // 0x4b-0x4e
191
+ PowerGenerationWatts int32 // 0x4f-0x52
192
+ UnknownInt12 int32 // 0x53-0x56 Fixed int zero?
193
+ SumOfPowerGenerationAndExportWatts int32 // 0x57-0x5a Sum of GridWatts and PVWatts (sometimes slightly inaccurate?)
194
+ UnknownBytes5 [21 ]byte // 0x5b-0x6f Fixed bytes?
183
195
}
184
196
185
197
// parseTimeSync unmarshals the time sync body.
@@ -274,14 +286,22 @@ func handleMetricsPacket(
274
286
"serial" : string (envelope .DeviceSerial [:]),
275
287
}
276
288
// record metrics
277
- gridExportWatts .With (labels ).Set (float64 (metrics .GridWatts ))
278
- pvGenerationWatts .With (labels ).Set (float64 (metrics .PVWatts ))
279
- sumOfGridAndPVWatts .With (labels ).Set (float64 (metrics .SumOfGridAndPVWatts ))
280
- gridExportDecawattHoursTotal .With (labels ).Set (float64 (metrics .GridExportDecawattHoursTotal ))
281
- pvGenerationDecawattHoursTotal .With (labels ).Set (float64 (metrics .PVGenerationDecawattHoursTotal ))
282
- sumOfGridExportAndPVDecawattHoursTotal .With (labels ).Set (float64 (metrics .SumOfGridExportAndPVDecawattHoursTotal ))
283
- gridImportDecawattHoursTotal .With (labels ).Set (float64 (metrics .GridImportDecawattHoursTotal ))
284
- sumOfGridImportAndPVDecawattHoursTotal .With (labels ).Set (float64 (metrics .SumOfGridImportAndPVDecawattHoursTotal ))
289
+ powerGenerationWatts .With (labels ).Set (
290
+ float64 (metrics .PowerGenerationWatts ))
291
+ powerExportWatts .With (labels ).Set (
292
+ float64 (metrics .PowerExportWatts ))
293
+ energyGenerationDecawattHoursTotal .With (labels ).Set (
294
+ float64 (metrics .EnergyGenerationDecawattHoursTotal ))
295
+ energyExportDecawattHoursTotal .With (labels ).Set (
296
+ float64 (metrics .EnergyExportDecawattHoursTotal ))
297
+ energyImportDecawattHoursTotal .With (labels ).Set (
298
+ float64 (metrics .EnergyImportDecawattHoursTotal ))
299
+ sumOfEnergyGenerationAndImportDecawattHoursTotal .With (labels ).Set (
300
+ float64 (metrics .SumOfEnergyGenerationAndImportDecawattHoursTotal ))
301
+ sumOfPowerGenerationAndExportWatts .With (labels ).Set (
302
+ float64 (metrics .SumOfPowerGenerationAndExportWatts ))
303
+ sumOfEnergyGenerationAndExportDecawattHoursTotal .With (labels ).Set (
304
+ float64 (metrics .SumOfEnergyGenerationAndExportDecawattHoursTotal ))
285
305
unknownInt5 .With (labels ).Set (float64 (metrics .UnknownInt5 ))
286
306
unknownInt6 .With (labels ).Set (float64 (metrics .UnknownInt6 ))
287
307
unknownInt7 .With (labels ).Set (float64 (metrics .UnknownInt7 ))
0 commit comments