Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from karolgil/kg/extendingMetrics
Browse files Browse the repository at this point in the history
Extending metrics
karolgil authored Mar 26, 2019
2 parents f4e47b5 + 446eb27 commit caa8177
Showing 2 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@

<groupId>com.getbase.jenkins.plugins</groupId>
<artifactId>build-history-metrics</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.1.1</version>
<name>Build history metrics plugin</name>
<description>Jenkins plugin to publish build metrics to external storage</description>
<packaging>hpi</packaging>
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package com.getbase.jenkins.plugins.metrics.history.influxdb.generators;

import com.synopsys.arc.jenkins.plugins.ownership.jobs.JobOwnerJobAction;
import com.synopsys.arc.jenkins.plugins.ownership.jobs.JobOwnerJobProperty;
import hudson.model.Result;
import hudson.model.Run;
import jenkins.metrics.impl.TimeInQueueAction;
import org.influxdb.dto.Point;

public class JenkinsBasePointGenerator implements PointGenerator {
public static final String MEASUREMENT_NAME = "jenkins_build_data";
public static final String JOB_NAME = "job_name";
public static final String BUILD_NUMBER = "build_number";
public static final String BUILD_RESULT = "build_result";
public static final String BUILD_TIMESTAMP = "build_timestamp";
public static final String BUILD_DURATION = "build_duration";
public static final String QUEUING_DURATION = "queuing_duration";
public static final String TOTAL_DURATION = "total_duration";
public static final String BUILD_STATUS_MESSAGE = "build_status_message";
public static final String JOB_OWNER = "job_owner";
public static final String JOB_SCORE = "job_score";
private static final String MEASUREMENT_NAME = "jenkins_build_data";
private static final String JOB_NAME = "job_name";
private static final String BUILD_NUMBER = "build_number";
private static final String BUILD_RESULT = "build_result";
private static final String BUILD_RESULT_INT = "build_result_int";
private static final String BUILD_TIMESTAMP = "build_timestamp";
private static final String BUILD_DURATION = "build_duration";
private static final String QUEUING_DURATION = "queuing_duration";
private static final String TOTAL_DURATION = "total_duration";
private static final String BUILD_STATUS_MESSAGE = "build_status_message";
private static final String JOB_OWNER = "job_owner";
private static final String JOB_SCORE = "job_score";
private static final String BUILD_URL = "build_url";
private static final String JOB_URL = "job_url";

private final Run<?, ?> build;

@@ -38,25 +40,30 @@ public Point[] generate() {
int score = build.getParent().getBuildHealth().getScore();
final Result result = build.getResult();
final String resultStr = result != null ? result.toString() : "UNKNOWN";
final Integer resultInt = resultStr.equals("SUCCESS") ? 1 : 0;
final String jobAbsoluteURL = build.getParent().getAbsoluteUrl();
final String buildAbsoluteURL = jobAbsoluteURL + build.getNumber();

Point.Builder point = Point
.measurement(MEASUREMENT_NAME)
.addField(JOB_NAME, build.getParent().getFullName())
.tag(JOB_NAME, build.getParent().getFullName())
.addField(BUILD_NUMBER, build.getNumber())
.addField(BUILD_RESULT, resultStr)
.tag(BUILD_RESULT, resultStr)
.addField(JOB_URL, jobAbsoluteURL)
.tag(JOB_URL, jobAbsoluteURL)
.addField(JOB_OWNER, owner)
.tag(JOB_OWNER, owner)
.addField(BUILD_NUMBER, build.getNumber())
.addField(BUILD_RESULT, resultStr)
.addField(BUILD_RESULT_INT, resultInt)
.addField(JOB_SCORE, score)
.tag(JOB_SCORE, Integer.toString(score))
.addField(BUILD_URL, buildAbsoluteURL)
.addField(BUILD_TIMESTAMP, build.getTimeInMillis())
.addField(BUILD_DURATION, duration)
.addField(QUEUING_DURATION, action.getQueuingDurationMillis())
.addField(TOTAL_DURATION, duration + action.getQueuingDurationMillis())
.addField(BUILD_STATUS_MESSAGE, build.getBuildStatusSummary().message);

return new Point[] {point.build()};
return new Point[]{point.build()};
}


0 comments on commit caa8177

Please sign in to comment.