Reporters

OpenMetrics reporter

The counts of a run as OpenMetrics gauges, one sample per format, for GitLab metrics reports and Prometheus-style tooling.

-r openmetrics writes the statistics of a run in the OpenMetrics text format: one gauge family per number, with an unlabeled sample for the whole run and one format="..." sample per format. GitLab reads the file as a metrics report and shows in a merge request how each number moved against the target branch; any parser of the Prometheus text format reads it as well. Available since jscpd 5.1.0.

Run it

Terminal
jscpd . -r openmetrics --output report
OpenMetrics report saved to report/jscpd-metrics.txt
.jscpd.json
{
  "reporters": ["console", "openmetrics"],
  "output": "report"
}

The output

Two of the eleven families, from the repository's fixtures/mcp-demo folder:

report/jscpd-metrics.txt
# HELP jscpd_clones_found Number of duplicated code blocks found.
# TYPE jscpd_clones_found gauge
jscpd_clones_found 3
jscpd_clones_found{format="bash"} 0
jscpd_clones_found{format="javascript"} 3
jscpd_clones_found{format="markdown"} 0
jscpd_clones_found{format="python"} 0
# HELP jscpd_duplicated_lines_percent Percentage of duplicated lines.
# TYPE jscpd_duplicated_lines_percent gauge
# UNIT jscpd_duplicated_lines_percent percent
jscpd_duplicated_lines_percent 17.708333333333336
jscpd_duplicated_lines_percent{format="bash"} 0
jscpd_duplicated_lines_percent{format="javascript"} 49.275362318840585
jscpd_duplicated_lines_percent{format="markdown"} 0
jscpd_duplicated_lines_percent{format="python"} 0
# EOF
MetricMeaning
jscpd_source_filesFiles analyzed
jscpd_lines_analyzedLines analyzed
jscpd_tokens_analyzedTokens analyzed
jscpd_clones_foundClones
jscpd_duplicated_linesDuplicated lines
jscpd_duplicated_tokensDuplicated tokens
jscpd_new_clonesClones absent from the baseline; 0 without --baseline
jscpd_new_duplicated_linesDuplicated lines in those clones; 0 without --baseline
jscpd_duplicated_lines_percentDuplication by lines, unit percent
jscpd_duplicated_tokens_percentDuplication by tokens, unit percent
jscpd_detection_duration_secondsTime spent on detection, unit seconds; the total only

Format names are escaped as the OpenMetrics grammar requires, and the file ends with # EOF.

Where it shows up

Declare the file as a metrics report artifact. Metrics reports need GitLab Premium or Ultimate.

.gitlab-ci.yml
jscpd:
  stage: test
  image: node:22
  before_script:
    - npm install -g jscpd@5
  script:
    - jscpd . -r console,openmetrics --output report
  artifacts:
    when: always
    reports:
      metrics: report/jscpd-metrics.txt

The merge request widget then lists each metric with its value on the target branch and the change.

With gates

--threshold does not change the file. A baseline fills jscpd_new_clones and jscpd_new_duplicated_lines, which stay at 0 otherwise. --kind narrows the counts to the kinds you name.

Options

FlagEffect on the file
-o, --outputThe directory of jscpd-metrics.txt
--baseline, --baseline-from-refValues for the two new gauges