id: surrealdb-table-record-high-watermark-and-storage-sentinel
namespace: company.data
labels:
env: production
system: surrealdb
category: data-platform
inputs:
- id: surrealdb_host
type: STRING
displayName: SurrealDB Host
description: Hostname or IP address of the SurrealDB server.
defaults: localhost
- id: surrealdb_namespace
type: STRING
displayName: SurrealDB Namespace
description: Target SurrealDB namespace containing the database and table.
defaults: analytics
- id: surrealdb_database
type: STRING
displayName: SurrealDB Database
description: Target SurrealDB database name.
defaults: production
- id: surrealdb_username
type: STRING
displayName: SurrealDB Username
description: Username used to authenticate against SurrealDB.
defaults: root
- id: target_table
type: STRING
displayName: Target Table
description: Name of the SurrealDB table to audit for record count and capacity
saturation.
defaults: events
- id: warning_threshold_records
type: INT
displayName: Warning Record Threshold
description: Record volume threshold that triggers a WARNING alert.
defaults: 50000
- id: critical_threshold_records
type: INT
displayName: Critical Record Threshold
description: Record volume threshold that triggers a CRITICAL quota incident alert.
defaults: 100000
- id: alert_on_warning
type: BOOL
displayName: Alert on Warning
description: Whether to dispatch Slack notifications for WARNING states in
addition to CRITICAL breaches.
defaults: true
triggers:
- id: periodic_capacity_schedule
type: io.kestra.plugin.core.trigger.Schedule
description: Periodic schedule trigger polling SurrealDB table metrics every 30 minutes.
cron: "*/30 * * * *"
disabled: true
inputs:
surrealdb_host: "localhost"
surrealdb_namespace: "analytics"
surrealdb_database: "production"
surrealdb_username: "root"
target_table: "events"
warning_threshold_records: 50000
critical_threshold_records: 100000
alert_on_warning: true
tasks:
- id: probe_table_record_metrics
type: io.kestra.plugin.surrealdb.Query
description: Execute a SurrealQL aggregation query to calculate total record
count and capture table capacity metrics. port is hard-coded to 8000
because it is a plain int property on the connection, not a Property<T>,
so it does not accept a Pebble expression; change it here directly if your
instance uses a different port.
host: "{{ inputs.surrealdb_host }}"
port: 8000
username: "{{ inputs.surrealdb_username }}"
password: "{{ secret('SURREALDB_PASSWORD') }}"
namespace: "{{ inputs.surrealdb_namespace }}"
database: "{{ inputs.surrealdb_database }}"
query: "SELECT count() AS total_records FROM {{ inputs.target_table }} GROUP ALL;"
fetchType: FETCH_ONE
- id: probe_table_schema_indexes
type: io.kestra.plugin.surrealdb.Query
description: Inspect table schema definitions and index configurations in
SurrealDB. port is hard-coded to 8000 for the same reason as
probe_table_record_metrics; change it here directly if your instance uses
a different port.
host: "{{ inputs.surrealdb_host }}"
port: 8000
username: "{{ inputs.surrealdb_username }}"
password: "{{ secret('SURREALDB_PASSWORD') }}"
namespace: "{{ inputs.surrealdb_namespace }}"
database: "{{ inputs.surrealdb_database }}"
query: "INFO FOR TABLE {{ inputs.target_table }};"
fetchType: FETCH_ONE
- id: classify_capacity_status
type: io.kestra.plugin.core.log.Log
description: Evaluate table record metrics against operational high-watermark
thresholds.
message: |
SurrealDB Capacity Evaluation for Table '{{ inputs.target_table }}':
- Record Count: {{ outputs.probe_table_record_metrics.row.total_records ?? 0 }}
- Warning Threshold: {{ inputs.warning_threshold_records }}
- Critical Threshold: {{ inputs.critical_threshold_records }}
- Active Indexes: {{ outputs.probe_table_schema_indexes.row.indexes | json }}
- id: route_by_saturation_level
type: io.kestra.plugin.core.flow.Switch
description: Branch flow execution based on SurrealDB table record volume
relative to high-watermark quotas.
value: "{{ (outputs.probe_table_record_metrics.row != null and
outputs.probe_table_record_metrics.row.total_records != null and
outputs.probe_table_record_metrics.row.total_records >=
inputs.critical_threshold_records) ? 'CRITICAL' :
((outputs.probe_table_record_metrics.row != null and
outputs.probe_table_record_metrics.row.total_records != null and
outputs.probe_table_record_metrics.row.total_records >=
inputs.warning_threshold_records) ? 'WARNING' : 'HEALTHY') }}"
cases:
CRITICAL:
- id: log_critical_saturation
type: io.kestra.plugin.core.log.Log
level: ERROR
message: "CRITICAL: Table '{{ inputs.target_table }}' has reached {{
outputs.probe_table_record_metrics.row.total_records }} records,
breaching the critical quota of {{ inputs.critical_threshold_records
}}!"
- id: alert_slack_critical
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Dispatch urgent high-priority incident alert to Slack on critical
quota breach.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "CRITICAL: SurrealDB Table '{{ inputs.target_table }}' breached record capacity quota!",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "SurrealDB Capacity Alert: CRITICAL Quota Breach",
"emoji": true
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Namespace / Database:*\n{{ inputs.surrealdb_namespace }} / {{ inputs.surrealdb_database }}"
},
{
"type": "mrkdwn",
"text": "*Target Table:*\n`{{ inputs.target_table }}`"
},
{
"type": "mrkdwn",
"text": "*Current Record Count:*\n*{{ outputs.probe_table_record_metrics.row.total_records }}*"
},
{
"type": "mrkdwn",
"text": "*Critical Quota Limit:*\n{{ inputs.critical_threshold_records }}"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Recommended Remediation:* Archive aged records, purge unneeded event logs, or provision additional SurrealDB storage volume."
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "Execution: {{ execution.id }} | Flow: {{ flow.id }} | Host: {{ inputs.surrealdb_host }}"
}
]
}
]
}
WARNING:
- id: log_warning_saturation
type: io.kestra.plugin.core.log.Log
level: WARN
message: "WARNING: Table '{{ inputs.target_table }}' has reached {{
outputs.probe_table_record_metrics.row.total_records }} records,
exceeding warning threshold of {{ inputs.warning_threshold_records
}}."
- id: alert_slack_warning
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Dispatch warning alert to Slack when warning capacity threshold is
exceeded.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
runIf: "{{ inputs.alert_on_warning }}"
payload: |
{
"text": "WARNING: SurrealDB Table '{{ inputs.target_table }}' capacity warning threshold exceeded.",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "SurrealDB Capacity Warning: High-Watermark Alert",
"emoji": true
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Table:*\n`{{ inputs.target_table }}`"
},
{
"type": "mrkdwn",
"text": "*Record Count:*\n{{ outputs.probe_table_record_metrics.row.total_records }}"
},
{
"type": "mrkdwn",
"text": "*Warning Threshold:*\n{{ inputs.warning_threshold_records }}"
},
{
"type": "mrkdwn",
"text": "*Critical Limit:*\n{{ inputs.critical_threshold_records }}"
}
]
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "Execution: {{ execution.id }} | Namespace: {{ flow.namespace }}"
}
]
}
]
}
HEALTHY:
- id: log_healthy_capacity
type: io.kestra.plugin.core.log.Log
message: "SurrealDB table '{{ inputs.target_table }}' capacity is HEALTHY: {{
outputs.probe_table_record_metrics.row.total_records ?? 0 }} records
(below warning threshold of {{ inputs.warning_threshold_records
}})."
- id: log_audit_summary
type: io.kestra.plugin.core.log.Log
description: Record a permanent audit log entry summarizing the capacity scan
for governance and trend analysis.
message: |
SURREALDB TABLE CAPACITY AUDIT SUMMARY:
- Execution ID: {{ execution.id }}
- Database: {{ inputs.surrealdb_namespace }}/{{ inputs.surrealdb_database }}
- Table: {{ inputs.target_table }}
- Record Count: {{ outputs.probe_table_record_metrics.row.total_records ?? 0 }}
- Status: {{ (outputs.probe_table_record_metrics.row != null and outputs.probe_table_record_metrics.row.total_records != null and outputs.probe_table_record_metrics.row.total_records >= inputs.critical_threshold_records) ? 'CRITICAL' : ((outputs.probe_table_record_metrics.row != null and outputs.probe_table_record_metrics.row.total_records != null and outputs.probe_table_record_metrics.row.total_records >= inputs.warning_threshold_records) ? 'WARNING' : 'HEALTHY') }}
- Timestamp: {{ now() }}
errors:
- id: alert_flow_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Dispatch emergency alert to Slack if SurrealDB connection or probe
execution fails.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "ERROR: SurrealDB Capacity Sentinel failed during execution {{ execution.id }}. Check Kestra execution logs."
}
- id: log_failure_context
type: io.kestra.plugin.core.log.Log
level: ERROR
message: "SurrealDB Table Capacity Sentinel failed during probe execution for
table {{ inputs.target_table }} on host {{ inputs.surrealdb_host }}."