Giter Site home page Giter Site logo

sonar-custom-metric-plugin's Introduction

SonarQube Custom Metric Plugin

Quality Gate Coverage Bug

This is a custom plugin for SonarQube - Continuous code quality inspection tool.

This plugin will allow to add custom metrics project to let quality gate checking for it.

Building

  • Clone this repository
  • Run ./gradle build or .\gradlew build on Windows
  • Find sonar-custom-metric-plugin-*.*.jar in ./build/libs

Installing

Copy the built sonar-custom-metric-plugin-*.*.jar plugin to SonarQube server plugin directory in <SonarQubeHome>/extensions/plugins/. Restart the SonarQube process.

SonarQube on Docker If you are using Docker compose file, copy the plugin to the container volume:

// sonarqube_sonarqube_1 is container name
docker cp sonar-customer-metric-plugin-0.1.jar sonarqube_sonarqube_1:/opt/sonarqube/extensions/plugins/
docker-compose restart

Defining metrics

The metrics have to be defined so that SonarQube can interpret them. This has to be done in .\src\main\java\jp\co\atware\sonar\custommetric\CustomMetrics.java.

This file contains more information on how to define these metrics.

Example:

	static final List<Metric> METRICS = Arrays.asList(

		new Metric.Builder(
            "MemoryUsage", "Memory usage", Metric.ValueType.INT)
            .setDirection(Metric.DIRECTION_WORST)
            .setQualitative(true)
            .setDomain(CoreMetrics.DOMAIN_RELIABILITY)
            .create(),

		new Metric.Builder(
            "MemoryUsagePercent", "Memory usage (in percent)", Metric.ValueType.FLOAT)
            .setDirection(Metric.DIRECTION_WORST)
            .setQualitative(true)
            .setDomain(CoreMetrics.DOMAIN_RELIABILITY)
            .create(),	

		new Metric.Builder(
            "Status", "Api status response", Metric.ValueType.STRING)
            .setDirection(Metric.DIRECTION_NONE)
            .setQualitative(true)
            .setDomain(CoreMetrics.DOMAIN_RELIABILITY)
            .create(),	

	);

Changing metric definitions requires a new version of the plugin, installing it and restarting the SonarQube process.

Writing custom metrics

Now that we defined the custom metrics, we have to collect and write the according values during the build and/or test process. These values need to be written into a file in the project file structure. This file uses a metricId,value format.

Example:

MemoryUsage,380
MemoryUsagePercent,0.34
Status,OK

The values can be various from int, double to string, depending on the metric definitions in the plugin (see above).

Transferring custom metrics

Once the metrics file is written, its relative path needs to be transferred to the SonarQube server. Use the variable name custom.metrics.reportFilePath

Example:

begin
  /d:sonar.host.url="..."
  /d:custom.metrics.reportFilePath="./custom-sonar-metrics.csv"
  ...

sonar-custom-metric-plugin's People

Contributors

awaescher avatar baohuy91 avatar

Watchers

 avatar

Forkers

chg-meridian

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.