log metrics for legacy controller

This commit is contained in:
Carsten Otto
2021-11-13 14:08:41 +01:00
parent a696e0bbd8
commit 887952d01e
12 changed files with 130 additions and 120 deletions

View File

@@ -1,5 +1,7 @@
package de.cotto.lndmanagej.controller;
import com.codahale.metrics.MetricRegistry;
import de.cotto.lndmanagej.metrics.Metrics;
import de.cotto.lndmanagej.model.Channel;
import de.cotto.lndmanagej.model.ChannelId;
import de.cotto.lndmanagej.model.LocalChannel;
@@ -27,28 +29,33 @@ public class LegacyController {
private final OwnNodeService ownNodeService;
private final FeeService feeService;
private final BalanceService balanceService;
private final Metrics metrics;
public LegacyController(
NodeService nodeService,
ChannelService channelService,
OwnNodeService ownNodeService,
FeeService feeService,
BalanceService balanceService
BalanceService balanceService,
Metrics metrics
) {
this.nodeService = nodeService;
this.channelService = channelService;
this.ownNodeService = ownNodeService;
this.feeService = feeService;
this.balanceService = balanceService;
this.metrics = metrics;
}
@GetMapping("/node/{pubkey}/alias")
public String getAlias(@PathVariable Pubkey pubkey) {
mark("getAlias");
return nodeService.getAlias(pubkey);
}
@GetMapping("/node/{pubkey}/open-channels")
public String getOpenChannelIds(@PathVariable Pubkey pubkey) {
public String getOpenChannelIdsForPubkey(@PathVariable Pubkey pubkey) {
mark("getOpenChannelIdsForPubkey");
return channelService.getOpenChannelsWith(pubkey).stream()
.map(Channel::getId)
.sorted()
@@ -58,6 +65,7 @@ public class LegacyController {
@GetMapping("/open-channels")
public String getOpenChannelIds() {
mark("getOpenChannelIds");
return getOpenChannelIdsSorted()
.map(ChannelId::toString)
.collect(Collectors.joining(NEWLINE));
@@ -65,6 +73,7 @@ public class LegacyController {
@GetMapping("/open-channels/compact")
public String getOpenChannelIdsCompact() {
mark("getOpenChannelIdsCompact");
return getOpenChannelIdsSorted()
.map(ChannelId::getCompactForm)
.collect(Collectors.joining(NEWLINE));
@@ -72,6 +81,7 @@ public class LegacyController {
@GetMapping("/open-channels/pretty")
public String getOpenChannelIdsPretty() {
mark("getOpenChannelIdsPretty");
return channelService.getOpenChannels().stream()
.sorted(Comparator.comparing(LocalChannel::getId))
.map(localChannel -> {
@@ -86,6 +96,7 @@ public class LegacyController {
@GetMapping("/peer-pubkeys")
public String getPeerPubkeys() {
mark("getPeerPubkeys");
return channelService.getOpenChannels().stream()
.map(LocalChannel::getRemotePubkey)
.map(Pubkey::toString)
@@ -96,36 +107,43 @@ public class LegacyController {
@GetMapping("/synced-to-chain")
public boolean syncedToChain() {
mark("syncedToChain");
return ownNodeService.isSyncedToChain();
}
@GetMapping("/channel/{channelId}/incoming-fee-rate")
public long getIncomingFeeRate(@PathVariable ChannelId channelId) {
mark("getIncomingFeeRate");
return feeService.getIncomingFeeRate(channelId);
}
@GetMapping("/channel/{channelId}/outgoing-fee-rate")
public long getOutgoingFeeRate(@PathVariable ChannelId channelId) {
mark("getOutgoingFeeRate");
return feeService.getOutgoingFeeRate(channelId);
}
@GetMapping("/channel/{channelId}/incoming-base-fee")
public long getIncomingBaseFee(@PathVariable ChannelId channelId) {
mark("getIncomingBaseFee");
return feeService.getIncomingBaseFee(channelId).milliSatoshis();
}
@GetMapping("/channel/{channelId}/outgoing-base-fee")
public long getOutgoingBaseFee(@PathVariable ChannelId channelId) {
mark("getOutgoingBaseFee");
return feeService.getOutgoingBaseFee(channelId).milliSatoshis();
}
@GetMapping("/channel/{channelId}/available-local-balance")
public long getAvailableLocalBalance(@PathVariable ChannelId channelId) {
mark("getAvailableLocalBalance");
return balanceService.getAvailableLocalBalance(channelId).satoshis();
}
@GetMapping("/channel/{channelId}/available-remote-balance")
public long getAvailableRemoteBalance(@PathVariable ChannelId channelId) {
mark("getAvailableRemoteBalance");
return balanceService.getAvailableRemoteBalance(channelId).satoshis();
}
@@ -134,4 +152,8 @@ public class LegacyController {
.map(Channel::getId)
.sorted();
}
private void mark(String name) {
metrics.mark(MetricRegistry.name(getClass(), name));
}
}