sonar_get_project_metrics
Get comprehensive project metrics including coverage, duplication, and quality ratings.
Description
Retrieves all quality metrics for a project in a single call. Provides a complete snapshot of project health including bugs, vulnerabilities, code smells, coverage, and duplication.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
metrics | array | No | All | Specific metrics to retrieve |
Available Metrics
Quality Metrics
| Metric | Description | Type |
|---|---|---|
bugs | Total bug count | number |
vulnerabilities | Security vulnerability count | number |
code_smells | Code smell count | number |
blocker_violations | Blocker severity issues | number |
critical_violations | Critical severity issues | number |
Coverage Metrics
| Metric | Description | Type |
|---|---|---|
coverage | Overall test coverage % | percentage |
line_coverage | Line coverage % | percentage |
branch_coverage | Branch coverage % | percentage |
uncovered_lines | Lines without tests | number |
Duplication Metrics
| Metric | Description | Type |
|---|---|---|
duplicated_lines_density | Duplication % | percentage |
duplicated_lines | Total duplicated lines | number |
duplicated_blocks | Number of duplicate blocks | number |
duplicated_files | Files with duplication | number |
Size Metrics
| Metric | Description | Type |
|---|---|---|
ncloc | Lines of code (no comments) | number |
lines | Total lines | number |
files | Total files | number |
functions | Total functions | number |
classes | Total classes | number |
Rating Metrics
| Metric | Description | Values |
|---|---|---|
reliability_rating | Bug rating | A-E (1-5) |
security_rating | Vulnerability rating | A-E (1-5) |
sqale_rating | Maintainability rating | A-E (1-5) |
Debt Metrics
| Metric | Description | Type |
|---|---|---|
sqale_index | Technical debt (minutes) | number |
sqale_debt_ratio | Debt ratio % | percentage |
Usage
Get All Metrics
Show me all project metrics
Tool call:
{}
Specific Metrics
Show me coverage and duplication stats
Tool call:
{
"metrics": ["coverage", "duplicated_lines_density", "uncovered_lines"]
}
Response Format
PROJECT METRICS
━━━━━━━━━━━━━━━
Project: my-awesome-app
Key: my-awesome-app-a1b2c3d4
📊 QUALITY OVERVIEW:
Bugs: 12 (Rating: B)
Vulnerabilities: 2 (Rating: C)
Code Smells: 156 (Rating: A)
📈 COVERAGE:
Overall: 67.3%
Line: 72.1%
Branch: 58.4%
Uncovered: 1,234 lines
📋 DUPLICATION:
Density: 4.2%
Lines: 890
Blocks: 45
Files: 12
📏 SIZE:
Lines of Code: 15,432
Files: 89
Functions: 456
Classes: 34
⏱️ TECHNICAL DEBT:
Total: 3d 4h (2,440 min)
Ratio: 2.3%
⭐ RATINGS:
Reliability: B
Security: C
Maintainability: A
Rating Scale
| Rating | Meaning | Threshold |
|---|---|---|
| A | Excellent | No issues |
| B | Good | Minor issues |
| C | Acceptable | Some issues |
| D | Poor | Many issues |
| E | Critical | Severe issues |
Examples
Example 1: Health Check
Prompt:
Give me a quick health check of the project
Tool Call:
{
"metrics": ["bugs", "vulnerabilities", "coverage", "reliability_rating", "security_rating"]
}
Example 2: Coverage Report
Prompt:
What's the test coverage situation?
Tool Call:
{
"metrics": ["coverage", "line_coverage", "branch_coverage", "uncovered_lines"]
}
Example 3: Code Size
Prompt:
How big is this codebase?
Tool Call:
{
"metrics": ["ncloc", "files", "functions", "classes"]
}
Best Practices
- Regular monitoring - Track metrics over time
- Focus on trends - Improvement matters more than absolute values
- Set thresholds - Define acceptable limits for your team
- Balance metrics - Don't optimize one at expense of others
Related Tools
sonar_get_quality_gate- Pass/fail statussonar_get_technical_debt- Debt analysissonar_get_coverage_gaps- Uncovered code