Skip to content

feat: add PM2 monitoring source - #83

Open
atlas-maxjb wants to merge 2 commits into
maxjb-xyz:mainfrom
atlas-maxjb:feat/pm2-monitoring
Open

atlas-maxjb wants to merge 2 commits into
maxjb-xyz:mainfrom
atlas-maxjb:feat/pm2-monitoring

Conversation

@atlas-maxjb

@atlas-maxjb atlas-maxjb commented Aug 8, 2026 •

Copy link
Copy Markdown

Summary

  • Add an env-gated agent PM2 watcher that polls pm2 jlist every 15 seconds, baselines the first snapshot, and emits normalized started, stopped, failed, and restart entries with structured metadata.
  • Wire the pm2 capability, per-node source config/admin catalog support, exact process-name filtering, and source UI/docs/OpenAPI entries.
  • Add focused PM2 transition, capability, source validation, and agent-config coverage.

Verification

  • agent: GOCACHE=/tmp/blackbox-gocache-agent GOPATH=/tmp/blackbox-gopath-agent go test ./... — PASS
  • server: GOCACHE=/tmp/blackbox-gocache-server GOPATH=/tmp/blackbox-gopath-server go test ./... — PASS
  • shared: go test ./... — PASS
  • web: npm run build — PASS
  • web: npm test — PASS (19 tests)
  • PM2-related frontend files: npx eslint src/components/SourceIcon.tsx src/components/sourceIcons.ts src/pages/SourceCatalog.tsx — PASS
  • Full web/npm run lint remains blocked by pre-existing errors in DemoIntroModal.tsx, useWebSocket.ts, session.tsx, and the existing state-reset rule at DataSourcesGroup.tsx:450, plus existing warnings; no PM2-specific lint errors were reported.

Summary by CodeRabbit

  • New Features

    • Added PM2 monitoring for Node.js process starts, stops, failures, and restarts.
    • Added configuration to enable PM2 monitoring and optionally select specific processes.
    • Added PM2 as a supported data source, node capability, and source type in the web interface.
    • Added PM2 availability reporting and configurable executable paths.
  • Documentation

    • Added setup, configuration, troubleshooting, and data-source documentation for PM2 monitoring.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@atlas-maxjb, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

Limit details: You’ve used all 1 included review currently available under your plan.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9af4e1ee-4f42-47eb-9916-bd53a5e53a67

📥 Commits

Reviewing files that changed from the base of the PR and between 3d998bb and a6cae42.

📒 Files selected for processing (5)
  • agent/internal/pm2/watcher.go
  • agent/internal/pm2/watcher_test.go
  • docs/site/docs/data-sources/pm2.md
  • server/internal/handlers/file_watcher_settings.go
  • server/internal/handlers/file_watcher_settings_test.go
📝 Walkthrough

Walkthrough

This change adds PM2 as an agent-scoped data source. The server validates and delivers PM2 settings. The agent polls pm2 jlist and emits lifecycle events. The web interface supports PM2 configuration and visuals. Documentation covers setup and behavior.

Changes

PM2 monitoring

Layer / File(s) Summary
Server PM2 source and configuration
server/internal/handlers/..., server/internal/models/data_source.go, server/docs/openapi.yaml, agent/internal/client/client.go
The server registers PM2 as a singleton source, validates and normalizes process names, and returns pm2_enabled and pm2_processes in the agent configuration.
PM2 polling and lifecycle transitions
agent/internal/pm2/watcher.go, agent/internal/pm2/watcher_test.go
The watcher runs timed pm2 jlist polls, filters processes, establishes baselines, tracks identities, and emits deterministic start, stop, failure, and restart entries.
Agent configuration and watcher startup
agent/main.go, agent/main_test.go
The agent loads and refreshes PM2 settings, checks WATCH_PM2 and PM2 availability, reports the pm2 capability, and starts the watcher.
Web source configuration and visuals
web/src/pages/DataSourcesGroup.tsx, web/src/pages/SourceCatalog.tsx, web/src/components/SourceIcon.tsx, web/src/components/sourceIcons.ts
The web interface provides PM2 defaults, process-list editing, documentation links, and PM2 icons and colors.
PM2 source documentation
docs/site/docs/data-sources/pm2.md, docs/site/docs/configuration/agent-environment.md, docs/site/docs/data-sources/overview.md, docs/site/docs/data-sources/node-capabilities.md, docs/site/docs/contributing/adding-a-data-source.md, docs/site/sidebars.ts
The documentation describes PM2 setup, filtering, lifecycle events, polling, capabilities, and troubleshooting.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Server
  participant Agent
  participant PM2
  participant EventStream
  Server->>Agent: Return pm2_enabled and pm2_processes
  Agent->>PM2: Execute pm2 jlist
  PM2-->>Agent: Return process list
  Agent->>Agent: Compare filtered snapshot with baseline
  Agent->>EventStream: Emit lifecycle transition entries
Loading

Possibly related PRs

  • maxjb-xyz/blackbox#67: Introduced the agent configuration and unified data-source system extended by this PM2 change.

Poem

PM2 wakes, its processes bright,
The watcher polls through day and night.
Starts and stops become a stream,
Restarts mark each changing beam.
Configured names guide the way.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: adding a PM2 monitoring source.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/site/docs/data-sources/pm2.md`:
- Around line 63-67: Update the troubleshooting command near the PM2 monitoring
instructions to invoke the configured executable via PM2_BIN, falling back to
pm2 when unset. Preserve the existing jlist argument and JSON verification
guidance.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 52ba02d9-754e-4149-8c6b-059ecd484d36

📥 Commits

Reviewing files that changed from the base of the PR and between aa9fcdf and 3d998bb.

📒 Files selected for processing (21)
  • agent/internal/client/client.go
  • agent/internal/pm2/watcher.go
  • agent/internal/pm2/watcher_test.go
  • agent/main.go
  • agent/main_test.go
  • docs/site/docs/configuration/agent-environment.md
  • docs/site/docs/contributing/adding-a-data-source.md
  • docs/site/docs/data-sources/node-capabilities.md
  • docs/site/docs/data-sources/overview.md
  • docs/site/docs/data-sources/pm2.md
  • docs/site/sidebars.ts
  • server/docs/openapi.yaml
  • server/internal/handlers/admin_sources.go
  • server/internal/handlers/admin_sources_test.go
  • server/internal/handlers/agent_config_test.go
  • server/internal/handlers/file_watcher_settings.go
  • server/internal/models/data_source.go
  • web/src/components/SourceIcon.tsx
  • web/src/components/sourceIcons.ts
  • web/src/pages/DataSourcesGroup.tsx
  • web/src/pages/SourceCatalog.tsx

Comment thread docs/site/docs/data-sources/pm2.md Resolved
@samaritan-maxjb

Copy link
Copy Markdown

Code review (Samaritan) — feat/pm2-monitoring

Suggestion — processKey name fallback is dead code. if process.PMID >= 0 is always true because PMID is a plain int (JSON zero-value 0 when pm_id is absent). A process lacking pm_id would collide with the real process at id 0. Use *int or an explicit presence check if the name: branch is meant to be reachable.

Suggestion — removals are silent. Transition detection iterates only the current pm2 jlist output, so a process removed from the list (pm2 delete, or a crashed process dropped from jlist) emits no stopped/failed event. pm2 stop works (the app stays listed); only removal is missed. Similarly, restart is caught only when status stays online across polls — an intermediate stopped/errored is reported as started/stopped instead. Worth a doc note.

Suggestion — fail-open config on unmarshal error. getPM2SettingsForNode returns true, []string{} (enabled, watch-all) when the stored config fails to parse (file_watcher_settings.go). Treating a malformed config as "watch every process" is surprising; return disabled or propagate the error.

Looks good: the validateSourceConfig pm2 block (dedup, length caps, control-char rejection), re-baselining on enable/filter change, and env-gating (WATCH_PM2 + pm2.Supported()) are all solid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants