Platform.sh User Documentation

InfluxDB (Database service)

Upsun Beta

Access our newest offering - Upsun!

Get your free trial by clicking the link below.

Get your Upsun free trial

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 Anchor to this heading

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.

Grid Dedicated Gen 3 Dedicated Gen 2
  • 2.7
  • 2.3
None available None available

Deprecated versions Anchor to this heading

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.

Grid Dedicated Gen 3 Dedicated Gen 2
  • 2.2
  • 1.8
  • 1.7
  • 1.3
  • 1.2
None available None available

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 Anchor to this heading

Example information available through the PLATFORM_RELATIONSHIPS environment variable or by running platform 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": "influxdbdatabase.internal",
  "hostname": "azertyuiopqsdfghjklm.influxdb.service._.eu-1.platformsh.site",
  "cluster": "azertyuiopqsdf-main-bvxea6i",
  "service": "influxdb",
  "type": "influxdb:2.7",
  "rel": "influxdb",
  "scheme": "http",
  "username": "admin",
  "password": "ChangeMe",
  "port": 8086,
  "path": null,
  "query": {
    "org": "main",
    "bucket": "main",
    "api_token": "azertyuiopqsdfghjklm1234567890"
  },
  "fragment": null,
  "public": false,
  "host_mapped": false,
  "ip": "123.456.78.90"
}

Usage example Anchor to this heading

1. Configure the service Anchor to this heading

To define the service, use the influxdb type:

.platform/services.yaml
# The name of the service container. Must be unique within a project.
<SERVICE_NAME>:

    type: influxdb:<VERSION>
    disk: 256

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 Anchor to this heading

To define the relationship, use the influxdb endpoint :

.platform.app.yaml
# Relationships enable access from this app to a given service.
relationships:
    <RELATIONSHIP_NAME>: "<SERVICE_NAME>:influxdb"

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 now has access to the service via the relationship <RELATIONSHIP_NAME> and its corresponding PLATFORM_RELATIONSHIPS environment variable.

Example Configuration Anchor to this heading

Service definition Anchor to this heading

.platform/services.yaml
# The name of the service container. Must be unique within a project.
influxdb:

    type: influxdb:2.7
    disk: 256

App configuration Anchor to this heading

.platform.app.yaml
# Relationships enable access from this app to a given service.
relationships:
    influxdbdatabase: "influxdb:influxdb"

Use in app Anchor to this heading

To use the configured service in your app, add a configuration file similar to the following to your project.

.platform.app.yaml
# Relationships enable an app container's access to a service.
relationships:
    influxdbdatabase: "influxdb:influxdb"

This configuration defines a single application myapp, whose source code exists in the directory <PROJECT_ROOT>/myapp, and has been provided access to the service (influxdb) via the relationship influxdbdatabase.

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:

myapp/.environment
# 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 ".influxdbdatabase[0].username")
export INFLUX_HOST=$(echo $RELATIONSHIPS_JSON | jq -r ".influxdbdatabase[0].host")
export INFLUX_ORG=$(echo $RELATIONSHIPS_JSON | jq -r ".influxdbdatabase[0].query.org")
export INFLUX_TOKEN=$(echo $RELATIONSHIPS_JSON | jq -r ".influxdbdatabase[0].query.api_token")
export INFLUX_BUCKET=$(echo $RELATIONSHIPS_JSON | jq -r ".influxdbdatabase[0].query.bucket")

The above file โ€” .environment in the myapp directory โ€” is automatically sourced by Platform.sh 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 Platform.sh-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 platform ify command to migrate a codebase to Platform.sh.

Export data Anchor to this heading

To export your data from InfluxDB, follow these steps:

  1. Install and set up the influx CLI.

  2. Connect to your InfluxDB service with the Platform.sh CLI:

    platform tunnel:single

    This opens an SSH tunnel to your InfluxDB service on your current environment and produces output like the following:

    SSH tunnel opened to influxdbdatabase at: http://127.0.0.1:30000
  3. Get the username, password and token from the relationship by running the following command:

    platform relationships -P RELATIONSHIP_NAME
  4. 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 Anchor to this heading

From a previous 2.x version Anchor to this heading

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 user key to username.
  • Move the org, bucket and api_token keys so they’re contained in a dictionary under the query key.

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": "influxdbdatabase.internal",
  "hostname": "azertyuiopqsdfghjklm.influxdb.service._.eu-1.platformsh.site",
  "cluster": "azertyuiopqsdf-main-bvxea6i",
  "service": "influxdb",
  "type": "influxdb:2.7",
  "rel": "influxdb",
  "scheme": "http",
  "username": "admin",
  "password": "ChangeMe",
  "port": 8086,
  "path": null,
  "query": {
    "org": "main",
    "bucket": "main",
    "api_token": "azertyuiopqsdfghjklm1234567890"
  },
  "fragment": null,
  "public": false,
  "host_mapped": false,
  "ip": "123.456.78.90"
}

From a 1.x version Anchor to this heading

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 .platform/services.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.

Is this page helpful?