-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
206 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
graylog2-server/src/main/java/org/graylog2/inputs/diagnosis/InputDiagnosisMetrics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.graylog2.inputs.diagnosis; | ||
|
||
import com.codahale.metrics.Gauge; | ||
import com.codahale.metrics.MetricRegistry; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
import org.apache.commons.collections4.queue.CircularFifoQueue; | ||
import org.graylog2.shared.metrics.MetricUtils; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
@Singleton | ||
public class InputDiagnosisMetrics { | ||
|
||
private static final int SIZE_FOR_15_MINUTES = 15; | ||
private final Map<String, CircularFifoQueue<Long>> metrics = new HashMap<>(); | ||
private final AtomicReference<MetricRegistry> localMetricRegistry = new AtomicReference<>(new MetricRegistry()); | ||
private final MetricRegistry metricRegistry; | ||
|
||
@Inject | ||
public InputDiagnosisMetrics(MetricRegistry metricRegistry) { | ||
this.metricRegistry = metricRegistry; | ||
} | ||
|
||
public void incCount(String metricName) { | ||
localMetricRegistry.get().counter(metricName).inc(); | ||
} | ||
|
||
void update() { | ||
MetricRegistry registry = localMetricRegistry.getAndSet(new MetricRegistry()); | ||
registry.getCounters().forEach((metric, counter) -> | ||
metrics.compute(metric, (m, q) -> { | ||
final CircularFifoQueue<Long> queue = Objects.requireNonNullElseGet(q, () -> new CircularFifoQueue<>(SIZE_FOR_15_MINUTES)); | ||
queue.add(counter.getCount()); | ||
MetricUtils.safelyRegister(metricRegistry, metric, (Gauge<Long>) () -> queue.stream() | ||
.mapToLong(value -> value) | ||
.sum()); | ||
return queue; | ||
})); | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
...2-server/src/main/java/org/graylog2/inputs/diagnosis/InputDiagnosisMetricsPeriodical.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.graylog2.inputs.diagnosis; | ||
|
||
import jakarta.inject.Inject; | ||
import org.graylog2.plugin.periodical.Periodical; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
public class InputDiagnosisMetricsPeriodical extends Periodical { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(InputDiagnosisMetricsPeriodical.class); | ||
|
||
private final InputDiagnosisMetrics inputDiagnosisMetrics; | ||
|
||
@Inject | ||
public InputDiagnosisMetricsPeriodical(InputDiagnosisMetrics inputDiagnosisMetrics) { | ||
this.inputDiagnosisMetrics = inputDiagnosisMetrics; | ||
} | ||
|
||
@Override | ||
public boolean runsForever() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean stopOnGracefulShutdown() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean startOnThisNode() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isDaemon() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public int getInitialDelaySeconds() { | ||
return 60; | ||
} | ||
|
||
@Override | ||
public int getPeriodSeconds() { | ||
return 60; | ||
} | ||
|
||
@Override | ||
protected @Nonnull Logger getLogger() { | ||
return LOG; | ||
} | ||
|
||
@Override | ||
public void doRun() { | ||
inputDiagnosisMetrics.update(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.