Skip to content
DevOps AI ToolKit
Newsletter
All guides
AI for Telegraf By James Joyner IV · · 8 min read

Telegraf Error Guide: 'took longer to collect than collection interval' — Fix Slow Inputs

Quick answer

Fix Telegraf 'took longer to collect than collection interval': give slow inputs their own interval, tune timeouts, split heavy plugins, and stop skipped collections and gaps in metrics.

  • #telegraf
  • #monitoring
  • #troubleshooting
  • #errors
Free toolkit

Fixing errors like this? Get 500 free DevOps AI prompts

500 copy-paste AI prompts for the stack you actually run — one PDF, free.

Overview

Each Telegraf input is scheduled to gather on its interval. If a plugin’s gather takes longer than that interval, the next scheduled collection can’t start on time and Telegraf warns you:

2026-07-11T12:00:00Z W! [inputs.snmp] took longer to collect than collection interval (10s)

The gather is running long — an SNMP walk, an exec script, or a SQL query that just can’t finish in the window. Collections start overlapping or get skipped, producing uneven sample spacing and gaps in dashboards. This is a collection-side bottleneck, distinct from slow output flushing.

Symptoms

  • Repeated took longer to collect than collection interval warnings naming a specific input.
  • Uneven timestamps / gaps for that input’s series while other inputs stay steady.
  • Rising gather_time_ns for that plugin in the internal metrics.
  • CPU spikes on the Telegraf host when the slow plugin runs.
  • Timeouts inside the plugin (inputs.exec killed, SNMP request timeout, SQL query cancelled).

Common Root Causes

  • interval too aggressive for the work — a 10s interval on a wide SNMP table walk or a heavy DB query.
  • A slow remote or device — SNMP gear, a loaded database, or an HTTP endpoint that responds slowly.
  • One plugin doing too much — a single inputs.snmp covering many devices/OIDs, or one exec doing everything serially.
  • Missing or too-long plugin timeout, so a stuck target consumes the whole interval.
  • Expensive script/query — an exec/execd command or SQL statement without an index or limit.
  • Resource contention on the agent host (CPU, DNS, disk) inflating gather time.

How to diagnose

Enable the internal plugin and read the actual gather time per input:

[[inputs.internal]]
  collect_memstats = true
telegraf --config /etc/telegraf/telegraf.conf --test --input-filter internal \
  | grep -E 'gather_time_ns|errors'

Time a single collection of just the slow plugin to get a real number:

time telegraf --config /etc/telegraf/telegraf.conf --test --input-filter snmp >/dev/null

Watch the warnings live to see which input and how often:

journalctl -u telegraf -f | grep -iE 'took longer|collect|gather'

If the measured gather (say 18s) exceeds the plugin’s interval (10s), you’ve confirmed the cause.

Fixes

1. Give the slow input its own longer interval instead of slowing the whole agent:

[[inputs.snmp]]
  interval = "60s"          # slow walk polls less often; agent stays at 10s
  agents = ["udp://10.0.0.1:161"]
  version = 2
  community = "${SNMP_COMMUNITY}"
  timeout = "5s"
  retries = 1

2. Set a plugin timeout so a stuck target can’t eat the whole interval:

[[inputs.exec]]
  commands = ["/opt/collectors/metrics.sh"]
  timeout = "8s"            # kill a hung script before it overruns
  data_format = "influx"

3. Split one heavy plugin into several scoped instances so work parallelizes and each finishes fast:

[[inputs.snmp]]
  interval = "60s"
  agents = ["udp://10.0.0.1:161", "udp://10.0.0.2:161"]
  # ... core scalars only

[[inputs.snmp]]
  interval = "300s"         # the expensive full table walk, polled rarely
  agents = ["udp://10.0.0.1:161"]
  # ... ifTable / vendor tables

4. Make the underlying work cheaper — scope SNMP walks to explicit indexes, add an index or LIMIT to a SQL input query, or cache in an execd long-running collector instead of spawning a process each interval.

5. Move genuinely long jobs to execd/inputs.file — have an external cron write results to a file Telegraf tails cheaply, decoupling the expensive job from the collection interval.

What to watch out for

  • Don’t just widen the whole [agent] interval — that degrades resolution for every healthy input; scope the change to the slow plugin.
  • A plugin timeout longer than its interval defeats the purpose; keep timeout < interval.
  • Overlapping collections can duplicate or reorder samples — confirm sample spacing is even after the fix.
  • Alert on internal_gather.gather_time_ns per input so a slowly degrading source is caught before it starts skipping.
  • Splitting an SNMP/exec plugin multiplies connections/processes; watch device and host load after sharding.

More fixes in the Telegraf guides.

Free download · 368-page PDF

Get 500 Battle-Tested DevOps AI Prompts — Free

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.