Skip to content
Permalink
Browse files

Merge pull request #3 from mfriedenhagen/JENKINS-23933

JENKINS-23933: Expose build successful/unstable/failed metrics.
  • Loading branch information...
stephenc committed Sep 8, 2014
2 parents 79d151a + e409352 commit 264a210d6e4b6575ebf0f37f00385ac71315cfd2
Showing with 39 additions and 1 deletion.
  1. +39 −1 src/main/java/jenkins/metrics/impl/JenkinsMetricProviderImpl.java
@@ -25,10 +25,12 @@
package jenkins.metrics.impl;

import com.codahale.metrics.CachedGauge;
import com.codahale.metrics.Counter;
import com.codahale.metrics.DerivativeGauge;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Histogram;
import com.codahale.metrics.Meter;
import com.codahale.metrics.Metric;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.MetricSet;
import com.codahale.metrics.Timer;
@@ -47,6 +49,7 @@
import hudson.model.Node;
import hudson.model.PeriodicWork;
import hudson.model.Queue;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.model.listeners.RunListener;
@@ -124,6 +127,10 @@
* The amount of time jobs are building.
*/
private Timer jenkinsJobBuildingTime;
/**
* Run Results.
*/
private HashMap<String, Meter> jenkinsRunResults = new HashMap<String, Meter>();
/**
* The amount of time jobs take from initial scheduling to completion.
*/
@@ -360,10 +367,25 @@ protected Integer loadValue() {
}
return count;
}
})
}),
metric(name("jenkins", "runs"), runCounters())
);
}

private MetricSet runCounters() {
final Map<String, Metric> runCounters = new HashMap<String, Metric>();
for (String resultName : ResultRunListener.ALL) {
Meter counter = new Meter();
jenkinsRunResults.put(resultName, counter);
runCounters.put(resultName, counter);
}
return new MetricSet() {
public Map<String, Metric> getMetrics() {
return runCounters;
}
};
}

public static JenkinsMetricProviderImpl instance() {
return Jenkins.getInstance().getExtensionList(MetricProvider.class).get(JenkinsMetricProviderImpl.class);
}
@@ -518,6 +540,22 @@ protected synchronized void doRun() throws Exception {

}

@Extension
public static class ResultRunListener extends RunListener<Run> {
static final String[] ALL = new String[]{
"success", "unstable", "failure", "not_built", "aborted", "total"};

@Override
public synchronized void onCompleted(Run run, TaskListener listener) {
JenkinsMetricProviderImpl instance = instance();
if (instance != null) {
instance.jenkinsRunResults.get(String.valueOf(run.getResult()).toLowerCase()).mark();
instance.jenkinsRunResults.get("total").mark();
}
}

}

@Extension
public static class RunListenerImpl extends RunListener<Run> {
private Map<Run, List<Timer.Context>> contexts = new HashMap<Run, List<Timer.Context>>();

0 comments on commit 264a210

Please sign in to comment.
You can’t perform that action at this time.