Skip to content

ImpossibleForge/pfc-export-influxdb

Repository files navigation

pfc-export-influxdb

License: MIT Python PFC-JSONL Version

One-shot CLI export from InfluxDB 2.x measurements to pfc-jsonl cold-storage archives.

The problem

You need to move a specific time range of InfluxDB metrics out of your hot bucket — for compliance, cost reduction, or long-term analysis. The InfluxDB CLI exports raw line protocol, which is hard to query later. Manual Flux scripts are error-prone. And without an index, any archive is a full-decompress situation.

What it does

pfc-export-influxdb runs a Flux query against your InfluxDB 2.x instance, streams the results to a compressed .pfc archive with a block-level timestamp index, and reports compression stats. One command, one archive, ready for DuckDB queries.

InfluxDB bucket → Flux query → JSONL → pfc_jsonl compress → .pfc + .pfc.bidx

Output is long format — one JSONL line per field-value record, tags preserved as columns:

{"timestamp": "2024-01-15T10:00:00Z", "_measurement": "cpu", "_field": "usage_idle", "_value": 97.2, "host": "web-01"}
{"timestamp": "2024-01-15T10:00:00Z", "_measurement": "cpu", "_field": "usage_user", "_value": 1.5,  "host": "web-01"}

Install

pip install pfc-export-influxdb
# or
pip install influxdb-client

Install the pfc_jsonl binary:

curl -L https://github.com/ImpossibleForge/pfc-jsonl/releases/latest/download/pfc_jsonl-linux-x64 \
     -o /usr/local/bin/pfc_jsonl && chmod +x /usr/local/bin/pfc_jsonl

Usage

Basic export — one measurement, one time range

pfc-export-influxdb \
  --url   http://localhost:8086 \
  --token MY_TOKEN \
  --org   my-org \
  --bucket my-bucket \
  --measurement cpu \
  --from-ts 2024-01-01T00:00:00Z \
  --to-ts   2024-04-01T00:00:00Z \
  --output  cpu_q1_2024.pfc

Export all measurements in a bucket

Omit --measurement to export everything in the bucket for the given range:

pfc-export-influxdb \
  --url http://localhost:8086 --token MY_TOKEN \
  --org my-org --bucket sensors \
  --from-ts 2024-01-01 --to-ts 2024-07-01 \
  --output sensors_h1_2024.pfc

InfluxDB Cloud

pfc-export-influxdb \
  --url   https://eu-central-1-1.aws.cloud2.influxdata.com \
  --token MY_CLOUD_TOKEN \
  --org   my-org \
  --bucket production-metrics \
  --measurement http_requests \
  --from-ts 2024-01-01 \
  --output  http_requests_2024.pfc --verbose

Python API

from pfc_export_influxdb import export_to_pfc

stats = export_to_pfc(
    url="http://localhost:8086",
    token="my-token",
    org="my-org",
    bucket="my-bucket",
    measurement="cpu",
    from_ts="2024-01-01T00:00:00Z",
    to_ts="2024-04-01T00:00:00Z",
    output_path="cpu_q1_2024.pfc",
    pfc_binary="/usr/local/bin/pfc_jsonl",
    verbose=True,
)
print(f"{stats['rows']:,} records → {stats['ratio_pct']:.1f}% of JSONL")

Config reference

Flag Required Default Description
--url InfluxDB URL (e.g. http://localhost:8086)
--token InfluxDB API token
--org Organization name
--bucket Source bucket
--from-ts Export start time (ISO 8601)
--measurement all Measurement name to filter on
--to-ts now Export end time (ISO 8601, exclusive)
--output auto Output .pfc path (default: {measurement}_{from}.pfc)
--pfc-binary auto Path to pfc_jsonl binary
--verbose false Show progress and compression stats

--from-ts and --to-ts accept: 2024-01-01, 2024-01-01T00:00:00, 2024-01-01T00:00:00Z

Querying archives with DuckDB

INSTALL pfc FROM community;
LOAD pfc;

-- Query a specific time window — only relevant blocks decompress
SELECT _measurement, _field, avg(_value) as avg_val, host
FROM pfc_scan('cpu_q1_2024.pfc')
WHERE timestamp BETWEEN '2024-02-01' AND '2024-02-28'
  AND _field = 'usage_idle'
GROUP BY _measurement, _field, host
ORDER BY avg_val DESC;

Part of the PFC Ecosystem

→ View all PFC tools & integrations

Direct integration Why
pfc-archiver-influxdb Daemon version — continuous automated archiving instead of one-shot
pfc-duckdb Query the archives this tool creates — time-range queries without full decompress
pfc-gateway HTTP REST query layer over .pfc archives — no DuckDB required

Disclaimer

pfc-export-influxdb is an independent open-source project and is not affiliated with, endorsed by, or associated with InfluxData, Inc. or the InfluxDB project.


License

pfc-export-influxdb (this repository) is released under the MIT License — see LICENSE.

The PFC-JSONL binary (pfc_jsonl) is proprietary software — free for personal and open-source use. Commercial use requires a license: info@impossibleforge.com

Releases

No releases published

Packages

 
 
 

Contributors

Languages