How to use the command 'influx' (with examples)

How to use the command 'influx' (with examples)

The ‘influx’ command is a command-line client for InfluxDB, a time series database. It allows users to interact with an InfluxDB instance and perform various tasks, such as connecting to a database, executing commands, and formatting output.

Use case 1: Connect to an InfluxDB running on localhost with no credentials

Code:

influx

Motivation: This use case is useful when you want to connect to an InfluxDB instance running on your localhost without providing any credentials. It is commonly used for testing or development purposes.

Explanation: The ‘influx’ command without any arguments will connect to the InfluxDB instance running on localhost with default settings. It assumes that the InfluxDB server is running on the default port (8086), and there are no authentication requirements.

Example output:

Connected to http://localhost:8086 version 1.7.9
InfluxDB shell version: 1.7.9

Use case 2: Connect with a specific username (will prompt for a password)

Code:

influx -username username -password ""

Motivation: This use case is useful when you want to connect to an InfluxDB instance with a specific username and prompt for a password. It can be used when you have authentication enabled on your InfluxDB server.

Explanation: The ‘-username’ flag is used to specify the username for the connection. In the example above, replace ‘username’ with the desired username. The ‘-password’ flag is used to prompt for the password. When running the command, it will ask you to enter the password.

Example output:

Connected to http://localhost:8086 version 1.7.9
InfluxDB shell version: 1.7.9

Use case 3: Connect to a specific host

Code:

influx -host hostname

Motivation: This use case is useful when you want to connect to an InfluxDB instance running on a specific host. It can be used when your InfluxDB server is not running on localhost.

Explanation: The ‘-host’ flag is used to specify the hostname or IP address of the InfluxDB server. In the example above, replace ‘hostname’ with the desired host name or IP address.

Example output:

Connected to http://hostname:8086 version 1.7.9
InfluxDB shell version: 1.7.9

Use case 4: Use a specific database

Code:

influx -database database_name

Motivation: This use case is useful when you want to work with a specific database in your InfluxDB instance. It allows you to switch to a particular database and perform queries or operations on it.

Explanation: The ‘-database’ flag is used to specify the name of the database you want to connect to. In the example above, replace ‘database_name’ with the desired database name.

Example output:

Connected to http://localhost:8086 version 1.7.9
InfluxDB shell version: 1.7.9
Using database database_name

Use case 5: Execute a given command

Code:

influx -execute "influxql_command"

Motivation: This use case is useful when you want to execute a specific InfluxQL command without entering the interactive shell. It can be used for automation or running scripted commands.

Explanation: The ‘-execute’ flag is used to specify the InfluxQL command you want to execute. In the example above, replace ‘influxql_command’ with the desired InfluxQL command.

Example output:

name: my_measurement
time                value
----                -----
1577836800000000000 10
1577923200000000000 20

Use case 6: Return output in a specific format

Code:

influx -execute "influxql_command" -format json|csv|column

Motivation: This use case is useful when you want to customize the output format of the executed InfluxQL command. It allows you to retrieve the output as JSON, CSV, or in column format.

Explanation: The ‘-format’ flag is used to specify the output format of the executed command. Choose one of the options: json, csv, or column. In the example above, replace ‘influxql_command’ with the desired InfluxQL command.

Example output (JSON format):

{
    "results": [
        {
            "series": [
                {
                    "name": "my_measurement",
                    "columns": ["time", "value"],
                    "values": [
                        [1577836800000000000, 10],
                        [1577923200000000000, 20]
                    ]
                }
            ]
        }
    ]
}

Conclusion:

The ‘influx’ command is a versatile tool for interacting with an InfluxDB instance. It provides various options for connecting, executing commands, and formatting output. By understanding these use cases, you can effectively work with InfluxDB and perform tasks efficiently.

Related Posts

How to use the command fg (with examples)

How to use the command fg (with examples)

The fg command is used to bring suspended or running background jobs to the foreground.

Read More
How to use the command tskill (with examples)

How to use the command tskill (with examples)

The tskill command is used to terminate or end a process running in a session on a Remote Desktop Session Host.

Read More
How to use the command jarsigner (with examples)

How to use the command jarsigner (with examples)

The jarsigner command is a utility provided by Java to sign and verify Java archive (JAR) files.

Read More