def test_explicit_retention_policy(self, post): client = Client('https://*****:*****@localhost:8086/testdb', retention_policy='rp_four_weeks') client.write('temperature', value=21.3, timestamp=1476107241) post.assert_called_with( 'https://localhost:8086/write?precision=s&db=testdb&rp=rp_four_weeks', auth=('user', 'pass'), data='temperature value=21.3 1476107241')
def test_connection(self): """ Should be able to pass a http connection URI. """ client = Client('http://*****:*****@localhost:8086/databasename') assert client.connection.auth == ('user', 'pass') assert client.connection.uri == 'http://localhost:8086' assert client.connection.db == 'databasename'
#!/usr/bin/env python from inflow import Client client = Client('http://*****:*****@localhost:8086/databasename', retention_policy='rp_four_weeks') client.write('temperature', value=21.3)
#!/usr/bin/env python from inflow import Client client = Client('http://*****:*****@localhost:8086/databasename') results = client.query('SELECT * FROM "temperatures"', epoch='s')
#!/usr/bin/env python from inflow import Client client = Client('http://*****:*****@localhost:8086/databasename', timeout=0.01) client.write('temperature', value=21.3)
# --- write to the DB on the server directly: # ssh tpc14 ;influx -precision rfc3339 # > use influxdb_scs # > SHOW FIELD KEYS FROM "osubw" # > SELECT * FROM "osubw" # --- or send data to the DB from daint: # ----------> ~/linux.git/hpc/gpu/g2g.sh # module load daint-gpu # module use /apps/daint/UES/jenkins/daint-gpu-jenkins-testPR/modules/all # module load influxdb/4.0.0-CrayGNU-2016.11-Python-3.5.2 from inflow import Client client = Client('http://tpc14.cscs.ch:8086/influxdb_scs') # client = Client('http://gorner02.cscs.ch:8086/influx_scs') # , precision='ms') # client.write('temperature', value=21.3, timestamp=1476191999000) # results = client.query('SELECT * FROM "temperature"') # res = client.query('SELECT * FROM "osubw"') res = client.query('SHOW FIELD KEYS FROM "osubw"') print (res) # client.query('SELECT * FROM "temperature"') # client.query('SHOW FIELD KEYS from "temperature"') # client.query('DROP SERIES FROM "temperature"') # , epoch='s') #cscs: datetimeinflux=`date -d "$datetime" +%s%N` # date -d @1476191999000 --> Mon Aug 30 15:03:20 CEST 48748
def test_bad_uri(self): """ Should throw a ValueError when the given uri is not valid. """ with pytest.raises(ValueError): Client('invalid')
def test_no_database_name(self): """ A database name should be specified. """ with pytest.raises(ValueError): Client('https://localhost:8086/')
def test_bad_scheme(self): """ Currently we only support the http and https schemes. """ with pytest.raises(ValueError): Client('udp://localhost:8086/databasename')
def test_no_port(self): """ Should be able to not provide a port. """ client = Client('http://localhost/databasename') assert client.connection.uri == 'http://localhost'
def test_no_auth(self): """ Should be able to parse connection uri without auth. """ client = Client('http://localhost:8086/databasename') assert client.connection.auth is None
def client(): return Client('https://*****:*****@localhost:8086/testdb', timeout=1)
#!/usr/bin/env python from inflow import Client client = Client('http://*****:*****@localhost:8086/databasename', precision='ms') client.write('temperature', value=21.3, timestamp=1476191999000)
#!/usr/bin/env python from inflow import Client, Measurement client = Client('http://*****:*****@localhost:8086/databasename') client.write([ Measurement(name='temperature', tags={ 'location': 'groningen', 'sensor_type': 'ni1000' }, value=21.3, timestamp=1475845863), Measurement(name='temperature', tags={ 'location': 'groningen', 'sensor_type': 'ni1000' }, value=20.1, timestamp=1475848864) ])
#!/usr/bin/env python from inflow import Client client = Client('http://*****:*****@localhost:8086/databasename') temperature = dict(name='temperature', tags={ 'location': 'groningen', 'sensor_type': 'ni1000' }) client.write(temperature, [{ 'value': 21.3, 'timestamp': 1475845863 }, { 'value': 20.1, 'timestamp': 1475846182 }])
#!/usr/bin/env python from inflow import Client client = Client('http://*****:*****@localhost:8086/databasename') client.write('temperature', timestamp=1475846182, lower_sensor=20.9, upper_sensor=23.2)