mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-22 15:35:10 +01:00
use metrics library for spring integration
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package de.cotto.lndmanagej.controller;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.codahale.metrics.annotation.Timed;
|
||||
import de.cotto.lndmanagej.controller.dto.BalanceInformationDto;
|
||||
import de.cotto.lndmanagej.controller.dto.ChannelDetailsDto;
|
||||
import de.cotto.lndmanagej.controller.dto.ChannelDto;
|
||||
@@ -9,7 +9,6 @@ import de.cotto.lndmanagej.controller.dto.FeeReportDto;
|
||||
import de.cotto.lndmanagej.controller.dto.ObjectMapperConfiguration;
|
||||
import de.cotto.lndmanagej.controller.dto.OnChainCostsDto;
|
||||
import de.cotto.lndmanagej.controller.dto.PoliciesDto;
|
||||
import de.cotto.lndmanagej.metrics.Metrics;
|
||||
import de.cotto.lndmanagej.model.BalanceInformation;
|
||||
import de.cotto.lndmanagej.model.ChannelId;
|
||||
import de.cotto.lndmanagej.model.ClosedChannel;
|
||||
@@ -39,7 +38,6 @@ import javax.annotation.Nullable;
|
||||
public class ChannelController {
|
||||
private final ChannelService channelService;
|
||||
private final NodeService nodeService;
|
||||
private final Metrics metrics;
|
||||
private final BalanceService balanceService;
|
||||
private final OnChainCostService onChainCostService;
|
||||
private final PolicyService policyService;
|
||||
@@ -51,8 +49,7 @@ public class ChannelController {
|
||||
BalanceService balanceService,
|
||||
OnChainCostService onChainCostService,
|
||||
PolicyService policyService,
|
||||
FeeService feeService,
|
||||
Metrics metrics
|
||||
FeeService feeService
|
||||
) {
|
||||
this.channelService = channelService;
|
||||
this.nodeService = nodeService;
|
||||
@@ -60,12 +57,11 @@ public class ChannelController {
|
||||
this.onChainCostService = onChainCostService;
|
||||
this.policyService = policyService;
|
||||
this.feeService = feeService;
|
||||
this.metrics = metrics;
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/")
|
||||
public ChannelDto getBasicInformation(@PathVariable ChannelId channelId) throws NotFoundException {
|
||||
mark("getBasicInformation");
|
||||
LocalChannel localChannel = channelService.getLocalChannel(channelId).orElse(null);
|
||||
if (localChannel == null) {
|
||||
throw new NotFoundException();
|
||||
@@ -74,9 +70,9 @@ public class ChannelController {
|
||||
return new ChannelDto(localChannel, closeDetailsForChannel);
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/details")
|
||||
public ChannelDetailsDto getDetails(@PathVariable ChannelId channelId) throws NotFoundException {
|
||||
mark("getDetails");
|
||||
LocalChannel localChannel = channelService.getLocalChannel(channelId).orElse(null);
|
||||
if (localChannel == null) {
|
||||
throw new NotFoundException();
|
||||
@@ -94,24 +90,24 @@ public class ChannelController {
|
||||
);
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/balance")
|
||||
public BalanceInformationDto getBalance(@PathVariable ChannelId channelId) {
|
||||
mark("getBalance");
|
||||
BalanceInformation balanceInformation = balanceService.getBalanceInformation(channelId)
|
||||
.orElse(BalanceInformation.EMPTY);
|
||||
return BalanceInformationDto.createFrom(balanceInformation);
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/policies")
|
||||
public PoliciesDto getPolicies(@PathVariable ChannelId channelId) {
|
||||
mark("getPolicies");
|
||||
LocalChannel localChannel = channelService.getLocalChannel(channelId).orElse(null);
|
||||
return getPoliciesForChannel(localChannel);
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/close-details")
|
||||
public ClosedChannelDetailsDto getCloseDetails(@PathVariable ChannelId channelId) throws NotFoundException {
|
||||
mark("getCloseDetails");
|
||||
ClosedChannel closedChannel = channelService.getClosedChannel(channelId).orElse(null);
|
||||
if (closedChannel == null) {
|
||||
throw new NotFoundException();
|
||||
@@ -119,9 +115,9 @@ public class ChannelController {
|
||||
return new ClosedChannelDetailsDto(closedChannel.getCloseInitiator(), closedChannel.getCloseHeight());
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/fee-report")
|
||||
public FeeReportDto getFeeReport(@PathVariable ChannelId channelId) {
|
||||
mark("getFeeReport");
|
||||
return getFeeReportDto(channelId);
|
||||
}
|
||||
|
||||
@@ -156,8 +152,4 @@ public class ChannelController {
|
||||
return ClosedChannelDetailsDto.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
private void mark(String name) {
|
||||
metrics.mark(MetricRegistry.name(getClass(), name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package de.cotto.lndmanagej.controller;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import de.cotto.lndmanagej.metrics.Metrics;
|
||||
import com.codahale.metrics.annotation.Timed;
|
||||
import de.cotto.lndmanagej.model.LocalOpenChannel;
|
||||
import de.cotto.lndmanagej.model.Pubkey;
|
||||
import de.cotto.lndmanagej.service.ChannelService;
|
||||
@@ -19,21 +18,18 @@ public class LegacyController {
|
||||
private static final String NEWLINE = "\n";
|
||||
private final NodeService nodeService;
|
||||
private final ChannelService channelService;
|
||||
private final Metrics metrics;
|
||||
|
||||
public LegacyController(
|
||||
NodeService nodeService,
|
||||
ChannelService channelService,
|
||||
Metrics metrics
|
||||
ChannelService channelService
|
||||
) {
|
||||
this.nodeService = nodeService;
|
||||
this.channelService = channelService;
|
||||
this.metrics = metrics;
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/open-channels/pretty")
|
||||
public String getOpenChannelIdsPretty() {
|
||||
metrics.mark(MetricRegistry.name(getClass(), "getOpenChannelIdsPretty"));
|
||||
return channelService.getOpenChannels().stream()
|
||||
.sorted(Comparator.comparing(LocalOpenChannel::getId))
|
||||
.map(localOpenChannel -> {
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package de.cotto.lndmanagej.controller;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.codahale.metrics.annotation.Timed;
|
||||
import de.cotto.lndmanagej.controller.dto.BalanceInformationDto;
|
||||
import de.cotto.lndmanagej.controller.dto.ChannelsForNodeDto;
|
||||
import de.cotto.lndmanagej.controller.dto.FeeReportDto;
|
||||
import de.cotto.lndmanagej.controller.dto.NodeDetailsDto;
|
||||
import de.cotto.lndmanagej.controller.dto.ObjectMapperConfiguration;
|
||||
import de.cotto.lndmanagej.controller.dto.OnChainCostsDto;
|
||||
import de.cotto.lndmanagej.metrics.Metrics;
|
||||
import de.cotto.lndmanagej.model.BalanceInformation;
|
||||
import de.cotto.lndmanagej.model.Channel;
|
||||
import de.cotto.lndmanagej.model.ChannelId;
|
||||
@@ -34,7 +33,6 @@ import java.util.stream.Collectors;
|
||||
@Import(ObjectMapperConfiguration.class)
|
||||
public class NodeController {
|
||||
private final NodeService nodeService;
|
||||
private final Metrics metrics;
|
||||
private final ChannelService channelService;
|
||||
private final OnChainCostService onChainCostService;
|
||||
private final BalanceService balanceService;
|
||||
@@ -45,26 +43,24 @@ public class NodeController {
|
||||
ChannelService channelService,
|
||||
OnChainCostService onChainCostService,
|
||||
BalanceService balanceService,
|
||||
FeeService feeService,
|
||||
Metrics metrics
|
||||
FeeService feeService
|
||||
) {
|
||||
this.nodeService = nodeService;
|
||||
this.channelService = channelService;
|
||||
this.onChainCostService = onChainCostService;
|
||||
this.balanceService = balanceService;
|
||||
this.feeService = feeService;
|
||||
this.metrics = metrics;
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/alias")
|
||||
public String getAlias(@PathVariable Pubkey pubkey) {
|
||||
mark("getAlias");
|
||||
return nodeService.getAlias(pubkey);
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/details")
|
||||
public NodeDetailsDto getDetails(@PathVariable Pubkey pubkey) {
|
||||
mark("getDetails");
|
||||
Node node = nodeService.getNode(pubkey);
|
||||
Coins openCosts = onChainCostService.getOpenCostsWith(pubkey);
|
||||
Coins closeCosts = onChainCostService.getCloseCostsWith(pubkey);
|
||||
@@ -83,29 +79,29 @@ public class NodeController {
|
||||
);
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/open-channels")
|
||||
public ChannelsForNodeDto getOpenChannelIdsForPubkey(@PathVariable Pubkey pubkey) {
|
||||
mark("getOpenChannelIdsForPubkey");
|
||||
List<ChannelId> channels = toSortedList(channelService.getOpenChannelsWith(pubkey));
|
||||
return new ChannelsForNodeDto(pubkey, channels);
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/all-channels")
|
||||
public ChannelsForNodeDto getAllChannelIdsForPubkey(@PathVariable Pubkey pubkey) {
|
||||
mark("getAllChannelIdsForPubkey");
|
||||
List<ChannelId> channels = toSortedList(channelService.getAllChannelsWith(pubkey));
|
||||
return new ChannelsForNodeDto(pubkey, channels);
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/balance")
|
||||
public BalanceInformationDto getBalance(@PathVariable Pubkey pubkey) {
|
||||
mark("getBalance");
|
||||
return BalanceInformationDto.createFrom(balanceService.getBalanceInformation(pubkey));
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/fee-report")
|
||||
public FeeReportDto getFeeReport(@PathVariable Pubkey pubkey) {
|
||||
mark("getFeeReport");
|
||||
return getFeeReportDto(pubkey);
|
||||
}
|
||||
|
||||
@@ -119,9 +115,4 @@ public class NodeController {
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void mark(String getDetails) {
|
||||
metrics.mark(MetricRegistry.name(getClass(), getDetails));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package de.cotto.lndmanagej.controller;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.codahale.metrics.annotation.Timed;
|
||||
import de.cotto.lndmanagej.controller.dto.OnChainCostsDto;
|
||||
import de.cotto.lndmanagej.metrics.Metrics;
|
||||
import de.cotto.lndmanagej.model.ChannelId;
|
||||
import de.cotto.lndmanagej.model.Coins;
|
||||
import de.cotto.lndmanagej.model.Pubkey;
|
||||
@@ -16,32 +15,30 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RequestMapping("/api/")
|
||||
public class OnChainCostsController {
|
||||
private final OnChainCostService onChainCostService;
|
||||
private final Metrics metrics;
|
||||
|
||||
public OnChainCostsController(OnChainCostService onChainCostService, Metrics metrics) {
|
||||
public OnChainCostsController(OnChainCostService onChainCostService) {
|
||||
this.onChainCostService = onChainCostService;
|
||||
this.metrics = metrics;
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/node/{pubkey}/on-chain-costs")
|
||||
public OnChainCostsDto getCostsForPeer(@PathVariable Pubkey pubkey) {
|
||||
metrics.mark(MetricRegistry.name(getClass(), "getCostsForPeer"));
|
||||
return new OnChainCostsDto(
|
||||
onChainCostService.getOpenCostsWith(pubkey),
|
||||
onChainCostService.getCloseCostsWith(pubkey)
|
||||
);
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/channel/{channelId}/open-costs")
|
||||
public long getOpenCostsForChannel(@PathVariable ChannelId channelId) throws CostException {
|
||||
metrics.mark(MetricRegistry.name(getClass(), "getOpenCostsForChannel"));
|
||||
return onChainCostService.getOpenCosts(channelId).map(Coins::satoshis)
|
||||
.orElseThrow(() -> new CostException("Unable to get open costs for channel with ID " + channelId));
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/channel/{channelId}/close-costs")
|
||||
public long getCloseCostsForChannel(@PathVariable ChannelId channelId) throws CostException {
|
||||
metrics.mark(MetricRegistry.name(getClass(), "getCloseCostsForChannel"));
|
||||
return onChainCostService.getCloseCosts(channelId).map(Coins::satoshis)
|
||||
.orElseThrow(() -> new CostException("Unable to get close costs for channel with ID " + channelId));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package de.cotto.lndmanagej.controller;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.codahale.metrics.annotation.Timed;
|
||||
import de.cotto.lndmanagej.controller.dto.ChannelsDto;
|
||||
import de.cotto.lndmanagej.controller.dto.ObjectMapperConfiguration;
|
||||
import de.cotto.lndmanagej.controller.dto.PubkeysDto;
|
||||
import de.cotto.lndmanagej.metrics.Metrics;
|
||||
import de.cotto.lndmanagej.model.ChannelId;
|
||||
import de.cotto.lndmanagej.model.LocalChannel;
|
||||
import de.cotto.lndmanagej.model.LocalOpenChannel;
|
||||
@@ -25,29 +24,27 @@ import java.util.stream.Collectors;
|
||||
public class StatusController {
|
||||
private final OwnNodeService ownNodeService;
|
||||
private final ChannelService channelService;
|
||||
private final Metrics metrics;
|
||||
|
||||
public StatusController(OwnNodeService ownNodeService, ChannelService channelService, Metrics metrics) {
|
||||
public StatusController(OwnNodeService ownNodeService, ChannelService channelService) {
|
||||
this.ownNodeService = ownNodeService;
|
||||
this.channelService = channelService;
|
||||
this.metrics = metrics;
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/synced-to-chain")
|
||||
public boolean isSyncedToChain() {
|
||||
mark("isSyncedToChain");
|
||||
return ownNodeService.isSyncedToChain();
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/block-height")
|
||||
public int getBlockHeight() {
|
||||
mark("getBlockHeight");
|
||||
return ownNodeService.getBlockHeight();
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/open-channels/")
|
||||
public ChannelsDto getOpenChannels() {
|
||||
mark("getOpenChannels");
|
||||
List<ChannelId> channelIds = channelService.getOpenChannels().stream()
|
||||
.map(LocalOpenChannel::getId)
|
||||
.sorted()
|
||||
@@ -56,9 +53,9 @@ public class StatusController {
|
||||
return new ChannelsDto(channelIds);
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/open-channels/pubkeys")
|
||||
public PubkeysDto getPubkeysForOpenChannels() {
|
||||
mark("getPubkeysForOpenChannels");
|
||||
List<Pubkey> pubkeys = channelService.getOpenChannels().stream()
|
||||
.map(LocalOpenChannel::getRemotePubkey)
|
||||
.sorted()
|
||||
@@ -67,9 +64,9 @@ public class StatusController {
|
||||
return new PubkeysDto(pubkeys);
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/all-channels/")
|
||||
public ChannelsDto getAllChannels() {
|
||||
mark("getAllChannels");
|
||||
List<ChannelId> channelIds = channelService.getAllLocalChannels()
|
||||
.map(LocalChannel::getId)
|
||||
.sorted()
|
||||
@@ -78,9 +75,9 @@ public class StatusController {
|
||||
return new ChannelsDto(channelIds);
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/all-channels/pubkeys")
|
||||
public PubkeysDto getPubkeysForAllChannels() {
|
||||
mark("getPubkeysForAllChannels");
|
||||
List<Pubkey> pubkeys = channelService.getAllLocalChannels()
|
||||
.map(LocalChannel::getRemotePubkey)
|
||||
.sorted()
|
||||
@@ -89,7 +86,4 @@ public class StatusController {
|
||||
return new PubkeysDto(pubkeys);
|
||||
}
|
||||
|
||||
private void mark(String name) {
|
||||
metrics.mark(MetricRegistry.name(getClass(), name));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user