-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxci.lua
239 lines (229 loc) · 4.95 KB
/
xci.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
require('strict').on()
local metrics = require('metrics')
local http_router = require('http.router').new()
local http_handler = require('metrics.plugins.prometheus').collect_http
local http_server = require('http.server').new('0.0.0.0', 8088)
local function xci_metric_callback(self)
-- xtender
self.gauge.xt_ubat_min:set(
xp.unpack_le_float(
xp():read_user_info(101, 3090)
))
self.gauge.xt_uin:set(
xp.unpack_le_float(
xp():read_user_info(101, 3113)
))
self.gauge.xt_iin:set(
xp.unpack_le_float(
xp():read_user_info(101, 3116)
))
self.gauge.xt_pout:set(
xp.unpack_le_float(
xp():read_user_info(101, 3098)
))
self.gauge.xt_pout_plus:set(
xp.unpack_le_float(
xp():read_user_info(101, 3097)
))
self.gauge.xt_fout:set(
xp.unpack_le_float(
xp():read_user_info(101, 3110)
))
self.gauge.xt_fin:set(
xp.unpack_le_float(
xp():read_user_info(101, 3122)
))
self.gauge.xt_phase:set(
xp.unpack_le16(
xp():read_user_info(101, 3010)
))
self.gauge.xt_state:set(
xp.unpack_le16(
xp():read_user_info(101, 3049)
))
self.gauge.xt_mode:set(
xp.unpack_le16(
xp():read_user_info(101, 3028)
))
self.gauge.xt_transfert:set(
xp.unpack_le16(
xp():read_user_info(101, 3020)
))
self.gauge.xt_rel_out:set(
xp.unpack_le16(
xp():read_user_info(101, 3030)
))
self.gauge.xt_rel_gnd:set(
xp.unpack_le16(
xp():read_user_info(101, 3074)
))
self.gauge.xt_rel_neutral:set(
xp.unpack_le16(
xp():read_user_info(101, 3075)
))
self.gauge.xt_rme:set(
xp.unpack_le16(
xp():read_user_info(101, 3086)
))
self.gauge.xt_aux1:set(
xp.unpack_le16(
xp():read_user_info(101, 3031)
))
self.gauge.xt_aux1_mode:set(
xp.unpack_le16(
xp():read_user_info(101, 3054)
))
self.gauge.xt_aux2:set(
xp.unpack_le16(
xp():read_user_info(101, 3032)
))
self.gauge.xt_aux2_mode:set(
xp.unpack_le16(
xp():read_user_info(101, 3055)
))
self.gauge.xt_ubat:set(
xp.unpack_le_float(
xp():read_user_info(101, 3092)
))
self.gauge.xt_ibat:set(
xp.unpack_le_float(
xp():read_user_info(101, 3095)
))
self.gauge.xt_pin_a:set(
xp.unpack_le_float(
xp():read_user_info(101, 3119)
))
self.gauge.xt_pout_a:set(
xp.unpack_le_float(
xp():read_user_info(101, 3101)
))
self.gauge.xt_dev1_plus:set(
xp.unpack_le_float(
xp():read_user_info(101, 3103)
))
-- variotrack
self.gauge.vt_psom:set(
xp.unpack_le_float(
xp():read_user_info(301, 11043)
))
self.gauge.vt_state:set(
xp.unpack_le16(
xp():read_user_info(301, 11069)
))
self.gauge.vt_mode:set(
xp.unpack_le16(
xp():read_user_info(301, 11016)
))
self.gauge.vt_dev1:set(
xp.unpack_le_float(
xp():read_user_info(301, 11045)
))
self.gauge.vt_upvm:set(
xp.unpack_le_float(
xp():read_user_info(301, 11041)
))
self.gauge.vt_ibam:set(
xp.unpack_le_float(
xp():read_user_info(301, 11040)
))
self.gauge.vt_ubam:set(
xp.unpack_le_float(
xp():read_user_info(301, 11039)
))
self.gauge.vt_phas:set(
xp.unpack_le16(
xp():read_user_info(301, 11038)
))
self.gauge.vt_rme:set(
xp.unpack_le16(
xp():read_user_info(301, 11082)
))
self.gauge.vt_aux1:set(
xp.unpack_le16(
xp():read_user_info(301, 11061)
))
self.gauge.vt_aux1_mode:set(
xp.unpack_le16(
xp():read_user_info(101, 11063)
))
self.gauge.vt_aux2:set(
xp.unpack_le16(
xp():read_user_info(301, 11062)
))
self.gauge.vt_aux2_mode:set(
xp.unpack_le16(
xp():read_user_info(101, 11064)
))
self.gauge.vt_aux3:set(
xp.unpack_le16(
xp():read_user_info(301, 11077)
))
self.gauge.vt_aux3_mode:set(
xp.unpack_le16(
xp():read_user_info(101, 11064)
))
self.gauge.vt_aux4:set(
xp.unpack_le16(
xp():read_user_info(301, 11078)
))
self.gauge.vt_aux4_mode:set(
xp.unpack_le16(
xp():read_user_info(101, 11080)
))
-- bsp
self.gauge.bsp_ubat:set(
xp.unpack_le_float(
xp():read_user_info(601, 7030)
))
self.gauge.bsp_ibat:set(
xp.unpack_le_float(
xp():read_user_info(601, 7031)
))
self.gauge.bsp_soc:set(
xp.unpack_le_float(
xp():read_user_info(601, 7032)
))
self.gauge.bsp_tbat:set(
xp.unpack_le_float(
xp():read_user_info(601, 7033)
))
end
local xci_metric = {
counter = setmetatable({}, {
__index = function(self, k)
local cc = rawget(self, k)
if cc == nil then
cc = metrics.counter('xci_' .. k)
self.k = cc
end
return cc
end}),
gauge = setmetatable({}, {
__index = function(self, k)
local gg = rawget(self, k)
if gg == nil then
gg = metrics.gauge('xci_' .. k)
self.k = gg
end
return gg
end}),
histogram = setmetatable({}, {
__index = function(self, k)
local hh = rawget(self, k)
if hh == nil then
hh = metrics.histogram('xci_' .. k)
self.k = hh
end
return hh
end}),
}
return {
start = function()
metrics.register_callback(
setmetatable(xci_metric, {__call = xci_metric_callback})
)
http_server:set_router(http_router)
http_router:route({path = '/metrics'}, function(...) return http_handler(...) end)
http_server:start()
end
}