InfluxDB (Database service)
Back to home
On this page
InfluxDB is a time series database optimized for high-write-volume use cases such as logs, sensor data, and real-time analytics.
It exposes an HTTP API for client interaction. See the InfluxDB documentation for more information.
Supported versions
You can select the major and minor version.
Patch versions are applied periodically for bug fixes and the like. When you deploy your app, you always get the latest available patches.
- 2.7
- 2.3
Deprecated versions
The following versions are still available in your projects, but they’re at their end of life and are no longer receiving security updates from upstream.
- 2.2
- 1.8
- 1.7
- 1.3
- 1.2
To ensure your project remains stable in the future, switch to a supported version. See more information on how to upgrade to version 2.3 or later.
Relationship reference
Example information available through the PLATFORM_RELATIONSHIPS environment variable
or by running upsun relationships.
Note that the information about the relationship can change when an app is redeployed or restarted
or the relationship is changed.
So your apps should only rely on the PLATFORM_RELATIONSHIPS environment variable directly rather than hard coding any values.
{
"host": "influxdb27.internal",
"hostname": "3xqrvge7ohuvzhjcityyphqcja.influxdb27.service._.ca-1.upsunapp.com",
"cluster": "jqwcjci6jmwpw-main-bvxea6i",
"service": "influxdb27",
"type": "influxdb:2.7",
"rel": "influxdb",
"scheme": "http",
"username": "admin",
"password": "ChangeMe",
"port": 8086,
"path": null,
"query": {
"org": "main",
"bucket": "main",
"api_token": "d85b1219ee8cef8f84d33216257e44d51ddd52e89ae7acbd5ab1d01d320e2f7f"
},
"fragment": null,
"public": false,
"host_mapped": false,
"ip": "169.254.99.35"
} Usage example
1. Configure the service
To define the service, use
the influxdb type:
services:
# The name of the service container. Must be unique within a project.
<SERVICE_NAME>:
type: influxdb:<VERSION>Note that changing the name of the service replaces it with a brand new service and all existing data is lost. Back up your data before changing the service.
2. Add the relationship
To define the relationship, use the influxdb endpoint
:
applications:
# The name of the app container. Must be unique within a project.
<APP_NAME>:
# Relationships enable access from this app to a given service.
relationships:
<RELATIONSHIP_NAME>: "<SERVICE_NAME>:influxdb"
services:
# The name of the service container. Must be unique within a project.
<SERVICE_NAME>:
type: influxdb:<VERSION>You can define <SERVICE_NAME> and <RELATIONSHIP_NAME> as you like, but it’s best if they’re distinct.
With this definition, the application container (<APP_NAME>) now has access to the service via the relationship <RELATIONSHIP_NAME>.
Example Configuration
App and Service configuration
applications:
# The name of the app container. Must be unique within a project.
myapp:
# Relationships enable access from this app to a given service.
relationships:
influxtimedb: "timedb:influxdb"
services:
# The name of the service container. Must be unique within a project.
timedb:
type: influxdb:2.7 Use in app
To use the configured service in your app, add a configuration file similar to the following to your project.
applications:
# The name of the app container. Must be unique within a project.
myapp:
# The location of the application's code.
source:
root: "myapp"
# Relationships enable an app container's access to a service.
relationships:
influxtimedb: "timedb:influxdb"
services:
# The name of the service container. Must be unique within a project.
timedb:
type: influxdb:2.7This configuration defines a single application myapp, whose source code exists in the directory <PROJECT_ROOT>/myapp, and has been provided access to the service (timedb) via the relationship influxtimedb.
From this, myapp can retrieve access credentials to the service through the environment variable PLATFORM_RELATIONSHIPS.
That variable is a base64-encoded JSON object, but can be decoded at runtime (using the built-in tool jq) to provide more accessible environment variables to use within the application itself:
# Decode the built-in credentials object variable.
export RELATIONSHIPS_JSON=$(echo $PLATFORM_RELATIONSHIPS | base64 --decode)
# Set environment variables for common InfluxDB credentials.
export INFLUX_USER=$(echo $RELATIONSHIPS_JSON | jq -r ".influxtimedb[0].username")
export INFLUX_HOST=$(echo $RELATIONSHIPS_JSON | jq -r ".influxtimedb[0].host")
export INFLUX_ORG=$(echo $RELATIONSHIPS_JSON | jq -r ".influxtimedb[0].query.org")
export INFLUX_TOKEN=$(echo $RELATIONSHIPS_JSON | jq -r ".influxtimedb[0].query.api_token")
export INFLUX_BUCKET=$(echo $RELATIONSHIPS_JSON | jq -r ".influxtimedb[0].query.bucket")The above file โ .environment in the myapp directory โ is automatically sourced by Upsun into the runtime environment, so that the variable INFLUX_HOST can be used within the application to connect to the service.
Note that INFLUX_HOST, and all Upsun-provided environment variables like PLATFORM_RELATIONSHIPS, are environment-dependent. Unlike the build produced for a given commit, they can’t be reused across environments and only allow your app to connect to a single service instance on a single environment.
A file very similar to this is generated automatically for your when using the upsun ify command to migrate a codebase to Upsun.
Export data
To export your data from InfluxDB, follow these steps:
-
Install and set up the
influxCLI. -
Connect to your InfluxDB service with the Upsun CLI:
upsun tunnel:singleThis opens an SSH tunnel to your InfluxDB service on your current environment and produces output like the following:
SSH tunnel opened to influxdb at: http://127.0.0.1:30000 -
Get the username, password and token from the relationship by running the following command:
upsun relationships -P RELATIONSHIP_NAME -
Adapt and run InfluxDB’s CLI export command.
influx backup --host URL_FROM_STEP_2 --token API_TOKEN_FROM_STEP_3
Upgrade to version 2.3 or later
From a previous 2.x version
From version 2.3 onward, the structure of relationships changes.
If you’re using a prior 2.x version, your app might currently rely on pulling the bucket, org, api_token,
or user values available in the PLATFORM_RELATIONSHIPS environment variable.
If so, to ensure your upgrade is successful, make the following changes to your connection logic:
- Rename the
userkey tousername. - Move the
org,bucketandapi_tokenkeys so they’re contained in a dictionary under thequerykey.
If you’re relying on any other attributes connecting to InfluxDB, they remain accessible as top-level keys from the PLATFORM_RELATIONSHIPS environment variable, aside from those addressed above:
{
"host": "influxdb27.internal",
"hostname": "3xqrvge7ohuvzhjcityyphqcja.influxdb27.service._.ca-1.upsunapp.com",
"cluster": "jqwcjci6jmwpw-main-bvxea6i",
"service": "influxdb27",
"type": "influxdb:2.7",
"rel": "influxdb",
"scheme": "http",
"username": "admin",
"password": "ChangeMe",
"port": 8086,
"path": null,
"query": {
"org": "main",
"bucket": "main",
"api_token": "d85b1219ee8cef8f84d33216257e44d51ddd52e89ae7acbd5ab1d01d320e2f7f"
},
"fragment": null,
"public": false,
"host_mapped": false,
"ip": "169.254.99.35"
} From a 1.x version
From version 2.3 onward, InfluxDB includes an upgrade utility that can convert databases from previous versions to version 2.3 or later.
To upgrade from a 1.x version to 2.3 or later,
change the service version in your .upsun/config.yaml file and push your project.
Any existing data you had in your 1.x system is automatically upgraded for you into the 2.3+ system.
Note
During an upgrade from a 1.x version to a 2.3 version or later, a new admin password and a new admin API token are automatically generated. Previous credentials can’t be retained.
You can retrieve your new credentials through the PLATFORM_RELATIONSHIPS environment variable or by running upsun relationships.