Java 类com.codahale.metrics.DerivativeGauge 实例源码

项目:metrics-plugin    文件:Metrics.java   
/**
 * {@inheritDoc}
 */
@NonNull
@Override
public MetricSet getMetricSet() {
    Jenkins jenkins = Jenkins.getInstance();
    if (jenkins == null) {
        throw new AssertionError("Jenkins is missing");
    }
    HealthChecker c = jenkins.getExtensionList(PeriodicWork.class).get(HealthChecker.class);
    if (c == null) {
        throw new AssertionError("HealthChecker is missing");
    }
    return metrics(
            metric(name("jenkins", "health-check", "duration"), c.getHealthCheckDuration()),
            metric(name("jenkins", "health-check", "count"), c.getHealthCheckCount()),
            metric(name("jenkins", "health-check", "score"), c.getHealthCheckScore()),
            metric(name("jenkins", "health-check", "inverse-score"), new DerivativeGauge<Double, Double>(c.getHealthCheckScore()) {
                @Override
                protected Double transform(Double value) {
                    return value == null ? null : 1.0 - value;
                }
            })
    );
}