IMD SolutionComputing LibraryShop main store

Explainer

Why Telegraf re-imports a static CSV every 10 seconds

Edge computing and IIoT Published 6 min read By IMD Solution engineering team

Short answer

The agent interval is a collection schedule, not a one-shot import: every cycle the file input re-reads the whole CSV and emits the same rows again. With timestamps taken from the file, InfluxDB overwrites identical points, so the database stays flat while the write load never stops. Import once and stop the agent, or feed it a file that only gains new rows.

On this page
  1. The interval is a collection schedule, not an import trigger
  2. What the log lines prove
  3. Why the database stays flat while the writes continue
  4. Prove the parse before blaming the output
  5. Match the parser settings to the file
  6. Worked example: the write load for 249 rows on a 10 s interval
  7. One import or continuous collection
  8. Questions asked

Nothing is broken: the import worked the first time, and Telegraf has been repeating it ever since. Every cycle the agent runs each loaded input again, and the file input re-reads the whole CSV and turns every row into metrics again, whether or not anything changed. With a static file, the same batch is rewritten on every cycle until you stop the process. Because the point timestamps come from the file, InfluxDB overwrites the same points each time, so the database stays flat while the writes never stop. The fix is a decision, not a setting: for a one-time import, stop after the first full batch; for ongoing data, feed Telegraf a file that only ever gains new rows.

The interval is a collection schedule, not an import trigger #

The interval printed at startup comes from the [agent] section of your configuration, and it means one thing: for as long as the process runs, the agent repeats a full collection cycle at that period. The file input is a polling input. Each cycle it reads the listed files in full and hands the content to a configurable parser, which emits one metric per data row again. Nothing on that path records what was already delivered — there is no imported flag and no saved read position — so an unchanged file produces an identical batch every cycle.

The documentation defines the interval as the period between collections, and the project's issue tracker carries reports like number 3492, filed when an input does not poll at its configured cadence. No documented agent or file-input option turns the read into a one-shot import. A longer interval slows the replay; it never ends it.

What the log lines prove #

The startup and cycle output answers the whole question if you read it line by line:

Log line What it proves What it does not prove
Loaded inputs: file the file input is configured and active that the file parses
Loaded outputs: influxdb an InfluxDB output is configured that it connected
Successfully connected to outputs.influxdb the agent reached the database that any metric was written
Interval:10s the agent collects on a fixed period that the file changed between cycles
Wrote batch of 249 metrics, again and again the parser emitted the full row count and the output accepted it that any of the data is new

Read together, these lines describe a healthy pipeline doing exactly what it was configured to do, repeatedly. The replay is the only defect, and it is a workflow defect, not a parsing one.

Why the database stays flat while the writes continue #

InfluxDB identifies each point by its measurement, tag set and timestamp; a write that repeats all three replaces the stored point instead of adding a new one. The configuration takes its timestamps from the file's time column, through csv_timestamp_column = "time", so every cycle submits points with the same identity and the same values. Each write overwrites the last one, and a query returns one point per row however long the agent runs. That identity rule is general: it is also why Telegraf writes one InfluxDB point from 80 MQTT entries when the entries share a timestamp.

Remove the timestamp option and the behavior flips. The parser then stamps each metric with the collection time, every cycle lands at a new timestamp, and the series grows by the full row count on every cycle. Neither variant is what a one-time import wants: the first hides the replay, the second multiplies it.

Prove the parse before blaming the output #

Run telegraf --test before any real run. Test mode gathers each input once, prints the resulting metrics to the terminal and skips the outputs entirely, so it answers exactly one question: does every row of the file parse with the current settings? If it does, the parser side is finished. Delivery is proven separately, by the connection line and the first Wrote batch message of a real run started with telegraf --config telegraf.conf. A connection that never produces a batch message is the opposite failure — the case where a Telegraf MQTT consumer connects but writes no data to InfluxDB — and it points downstream of the parser, not at the CSV.

Match the parser settings to the file #

The file input is one of Telegraf's general-purpose plugins that parse their data with a configurable parser, and the CSV parser has its own option set. The draft configuration from the case:

[[inputs.file]]
  files = ["example"]
  data_format = "csv"
  csv_skip_rows = 2
  csv_skip_columns = 0
  csv_delimiter = ";"
  csv_header_row_count = 2
  csv_timestamp_column = "time"
  csv_timestamp_format = "2006-01-02T15:04:05Z07:00"

Each value must match the actual file, verified in test output rather than assumed. files lists the CSVs to read, and example must become the path of the file you are importing. csv_delimiter = ";" overrides the parser's comma default because this file is semicolon-separated. csv_skip_rows = 2 drops two rows ahead of the headers, and csv_header_row_count = 2 builds the metric names from two header rows. The timestamp pair takes the point time from the time column and reads it with the reference layout shown. If the test prints only the final row of the file, the header and skip counts are the first suspects — the failure covered in why Telegraf inputs.file writes only the last CSV line.

Worked example: the write load for 249 rows on a 10 s interval #

The inputs, with where each comes from:

  • Row count: 249 data rows — the example file in the case, confirmed by the batch message.
  • Collection interval: 10 s — the startup log line.
  • Point identity: timestamps taken from the file's time column, per the configuration above, so every cycle submits the same points.

The rule, in words: cycles per hour equal the seconds in an hour divided by the interval; point-writes per hour equal the row count times the cycles per hour; and the distinct stored points stay equal to the row count, because identical identities overwrite.

The arithmetic:

  • 3600 s ÷ 10 s = 360 cycles per hour
  • 249 rows × 360 cycles per hour = 89,640 point-writes per hour
  • 89,640 × 24 = 2,151,360 point-writes per day
  • distinct points stored: the full row count, unchanged since the first cycle

Result: the agent performs 89,640 writes per hour, 2,151,360 per day, and the stored data never changes.

Decision, with its threshold: a continuous poll earns its place only when the file gains at least one new row per interval on average. Below that rate, run one import per file — start the agent, wait for the first full batch message, stop it. For a file that never changes the arrival rate is zero, so the continuous run is pure write load.

One import or continuous collection #

The decision for each case:

  • The file is finished and static, as in this case: run telegraf --config telegraf.conf, wait for the first Wrote batch message carrying the full row count, then stop with CTRL+C. The import is done; the agent has nothing left to do.
  • A new file appears occasionally: launch one run per file from whatever writes it, the generating script or a scheduled task, so each run imports one batch and exits.
  • Rows keep arriving in one growing file: replace the whole-file read with an input that follows the growing file and parses only the appended lines, and let the agent run continuously.

Whatever you choose, keep the two facts apart: the interval controls how often Telegraf works, and only the source decides whether that work produces anything new.

Questions asked

Does stopping Telegraf with CTRL+C lose the final batch?

No. On CTRL+C the agent flushes its buffer before it exits, and the log proves it: the buffer drains to 0 / 10000 metrics and the agent then reports Stopped Successfully. Those two lines are the evidence that the last batch reached the output. Stop only after the first full batch message, and treat the import as complete when the stopped line appears.

Is there an interval setting that makes the CSV import run only once?

No. The interval only sets the period between collections, so a longer one slows the replay without ending it. With a 60 s interval the file would still be read 60 times per hour, 3600 s divided by 60 s, one sixth of the write load and no new data at all. One-shot behavior comes from stopping the agent after the first batch or from an input that reads only appended lines.

The test run prints every row, so why is InfluxDB still empty?

Test mode prints the parsed metrics and never touches the outputs, so a full printout proves the CSV settings only. Delivery needs a real run with the config file; there, the connection line and a wrote-batch message are the evidence. If the connection succeeds and no batch message ever appears, the fault sits downstream of the parser, in the output or the network path, and no change to the CSV options will fix it.

Can a retention policy clean up the repeated writes?

It cannot, because there are no duplicate points to remove: with timestamps taken from the file, each cycle overwrites the same points and the stored count stays equal to the row count. A retention policy drops points by age, so it would delete the imported history, not the replay. Remove the replay at the source instead, by stopping the agent after one batch or by feeding it new rows only.

Keep reading

  • Explainer

    What one Telegraf point really costs on InfluxDB disk

    InfluxDB writes points into compressed columns, so nothing in a query reports the bytes one stored point occupies. Trim each point to value, timestamp and topic tag, measure one sensor's compacted size over a test week, and scale it by the point count that your interval, sensor count and retention days produce.

    Edge computing and IIoT

  • Troubleshooting

    Telegraf MQTT consumer connects but writes no data to InfluxDB

    An empty 0 / 10000 output buffer with both the MQTT and InfluxDB connections up means no metrics are reaching Telegraf's parser. Prove live delivery with a second subscriber on a different client ID before touching parser or buffer settings: the two startup connections are independent events, and with qos = 0 and a non-persistent session, traffic published while Telegraf is offline is unrecoverable.

    Edge computing and IIoT

  • How-to

    Build multidimensional arrays in Node-RED for InfluxDB writes

    Cache each subscription's last value per point, re-emit it on a 100 ms inject tick, batch 10 samples per point and join them into one multidimensional array, then format line protocol in a single function node so one influxdb out node writes the whole batch. Ten points at a 100 ms tick become one 100-line write per second; the demonstrated flow neared Node-RED's limit at 80 points.

    Edge computing and IIoT

Log one-second trends and one-minute reports in one historian