@@ -20,6 +20,7 @@ import (
20
20
"time"
21
21
22
22
"github.com/ghodss/yaml"
23
+ "github.com/nats-io/jsm.go"
23
24
"github.com/nats-io/jsm.go/api"
24
25
"github.com/nats-io/jsm.go/monitor"
25
26
"github.com/nats-io/jsm.go/natscontext"
@@ -77,7 +78,7 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
77
78
78
79
// Collect implements prometheus.Collector
79
80
func (e * Exporter ) Collect (ch chan <- prometheus.Metric ) {
80
- callCheck := func (check * Check , f func (servers string , natsOpts []nats.Option , check * Check , result * monitor.Result )) {
81
+ callCheck := func (check * Check , f func (servers string , natsOpts []nats.Option , jsmOpts []jsm. Option , check * Check , result * monitor.Result )) {
81
82
result := & monitor.Result {Name : check .Name , Check : check .Kind , NameSpace : e .ns , RenderFormat : monitor .NagiosFormat }
82
83
defer result .Collect (ch )
83
84
@@ -91,12 +92,17 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
91
92
return
92
93
}
93
94
94
- f (nctx .ServerURL (), opts , check , result )
95
+ jsmopts , err := nctx .JSMOptions ()
96
+ if result .CriticalIfErr (err , "could not load jetstream options: %v" , err ) {
97
+ return
98
+ }
99
+
100
+ f (nctx .ServerURL (), opts , jsmopts , check , result )
95
101
log .Print (result )
96
102
}
97
103
98
104
for _ , check := range e .config .Checks {
99
- var f func (servers string , natsOpts []nats.Option , check * Check , result * monitor.Result )
105
+ var f func (servers string , natsOpts []nats.Option , jsmOpts []jsm. Option , check * Check , result * monitor.Result )
100
106
101
107
switch check .Kind {
102
108
case "connection" :
@@ -141,7 +147,7 @@ func (e *Exporter) natsContext(check *Check) (*natscontext.Context, error) {
141
147
return natscontext .New (ctxName , true )
142
148
}
143
149
144
- func (e * Exporter ) checkRequest (servers string , natsOpts []nats.Option , check * Check , result * monitor.Result ) {
150
+ func (e * Exporter ) checkRequest (servers string , natsOpts []nats.Option , jsmOpts []jsm. Option , check * Check , result * monitor.Result ) {
145
151
copts := monitor.CheckRequestOptions {}
146
152
err := yaml .Unmarshal (check .Properties , & copts )
147
153
if result .CriticalIfErr (err , "invalid properties: %v" , err ) {
@@ -152,7 +158,7 @@ func (e *Exporter) checkRequest(servers string, natsOpts []nats.Option, check *C
152
158
result .CriticalIfErr (err , "check failed: %v" , err )
153
159
}
154
160
155
- func (e * Exporter ) checkCredential (servers string , natsOpts []nats.Option , check * Check , result * monitor.Result ) {
161
+ func (e * Exporter ) checkCredential (servers string , natsOpts []nats.Option , jsmOpts []jsm. Option , check * Check , result * monitor.Result ) {
156
162
copts := monitor.CheckCredentialOptions {}
157
163
err := yaml .Unmarshal (check .Properties , & copts )
158
164
if result .CriticalIfErr (err , "invalid properties: %v" , err ) {
@@ -163,7 +169,7 @@ func (e *Exporter) checkCredential(servers string, natsOpts []nats.Option, check
163
169
result .CriticalIfErr (err , "check failed: %v" , err )
164
170
}
165
171
166
- func (e * Exporter ) checkServer (servers string , natsOpts []nats.Option , check * Check , result * monitor.Result ) {
172
+ func (e * Exporter ) checkServer (servers string , natsOpts []nats.Option , jsmOpts []jsm. Option , check * Check , result * monitor.Result ) {
167
173
copts := monitor.CheckServerOptions {}
168
174
err := yaml .Unmarshal (check .Properties , & copts )
169
175
if result .CriticalIfErr (err , "invalid properties: %v" , err ) {
@@ -174,7 +180,7 @@ func (e *Exporter) checkServer(servers string, natsOpts []nats.Option, check *Ch
174
180
result .CriticalIfErr (err , "check failed: %v" , err )
175
181
}
176
182
177
- func (e * Exporter ) checkJetStream (servers string , natsOpts []nats.Option , check * Check , result * monitor.Result ) {
183
+ func (e * Exporter ) checkJetStream (servers string , natsOpts []nats.Option , jsmOpts []jsm. Option , check * Check , result * monitor.Result ) {
178
184
copts := monitor.CheckJetStreamAccountOptions {
179
185
MemoryCritical : - 1 ,
180
186
MemoryWarning : - 1 ,
@@ -190,11 +196,11 @@ func (e *Exporter) checkJetStream(servers string, natsOpts []nats.Option, check
190
196
return
191
197
}
192
198
193
- err = monitor .CheckJetStreamAccount (servers , natsOpts , result , copts )
199
+ err = monitor .CheckJetStreamAccount (servers , natsOpts , jsmOpts , result , copts )
194
200
result .CriticalIfErr (err , "check failed: %v" , err )
195
201
}
196
202
197
- func (e * Exporter ) checkMeta (servers string , natsOpts []nats.Option , check * Check , result * monitor.Result ) {
203
+ func (e * Exporter ) checkMeta (servers string , natsOpts []nats.Option , jsmOpts []jsm. Option , check * Check , result * monitor.Result ) {
198
204
copts := monitor.CheckJetstreamMetaOptions {}
199
205
err := yaml .Unmarshal (check .Properties , & copts )
200
206
if result .CriticalIfErr (err , "invalid properties: %v" , err ) {
@@ -205,18 +211,18 @@ func (e *Exporter) checkMeta(servers string, natsOpts []nats.Option, check *Chec
205
211
result .CriticalIfErr (err , "check failed: %v" , err )
206
212
}
207
213
208
- func (e * Exporter ) checkMessage (servers string , natsOpts []nats.Option , check * Check , result * monitor.Result ) {
214
+ func (e * Exporter ) checkMessage (servers string , natsOpts []nats.Option , jsmOpts []jsm. Option , check * Check , result * monitor.Result ) {
209
215
copts := monitor.CheckStreamMessageOptions {}
210
216
err := yaml .Unmarshal (check .Properties , & copts )
211
217
if result .CriticalIfErr (err , "invalid properties: %v" , err ) {
212
218
return
213
219
}
214
220
215
- err = monitor .CheckStreamMessage (servers , natsOpts , result , copts )
221
+ err = monitor .CheckStreamMessage (servers , natsOpts , jsmOpts , result , copts )
216
222
result .CriticalIfErr (err , "check failed: %v" , err )
217
223
}
218
224
219
- func (e * Exporter ) checkKv (servers string , natsOpts []nats.Option , check * Check , result * monitor.Result ) {
225
+ func (e * Exporter ) checkKv (servers string , natsOpts []nats.Option , jsmOpts []jsm. Option , check * Check , result * monitor.Result ) {
220
226
copts := monitor.CheckKVBucketAndKeyOptions {
221
227
ValuesWarning : - 1 ,
222
228
ValuesCritical : - 1 ,
@@ -230,29 +236,29 @@ func (e *Exporter) checkKv(servers string, natsOpts []nats.Option, check *Check,
230
236
result .CriticalIfErr (err , "check failed: %v" , err )
231
237
}
232
238
233
- func (e * Exporter ) checkConsumer (servers string , natsOpts []nats.Option , check * Check , result * monitor.Result ) {
239
+ func (e * Exporter ) checkConsumer (servers string , natsOpts []nats.Option , jsmOpts []jsm. Option , check * Check , result * monitor.Result ) {
234
240
copts := monitor.ConsumerHealthCheckOptions {}
235
241
err := yaml .Unmarshal (check .Properties , & copts )
236
242
if result .CriticalIfErr (err , "invalid properties: %v" , err ) {
237
243
return
238
244
}
239
245
240
- err = monitor .ConsumerHealthCheck (servers , natsOpts , result , copts , api .NewDiscardLogger ())
246
+ err = monitor .ConsumerHealthCheck (servers , natsOpts , jsmOpts , result , copts , api .NewDiscardLogger ())
241
247
result .CriticalIfErr (err , "check failed: %v" , err )
242
248
}
243
249
244
- func (e * Exporter ) checkStream (servers string , natsOpts []nats.Option , check * Check , result * monitor.Result ) {
250
+ func (e * Exporter ) checkStream (servers string , natsOpts []nats.Option , jsmOpts []jsm. Option , check * Check , result * monitor.Result ) {
245
251
copts := monitor.CheckStreamHealthOptions {}
246
252
err := yaml .Unmarshal (check .Properties , & copts )
247
253
if result .CriticalIfErr (err , "invalid properties: %v" , err ) {
248
254
return
249
255
}
250
256
251
- err = monitor .CheckStreamHealth (servers , natsOpts , result , copts , api .NewDiscardLogger ())
257
+ err = monitor .CheckStreamHealth (servers , natsOpts , jsmOpts , result , copts , api .NewDiscardLogger ())
252
258
result .CriticalIfErr (err , "check failed: %v" , err )
253
259
}
254
260
255
- func (e * Exporter ) checkConnection (servers string , natsOpts []nats.Option , check * Check , result * monitor.Result ) {
261
+ func (e * Exporter ) checkConnection (servers string , natsOpts []nats.Option , jsmOpts []jsm. Option , check * Check , result * monitor.Result ) {
256
262
copts := monitor.CheckConnectionOptions {}
257
263
err := yaml .Unmarshal (check .Properties , & copts )
258
264
if result .CriticalIfErr (err , "invalid properties: %v" , err ) {
0 commit comments