HUB
Sign inSign up

mcarvin8/sfmon

By mcarvin8

•Updated 24 days ago

Monitor a Salesforce org and expose Prometheus metrics from a long-running Python service.

Image
0

4.3K

mcarvin8/sfmon repository overview

⁠Salesforce Monitoring (SFMon)

Docker Image Version Docker Pulls Docker Image Size PyPI Version PyPI - Python Version PyPI Downloads GitHub Marketplace Coverage

SFMon watches your Salesforce orgs and exposes what it finds as Prometheus metrics on :9001/metrics, so Salesforce shows up in the same dashboards and alerts as the rest of your infrastructure. It's one process with no database and no UI: your Prometheus-compatible backend stores the history, and Grafana shows it.

It's built for SRE and DevOps teams that already run Prometheus (or Victoria Metrics, Grafana Cloud, an OTel Collector) and look after one or more Salesforce orgs.

Warning

**Upgrading from v3?** v4 renamed every metric to start with `sfmon_`. Values are unchanged. See the [migration guide](https://github.com/mcarvin8/sfmon/blob/main/docs/METRICS_MIGRATION.md) for the old → new names and optional rules that keep v3 queries working.

⁠What you get

AreaWhat's measured
Governor limitsEvery org limit (API requests, bulk queries, data storage, ...) as used, max and % used, every 5 minutes
Apex healthFlex queue depth, long-running requests, concurrency errors, uncaught exceptions, async job status
Bulk APIDaily and hourly activity across Bulk API 1.0 and 2.0
LicensesUser licenses, permission set licenses and usage-based entitlements: used vs. total
Instance & TrustYour org's pod, active incidents from trust.salesforce.com, scheduled maintenance
Security & complianceForbidden profile assignments, logins, suspicious audit trail activity, report exports, large SOQL queries, org-wide sharing changes
Tech debtDormant users, deprecated Apex API versions, unused permission sets, workflow rules, empty queues and groups, PMD violations
DeploymentsDeployment and validation status and timing
SFMon itselfWhether each job's last run succeeded, when it last succeeded, and how long it took

All of these run on default schedules with no config file. The exceptions are PMD and minimal permission set reports, which need files you generate (Advanced setup⁠).

⁠Quick start

⁠1. Get an auth URL for the org

Use a dedicated monitoring user with API access. Making it an API Only User whose password never expires stops it from being locked out. It needs read access to whatever you want monitored; step 5 shows how to spot anything it can't see.

Log in to the org as that user with the Salesforce CLI, then print its auth URL:

sf org login web --alias sfmon-prod
sf org auth show-sfdx-auth-url --target-org sfmon-prod --no-prompt

The URL (force://...) is a long-lived credential: store it as a secret. The CLI is only needed for this step; SFMon doesn't use it at runtime. The URL is only available for orgs logged in with sf org login web.

⁠2. Run SFMon

Run the Docker image with the environment variables:

docker run -d --name sfmon -p 9001:9001 \
  -e SALESFORCE_AUTH_URL="force://..." \
  -e ORG_NAME="production" \
  mcarvin8/sfmon:latest

ORG_NAME becomes the org label on every metric.

Prefer not to use Docker? Install the package, set environment variables, and run the Python module:

pip install sfmon
SALESFORCE_AUTH_URL="force://PlatformCLI::..." 
ORG_NAME="production" 
python3 -m sfmon.salesforce_monitoring

Check it's up: curl http://localhost:9001/metrics

⁠3. Scrape it

Add SFMon to prometheus.yml:

scrape_configs:
  - job_name: sfmon
    static_configs:
      - targets: ["<host>:9001"]

No Prometheus to scrape with? Set OTEL_EXPORTER_OTLP_ENDPOINT and SFMon pushes metrics and logs over OTLP instead (details⁠).

⁠4. Import the dashboards

Import the JSON files in grafana/⁠ into Grafana and point them at your Prometheus data source. There are three: monitoring (limits, licenses, Apex, Bulk API, page times), audit, and tech debt.

⁠5. Check every job can do its work

After the first run (a few minutes), any job that failed or couldn't run its queries reports 0 here:

sfmon_job_success == 0

The usual cause is the monitoring user lacking access to an object or event log. SFMon's logs show the job and the error Salesforce returned. Fix the permission and the next run reports 1.

⁠Next steps

To...See
Alert in PromQL, alert on SFMon itself, or post to Slack without AlertmanagerAlerting⁠
Monitor several orgs from one containerMultiple orgs⁠
Run once from a CI cron job or GitHub Action instead of a daemonOne-shot mode⁠
Add your own SOQL metrics (CPQ, custom objects) without building an imageCustom metrics⁠
Run only some jobs (ops, audit, tech-debt presets) or change schedulesConfiguration⁠
Tune thresholds and timeouts, or read the auth URL from AWS Secrets ManagerEnvironment variables⁠
Add PMD and permission-set reports, or build your own imageAdvanced setup⁠
Move dashboards and alerts from v3 metric namesMigration guide⁠

Metrics vs. logs: metrics answer "is something wrong right now" and keep labels low-cardinality. The per-record detail behind them (which user, which deployment, login coordinates) goes to stdout as JSON log lines under an event field, for Loki, CloudWatch Logs, Datadog or any JSON log pipeline.

⁠How it compares

SFMonSalesforce proactive monitoring (paid)sfdx-hardis org monitoring
ModelAlways-on process serving /metrics, or a scheduled CI job via --onceSalesforce TAM/CSM engagement + event log filesScheduled CI jobs
OutputTime-series metricsSalesforce reports and guided reviewsGit diffs, Slack/Teams notifications, pipeline artifacts
AlertingPromQL + Alertmanager, or built-in SlackSalesforce notifications and reviewsSlack/Teams from CI
Data stays in your stackYesNoPartly
CostFree; you run the container or CI jobPaid add-onFree; you run the CI job
Best forTeams on Prometheus who want Salesforce as another scrape targetTeams buying Salesforce-managed oversightMetadata backup and drift detection in CI

SFMon and sfdx-hardis work well together: Hardis handles metadata backup and change detection, SFMon provides continuous time series.

⁠Authors

Originally developed by Deep Suthar and Matt Carvin (e.g. ECS / Kubernetes at Avalara).

Tag summary

Content type

Image

Digest

sha256:58888e588…

Size

122.2 MB

Last updated

24 days ago

docker pull mcarvin8/sfmon