| 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 |
/**
|
| 37472 |
amit |
11 |
* Publishes the two prepaid balance signals -- SMS credits and the ThinkWalnut
|
|
|
12 |
* recharge wallet -- on /actuator/prometheus, which alloy scrapes off
|
|
|
13 |
* 127.0.0.1:8081 on this host.
|
| 37395 |
amit |
14 |
*
|
| 37472 |
amit |
15 |
* Values are pushed in by {@link BalanceMonitorTasks}; -1 means "not read yet"
|
| 37395 |
amit |
16 |
* so a scrape before the first run is distinguishable from a genuine zero
|
|
|
17 |
* balance.
|
|
|
18 |
*/
|
|
|
19 |
@Component
|
|
|
20 |
public class BalanceGauges {
|
|
|
21 |
|
|
|
22 |
private static final int NOT_READ_YET = -1;
|
|
|
23 |
|
|
|
24 |
private final AtomicInteger smsBalance = new AtomicInteger(NOT_READ_YET);
|
|
|
25 |
private final AtomicReference<Double> rechargeWalletBalance =
|
|
|
26 |
new AtomicReference<>((double) NOT_READ_YET);
|
|
|
27 |
|
|
|
28 |
public BalanceGauges(MeterRegistry meterRegistry) {
|
|
|
29 |
Gauge.builder("sms_balance_remaining", smsBalance, AtomicInteger::get)
|
|
|
30 |
.description("SMS credits remaining with the messaging gateway; -1 = not read yet")
|
|
|
31 |
.register(meterRegistry);
|
|
|
32 |
|
|
|
33 |
Gauge.builder("recharge_wallet_balance_rupees", rechargeWalletBalance, AtomicReference::get)
|
|
|
34 |
.description("ThinkWalnut recharge wallet balance in rupees; -1 = not read yet")
|
|
|
35 |
.register(meterRegistry);
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
public void setSmsBalance(int count) {
|
|
|
39 |
smsBalance.set(count);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
public void setRechargeWalletBalance(double rupees) {
|
|
|
43 |
rechargeWalletBalance.set(rupees);
|
|
|
44 |
}
|
|
|
45 |
}
|