Skip to content

Commit d69d510

Browse files
committed
Add tutorial for exporting data from InfluxDB and importing into CrateDB
1 parent dffe8c8 commit d69d510

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

spikes/influxdb-to-cratedb/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.venv*
2+
*.wireproto
3+
*.py
4+
influxdb-write-to-postgresql

spikes/influxdb-to-cratedb/README.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# About
2+
Tutorial about migrating data from InfluxDB to CrateDB.
3+
4+
# Status
5+
This is a work in progress.
6+
7+
# Plan
8+
9+
- For creating data, use [tutorial_sine_wave.py].
10+
- For exporting data, use [influxdb-fetcher].
11+
- For importing data, use [influxdb-write-to-postgresql].
12+
13+
[tutorial_sine_wave.py]: https://github.com/influxdata/influxdb-python/blob/master/examples/tutorial_sine_wave.py
14+
[influxdb-fetcher]: https://github.com/hgomez/influxdb
15+
[influxdb-write-to-postgresql]: https://github.com/eras/influxdb-write-to-postgresql
16+
17+
18+
# Setup
19+
```sh
20+
# Install sine wave generator
21+
python3 -m venv .venv
22+
source .venv/bin/activate
23+
pip install influxdb
24+
wget https://raw.githubusercontent.com/influxdata/influxdb-python/master/examples/tutorial_sine_wave.py
25+
# Comment out the line `client.drop_database(DBNAME)` at line 60/61.
26+
27+
# Install InfluxDB Fetcher
28+
wget --no-clobber --output-document=/usr/local/bin/influxdb-fetcher https://raw.githubusercontent.com/hgomez/influxdb-fetcher/develop/bin/influxdb-fetcher
29+
chmod +x /usr/local/bin/influxdb-fetcher
30+
31+
# Install iw2pg: Build Docker image
32+
git clone https://github.com/eras/influxdb-write-to-postgresql
33+
cd influxdb-write-to-postgresql; docker build --tag iw2pg .; cd ..
34+
```
35+
36+
37+
# Run with PostgreSQL
38+
```sh
39+
# Run databases and iw2pg side by side
40+
docker run -it --rm --publish 8086:8086 influxdb:1.8.3
41+
docker run -it --rm --env "POSTGRES_HOST_AUTH_METHOD=trust" --publish 5432:5432 --name postgresql postgres:13.1
42+
docker run -it --rm --publish 8087:8086 --link postgresql --volume $PWD/iw2pg-config-postgresql.yaml:/app/config.yaml iw2pg --verbosity=info
43+
44+
# Create data
45+
python tutorial_sine_wave.py
46+
47+
# Export data
48+
influxdb-fetcher http://localhost:8086 root root tutorial "SELECT * FROM foobar" > foobar.wireproto
49+
50+
# Import data
51+
psql postgres://postgres:postgres@localhost --command='CREATE DATABASE tutorial;'
52+
cat foobar.wireproto | http http://localhost:8087/write?db=tutorial
53+
54+
# Verify data
55+
psql postgres://postgres:postgres@localhost/tutorial --command='SELECT * FROM foobar;'
56+
```
57+
58+
# Run with CrateDB
59+
```sh
60+
# Run databases and iw2pg side by side
61+
docker run -it --rm --publish 8086:8086 influxdb:1.8.3
62+
docker run -it --rm --publish 5432:5432 --name cratedb crate/crate:nightly
63+
docker run -it --rm --publish 8087:8086 --link cratedb --volume $PWD/iw2pg-config-cratedb.yaml:/app/config.yaml iw2pg --verbosity=info
64+
65+
# Create data
66+
python tutorial_sine_wave.py
67+
68+
# Export data
69+
influxdb-fetcher http://localhost:8086 root root tutorial "SELECT * FROM foobar" > foobar.wireproto
70+
71+
# Import data
72+
cat foobar.wireproto | http http://localhost:8087/write?db=tutorial
73+
```
74+
75+
76+
## Bummer
77+
```text
78+
Result status PGRES_FATAL_ERROR unexpected (expected status:PGRES_TUPLES_OK); ERROR: Relation 'pg_indexes' unknown
79+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
databases:
2+
tutorial:
3+
db_host: cratedb
4+
db_port: 5432
5+
db_name: tutorial
6+
db_user: crate
7+
db_password: crate
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
databases:
2+
tutorial:
3+
db_host: postgresql
4+
db_port: 5432
5+
db_name: tutorial
6+
db_user: postgres
7+
db_password: postgres
8+
9+
#create_table:
10+
# regexp: /.+/
11+
# method: create_table
12+
13+
fields_jsonb_column: null
14+
tags_jsonb_column: null
15+
16+
#field_columns:
17+
# - value
18+
# - field2

0 commit comments

Comments
 (0)