Skip to content

spuder/csv2influxdb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

csv2influxdb

![Gitter](https://badges.gitter.im/Join Chat.svg)

Converts a CSV file into JSON for influxdb

Usage

Pass in --help for full options

-d, --database      Influxdb database name (Required)
-i, --in            CSV filename to read in
-o, --out           JSON filename to output to 
-p, --pretty        Output pretty formatted json
-h, --help          Display this help message.

Installation

gem install csv2influxdb

or

git clone https://github.com/spuder/csv2influxdb.git
bundle install

Tested with ruby 2.0.0 on OSX, if you encounter issues with any other versions, please open a github issue

What it does

Takes a csv:

year internet-explorer-usage murders-per-capita
2014 67 60
2015 51 55
2016 42 45

Outputs json with influxdb table headers (name,columns,points)

{
    "name": "murders",
    "columns": [
        "year",
        "internet-explorer-usage",
        "murders-per-capita"
    ],
    "points": [
        [
            "2014",
            "67",
            "60"
        ],
        [
            "2015",
            "51",
            "55"
        ],
        [
            "2016",
            "42",
            "45"
        ]
    ]
}

Examples

#####From CSV file, to JSON file

csv2influxdb -d derp -i murders.csv -o /tmp/influxdb_murders.json

#####Use stdin -> stdout

echo '"year","internet_explorer_usage","murders_per_capita"
2004,67,60
2005,51,55
2006,42,45' | csv2influxdb -d derp
{"name":"derp","columns":["year","internet_explorer_usage","murders_per_capita"],"points":[["2004","67","60"],["2005","51","55"],["2006","42","45"]]}

Obviously the stdin/stdout option won't work well for large amounts of data

#####Pretty

csv2influxdb -p -d derp -i foo.csv -o /tmp/bar.json

Avoid using -p unnecessarily since it wastes network bandwidth

Migrating Data

  • Export data from your relational database to csv.
  • Use csv2influxdbto convert to json
  • Use a tool like influxdb-backup to import push to influxdb

Why

There are plently of online csv to json converters, why not just use that one?

I tried all the online converters (this is the best one), but none of them could quite convert a csv into json that was compatible with influxdb. (no column headers, no json with multiple keys)

###Legal csv2influxdb is created by spuder, a fan of influxdb. It comes with no guarantee. It is a community project and is not supported nor afiliated with the creators of influxdb.

About

Converts a CSV file into json for influxdb

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages