The Return of the InfluxDB V1 Shell

Navigate to:

The community has spoken and the demand was clear:

“BRING BACK THE INTERACTIVE SHELL USED IN 1.X”

So it’s back… It works with InfluxDB V2… and has some improvements.

The interactive shell allowed users to write data and interactively query data using InfluxQL. For newer users, InfluxQL is the SQL-like query engine that was native to the first major version of InfluxDB.

The new and improved

So one of our new developers on the Edge Team, Andrew Lee, took on the challenge to restore the interactive shell within the new InfluxDB CLI. He has also made some great improvements to the overall experience:

Let’s break down what we saw in the video.

How do you access the new shell?

Before you drop into the new shell there is some housekeeping you need to take care of (this is something we are looking into to see if we can automate further):

  1. You do this by establishing a connection config:
    influx config create -u <IP/URL>:8086 -t <All-ACCESS-TOKEN> -o <ORGANISATION> -a
    Note: If you set up InfluxDB OSS using the Influx setup command, then a connection config will be pre-created for you.
  2. Since InfluxDB V2 now uses Flux by default and works with the notation of buckets rather than databases, we need to do some mapping. You can find the instructions to do that here.

Now we can drop into the InfluxQL interactive shell using the following command:

influx v1 shell

Autocompletion

One of the first things you will notice is the introduction of autocompletion. The interactive shell will now provide command suggestions.

Let’s take a look:

autocompletion

As you can see, I have a bucket called generators which has been mapped to a database. When I type the command use you can see autocomplete automatically suggests what databases I have available to me to complete the command.

You can see this theme also continues when building out your InfluxQL query. Providing suggestions for measurements I can pick from:

Providing-suggestions

This feature is a welcome addition to the interactive shell experience as it improves adoption for first-time users learning how to build queries with InfluxQL.

Previous commands and history

The interactive shell also allows you to navigate through previous commands using the up and down keys like you would with your basic shell. It also has a neat feature to show all of your command history by running:

> history

history

Improved table view

The interactive shell also comes with a new table view for displaying your returned query data:

Interactive-table-view-img10

I can navigate my returned data using the up and down arrows. Then press q to exit the table view. Looking at the above table the one issue I see is the time format. Not exactly human-readable. So let’s discuss format changing next.

If your table is too large, you can also scroll horizontally using the arrow keys:

scroll-table-horizontally

Time precision + data formats

So suppose I want to return my data with the following qualities:

  • Human readable timestamp
  • JSON format

Let’s see how we can do this in stages. Starting with the timestamp:

  1. We can define the precision of our timestamp using the following command:
    > precision rfc3339
  2. Run our query again:
    > SELECT * FROM "genData"

You can now see we have our pretty table format with the time value converted to rfc339 format:

table wiht converted value

Now let’s convert it to JSON:

  1. To select a new data output format, we can use the following command:
    > format json
    Note: CSV, Column & table views are also available.
  2. Run the query again (This time with LIMIT to reduce the number of metrics returned):
    > SELECT * FROM "genData" LIMIT 1

Here is our returned JSON:

{"results":[{"series":[{"columns":["time","fuel","generatorID","host","lat","load","lon","power","temperature","topic"],"name":"genData","values":[["2022-06-23T09:17:27.871988172Z",825,"generator3","9ec0ed8427de",33.92946,63,-116.97725,1759,207,"emergency_generator/generator3"]]}],"statement_id":0}]}

Now you might be thinking to yourself: sigh I now need to run this through a JSON formatter. We have got you covered. If you run the command:

>pretty

Rerun the query and the shell will format and auto-indent your JSON.

{
    "results": [
        {
            "series": [
                {
                    "columns": [
                        "time",
                        "fuel",
                        "generatorID",
                        "host",
                        "lat",
                        "load",
                        "lon",
                        "power",
                        "temperature",
                        "topic"
                    ],
                    "name": "genData",
                    "values": [
                        [
                            "2022-06-23T09:17:27.871988172Z",
                            825,
                            "generator3",
                            "9ec0ed8427de",
                            33.92946,
                            63,
                            -116.97725,
                            1759,
                            207,
                            "emergency_generator/generator3"
                        ]
                    ]
                }
            ],
            "statement_id": 0
        }
    ]
}

If you want to see what settings are currently enabled, you can run the following command:

> settings

To list these out.

Settings-value

Writing data

Lastly, let’s talk about writing metrics to InfluxDB via the interactive shell. Let’s say we had some wind farm data to manually upload:

>windfarm,location=UK,zone=A rotation_speed=400 1655991838619
  1. We need to set our precision parameter again to match the timestamp format of our line protocol. In our case, it’s milliseconds:
    > precision ms
  2. Next, we can insert the line protocol using the following command:
    > INSERT windfarm,location=UK,zone=A rotation_speed=400 1655991838619

We can now see that our metric has been stored within InfluxDB.

metric stored within InfluxDB

Since the DB is mapped to the bucket, we can also interact with the data using the UI and Flux.

Interact with the data using the UI and Flux

A couple caveats

So before you get ahead of yourself and permanently drop into the v1 shell, there are some caveats:

You currently cannot create databases from within the shell. This is largely down to InfluxDB buckets acting as the core storage mechanism in 2.x (fear not — there are already plans in motion to change this with automatic dprp mapping). For now, users are still required to create buckets and map them to databases.

Though on a positive note, the Gopher command is alive and well!

gopher

Conclusion

The Influx v1 shell will be released to the CLI very soon. Most of the work done by Andrew has now been merged. So you are more than welcome to build the CLI from source and let us know what you think.

The repo can be found here.

All of us at InfluxData take pride in the community that’s been built around InfluxDB. Please continue to share your feedback and feature requests as we are listening. It is through your feedback that this great feature was brought back and Gopher was saved from oblivion!