| 37395 |
amit |
1 |
package com.smartdukaan.cron.monitored;
|
|
|
2 |
|
|
|
3 |
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
4 |
import java.util.concurrent.atomic.AtomicReference;
|
|
|
5 |
|
|
|
6 |
import io.micrometer.core.instrument.Gauge;
|
|
|
7 |
import io.micrometer.core.instrument.MeterRegistry;
|
|
|
8 |
import org.springframework.stereotype.Component;
|
|
|
9 |
|
|
|
10 |
/**
|
|
|
11 |
* Publishes the two balance signals that used to be written to
|
|
|
12 |
* /var/log/services/nagios-Monitoring.properties for an NRPE check.
|
|
|
13 |
*
|
|
|
14 |
* The Nagios transport is gone — there is no Nagios server, and the NRPE
|
|
|
15 |
* daemons have been removed from every host — but the signals themselves are
|
|
|
16 |
* worth watching, so they are exposed on /actuator/prometheus instead.
|
|
|
17 |
*
|
|
|
18 |
* Values are pushed in by {@link NagiosMonitorTasks}; -1 means "not read yet"
|
|
|
19 |
* so a scrape before the first run is distinguishable from a genuine zero
|
|
|
20 |
* balance.
|
|
|
21 |
*/
|
|
|
22 |
@Component
|
|
|
23 |
public class BalanceGauges {
|
|
|
24 |
|
|
|
25 |
private static final int NOT_READ_YET = -1;
|
|
|
26 |
|
|
|
27 |
private final AtomicInteger smsBalance = new AtomicInteger(NOT_READ_YET);
|
|
|
28 |
private final AtomicReference<Double> rechargeWalletBalance =
|
|
|
29 |
new AtomicReference<>((double) NOT_READ_YET);
|
|
|
30 |
|
|
|
31 |
public BalanceGauges(MeterRegistry meterRegistry) {
|
|
|
32 |
Gauge.builder("sms_balance_remaining", smsBalance, AtomicInteger::get)
|
|
|
33 |
.description("SMS credits remaining with the messaging gateway; -1 = not read yet")
|
|
|
34 |
.register(meterRegistry);
|
|
|
35 |
|
|
|
36 |
Gauge.builder("recharge_wallet_balance_rupees", rechargeWalletBalance, AtomicReference::get)
|
|
|
37 |
.description("ThinkWalnut recharge wallet balance in rupees; -1 = not read yet")
|
|
|
38 |
.register(meterRegistry);
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
public void setSmsBalance(int count) {
|
|
|
42 |
smsBalance.set(count);
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
public void setRechargeWalletBalance(double rupees) {
|
|
|
46 |
rechargeWalletBalance.set(rupees);
|
|
|
47 |
}
|
|
|
48 |
}
|