forked from MinecraftUtilities/Backend
switch to mongo for metric storage
This commit is contained in:
parent
1c685ca414
commit
ce3067ee0e
@ -39,6 +39,8 @@ public class MetricService {
|
|||||||
this.influxWriteApi = influxAutoConfiguration.influxDBClient().getWriteApiBlocking();
|
this.influxWriteApi = influxAutoConfiguration.influxDBClient().getWriteApiBlocking();
|
||||||
this.metricsRepository = metricsRepository;
|
this.metricsRepository = metricsRepository;
|
||||||
|
|
||||||
|
Map<Metric<?>, Boolean> collectorEnabled = new HashMap<>();
|
||||||
|
|
||||||
// Register the metrics
|
// Register the metrics
|
||||||
registerMetric(new TotalRequestsMetric());
|
registerMetric(new TotalRequestsMetric());
|
||||||
registerMetric(new RequestsPerRouteMetric());
|
registerMetric(new RequestsPerRouteMetric());
|
||||||
@ -48,9 +50,18 @@ public class MetricService {
|
|||||||
registerMetric(new UniquePlayerLookupsMetric());
|
registerMetric(new UniquePlayerLookupsMetric());
|
||||||
registerMetric(new UniqueServerLookupsMetric());
|
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
|
// Load the metrics from Redis
|
||||||
loadMetrics();
|
loadMetrics();
|
||||||
|
|
||||||
|
for (Map.Entry<Metric<?>, Boolean> entry : collectorEnabled.entrySet()) {
|
||||||
|
entry.getKey().setCollector(entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
Timer.scheduleRepeating(() -> {
|
Timer.scheduleRepeating(() -> {
|
||||||
saveMetrics();
|
saveMetrics();
|
||||||
writeToInflux();
|
writeToInflux();
|
||||||
|
@ -7,6 +7,7 @@ import lombok.Getter;
|
|||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.annotation.Transient;
|
||||||
import org.springframework.data.mongodb.core.mapping.Document;
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
import xyz.mcutils.backend.service.MetricService;
|
import xyz.mcutils.backend.service.MetricService;
|
||||||
|
|
||||||
@ -28,8 +29,8 @@ public abstract class Metric<T> {
|
|||||||
* Should this metric be collected
|
* Should this metric be collected
|
||||||
* before pushing to Influx?
|
* before pushing to Influx?
|
||||||
*/
|
*/
|
||||||
@JsonIgnore
|
@Transient @JsonIgnore
|
||||||
private transient boolean collector;
|
private boolean collector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects the metric.
|
* Collects the metric.
|
||||||
|
Loading…
Reference in New Issue
Block a user