Documentation

usage.from() function

usage.from() is experimental and subject to change at any time.

usage.from() returns usage data from an InfluxDB Cloud organization.

Output data schema

  • http_request measurement
    • req_bytes field
    • resp_bytes field
    • org_id tag
    • endpoint tag
    • status tag
  • query_count measurement
    • req_bytes field
    • endpoint tag
    • orgID tag
    • status tag
  • storage_usage_bucket_bytes measurement
    • gauge field
    • bucket_id tag
    • org_id tag
Function type signature
(
    start: A,
    stop: B,
    ?host: string,
    ?orgID: string,
    ?raw: C,
    ?token: string,
) => stream[D] where D: Record
  • Copy
  • Fill window

For more information, see Function type signatures.

Parameters

start

(Required) Earliest time to include in results.

stop

(Required) Latest time to include in results.

host

InfluxDB Cloud region URL. Default is "".

(Required if executed outside of your InfluxDB Cloud organization or region).

orgID

InfluxDB Cloud organization ID. Default is "".

(Required if executed outside of your InfluxDB Cloud organization or region).

token

InfluxDB Cloud API token. Default is "".

(Required if executed outside of your InfluxDB Cloud organization or region).

raw

Return raw, high resolution usage data instead of downsampled usage data. Default is false.

usage.from() can query the following time ranges:

Data resolutionMaximum time range
raw1 hour
downsampled30 days

Examples

Query downsampled usage data for your InfluxDB Cloud organization

import "experimental/usage"
import "influxdata/influxdb/secrets"

token = secrets.get(key: "INFLUX_TOKEN")

usage.from(start: -30d, stop: now())
  • Copy
  • Fill window

Query raw usage data for your InfluxDB Cloud organization

import "experimental/usage"
import "influxdata/influxdb/secrets"

token = secrets.get(key: "INFLUX_TOKEN")

usage.from(start: -1h, stop: now(), raw: true)
  • Copy
  • Fill window

Query downsampled usage data for a different InfluxDB Cloud organization

import "experimental/usage"
import "influxdata/influxdb/secrets"

token = secrets.get(key: "INFLUX_TOKEN")

usage.from(
    start: -30d,
    stop: now(),
    host: "https://us-west-2-1.aws.cloud2.influxdata.com",
    orgID: "x000X0x0xx0X00x0",
    token: token,
)
  • Copy
  • Fill window

Query number of bytes in requests to the /api/v2/write endpoint

import "experimental/usage"

usage.from(start: -30d, stop: now())
    |> filter(fn: (r) => r._measurement == "http_request")
    |> filter(fn: (r) => r._field == "req_bytes")
    |> filter(fn: (r) => r.endpoint == "/api/v2/write")
    |> group(columns: ["_time"])
    |> sum()
    |> group()
  • Copy
  • Fill window

Query number of bytes returned from the /api/v2/query endpoint

import "experimental/usage"

usage.from(start: -30d, stop: now())
    |> filter(fn: (r) => r._measurement == "http_request")
    |> filter(fn: (r) => r._field == "resp_bytes")
    |> filter(fn: (r) => r.endpoint == "/api/v2/query")
    |> group(columns: ["_time"])
    |> sum()
    |> group()
  • Copy
  • Fill window

Query the query count for InfluxDB Cloud query endpoints

The following query returns query counts for the following query endpoints:

  • /api/v2/query: Flux queries
  • /query: InfluxQL queries
import "experimental/usage"

usage.from(start: -30d, stop: now())
    |> filter(fn: (r) => r._measurement == "query_count")
    |> sort(columns: ["_time"])
  • Copy
  • Fill window

Compare usage metrics to organization usage limits

The following query compares the amount of data written to and queried from your InfluxDB Cloud organization to your organization’s rate limits. It appends a limitReached column to each row that indicates if your rate limit was exceeded.

import "experimental/usage"

limits = usage.limits()

checkLimit = (tables=<-, limit) =>
    tables
        |> map(fn: (r) => ({r with _value: r._value / 1000, limit: int(v: limit) * 60 * 5}))
        |> map(fn: (r) => ({r with limitReached: r._value > r.limit}))

read =
    usage.from(start: -30d, stop: now())
        |> filter(fn: (r) => r._measurement == "http_request")
        |> filter(fn: (r) => r._field == "resp_bytes")
        |> filter(fn: (r) => r.endpoint == "/api/v2/query")
        |> group(columns: ["_time"])
        |> sum()
        |> group()
        |> checkLimit(limit: limits.rate.readKBs)

write =
    usage.from(start: -30d, stop: now())
        |> filter(fn: (r) => r._measurement == "http_request")
        |> filter(fn: (r) => r._field == "req_bytes")
        |> filter(fn: (r) => r.endpoint == "/api/v2/write")
        |> group(columns: ["_time"])
        |> sum()
        |> group()
        |> checkLimit(limit: limits.rate.writeKBs)

union(tables: [read, write])
  • Copy
  • Fill window

Was this page helpful?

Thank you for your feedback!


The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Read more

InfluxDB 3 Core and Enterprise are now in Beta

InfluxDB 3 Core and Enterprise are now available for beta testing, available under MIT or Apache 2 license.

InfluxDB 3 Core is a high-speed, recent-data engine that collects and processes data in real-time, while persisting it to local disk or object storage. InfluxDB 3 Enterprise is a commercial product that builds on Core’s foundation, adding high availability, read replicas, enhanced security, and data compaction for faster queries. A free tier of InfluxDB 3 Enterprise will also be available for at-home, non-commercial use for hobbyists to get the full historical time series database set of capabilities.

For more information, check out: