InfluxDB cli ready for people to play with

The code is on github. Installation should be simple

sudo make INSTALLPATH=/path/where/you/want/it

It will install any needed Perl modules for you. I’ve reduced the dependency set to LWP::UserAgent, Getopt::Lucid, JSON::PP, and some text processing. As much as I like Mojolicious, the UserAgent was 1/10th the speed of LWP for the same work.

Once it is done, point it over to an InfluxDB database instance:

landman@metal:~/work/development/influxdbcli$ ./influxdb-cli.pl --user scalable --pass XXXXXXX --host 192.168.101.250 --db unison --debug

unison> 

list some series

unison> list series
D[713]  Scalable::TSDB::_generate_url; dbquery = 'list series'
D[713]  Scalable::TSDB::_generate_url; query = 'p=scalable&u=scalable&chunked=1&time_precision=s&q=list%20series'
D[713]  Scalable::TSDB::_generate_url; url = 'http://192.168.101.250:8086/db/unison/series?p=XXXXXXXX&u=scalable&chunked=1&time_precision=s&q=list%20series'
D[713] Scalable::TSDB::_send_chunked_get_query -> reading 0.074382s 
D[713] Scalable::TSDB::_send_chunked_get_query -> reading 0.000197s 
D[713] Scalable::TSDB::_send_chunked_get_query -> reading 0.000173s 
...
D[713] Scalable::TSDB::_send_chunked_get_query -> bytes_received = 101922B 
D[713] Scalable::TSDB::_send_chunked_get_query return code = 200
D[713] Scalable::TSDB::_send_chunked_get_query tpos = 0
D[713] Scalable::TSDB::_send_chunked_get_query spos = 1
D[713] Scalable::TSDB::_send_chunked_get_query cols = [time,name]
D[713] Scalable::TSDB::_send_chunked_get_query -> mapping 0.138265s 
D[713] influxdb-cli.pl; DB query 'list series' took 0.219349s
D[713] influxdb-cli.pl; output formatting took 0.056791s
.------------------------------------------.
|      results: query = 'list series'      |
+------------------------------------------+
| series                                   |
+------------------------------------------+
| rsnode.sicloud.MHz.cpu0                  |
| rsnode.sicloud.MHz.cpu1                  |
...
| usn-ramboot.tcpinfo.icmperrs             |
| usn-ramboot.tcpinfo.iperrs               |
| usn-ramboot.tcpinfo.tcperrs              |
| usn-ramboot.tcpinfo.udperrs              |
'------------------------------------------'

D[713] influxdb-cli.pl; outputting took 0.109668s

The D[number] … bit are the debugging messages. You can turn debugging off if you wish by exiting and omitting the –debug option.

In short order, you’ll be able to toggle it from within the code itself.

Now lets select some values.

unison> select * from usn-ramboot.swapinfo.total
ERROR:
	message	= 'syntax error, unexpected '-', expecting $end
select * from usn-ramboot.swapinfo.total
                 ^'
	rc	= '400'

Uh oh, we ran into an escaping/quoting issue. Try again

unison> select * from "usn-ramboot.swapinfo.total" limit 10
.------------------------------------------------------------------------.
| results: query = 'select * from "usn-ramboot.swapinfo.total" limit 10' |
+------------------------+----------------------------+------------------+
| time                   | sequence_number            | value            |
+------------------------+----------------------------+------------------+
|             1423495580 |                          1 |                0 |
|             1423495579 |                          1 |                0 |
|             1423495578 |                          1 |                0 |
|             1423495577 |                          1 |                0 |
|             1423495576 |                          1 |                0 |
|             1423495575 |                          1 |                0 |
|             1423495574 |                          1 |                0 |
|             1423495573 |                          1 |                0 |
|             1423495572 |                          1 |                0 |
|             1423495571 |                          1 |                0 |
'------------------------+----------------------------+------------------'

Much better. Ok, what about querying multiple series …

unison> select * from "usn-ramboot.swapinfo.total","usn-ramboot.swapinfo.used" limit 10
.----------------------------------------------------------------------------------------------------.
| results: query = 'select * from "usn-ramboot.swapinfo.total","usn-ramboot.swapinfo.used" limit 10' |
+---------------------------------+--------------------------------------+---------------------------+
| time                            | sequence_number                      | value                     |
+---------------------------------+--------------------------------------+---------------------------+
|                      1423495580 |                                    1 |                         0 |
|                      1423495579 |                                    1 |                         0 |
|                      1423495578 |                                    1 |                         0 |
|                      1423495577 |                                    1 |                         0 |
|                      1423495576 |                                    1 |                         0 |
|                      1423495575 |                                    1 |                         0 |
|                      1423495574 |                                    1 |                         0 |
|                      1423495573 |                                    1 |                         0 |
|                      1423495572 |                                    1 |                         0 |
|                      1423495571 |                                    1 |                         0 |
'---------------------------------+--------------------------------------+---------------------------'

Not too shabby. Why not do some computations on the values

unison> select value/10 from "usn-ramboot.swapinfo.total" limit 10
.-------------------------------------------------------------------------------.
| results: query = 'select value/10 from "usn-ramboot.swapinfo.total" limit 10' |
+--------------------------+-------------------------------+--------------------+
| time                     | sequence_number               | expr0              |
+--------------------------+-------------------------------+--------------------+
|               1423495580 |                             1 |                  0 |
|               1423495579 |                             1 |                  0 |
|               1423495578 |                             1 |                  0 |
|               1423495577 |                             1 |                  0 |
|               1423495576 |                             1 |                  0 |
|               1423495575 |                             1 |                  0 |
|               1423495574 |                             1 |                  0 |
|               1423495573 |                             1 |                  0 |
|               1423495572 |                             1 |                  0 |
|               1423495571 |                             1 |                  0 |
'--------------------------+-------------------------------+--------------------'

unison> select mean(value/10) from "usn-ramboot.swapinfo.total" limit 10
.-------------------------------------------------------------------------------------.
| results: query = 'select mean(value/10) from "usn-ramboot.swapinfo.total" limit 10' |
+------------------------------------------+------------------------------------------+
| time                                     | mean                                     |
+------------------------------------------+------------------------------------------+
|                                        0 |                                        0 |
'------------------------------------------+------------------------------------------'

unison> select max(value/10) from "usn-ramboot.swapinfo.total" group by time(1h)
.---------------------------------------------------------------------------------------------.
| results: query = 'select max(value/10) from "usn-ramboot.swapinfo.total" group by time(1h)' |
+--------------------------------------------------+------------------------------------------+
| time                                             | max                                      |
+--------------------------------------------------+------------------------------------------+
|                                       1423494000 |                                        0 |
|                                       1423490400 |                                        0 |
|                                       1423486800 |                                        0 |
|                                       1423483200 |                                        0 |
|                                       1423479600 |                                        0 |
|                                       1423476000 |                                        0 |
|                                       1423472400 |                                        0 |

You can see some pretty nice query capabilities. You can also output to csv and adjust the separator. And set an output file

unison> select max(value/10) from "usn-ramboot.swapinfo.total" group by time(1d)
#time time max
1423440000 0
1423353600 0
1423267200 0
1423180800 0
1423094400 0
1423008000 0

unison> \set output=test.data
unison> select max(value/10) from "usn-ramboot.swapinfo.total" group by time(1d)
unison> 

landman@metal:~/work/development/influxdbcli$ cat test.data 
#time time max
1423440000 0
1423353600 0
1423267200 0
1423180800 0
1423094400 0
1423008000 0

Nice, huh?

There are still a number of bugs, but this is ready for alpha. Please do feel free to start beating on it, and we’ll fix bugs as rapidly as possible.

We’ve selected InfluxDB for a graphite replacement backend for Unison and indeed, for all our FastPath appliances. We’ll be updating sios-metrics plugins so we can remove the collectl dependency (massive overkill for what we need) on our monitoring.

Viewed 41347 times by 5553 viewers

Facebooktwittergoogle_plusredditpinterestlinkedinmail