Skip to content
DevOps AI ToolKit
Newsletter
All prompts
AI for Telegraf Difficulty: Advanced ClaudeChatGPTCursor

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

More Telegraf prompts & error guides

Browse every Telegraf prompt and troubleshooting guide in one place.

Free download · 368-page PDF

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.