From 9909f7cf7d5c0e2ad9ac68da19b7b083e463f1fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georg=20=C3=96ttl?= Date: Sat, 29 Apr 2017 15:22:13 +0200 Subject: [PATCH] Add first two gitblit specific metrics Added metrics for: 1. git_garbage_collects_total 2. ldap_sync_latency_seconds. --- .../com/gitblit/service/GarbageCollectorService.java | 8 +++++++- src/main/java/com/gitblit/service/LdapSyncService.java | 7 +++++++ .../java/com/gitblit/service/PrometheusMetrics.java | 10 ++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/gitblit/service/PrometheusMetrics.java diff --git a/src/main/java/com/gitblit/service/GarbageCollectorService.java b/src/main/java/com/gitblit/service/GarbageCollectorService.java index b98560fd9..fce5c5112 100644 --- a/src/main/java/com/gitblit/service/GarbageCollectorService.java +++ b/src/main/java/com/gitblit/service/GarbageCollectorService.java @@ -23,6 +23,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; +import io.prometheus.client.Counter; import org.eclipse.jgit.api.GarbageCollectCommand; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.lib.Repository; @@ -35,6 +36,8 @@ import com.gitblit.models.RepositoryModel; import com.gitblit.utils.FileUtils; +import static com.gitblit.service.PrometheusMetrics.GIT_GARBAGE_COLLECTS_TOTAL; + /** * The Garbage Collector Service handles periodic garbage collection in repositories. * @@ -129,6 +132,9 @@ public void close() { forceClose.set(true); } + private final Counter garbageCollectsTotal = Counter.build() + .name(GIT_GARBAGE_COLLECTS_TOTAL).help(GIT_GARBAGE_COLLECTS_TOTAL).register(); + @Override public void run() { if (!isReady()) { @@ -200,7 +206,7 @@ public void run() { // do the deed gc.call(); - + garbageCollectsTotal.inc(); garbageCollected = true; } } catch (Exception e) { diff --git a/src/main/java/com/gitblit/service/LdapSyncService.java b/src/main/java/com/gitblit/service/LdapSyncService.java index 7ae19aad8..4b1cb04ff 100644 --- a/src/main/java/com/gitblit/service/LdapSyncService.java +++ b/src/main/java/com/gitblit/service/LdapSyncService.java @@ -17,6 +17,7 @@ import java.util.concurrent.atomic.AtomicBoolean; +import io.prometheus.client.Histogram; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,6 +25,8 @@ import com.gitblit.Keys; import com.gitblit.auth.LdapAuthProvider; +import static com.gitblit.service.PrometheusMetrics.LDAP_SYNC_LATENCY_SECONDS; + /** * @author Alfred Schmid * @@ -31,6 +34,8 @@ public final class LdapSyncService implements Runnable { private final Logger logger = LoggerFactory.getLogger(LdapSyncService.class); + private final Histogram ldapSyncLatency = Histogram.build().name(LDAP_SYNC_LATENCY_SECONDS). + help(LDAP_SYNC_LATENCY_SECONDS).register(); private final IStoredSettings settings; @@ -51,12 +56,14 @@ public LdapSyncService(IStoredSettings settings, LdapAuthProvider ldapAuthProvid public void run() { logger.info("Starting user and group sync with ldap service"); if (!running.getAndSet(true)) { + Histogram.Timer requestTimer = ldapSyncLatency.startTimer(); try { ldapAuthProvider.sync(); } catch (Exception e) { logger.error("Failed to synchronize with ldap", e); } finally { running.getAndSet(false); + requestTimer.observeDuration(); } } logger.info("Finished user and group sync with ldap service"); diff --git a/src/main/java/com/gitblit/service/PrometheusMetrics.java b/src/main/java/com/gitblit/service/PrometheusMetrics.java new file mode 100644 index 000000000..1005c75f6 --- /dev/null +++ b/src/main/java/com/gitblit/service/PrometheusMetrics.java @@ -0,0 +1,10 @@ +package com.gitblit.service; + +class PrometheusMetrics { + + /** Number of garbage collects */ + static final String GIT_GARBAGE_COLLECTS_TOTAL = "git_garbage_collects_total"; + + /** Ldap Sync Latency in second */ + static final String LDAP_SYNC_LATENCY_SECONDS = "ldap_sync_latency_seconds"; +}