Telegraf SQL Database Input Prompt
Turn arbitrary SQL queries into metrics with inputs.sql — driver/DSN setup, mapping result columns to tags and fields, query scheduling, and timeouts — so business and DB-internal metrics flow into your TSDB without a custom exporter.
- Target user
- DBAs/data engineers exposing SQL query results as metrics via Telegraf
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT, Cursor
The prompt
You are a senior DBA/observability engineer who has exposed SQL-derived metrics through Telegraf's `inputs.sql` and knows how a careless monitoring query can hurt a production database. Help me build a safe, correct config.
I will provide:
- The database engine (Postgres/MySQL/MSSQL/ClickHouse/SQLite) and version
- The queries or business questions (row counts, queue depth, lag, revenue-per-minute, DB internals)
- The connection details and how sensitive the DB is
Deliver:
1. **Driver & DSN** — the correct `driver` and `dsn` format for my engine, with credentials from `${ENV}`/secretstore, connection pool/timeout settings, and TLS/sslmode.
2. **Query blocks** — `[[inputs.sql.query]]` with `query`, `measurement`, and the crucial `tag_columns` vs field mapping so identifying columns become tags and numeric columns become fields. Handle `field_columns_include`/`exclude` and column typing.
3. **Timestamps** — `time_column`/`time_format` to use a row's own timestamp where it exists, else collection time.
4. **Query safety** — least-privilege read-only role, EXPLAIN-verified queries, LIMIT/aggregation to bound result size and cardinality, and per-query `timeout`.
5. **Scheduling & cost** — `interval` per query (expensive analytics less often than cheap gauges), and how to avoid overlapping runs on a slow query.
6. **Cardinality control** — flag any tag_column (user id, order id) whose distinct values would explode series, and bucket/aggregate instead.
Output: (a) a commented `inputs.sql` TOML block with one or more query blocks, (b) the column→tag/field mapping table, (c) a query-cost/interval note, and (d) a `telegraf --test` validation and a reminder to run EXPLAIN first.
Bias toward: read-only least-privilege accounts, EXPLAIN-checked bounded queries, secret injection, and low-cardinality tag columns.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Telegraf Exec & Execd Custom Input Prompt
Build custom metric collectors with inputs.exec (run a script per interval) and inputs.execd (long-running streaming process) — choosing the right one, picking a data_format, and handling stdout/stderr, exit codes, and timeouts safely.
-
Choose and Design the Right Telegraf Input Plugin for a Source
Pick the best Telegraf input plugin for a given data source (an app, host, API, log, queue, or device) and produce a production-ready inputs configuration with the right tags, fields, interval, and parser — instead of guessing between exec, http, prometheus, and a native plugin.
-
Telegraf Docker Input Metrics Collection Prompt
Configure inputs.docker to collect per-container CPU, memory, network, and blkio metrics with the right label mapping, container filtering, and socket permissions — without drowning your TSDB in ephemeral-container cardinality.
-
Telegraf HTTP JSON Input Design Prompt
Poll REST/JSON HTTP endpoints with inputs.http and parse the response with json_v2 — mapping nested fields, arrays, and objects into well-tagged metrics with correct auth, timeouts, and failure handling.
More Telegraf prompts & error guides
Browse every Telegraf prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.