Question about Sonar system info webapi - ncloc by language calculation


I would like to get the number of lines of code by language on my SonarQube instance in order to create a custom prometheus exporter. I’m using SonarQube

I saw that an api (api/system/info) was available and was returning a key “nclocByLanguage”. However, the sum I get for all the ncloc of the detected languages don’t match up with the other metric named “ncloc”.

Here is what I got

"ncloc": 168724,
"nclocByLanguage": [
        "language": "css",
        "ncloc": 132
        "language": "java",
        "ncloc": 880
        "language": "web",
        "ncloc": 42
        "language": "xml",
        "ncloc": 1848
        "language": "go",
        "ncloc": 2715
        "language": "js",
        "ncloc": 7033

What happened to the other 100k + lines that are appearing on the ncloc metric ?
Is this because the langage of those lines is not well detected ?

Best Regards

Hey there.

You are probably facing this: SONAR-13915

Yes it seems that is what is happening
I just checked and a lot of branches are indeed used for the calculation of the total ncloc count instead of the main branch, which is used to calculate the ncloc by language.

Thanks for you quick answer !

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.