Improve VPS health response DTO and metrics
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.litoralregas.vpnprovisioner.vps;
|
package com.litoralregas.vpnprovisioner.vps;
|
||||||
|
|
||||||
|
import com.litoralregas.vpnprovisioner.vps.dto.VpsHealthResponse;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@@ -14,8 +15,8 @@ public class VpsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "/health", produces = MediaType.APPLICATION_JSON_VALUE)
|
@GetMapping(value = "/health", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
public String health() {
|
public VpsHealthResponse health() {
|
||||||
return wireGuardVpsService.getVpsHealthJson();
|
return wireGuardVpsService.getVpsHealth();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(
|
@PostMapping(
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package com.litoralregas.vpnprovisioner.vps;
|
package com.litoralregas.vpnprovisioner.vps;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.litoralregas.vpnprovisioner.vps.dto.VpsHealthResponse;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -14,9 +17,11 @@ public class WireGuardVpsService {
|
|||||||
Pattern.compile("\\b198\\.19\\.\\d{1,3}\\.\\d{1,3}\\b");
|
Pattern.compile("\\b198\\.19\\.\\d{1,3}\\.\\d{1,3}\\b");
|
||||||
|
|
||||||
private final SshService sshService;
|
private final SshService sshService;
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
public WireGuardVpsService(SshService sshService) {
|
public WireGuardVpsService(SshService sshService, ObjectMapper objectMapper) {
|
||||||
this.sshService = sshService;
|
this.sshService = sshService;
|
||||||
|
this.objectMapper = objectMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> findUsedVpnIps() {
|
public Set<String> findUsedVpnIps() {
|
||||||
@@ -66,7 +71,7 @@ public class WireGuardVpsService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVpsHealthJson() {
|
public VpsHealthResponse getVpsHealth() {
|
||||||
SshCommandResult result = sshService.executeOnConfiguredVps(
|
SshCommandResult result = sshService.executeOnConfiguredVps(
|
||||||
"sudo /usr/local/sbin/lr-vps-health"
|
"sudo /usr/local/sbin/lr-vps-health"
|
||||||
);
|
);
|
||||||
@@ -77,7 +82,14 @@ public class WireGuardVpsService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.stdout();
|
try {
|
||||||
|
return objectMapper.readValue(result.stdout(), VpsHealthResponse.class);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Invalid VPS health JSON returned by script",
|
||||||
|
e
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String restoreLastWireGuardBackup() {
|
public String restoreLastWireGuardBackup() {
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.litoralregas.vpnprovisioner.vps.dto;
|
||||||
|
|
||||||
|
public record VpsHealthResponse(
|
||||||
|
String wireGuardInterface,
|
||||||
|
boolean wireGuardRunning,
|
||||||
|
int wireGuardPeerCount,
|
||||||
|
boolean wireGuardConfigExists,
|
||||||
|
String udp2rawService,
|
||||||
|
boolean udp2rawActive,
|
||||||
|
String latestWireGuardBackup,
|
||||||
|
String systemUptime,
|
||||||
|
int diskUsagePercent,
|
||||||
|
int memoryUsagePercent,
|
||||||
|
String loadAverage,
|
||||||
|
String publicIp
|
||||||
|
) {
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user