🔊 Better logging

This commit is contained in:
andreas.dinauer 2025-11-17 21:06:53 +01:00
parent e231e4d6ae
commit e105306a6f
4 changed files with 40 additions and 6 deletions

View File

@ -5,18 +5,18 @@ meta {
}
get {
url: http://localhost:4000/api/metrics/POD-2/WORKLOAD?bucket-unit=DAILY
url: http://localhost:4000/api/metrics/analytics-backend-deployment-8695d9f87f-v8n7r/WORKLOAD?bucket-unit=RAW
body: none
auth: basic
}
params:query {
bucket-unit: DAILY
bucket-unit: RAW
}
auth:basic {
username: kubooboo
password: password
username: test
password: test
}
settings {

View File

@ -26,7 +26,9 @@ body:json {
"RELATIVE_CPU": "20",
"RELATIVE_MEMORY": "23",
"RELATIVE_DISK_USAGE": "56",
"TOTAL_DISK_SPACE": "73483209348"
"TOTAL_DISK_SPACE": "73483209348",
"REQUESTS": "2",
"AVERAGE_REQUESTS": "465"
}
}
}

View File

@ -6,13 +6,19 @@ import java.util.Optional;
import jakarta.inject.Inject;
import jakarta.ws.rs.*;
import org.jboss.logging.Logger;
import dev.dinauer.metrics.service.client.auth.AuthenticationService;
import dev.dinauer.metrics.service.model.Bucket;
import dev.dinauer.metrics.service.model.BucketUnit;
import dev.dinauer.metrics.service.utils.Timer;
@Path("/{resource}/{metric}")
public class Resource
{
@Inject
Logger LOG;
@Inject
AuthenticationService authenticationService;
@ -24,7 +30,9 @@ public class Resource
{
if (authenticationService.canWrite())
{
Timer timer = Timer.start();
service.index(resource, metric, insert.owner(), insert.values());
LOG.infof("Indexing in %s seconds.", timer.stop());
}
else
{
@ -37,7 +45,10 @@ public class Resource
{
if (authenticationService.canRead())
{
return service.get(resource, metric, bucketUnit.orElse(BucketUnit.RAW));
Timer timer = Timer.start();
List<Bucket> buckets = service.get(resource, metric, bucketUnit.orElse(BucketUnit.RAW));
LOG.infof("Retrieving %s buckets in %s seconds.", buckets.size(), timer.stop());
return buckets;
}
else
{

View File

@ -0,0 +1,21 @@
package dev.dinauer.metrics.service.utils;
public class Timer
{
long start;
public Timer()
{
this.start = System.nanoTime();
}
public static Timer start()
{
return new Timer();
}
public double stop()
{
return (System.nanoTime() - start) / 1_000_000_000.0;
}
}