Skip to content

Instantly share code, notes, and snippets.

@smly
Last active January 19, 2016 01:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save smly/7334560 to your computer and use it in GitHub Desktop.
Save smly/7334560 to your computer and use it in GitHub Desktop.
a Dockerfile to build InfluxDB container

Build InfluxDB container

$ git clone https://gist.github.com/7334560.git
$ cd 7334560
$ docker build .
[snip]
Successfully built bc16b7ab3dbd

$ docker run bc16b7ab3dbd
2013/11/06 13:46:49 Loading Config from config.json.sample
2013/11/06 13:46:49 Starting Influx Server...
2013/11/06 13:46:49 Opening database at  /tmp/influxdb/development/db
2013/11/06 13:46:49 Initializing Raft HTTP server
2013/11/06 13:46:49 Listening at: http://localhost:8090
2013/11/06 13:46:49 Initializing Raft Server: /tmp/influxdb/development/raft 8090
2013/11/06 13:46:49 Couldn't contact a leader so initializing new cluster for server on port:  8090
2013/11/06 13:46:50
2013/11/06 13:46:50 Starting admin interface on port 8083
2013/11/06 13:46:50 Starting Http Api server on port 8086

Using InfluxDB's HTTP API with Python-client

$ git clone http://github.com/influxdb/influxdb-python && cd influxdb-python
$ git checkout v0.1.1

$ python --version
Python 2.7.3
$ virtualenv venv
$ source venv/bin/activate

$ python setup.py install
$ python examples/tutorial.py --host=172.17.0.57 --port=8086
Create database: example
Get list of database users: []
Add database user: smly
Get list of database users again: [{u'username': u'smly'}]
Swtich user: smly
Write points: [{'points': [['1', 1, 1.0], ['2', 2, 2.0]], 'name': 'foo', 'columns': ['column_one', 'column_two', 'column_three']}]
Queying data: select column_one from foo;
Result: [{"name":"foo","columns":["time","sequence_number","column_one"],"points":[[1383886725,2,"2"],[1383886725,1,"1"]]}]
Swtich user: root
Delete database: example

Using InfluxDB's HTTP API with python-requests

$ virtualenv venv
$ source venv/bin/activate
$ pip install requests
$ python
Python 2.7.5+ (default, Sep 19 2013, 13:48:49)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> import json
>>>
>>> data = [
...   {
...     "name": "events",
...     "columns": ["state", "email", "type"],
...     "points": [
...       ["ny", "paul@influxdb.org", "follow"],
...       ["ny", "todd@influxdb.org", "open"]
...     ]
...   },
...   {
...     "name": "errors",
...     "columns": ["class", "file", "user", "severity"],
...     "points": [
...       ["DivideByZero", "example.py", "someguy@influxdb.org", "fatal"]
...     ]
...   }
... ]
>>> url = 'http://172.17.0.47:8086'
>>> headers={'Content-type': 'application/json', 'Accept': 'text/plain'}

>>> ########
>>> ### Create database
>>> resp = requests.post(url + '/db?u=root&p=root', data=json.dumps({'name': 'development'}), headers=headers)
>>> resp
<Response [201]>
>>> resp.content
''

>>> ########
>>> ### Get list of database users
>>> resp = requests.get(url + '/db/development/users?u=root&p=root')
>>> resp
<Response [200]>
>>> resp.content
'[]'

>>> ########
>>> ### Add database user ('user' is not expected, but this request is accepted...)
>>> resp = requests.post(url + '/db/development/users?u=root&p=root', data=json.dumps({'user': 'smly', 'password': 'standardml'}), headers=headers)
>>> resp
<Response [200]>
>>> resp.content

>>> ########
>>> ### Get list of database users. wow, a ghost user '' is listed.
>>> ### (Resolved after https://github.com/influxdb/influxdb/commit/d7628935a)
>>> resp = requests.get(url + '/db/development/users?u=root&p=root')
>>> resp.content
'[{"username":""}]'

>>> ########
>>> ### Add database user again. 'username' is expected.
>>> resp = requests.post(url + '/db/development/users?u=root&p=root', data=json.dumps({'username': 'smly', 'password': 'standardml'}), headers=headers)

>>> resp = requests.get(url + '/db/development/users?u=root&p=root')
>>> resp.content
'[{"username":""},{"username":"smly"}]'

>>> ### Can't delete the ghost user...
>>> ### (Resolved after https://github.com/influxdb/influxdb/commit/d7628935a)
>>> resp = requests.delete(url + '/db/development/users/?u=root&p=root')
>>> resp
<Response [404]>
>>> resp.content
'404 page not found\n'

>>> ### Add data points.
>>> resp = requests.post(url + '/db/development/series?u=smly&p=standardml', data=json.dumps(data), headers=headers)
>>> resp
<Response [200]>
>>> resp.content
''

FROM ubuntu
ADD influxdb-install.sh /influxdb-install.sh
RUN /bin/bash /influxdb-install.sh
EXPOSE 8083 8086
CMD /opt/influxdb/run
#!/bin/bash
echo "deb http://us.archive.ubuntu.com/ubuntu/ precise universe" >> /etc/apt/sources.list
echo "deb http://us.archive.ubuntu.com/ubuntu/ precise-updates universe" >> /etc/apt/sources.list
apt-get update
apt-get -y install wget protobuf-compiler bzr mercurial bison flex g++ make git
mkdir /opt
cd /opt
cat <<EOF > /opt/goenv
export GOROOT=/opt/go
export PATH=${PATH}:/opt/go/bin
EOF
wget http://go.googlecode.com/files/go1.1.2.linux-amd64.tar.gz
tar zxvf go1.1.2.linux-amd64.tar.gz
rm go1.1.2.linux-amd64.tar.gz
wget https://github.com/influxdb/influxdb/archive/v0.0.7.tar.gz
tar zxvf v0.0.7.tar.gz
rm v0.0.7.tar.gz
ln -s /opt/influxdb-0.0.7 /opt/influxdb
cd /opt/influxdb
cat <<EOF > /opt/influxdb/run
#!/bin/bash
source /opt/goenv
cd /opt/influxdb
./server
EOF
chmod a+x /opt/influxdb/run
source /opt/goenv
./build.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment