mirror of
https://github.com/valitydev/exporter-wallet-balances.git
synced 2024-11-06 10:15:18 +00:00
fix for update gauge value (#7)
This commit is contained in:
parent
21443fb8f2
commit
f60c8ec652
@ -6,9 +6,17 @@ import io.micrometer.core.instrument.MultiGauge;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Configuration
|
||||
public class GaugeConfig {
|
||||
|
||||
@Bean
|
||||
public Map<String, Double> walletBalancesAggregatesMap() {
|
||||
return new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MultiGauge multiGaugeWalletBalancesAmount(MeterRegistry meterRegistry) {
|
||||
return MultiGauge.builder(Metric.WALLET_BALANCES_AMOUNT.getName())
|
||||
|
@ -16,6 +16,6 @@ public enum Metric {
|
||||
private final String description;
|
||||
|
||||
private static String formatWithPrefix(String name) {
|
||||
return String.format("ewm_%s", name);
|
||||
return String.format("ewb_%s", name);
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,9 @@ public class OpenSearchService {
|
||||
private String intervalTime;
|
||||
|
||||
@SneakyThrows
|
||||
public List<WalletBalanceData> getWalletBalanceDataByInterval() {
|
||||
public List<WalletBalanceData> getWalletsBalancesDataByInterval() {
|
||||
return openSearchClient.search(s -> s
|
||||
.size(10000)
|
||||
.index(openSearchProperties.getIndex())
|
||||
.sort(builder -> builder
|
||||
.field(builder1 -> builder1
|
||||
|
@ -9,6 +9,8 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@ -17,20 +19,26 @@ public class WalletBalancesService {
|
||||
|
||||
private final OpenSearchService openSearchService;
|
||||
private final MeterRegistryService meterRegistryService;
|
||||
private final Map<String, Double> walletBalancesAggregatesMap;
|
||||
|
||||
public void registerMetrics() {
|
||||
var walletBalanceData = openSearchService.getWalletBalanceDataByInterval();
|
||||
walletBalanceData
|
||||
.forEach(dto -> {
|
||||
final var amount = Double.parseDouble(dto.getWallet().getBalance().getAmount());
|
||||
var gauge = Gauge.builder(Metric.WALLET_BALANCES_AMOUNT.getName(), this, o -> amount)
|
||||
var walletsBalancesDataByInterval = openSearchService.getWalletsBalancesDataByInterval();
|
||||
for (WalletBalanceData walletBalanceData : walletsBalancesDataByInterval) {
|
||||
var id = walletBalanceData.getWallet().getId();
|
||||
if (!walletBalancesAggregatesMap.containsKey(id)) {
|
||||
var gauge = Gauge.builder(
|
||||
Metric.WALLET_BALANCES_AMOUNT.getName(),
|
||||
walletBalancesAggregatesMap,
|
||||
map -> map.get(id))
|
||||
.description(Metric.WALLET_BALANCES_AMOUNT.getDescription())
|
||||
.tags(getTags(dto));
|
||||
.tags(getTags(walletBalanceData));
|
||||
meterRegistryService.registry(gauge);
|
||||
});
|
||||
}
|
||||
walletBalancesAggregatesMap.put(id, Double.parseDouble(walletBalanceData.getWallet().getBalance().getAmount()));
|
||||
}
|
||||
var registeredMetricsSize = meterRegistryService.getRegisteredMetricsSize(Metric.WALLET_BALANCES_AMOUNT.getName());
|
||||
log.info("Payments with final statuses metrics have been registered to 'prometheus', " +
|
||||
"registeredMetricsSize = {}, clientSize = {}", registeredMetricsSize, walletBalanceData.size());
|
||||
"registeredMetricsSize = {}, clientSize = {}", registeredMetricsSize, walletsBalancesDataByInterval.size());
|
||||
}
|
||||
|
||||
private Tags getTags(WalletBalanceData dto) {
|
||||
|
Loading…
Reference in New Issue
Block a user