๐ฅ๏ธ CodeMonitor
CodeMonitor is a powerful Ruby gem that collects code quality metrics, dependency information, test coverage, and other important statistics from your repository. It aggregates data from multiple analysis tools (linters, type checkers, test frameworks, etc.) and sends them to time series databases or monitoring providers like Datadog for tracking trends over time.
๐ What Does It Do?
CodeMonitor acts as a centralized metrics collection hub for your codebase. It:
- Collects metrics from various development tools and analysis extractors
- Aggregates data from linters (ESLint, Rubocop, Semgrep), type checkers (Sorbet), test coverage tools (Jest, SimpleCov), dependency analyzers (npm, Knip, Packwerk), and more
- Normalizes metrics into a consistent format
- Pushes data to monitoring providers (Datadog, Console output)
- Tracks trends over time to help you monitor code quality, technical debt, and project health
๐ Installation
Add this line to your application's Gemfile:
gem 'codemonitor'
And then execute:
bundle install
Or install it yourself as:
gem install codemonitor
๐ป Usage
Basic Usage
Run CodeMonitor in your project directory:
codemonitor
By default, it will:
- Auto-detect which extractors are available (based on configuration files)
- Collect metrics from all detected extractors
- Output results to the console
Configuration
Configure CodeMonitor using environment variables:
CODEMONITOR_PROVIDER: Choose where to send metrics (console or datadog). Default: console
CODEMONITOR_EXTRACTORS: Comma-separated list of specific extractors to run (e.g., git,eslint,npm). If not set, all available extractors run.
Example:
# Send metrics to Datadog
CODEMONITOR_PROVIDER=datadog DATADOG_API_KEY=your_key codemonitor
# Run only specific extractors
CODEMONITOR_EXTRACTORS=git,npm,eslint codemonitor
Extractors
Extractors are the data collectors that extract metrics from various tools and sources. Each extractor automatically activates when its requirements are met.
Git
Collects repository statistics including commits, branches, tags, contributors, and file metrics.
Requirements:
- A
.git folder in the current directory
Options:
CODEMONITOR_GIT_FILES_THRESHOLD: Filter out file extension metrics below this count (Default: 0)
Metrics:
| Metric |
Description |
git_number_of_commits |
Total number of commits in the repository |
git_number_of_branches |
Total number of branches |
git_number_of_tags |
Total number of tags |
git_number_of_contributors |
Total number of unique contributors |
git_number_of_files |
Total number of tracked files |
git_number_of_ignores_files |
Number of ignored files |
git_number_of_lines |
Total lines of code across all files |
git_file_extensions_* |
File count per extension (e.g., git_file_extensions_rb, git_file_extensions_js) |
ESLint
Collects JavaScript/TypeScript linting metrics including violations by severity and rule.
Requirements:
eslint.output.json file in the current directory
Generate the required file:
eslint -f json -o eslint.output.json
Options:
CODEMONITOR_ESLINT_THRESHOLD: Only report rules with violations >= this threshold (Default: 10)
Metrics:
| Metric |
Description |
eslint_number_of_offended_files |
Number of files with ESLint violations |
eslint_number_of_offenses |
Total number of ESLint violations |
eslint_number_of_correctable |
Number of auto-fixable violations |
eslint_severity_warning |
Number of warnings |
eslint_severity_error |
Number of errors |
eslint_rule_* |
Violation count per rule (e.g., eslint_rule_no_console) |
npm
Collects Node.js dependency information including counts, computed dependencies, and vulnerability data from npm audit.
Requirements:
package.json file in the current directory
package-lock.json file in the current directory
Metrics:
| Metric |
Description |
npm_number_of_prod_dependencies |
Number of production dependencies |
npm_number_of_dev_dependencies |
Number of development dependencies |
npm_number_of_scripts |
Number of npm scripts defined |
npm_number_of_computed_prod_dependencies |
Total production dependencies (including transitive) |
npm_number_of_computed_dev_dependencies |
Total dev dependencies (including transitive) |
npm_number_of_computed_optional_dependencies |
Total optional dependencies |
npm_number_of_computed_peer_dependencies |
Total peer dependencies |
npm_number_of_computed_peer_optional_dependencies |
Total optional peer dependencies |
npm_number_of_computed_total_dependencies |
Grand total of all dependencies |
npm_number_of_vulnerable_dependencies_info |
Vulnerabilities: info severity |
npm_number_of_vulnerable_dependencies_low |
Vulnerabilities: low severity |
npm_number_of_vulnerable_dependencies_moderate |
Vulnerabilities: moderate severity |
npm_number_of_vulnerable_dependencies_high |
Vulnerabilities: high severity |
npm_number_of_vulnerable_dependencies_critical |
Vulnerabilities: critical severity |
npm_number_of_vulnerable_dependencies_total |
Total number of vulnerabilities |
Packwerk
Collects metrics from Shopify's Packwerk package system for Ruby, tracking dependency and privacy violations.
Requirements:
package_todo.yml files present in the project (in any subdirectory)
Metrics:
| Metric |
Description |
packwerk_number_of_dependency_violations |
Number of package dependency violations |
packwerk_number_of_privacy_violations |
Number of package privacy violations |
Rubocop
Collects Ruby linting metrics from Rubocop, including violations by severity and cop.
Requirements:
rubocop.output.json file in the current directory
Generate the required file:
bundle exec rubocop -f json -o rubocop.output.json
Options:
CODEMONITOR_RUBOCOP_THRESHOLD: Only report cops with violations >= this threshold (Default: 50)
Metrics:
| Metric |
Description |
rubocop_number_of_offenses |
Total number of Rubocop violations |
rubocop_number_of_correctable |
Number of auto-correctable violations |
rubocop_severity_* |
Violations by severity (e.g., rubocop_severity_warning) |
rubocop_cop_* |
Violations per cop (e.g., rubocop_cop_style_frozen_string_literal_comment) |
Semgrep
Collects security and code quality findings from Semgrep.
Requirements:
semgrep.output.json file in the current directory
Generate the required file:
semgrep --json -o semgrep.output.json
Options:
CODEMONITOR_SEMGREP_THRESHOLD: Only report check IDs with findings >= this threshold (Default: 50)
Metrics:
| Metric |
Description |
semgrep_number_of_offenses |
Total number of Semgrep findings |
semgrep_number_of_errors |
Number of Semgrep errors during analysis |
semgrep_check_* |
Findings per check ID |
Knip
Collects unused code metrics from Knip, identifying unused dependencies, exports, and types.
Requirements:
knip.output.json file in the current directory
Generate the required file:
knip --reporter json > knip.output.json
Metrics:
| Metric |
Description |
knip_number_of_dependecies |
Unused dependencies |
knip_number_of_devDependencies |
Unused dev dependencies |
knip_number_of_optionalPeerDependencies |
Unused optional peer dependencies |
knip_number_of_unlisted |
Unlisted dependencies |
knip_number_of_binaries |
Unused binaries |
knip_number_of_unresolved |
Unresolved imports |
knip_number_of_exports |
Unused exports |
knip_number_of_types |
Unused types |
knip_number_of_enumMembers |
Unused enum members |
knip_number_of_duplicates |
Duplicate exports |
Sorbet
Collects type coverage metrics from Sorbet, Stripe's type checker for Ruby.
Requirements:
sorbet.output.json file in the current directory
Generate the required file:
bundle exec srb tc --metrics-prefix 'codemetrics' --metrics-file sorbet.output.json
Metrics:
| Metric |
Description |
sorbet_number_of_sig_count |
Number of type signatures |
sorbet_number_of_input_classes_total |
Total number of classes |
sorbet_number_of_input_sends_total |
Total number of method calls |
sorbet_number_of_input_files |
Number of Ruby files analyzed |
sorbet_number_of_input_methods_total |
Total number of methods |
sorbet_number_of_input_modules_total |
Total number of modules |
sorbet_number_of_sigil_true |
Files with typed: true |
sorbet_number_of_sigil_false |
Files with typed: false |
sorbet_number_of_sigil_autogenerated |
Files with typed: autogenerated |
sorbet_number_of_sigil_strong |
Files with typed: strong |
sorbet_number_of_sigil_strict |
Files with typed: strict |
sorbet_number_of_sigil_ignore |
Files with typed: ignore |
SCC (Sloc Cloc and Code)
Collects code statistics from SCC, including lines of code, complexity, and language breakdowns.
Requirements:
scc.output.json file in the current directory
Generate the required file:
scc -f json > scc.output.json
Metrics:
| Metric |
Description |
scc_total_bytes |
Total bytes across all files |
scc_total_lines |
Total lines across all files |
scc_total_code |
Total lines of code |
scc_total_comment |
Total comment lines |
scc_total_blank |
Total blank lines |
scc_total_complexity |
Total cyclomatic complexity |
scc_total_count |
Total number of files |
scc_total_weightedcomplexity |
Weighted complexity score |
scc_type_*_* |
Per-language metrics (e.g., scc_type_ruby_code, scc_type_javascript_lines) |
Jest
Collects JavaScript/TypeScript test coverage metrics from Jest's JSON summary reporter.
Requirements:
jest_json_summary.output.json file in the current directory
Configure Jest to generate this file using the json-summary reporter in your jest.config.js.
Metrics:
| Metric |
Description |
jest_json_summary_lines_total |
Total lines in test coverage |
jest_json_summary_lines_covered |
Covered lines |
jest_json_summary_lines_skipped |
Skipped lines |
jest_json_summary_lines_pct |
Line coverage percentage |