Skip to content

Commit

Permalink
Add first two gitblit specific metrics
Browse files Browse the repository at this point in the history
Added metrics for:

1. git_garbage_collects_total
2. ldap_sync_latency_seconds.
  • Loading branch information
goettl79 committed Apr 29, 2017
1 parent 457afba commit f2d822e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -200,7 +206,7 @@ public void run() {

// do the deed
gc.call();

garbageCollectsTotal.inc();
garbageCollected = true;
}
} catch (Exception e) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/gitblit/service/LdapSyncService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,25 @@

import java.util.concurrent.atomic.AtomicBoolean;

import io.prometheus.client.Histogram;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
import com.gitblit.auth.LdapAuthProvider;

import static com.gitblit.service.PrometheusMetrics.LDAP_SYNC_LATENCY_SECONDS;

/**
* @author Alfred Schmid
*
*/
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;

Expand All @@ -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");
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/gitblit/service/PrometheusMetrics.java
Original file line number Diff line number Diff line change
@@ -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";
}

0 comments on commit f2d822e

Please sign in to comment.