Sumit Bisht
Sumit Bisht

Reputation: 1517

Unable to present custom metrics value in Sonar

I have a custom measure in Sonar named, XMetObj under the domain, 'Complexity'. I have added the 'Custom Measures' into the project. Now while trying to access it through a java RESTful client, the application fails to detect this measure.

    Sonar sonar = Sonar.create("http://localhost:9000", "admin", "admin");
    String prjKey = "sampletest:junit";
    Query<Resource> resourceQuery = ResourceQuery.createForMetrics(prjKey, "Custom Measures", "Complexity", "XMetObj");
    if(resourceQuery==null){
        return;
    }
    Resource metrics = sonar.find(resourceQuery);
    if(metrics==null){
        return;
    }
    List<Measure> measures = metrics.getMeasures();
    for(Measure m:measures){
        m.setData("metrics");
        System.out.println(m.getData());
    }

I am able to get metrics for some projects, but the list of measures remain empty. I am also trying to insert new data into this custom metrics, but that too is also failing. Is this the correct way to display the metrics. I am not using a plugin as the metric values are already stored in a database and I wish these values to be project specific, but have contents from an external data-source.

Upvotes: 1

Views: 957

Answers (1)

If you want to retrieve measures for your metric, you have to use the metric key, not the metric name:

ResourceQuery.createForMetrics(String resourceKeyOrId, String... metricKeys)

So to get your measure, you must do something like:

ResourceQuery.createForMetrics(prjKey, "your_metric_key")

Upvotes: 1

Related Questions