switch to mongo for metric storage
Some checks failed
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Failing after 54s

This commit is contained in:
Lee 2024-04-18 13:34:43 +01:00
parent 1c685ca414
commit ce3067ee0e
2 changed files with 14 additions and 2 deletions

View File

@ -39,6 +39,8 @@ public class MetricService {
this.influxWriteApi = influxAutoConfiguration.influxDBClient().getWriteApiBlocking();
this.metricsRepository = metricsRepository;
Map<Metric<?>, Boolean> collectorEnabled = new HashMap<>();
// Register the metrics
registerMetric(new TotalRequestsMetric());
registerMetric(new RequestsPerRouteMetric());
@ -48,9 +50,18 @@ public class MetricService {
registerMetric(new UniquePlayerLookupsMetric());
registerMetric(new UniqueServerLookupsMetric());
// please god forgive my sins; this is the worst code I've ever written
for (Metric<?> metric : metrics.values()) {
collectorEnabled.put(metric, metric.isCollector());
}
// Load the metrics from Redis
loadMetrics();
for (Map.Entry<Metric<?>, Boolean> entry : collectorEnabled.entrySet()) {
entry.getKey().setCollector(entry.getValue());
}
Timer.scheduleRepeating(() -> {
saveMetrics();
writeToInflux();

View File

@ -7,6 +7,7 @@ import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
import xyz.mcutils.backend.service.MetricService;
@ -28,8 +29,8 @@ public abstract class Metric<T> {
* Should this metric be collected
* before pushing to Influx?
*/
@JsonIgnore
private transient boolean collector;
@Transient @JsonIgnore
private boolean collector;
/**
* Collects the metric.