feature: Add /api/info for simple instance stats
This commit is contained in:
parent
f5ebc873e9
commit
d807abe908
1 changed files with 49 additions and 0 deletions
|
@ -0,0 +1,49 @@
|
||||||
|
package eu.m724.mstats.api.resource;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import eu.m724.mstats.orm.Plugin;
|
||||||
|
import eu.m724.mstats.orm.Server;
|
||||||
|
import jakarta.ws.rs.GET;
|
||||||
|
import jakarta.ws.rs.Path;
|
||||||
|
import jakarta.ws.rs.Produces;
|
||||||
|
import jakarta.ws.rs.core.MediaType;
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
|
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||||
|
|
||||||
|
@Path("/api/info")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public class InfoApiResource {
|
||||||
|
@ConfigProperty(name = "quarkus.application.name")
|
||||||
|
String applicationName;
|
||||||
|
|
||||||
|
@ConfigProperty(name = "quarkus.application.version")
|
||||||
|
String applicationVersion;
|
||||||
|
|
||||||
|
@Path("/")
|
||||||
|
@GET
|
||||||
|
public Response info() {
|
||||||
|
InfoResponse response = new InfoResponse();
|
||||||
|
response.applicationInfo = new ApplicationInfo(applicationName, applicationVersion);
|
||||||
|
response.servers = Server.count();
|
||||||
|
response.plugins = Plugin.count();
|
||||||
|
|
||||||
|
// TODO Add more data like server versions
|
||||||
|
|
||||||
|
return Response.ok(response).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class InfoResponse {
|
||||||
|
public InfoResponse() {}
|
||||||
|
|
||||||
|
@JsonProperty("application")
|
||||||
|
public ApplicationInfo applicationInfo;
|
||||||
|
|
||||||
|
@JsonProperty("servers")
|
||||||
|
public long servers;
|
||||||
|
|
||||||
|
@JsonProperty("plugins")
|
||||||
|
public long plugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
public record ApplicationInfo(String name, String version) { }
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue