New to Kestra?
Use blueprints to kickstart your first workflows.
Automated MongoDB database profiler workflow to inspect system.profile, detect unindexed COLLSCAN queries, and alert Slack.
In high-scale MongoDB applications, missing indexes represent the primary cause of sudden cluster CPU spikes, replica set failovers, and cascading connection timeouts. When a query targets an unindexed field, the MongoDB query planner executes a full collection scan (COLLSCAN), inspecting every document in the collection from disk.
MongoDB includes an internal database profiler that logs slow operations and unindexed plan summaries to the system.profile capped collection. However, unless teams actively query this collection, unindexed operations go unnoticed until they cause production degradation.
This blueprint establishes an automated database profiler sentinel for MongoDB. Running every 15 minutes (or on-demand), it queries system.profile using an aggregation pipeline to detect operations executing with planSummary: /COLLSCAN/ that exceed your latency threshold. When detected, it dispatches an actionable Slack alert with the offending namespace, execution latency, and index creation guidance.
scheduled_profiler_audit trigger (io.kestra.plugin.core.trigger.Schedule) executes every 15 minutes, or runs on-demand via the Kestra UI.audit_profiler_entries task (io.kestra.plugin.mongodb.Aggregate) inspects system.profile using an aggregation pipeline, matching records where planSummary contains COLLSCAN and millis breaches slow_ms_threshold.evaluate_profiler_violations flowable task (io.kestra.plugin.core.flow.If) branches based on whether unindexed queries were returned.notify_dba_slack (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) delivers an actionable alert card with the namespace, operation type, duration, and indexing advice.log_nominal_status records nominal status in execution logs.export_profiler_manifest task records telemetry outputs for DBA dashboards.Monitoring MongoDB profiler collections typically requires setting up external log forwarders or custom monitoring agents. Kestra provides declarative, serverless orchestration: it connects directly via native MongoDB drivers, schedules regular inspections, conditionally alerts via Slack, securely handles connection strings, and maintains execution audit records.
| Name | Type | Default | Description |
|---|---|---|---|
database |
STRING | production |
MongoDB database where profiling is enabled. |
slow_ms_threshold |
INT | 100 |
Execution duration in milliseconds beyond which a query is flagged. |
slack_channel |
STRING | #dba-alerts |
Slack channel destination for MongoDB query performance alerts. |
{{ outputs.audit_profiler_entries.rows }}: Array of profiler records containing ns, op, planSummary, exec_time_ms, and client.{{ outputs.audit_profiler_entries.size }}: Total number of unindexed slow operations detected.{{ outputs.evaluate_profiler_violations }}: Result of conditional branch evaluation.{{ outputs.export_profiler_manifest.value }}: Structured JSON telemetry manifest recording execution timestamp and status.db.setProfilingLevel(1, { slowms: 100 })).system.profile collection.MONGODB_URI: MongoDB connection URI (e.g. mongodb+srv://<username>:<password>@cluster.mongodb.net/?retryWrites=true&w=majority).SLACK_WEBHOOK_URL: Slack Incoming Webhook endpoint URL used for sending alert notifications.db.setProfilingLevel(1, { slowms: 100 }).MONGODB_URI and SLACK_WEBHOOK_URL in your Kestra namespace secrets.db.setProfilingLevel(1, { slowms: 100 }) in mongosh prior to executing this blueprint.system.profile is a capped collection. When it reaches its maximum size (default 1MB), older entries are overwritten. Schedule this flow frequently (e.g., every 15 minutes) to ensure complete capture.io.kestra.plugin.github.issues.Create.