diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index da39eaf1a..bbdac5194 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -8,30 +8,33 @@ GitHub Copilot should help document InfluxData products by creating clear, accur - **Product version data**: `/data/products.yml` - **Products**: + - InfluxDB 3 Core + - Documentation source path: `/content/influxdb3/core` + - Code repositories: https://github.com/influxdata/influxdb, https://github.com/influxdata/influxdb3_core + - InfluxDB 3 Enterprise + - Documentation source path: `/content/influxdb3/enterprise` + - Code repositories: https://github.com/influxdata/influxdb, https://github.com/influxdata/influxdb3_enterprise + - InfluxDB Cloud Dedicated + - Documentation source path: `/content/influxdb3/cloud-dedicated` + - Code repository: https://github.com/influxdata/influxdb + - InfluxDB Cloud Serverless + - Documentation source path: `/content/influxdb3/cloud-serverless` + - Code repository: https://github.com/influxdata/idpe + - InfluxDB Cloud v2 (TSM) + - Documentation source path: `/content/influxdb/cloud` + - Code repository: https://github.com/influxdata/idpe + - InfluxDB Clustered + - Documentation source path: `/content/influxdb3/clustered` + - Code repository: https://github.com/influxdata/influxdb + - InfluxDB Enterprise v1 (1.x) + - Documentation source path: `/content/influxdb/enterprise_influxdb` + - Code repository: https://github.com/influxdata/influxdb - InfluxDB OSS 1.x - Documentation source path: `/content/influxdb/v1` - Code repository: https://github.com/influxdata/influxdb - InfluxDB OSS 2.x - Documentation source path: `/content/influxdb/v2` - Code repository: https://github.com/influxdata/influxdb - - InfluxDB 3 Core - - Documentation source path: `/content/influxdb3/core` - - Code repositories: https://github.com/influxdata/influxdb, https://github.com/influxdata/influxdb3_core - - InfluxDB Enterprise v1 (1.x) - - Documentation source path: `/content/influxdb/enterprise_influxdb` - - Code repository: https://github.com/influxdata/influxdb - - InfluxDB Cloud v2 (TSM) - - Documentation source path: `/content/influxdb/cloud` - - Code repository: https://github.com/influxdata/idpe - - InfluxDB 3 Cloud Dedicated - - Documentation source path: `/content/influxdb3/cloud-dedicated` - - Code repository: https://github.com/influxdata/influxdb - - InfluxDB 3 Cloud Serverless - - Documentation source path: `/content/influxdb3/cloud-serverless` - - Code repository: https://github.com/influxdata/idpe - - InfluxDB 3 Clustered - - Documentation source path: `/content/influxdb3/clustered` - - Code repository: https://github.com/influxdata/influxdb - Telegraf - Documentation source path: `/content/telegraf/v1` - Code repository: https://github.com/influxdata/telegraf @@ -79,7 +82,7 @@ GitHub Copilot should help document InfluxData products by creating clear, accur product_version: weight: # Page order (1-99, 101-199, etc.) ``` - +- Follow the shortcode documentation in `CONTRIBUTING.md` - Use provided shortcodes correctly: - Notes/warnings: `{{% note %}}`, `{{% warn %}}` - Product-specific: `{{% enterprise %}}`, `{{% cloud %}}` @@ -123,6 +126,7 @@ Table: keys: [_start, _stop, _field, _measurement] ## API Documentation +- `/api-docs` contains OpenAPI spec files used for API reference documentation - Follow OpenAPI specification patterns - Match REST API examples to current implementation - Include complete request/response examples diff --git a/.gitignore b/.gitignore index 7faf70c94..a701b05a8 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,12 @@ node_modules /content/influxdb*/**/api/**/*.html !api-docs/**/.config.yml /api-docs/redoc-static.html* +/telegraf-build +!telegraf-build/templates +!telegraf-build/scripts +!telegraf-build/README.md +/cypress/screenshots/* +/influxdb3cli-build-scripts/content .vscode/* .idea **/config.toml diff --git a/.vscode/settings.json b/.vscode/settings.json index 002907174..2c18d3282 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,12 +1,12 @@ { - "commentAnchors.tags.anchors": - { "SOURCE": { - "scope": "file", - "behavior": "link", - "iconColor": "#FF0000", - "highlightColor": "#FF0000", - "style": "bold" - }}, + "commentAnchors.tags.anchors": + { "SOURCE": { + "scope": "file", + "behavior": "link", + "iconColor": "#FF0000", + "highlightColor": "#FF0000", + "style": "bold" + }}, "commentAnchors.workspace.matchFiles": "**/*.{md,ini,json,yaml,yml}", "commentAnchors.workspace.enabled": true, "yaml.schemas": { @@ -15,10 +15,17 @@ "vale.valeCLI.config": "${workspaceFolder}/.vale.ini", "vale.valeCLI.minAlertLevel": "warning", "github.copilot.chat.codeGeneration.useInstructionFiles": true, - "github.copilot.chat.codeGeneration.instructionFiles": [ + "github.copilot.chat.codeGeneration.instructions": [ { - "path": "${workspaceFolder}/.github/copilot-instructions.md", - "enabled": true + "file": "${workspaceFolder}/.github/copilot-instructions.md", } ], + "github.copilot.chat.pullRequestDescriptionGeneration.instructions": [ + { + "file": "${workspaceFolder}/.github/copilot-instructions.md", + } + ], + "cSpell.words": [ + "influxctl" + ] } \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c5b99666c..dad714a79 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -455,15 +455,11 @@ v2: /influxdb/v2.0/get-started/ Use the `prepend` and `append` frontmatter to add content to the top or bottom of a page. Each has the following fields: -- **block:** _(Optional)_ block style to wrap content in (note, warn, cloud, or enterprise) -- **content:** _**(Required)**_ markdown content to add. - ```yaml -append: - block: note - content: | - #### This is example markdown content - This is just an example note block that gets appended to the article. +append: | + > [!Note] + > #### This is example markdown content + > This is just an example note block that gets appended to the article. ``` Use this frontmatter with [cascade](#cascade) to add the same content to @@ -471,11 +467,10 @@ all children pages as well. ```yaml cascade: - append: - block: note - content: | - #### This is example markdown content - This is just an example note block that gets appended to the article. + append: | + > [!Note] + > #### This is example markdown content + > This is just an example note block that gets appended to the article. ``` ### Cascade @@ -582,14 +577,14 @@ Easier to maintain being you update the version number in the `data/products.yml ### Latest influx CLI version -Use the `{{< latest-cli >}}` shortcode to add the latest version of the `influx` +Use the `{{< latest-patch cli=true >}}` shortcode to add the latest version of the `influx` CLI supported by the minor version of InfluxDB. By default, this shortcode parses the minor version from the URL. To specify a specific minor version, use the `version` argument. Maintain CLI version numbers in the `data/products.yml` file instead of updating individual links and code examples. ```md -{{< latest-cli >}} +{{< latest-patch cli=true >}} {{< latest-cli version="2.1" >}} ``` @@ -1131,6 +1126,28 @@ The following table shows which children types use which frontmatter properties: | `list_code_example` | ✓ | | | | `list_query_example` | ✓ | | | +### Authentication token link + +Use the `{{% token-link "" "%}}` shortcode to +automatically generate links to token management documentation. The shortcode +accepts two _optional_ arguments: + +- **descriptor**: An optional token descriptor +- **link_append**: An optional path to append to the token management link path, + `///admin/tokens/`. + +```md +{{% token-link "database" "resource/" }} + + +[database token](/influxdb3/enterprise/admin/tokens/resource/) +``` + +InfluxDB 3 Enterprise and InfluxDB 3 Core support different kinds of tokens. +The shortcode has a blacklist of token descriptors for each that will prevent +unsupported descriptors from appearing in the rendered output based on the +current product. + ### Inline icons The `icon` shortcode allows you to inject icons in paragraph text. @@ -1638,6 +1655,31 @@ Supported argument values: {{< influxdb/host "serverless" >}} ``` +### User-populated placeholders + +Use the `code-placeholders` shortcode to format placeholders +as text fields that users can populate with their own values. +The shortcode takes a regular expression for matching placeholder names. +Use the `code-placeholder-key` shortcode to format the placeholder names in +text that describes the placeholder--for example: + +``` +{{% code-placeholders "DATABASE_NAME|USERNAME|PASSWORD_OR_TOKEN|API_TOKEN|exampleuser@influxdata.com" %}} +```sh +curl --request POST http://localhost:8086/write?db=DATABASE_NAME \ + --header "Authorization: Token API_TOKEN" \ + --data-binary @path/to/line-protocol.txt +``` +{{% /code-placeholders %}} + +Replace the following: + +- {{% code-placeholder-key %}}`DATABASE_NAME` and `RETENTION_POLICY`{{% /code-placeholder-key %}}: the [database and retention policy mapping (DBRP)](/influxdb/v2/reference/api/influxdb-1x/dbrp/) for the InfluxDB v2 bucket that you want to write to +- {{% code-placeholder-key %}}`USERNAME`{{% /code-placeholder-key %}}: your [InfluxDB 1.x username](/influxdb/v2/reference/api/influxdb-1x/#manage-credentials) +- {{% code-placeholder-key %}}`PASSWORD_OR_TOKEN`{{% /code-placeholder-key %}}: your [InfluxDB 1.x password or InfluxDB API token](/influxdb/v2/reference/api/influxdb-1x/#manage-credentials) +- {{% code-placeholder-key %}}`API_TOKEN`{{% /code-placeholder-key %}}: your [InfluxDB API token](/influxdb/v2/admin/tokens/) +``` + ## InfluxDB API documentation InfluxData uses [Redoc](https://github.com/Redocly/redoc) to generate the full diff --git a/api-docs/influxdb3/core/v3/content/tag-groups.yml b/api-docs/influxdb3/core/v3/content/tag-groups.yml index 5289ddb33..364d5e794 100644 --- a/api-docs/influxdb3/core/v3/content/tag-groups.yml +++ b/api-docs/influxdb3/core/v3/content/tag-groups.yml @@ -2,11 +2,14 @@ tags: - Quick start - Authentication + - Cache data - Common parameters - Response codes - Compatibility endpoints - - Data I/O - - Databases + - Database - Processing engine - Server information - - Tables + - Table + - Token + - Query data + - Write data diff --git a/api-docs/influxdb3/core/v3/ref.yml b/api-docs/influxdb3/core/v3/ref.yml index 7c344f7d7..7d1ba6a38 100644 --- a/api-docs/influxdb3/core/v3/ref.yml +++ b/api-docs/influxdb3/core/v3/ref.yml @@ -43,8 +43,50 @@ security: tags: - name: Authentication description: | - During the initial Alpha phase, InfluxDB 3 Core does not require authentication. + Authenticate to the InfluxDB 3 API using a bearer token. + + The InfluxDB 3 API uses tokens for authentication. + To authenticate, include the `Authorization` header in your request with the value `Bearer `. + The token must be a valid InfluxDB 3 admin token. + + #### Related guides + + - [Manage tokens](/influxdb3/core/admin/tokens/) + - [Authentication and authorization](/influxdb3/core/reference/authentication/) x-traitTag: true + - name: Cache data + description: | + Manage the in-memory cache. + + #### Distinct Value Cache + + The Distinct Value Cache (DVC) lets you cache distinct + values of one or more columns in a table, improving the performance of + queries that return distinct tag and field values. + + The DVC is an in-memory cache that stores distinct values for specific columns + in a table. When you create an DVC, you can specify what columns' distinct + values to cache, the maximum number of distinct value combinations to cache, and + the maximum age of cached values. A DVC is associated with a table, which can + have multiple DVCs. + + #### Last value cache + + The Last Value Cache (LVC) lets you cache the most recent + values for specific fields in a table, improving the performance of queries that + return the most recent value of a field for specific series or the last N values + of a field. + + The LVC is an in-memory cache that stores the last N number of values for + specific fields of series in a table. When you create an LVC, you can specify + what fields to cache, what tags to use to identify each series, and the + number of values to cache for each unique series. + An LVC is associated with a table, which can have multiple LVCs. + + #### Related guides + + - [Manage the Distinct Value Cache](/influxdb3/core/admin/distinct-value-cache/) + - [Manage the Last Value Cache](/influxdb3/core/admin/last-value-cache/) - name: Compatibility endpoints description: | InfluxDB 3 provides compatibility endpoints for InfluxDB 1.x and InfluxDB 2.x workloads and clients. @@ -72,19 +114,8 @@ tags: ### Server information Server information endpoints such as `/health` and `metrics` are compatible with InfluxDB 1.x and InfluxDB 2.x clients. - - name: Data I/O - description: | - Write and query data - - #### Data flow in InfluxDB 3 Core - - 1. **Incoming writes**: The system validates incoming data and stores it in the write buffer (in memory). If the `no_sync` write option is enabled (`no_sync=true`), the server sends a response to acknowledge the write. - 2. **WAL flush**: Every second (default), the system flushes the write buffer to the Write-Ahead Log (WAL) for persistence in the Object store. If `no_sync=false` (default), the server sends a response to acknowledge the write. - 3. **Query availability**: After WAL persistence completes, data moves to the queryable buffer where it becomes available for queries. By default, the server keeps up to 900 WAL files (15 minutes of data) buffered. - 4. **Long-term storage in Parquet**: Every ten minutes (default), the system persists the oldest data from the queryable buffer to the Object store in Parquet format. InfluxDB keeps the remaining data (the most recent 5 minutes) in memory. - 5. **In-memory cache**: InfluxDB puts Parquet files into an in-memory cache so that queries against the most recently persisted data don't have to go to object storage. - - name: Databases - description: Create, read, update, and delete database and cache resources + - name: Database + description: Manage databases - description: | Most InfluxDB API endpoints require parameters in the request--for example, specifying the database to use. @@ -119,28 +150,38 @@ tags: Use Processing engine plugins and triggers to run code and perform tasks for different database events. To get started with the Processing engine, see the [Processing engine and Python plugins](/influxdb3/core/processing-engine/) guide. + - name: Query data + description: Query data using SQL or InfluxQL - name: Quick start description: | - 1. [Check the status](#section/Server-information) of the InfluxDB server. + 1. [Create an admin token](#section/Authentication) for the InfluxDB 3 Core API. ```bash - curl "http://localhost:8181/health" + curl -X POST "http://localhost:8181/api/v3/configure/token/admin" + ``` + 2. [Check the status](#section/Server-information) of the InfluxDB server. + + ```bash + curl "http://localhost:8181/health" \ + --header "Authorization: Bearer ADMIN_TOKEN" ``` - 2. [Write data](#section/Compatibility-endpoints/Write-data) to InfluxDB. + 3. [Write data](#operation/PostWriteLP) to InfluxDB. ```bash - curl "http://localhost:8181/api/v3/write_lp?db=sensors&precision=auto" \ + curl "http://localhost:8181/api/v3/write_lp?db=sensors&precision=auto" + --header "Authorization: Bearer ADMIN_TOKEN" \ --data-raw "home,room=Kitchen temp=72.0 home,room=Living\ room temp=71.5" ``` If all data is written, the response is `204 No Content`. - 3. [Query data](#section/Compatibility-endpoints/Query-data) from InfluxDB. + 4. [Query data](#operation/GetExecuteQuerySQL) from InfluxDB. ```bash curl -G "http://localhost:8181/api/v3/query_sql" \ + --header "Authorization: Bearer ADMIN_TOKEN" \ --data-urlencode "db=sensors" \ --data-urlencode "q=SELECT * FROM home WHERE room='Living room'" \ --data-urlencode "format=jsonl" @@ -156,8 +197,12 @@ tags: x-traitTag: true - name: Server information description: Retrieve server metrics, status, and version information - - name: Tables + - name: Table description: Manage table schemas and data + - name: Token + description: Manage tokens for authentication and authorization + - name: Write data + description: Write data to InfluxDB 3 paths: /write: post: @@ -244,7 +289,7 @@ paths: description: Request entity too large. tags: - Compatibility endpoints - - Data I/O + - Write data /api/v2/write: post: operationId: PostV2Write @@ -327,7 +372,7 @@ paths: description: Request entity too large. tags: - Compatibility endpoints - - Data I/O + - Write data /api/v3/write_lp: post: operationId: PostWriteLP @@ -387,7 +432,7 @@ paths: '422': description: Unprocessable entity. tags: - - Data I/O + - Write data /api/v3/query_sql: get: operationId: GetExecuteQuerySQL @@ -446,7 +491,7 @@ paths: '422': description: Unprocessable entity. tags: - - Data I/O + - Query data post: operationId: PostExecuteQuerySQL summary: Execute SQL query @@ -485,7 +530,7 @@ paths: '422': description: Unprocessable entity. tags: - - Data I/O + - Query data /api/v3/query_influxql: get: operationId: GetExecuteInfluxQLQuery @@ -533,7 +578,7 @@ paths: '422': description: Unprocessable entity. tags: - - Data I/O + - Query data post: operationId: PostExecuteQueryInfluxQL summary: Execute InfluxQL query @@ -572,7 +617,7 @@ paths: '422': description: Unprocessable entity. tags: - - Data I/O + - Query data /query: get: operationId: GetV1ExecuteQuery @@ -678,7 +723,7 @@ paths: '422': description: Unprocessable entity. tags: - - Data I/O + - Query data - Compatibility endpoints post: operationId: PostExecuteV1Query @@ -789,7 +834,7 @@ paths: '422': description: Unprocessable entity. tags: - - Data I/O + - Query data - Compatibility endpoints /health: get: @@ -863,7 +908,7 @@ paths: '404': description: Database not found. tags: - - Databases + - Database post: operationId: PostConfigureDatabase summary: Create a database @@ -884,7 +929,7 @@ paths: '409': description: Database already exists. tags: - - Databases + - Database delete: operationId: DeleteConfigureDatabase summary: Delete a database @@ -901,7 +946,7 @@ paths: '404': description: Database not found. tags: - - Databases + - Database /api/v3/configure/table: post: operationId: PostConfigureTable @@ -923,7 +968,7 @@ paths: '404': description: Database not found. tags: - - Tables + - Table delete: operationId: DeleteConfigureTable summary: Delete a table @@ -945,14 +990,15 @@ paths: '404': description: Table not found. tags: - - Tables + - Table /api/v3/configure/distinct_cache: post: operationId: PostConfigureDistinctCache summary: Create distinct cache description: Creates a distinct cache for a table. tags: - - Tables + - Cache data + - Table requestBody: required: true content: @@ -992,7 +1038,8 @@ paths: '409': description: Cache already exists. tags: - - Tables + - Cache data + - Table delete: operationId: DeleteConfigureLastCache summary: Delete last cache @@ -1019,7 +1066,8 @@ paths: '404': description: Cache not found. tags: - - Tables + - Cache data + - Table /api/v3/configure/processing_engine_trigger: post: operationId: PostConfigureProcessingEngineTrigger @@ -1280,6 +1328,50 @@ paths: description: Processing failure. tags: - Processing engine + /api/v3/configure/token/admin: + post: + operationId: PostCreateAdminToken + summary: Create admin token + description: | + Creates an admin token. + An admin token is a special type of token that has full access to all resources in the system. + + This endpoint is only available in InfluxDB 3 Enterprise. + responses: + '201': + description: | + Success. The admin token has been created. + The response body contains the token string and metadata. + content: + application/json: + schema: + $ref: '#/components/schemas/AdminTokenObject' + '401': + $ref: '#/components/responses/Unauthorized' + tags: + - Authentication + - Token + /api/v3/configure/token/admin/regenerate: + post: + operationId: PostRegenerateAdminToken + summary: Regenerate admin token + description: | + Regenerates an admin token and revokes the previous token with the same name. + + This endpoint is only available in InfluxDB 3 Enterprise. + parameters: [] + responses: + '201': + description: Success. The admin token has been regenerated. + content: + application/json: + schema: + $ref: '#/components/schemas/AdminTokenObject' + '401': + $ref: '#/components/responses/Unauthorized' + tags: + - Authentication + - Token components: parameters: AcceptQueryHeader: @@ -1416,6 +1508,29 @@ components: schema: $ref: '#/components/schemas/QueryRequestObject' schemas: + AdminTokenObject: + type: object + properties: + id: + type: integer + name: + type: string + token: + type: string + hash: + type: string + created_at: + type: string + format: date-time + expiry: + format: date-time + example: + id: 0 + name: _admin + token: apiv3_00xx0Xx0xx00XX0x0 + hash: 00xx0Xx0xx00XX0x0 + created_at: '2025-04-18T14:02:45.331Z' + expiry: null ContentEncoding: type: string enum: @@ -1457,13 +1572,10 @@ components: description: | Acknowledges a successful write without waiting for WAL persistence. - #### Data flow in InfluxDB 3 Core + #### Related - 1. **Incoming writes**: The system validates incoming data and stores it in the write buffer (in memory). If the `no_sync` write option is enabled (`no_sync=true`), the server sends a response to acknowledge the write. - 2. **WAL flush**: Every second (default), the system flushes the write buffer to the Write-Ahead Log (WAL) for persistence in the Object store. If `no_sync=false` (default), the server sends a response to acknowledge the write. - 3. **Query availability**: After WAL persistence completes, data moves to the queryable buffer where it becomes available for queries. By default, the server keeps up to 900 WAL files (15 minutes of data) buffered. - 4. **Long-term storage in Parquet**: Every ten minutes (default), the system persists the oldest data from the queryable buffer to the Object store in Parquet format. InfluxDB keeps the remaining data (the most recent 5 minutes) in memory. - 5. **In-memory cache**: InfluxDB puts Parquet files into an in-memory cache so that queries against the most recently persisted data don't have to go to object storage. + - [Use the HTTP API and client libraries to write data](/influxdb3/core/write-data/api-client-libraries/) + - [Data durability](/influxdb3/core/reference/internals/durability/) PrecisionWriteCompatibility: enum: - ms @@ -1782,11 +1894,14 @@ x-tagGroups: tags: - Quick start - Authentication + - Cache data - Common parameters - Response codes - Compatibility endpoints - - Data I/O - - Databases + - Database - Processing engine - Server information - - Tables + - Table + - Token + - Query data + - Write data diff --git a/api-docs/influxdb3/enterprise/v3/content/tag-groups.yml b/api-docs/influxdb3/enterprise/v3/content/tag-groups.yml index 5289ddb33..364d5e794 100644 --- a/api-docs/influxdb3/enterprise/v3/content/tag-groups.yml +++ b/api-docs/influxdb3/enterprise/v3/content/tag-groups.yml @@ -2,11 +2,14 @@ tags: - Quick start - Authentication + - Cache data - Common parameters - Response codes - Compatibility endpoints - - Data I/O - - Databases + - Database - Processing engine - Server information - - Tables + - Table + - Token + - Query data + - Write data diff --git a/api-docs/influxdb3/enterprise/v3/ref.yml b/api-docs/influxdb3/enterprise/v3/ref.yml index 5738d28f7..28babb0c0 100644 --- a/api-docs/influxdb3/enterprise/v3/ref.yml +++ b/api-docs/influxdb3/enterprise/v3/ref.yml @@ -43,8 +43,50 @@ security: tags: - name: Authentication description: | - During the initial Alpha phase, InfluxDB 3 Enterprise does not require authentication. + Authenticate to the InfluxDB 3 API using a bearer token. + + The InfluxDB 3 API uses tokens for authentication. + To authenticate, include the `Authorization` header in your request with the value `Bearer `. + The token must be a valid InfluxDB 3 admin token or a resource token with the required permissions for the requested operation. + + #### Related guides + + - [Manage tokens](/influxdb3/enterprise/admin/tokens/) + - [Authentication and authorization](/influxdb3/enterprise/reference/authentication/) x-traitTag: true + - name: Cache data + description: | + Manage the in-memory cache. + + #### Distinct Value Cache + + The Distinct Value Cache (DVC) lets you cache distinct + values of one or more columns in a table, improving the performance of + queries that return distinct tag and field values. + + The DVC is an in-memory cache that stores distinct values for specific columns + in a table. When you create an DVC, you can specify what columns' distinct + values to cache, the maximum number of distinct value combinations to cache, and + the maximum age of cached values. A DVC is associated with a table, which can + have multiple DVCs. + + #### Last value cache + + The Last Value Cache (LVC) lets you cache the most recent + values for specific fields in a table, improving the performance of queries that + return the most recent value of a field for specific series or the last N values + of a field. + + The LVC is an in-memory cache that stores the last N number of values for + specific fields of series in a table. When you create an LVC, you can specify + what fields to cache, what tags to use to identify each series, and the + number of values to cache for each unique series. + An LVC is associated with a table, which can have multiple LVCs. + + #### Related guides + + - [Manage the Distinct Value Cache](/influxdb3/enterprise/admin/distinct-value-cache/) + - [Manage the Last Value Cache](/influxdb3/enterprise/admin/last-value-cache/) - name: Compatibility endpoints description: | InfluxDB 3 provides compatibility endpoints for InfluxDB 1.x and InfluxDB 2.x workloads and clients. @@ -72,19 +114,8 @@ tags: ### Server information Server information endpoints such as `/health` and `metrics` are compatible with InfluxDB 1.x and InfluxDB 2.x clients. - - name: Data I/O - description: | - Write and query data - - #### Data flow in InfluxDB 3 Enterprise - - 1. **Incoming writes**: The system validates incoming data and stores it in the write buffer (in memory). If the `no_sync` write option is enabled (`no_sync=true`), the server sends a response to acknowledge the write. - 2. **WAL flush**: Every second (default), the system flushes the write buffer to the Write-Ahead Log (WAL) for persistence in the Object store. If `no_sync=false` (default), the server sends a response to acknowledge the write. - 3. **Query availability**: After WAL persistence completes, data moves to the queryable buffer where it becomes available for queries. By default, the server keeps up to 900 WAL files (15 minutes of data) buffered. - 4. **Long-term storage in Parquet**: Every ten minutes (default), the system persists the oldest data from the queryable buffer to the Object store in Parquet format. InfluxDB keeps the remaining data (the most recent 5 minutes) in memory. - 5. **In-memory cache**: InfluxDB puts Parquet files into an in-memory cache so that queries against the most recently persisted data don't have to go to object storage. - - name: Databases - description: Create, read, update, and delete database and cache resources + - name: Database + description: Manage databases - description: | Most InfluxDB API endpoints require parameters in the request--for example, specifying the database to use. @@ -119,28 +150,38 @@ tags: Use Processing engine plugins and triggers to run code and perform tasks for different database events. To get started with the Processing engine, see the [Processing engine and Python plugins](/influxdb3/enterprise/processing-engine/) guide. + - name: Query data + description: Query data using SQL or InfluxQL - name: Quick start description: | - 1. [Check the status](#section/Server-information) of the InfluxDB server. + 1. [Create an admin token](#section/Authentication) for the InfluxDB 3 Enterprise API. ```bash - curl "http://localhost:8181/health" + curl -X POST "http://localhost:8181/api/v3/enterprise/configure/token/admin" + ``` + 2. [Check the status](#section/Server-information) of the InfluxDB server. + + ```bash + curl "http://localhost:8181/health" \ + --header "Authorization: Bearer ADMIN_TOKEN" ``` - 2. [Write data](#section/Compatibility-endpoints/Write-data) to InfluxDB. + 3. [Write data](#operation/PostWriteLP) to InfluxDB. ```bash - curl "http://localhost:8181/api/v3/write_lp?db=sensors&precision=auto" \ + curl "http://localhost:8181/api/v3/write_lp?db=sensors&precision=auto" + --header "Authorization: Bearer ADMIN_TOKEN" \ --data-raw "home,room=Kitchen temp=72.0 home,room=Living\ room temp=71.5" ``` If all data is written, the response is `204 No Content`. - 3. [Query data](#section/Compatibility-endpoints/Query-data) from InfluxDB. + 4. [Query data](#operation/GetExecuteQuerySQL) from InfluxDB. ```bash curl -G "http://localhost:8181/api/v3/query_sql" \ + --header "Authorization: Bearer ADMIN_TOKEN" \ --data-urlencode "db=sensors" \ --data-urlencode "q=SELECT * FROM home WHERE room='Living room'" \ --data-urlencode "format=jsonl" @@ -156,8 +197,12 @@ tags: x-traitTag: true - name: Server information description: Retrieve server metrics, status, and version information - - name: Tables + - name: Table description: Manage table schemas and data + - name: Token + description: Manage tokens for authentication and authorization + - name: Write data + description: Write data to InfluxDB 3 paths: /write: post: @@ -244,7 +289,7 @@ paths: description: Request entity too large. tags: - Compatibility endpoints - - Data I/O + - Write data /api/v2/write: post: operationId: PostV2Write @@ -327,7 +372,7 @@ paths: description: Request entity too large. tags: - Compatibility endpoints - - Data I/O + - Write data /api/v3/write_lp: post: operationId: PostWriteLP @@ -387,7 +432,7 @@ paths: '422': description: Unprocessable entity. tags: - - Data I/O + - Write data /api/v3/query_sql: get: operationId: GetExecuteQuerySQL @@ -446,7 +491,7 @@ paths: '422': description: Unprocessable entity. tags: - - Data I/O + - Query data post: operationId: PostExecuteQuerySQL summary: Execute SQL query @@ -485,7 +530,7 @@ paths: '422': description: Unprocessable entity. tags: - - Data I/O + - Query data /api/v3/query_influxql: get: operationId: GetExecuteInfluxQLQuery @@ -533,7 +578,7 @@ paths: '422': description: Unprocessable entity. tags: - - Data I/O + - Query data post: operationId: PostExecuteQueryInfluxQL summary: Execute InfluxQL query @@ -572,7 +617,7 @@ paths: '422': description: Unprocessable entity. tags: - - Data I/O + - Query data /query: get: operationId: GetV1ExecuteQuery @@ -678,7 +723,7 @@ paths: '422': description: Unprocessable entity. tags: - - Data I/O + - Query data - Compatibility endpoints post: operationId: PostExecuteV1Query @@ -789,7 +834,7 @@ paths: '422': description: Unprocessable entity. tags: - - Data I/O + - Query data - Compatibility endpoints /health: get: @@ -863,7 +908,7 @@ paths: '404': description: Database not found. tags: - - Databases + - Database post: operationId: PostConfigureDatabase summary: Create a database @@ -884,7 +929,7 @@ paths: '409': description: Database already exists. tags: - - Databases + - Database delete: operationId: DeleteConfigureDatabase summary: Delete a database @@ -901,7 +946,7 @@ paths: '404': description: Database not found. tags: - - Databases + - Database /api/v3/configure/table: post: operationId: PostConfigureTable @@ -923,7 +968,7 @@ paths: '404': description: Database not found. tags: - - Tables + - Table delete: operationId: DeleteConfigureTable summary: Delete a table @@ -945,14 +990,15 @@ paths: '404': description: Table not found. tags: - - Tables + - Table /api/v3/configure/distinct_cache: post: operationId: PostConfigureDistinctCache summary: Create distinct cache description: Creates a distinct cache for a table. tags: - - Tables + - Cache data + - Table requestBody: required: true content: @@ -992,7 +1038,8 @@ paths: '409': description: Cache already exists. tags: - - Tables + - Cache data + - Table delete: operationId: DeleteConfigureLastCache summary: Delete last cache @@ -1019,7 +1066,8 @@ paths: '404': description: Cache not found. tags: - - Tables + - Cache data + - Table /api/v3/configure/processing_engine_trigger: post: operationId: PostConfigureProcessingEngineTrigger @@ -1280,6 +1328,73 @@ paths: description: Processing failure. tags: - Processing engine + /api/v3/configure/enterprise/token: + post: + operationId: PostCreateResourceToken + summary: Create a resource token + description: | + Creates a resource (fine-grained permissions) token. + A resource token is a token that has access to specific resources in the system. + + This endpoint is only available in InfluxDB 3 Enterprise. + responses: + '201': + description: | + Success. The resource token has been created. + The response body contains the token string and metadata. + content: + application/json: + schema: + $ref: '#/components/schemas/ResourceTokenObject' + '401': + $ref: '#/components/responses/Unauthorized' + tags: + - Authentication + - Token + /api/v3/configure/enterprise/token/admin: + post: + operationId: PostCreateAdminToken + summary: Create admin token + description: | + Creates an admin token. + An admin token is a special type of token that has full access to all resources in the system. + + This endpoint is only available in InfluxDB 3 Enterprise. + responses: + '201': + description: | + Success. The admin token has been created. + The response body contains the token string and metadata. + content: + application/json: + schema: + $ref: '#/components/schemas/AdminTokenObject' + '401': + $ref: '#/components/responses/Unauthorized' + tags: + - Authentication + - Token + /api/v3/configure/enterprise/token/admin/regenerate: + post: + operationId: PostRegenerateAdminToken + summary: Regenerate admin token + description: | + Regenerates an admin token and revokes the previous token with the same name. + + This endpoint is only available in InfluxDB 3 Enterprise. + parameters: [] + responses: + '201': + description: Success. The admin token has been regenerated. + content: + application/json: + schema: + $ref: '#/components/schemas/AdminTokenObject' + '401': + $ref: '#/components/responses/Unauthorized' + tags: + - Authentication + - Token components: parameters: AcceptQueryHeader: @@ -1416,6 +1531,67 @@ components: schema: $ref: '#/components/schemas/QueryRequestObject' schemas: + AdminTokenObject: + type: object + properties: + id: + type: integer + name: + type: string + token: + type: string + hash: + type: string + created_at: + type: string + format: date-time + expiry: + format: date-time + example: + id: 0 + name: _admin + token: apiv3_00xx0Xx0xx00XX0x0 + hash: 00xx0Xx0xx00XX0x0 + created_at: '2025-04-18T14:02:45.331Z' + expiry: null + ResourceTokenObject: + type: object + properties: + token_name: + type: string + permissions: + type: array + items: + type: object + properties: + resource_type: + type: string + enum: + - system + - db + resource_identifier: + type: array + items: + type: string + actions: + type: array + items: + type: string + enum: + - read + - write + expiry_secs: + type: integer + description: The expiration time in seconds. + example: + token_name: All system information + permissions: + - resource_type: system + resource_identifier: + - '*' + actions: + - read + expiry_secs: 300000 ContentEncoding: type: string enum: @@ -1457,13 +1633,10 @@ components: description: | Acknowledges a successful write without waiting for WAL persistence. - #### Data flow in InfluxDB 3 Enterprise + #### Related - 1. **Incoming writes**: The system validates incoming data and stores it in the write buffer (in memory). If the `no_sync` write option is enabled (`no_sync=true`), the server sends a response to acknowledge the write. - 2. **WAL flush**: Every second (default), the system flushes the write buffer to the Write-Ahead Log (WAL) for persistence in the Object store. If `no_sync=false` (default), the server sends a response to acknowledge the write. - 3. **Query availability**: After WAL persistence completes, data moves to the queryable buffer where it becomes available for queries. By default, the server keeps up to 900 WAL files (15 minutes of data) buffered. - 4. **Long-term storage in Parquet**: Every ten minutes (default), the system persists the oldest data from the queryable buffer to the Object store in Parquet format. InfluxDB keeps the remaining data (the most recent 5 minutes) in memory. - 5. **In-memory cache**: InfluxDB puts Parquet files into an in-memory cache so that queries against the most recently persisted data don't have to go to object storage. + - [Use the HTTP API and client libraries to write data](/influxdb3/enterprise/write-data/api-client-libraries/) + - [Data durability](/influxdb3/enterprise/reference/internals/durability/) PrecisionWriteCompatibility: enum: - ms @@ -1782,11 +1955,14 @@ x-tagGroups: tags: - Quick start - Authentication + - Cache data - Common parameters - Response codes - Compatibility endpoints - - Data I/O - - Databases + - Database - Processing engine - Server information - - Tables + - Table + - Token + - Query data + - Write data diff --git a/assets/js/code-placeholders.js b/assets/js/code-placeholders.js index 3912df97d..596364819 100644 --- a/assets/js/code-placeholders.js +++ b/assets/js/code-placeholders.js @@ -1,30 +1,52 @@ -const placeholderWrapper = '.code-placeholder-wrapper'; +import $ from 'jquery'; + const placeholderElement = 'var.code-placeholder'; const editIcon = ""; // When clicking a placeholder, append the edit input -function handleClick(element) { - $(element).on('click', function() { +function handleClick($element) { + const $placeholder = $($element).find(placeholderElement); + $placeholder.on('click', function() { var placeholderData = $(this)[0].dataset; - var placeholderID = placeholderData.codeVar; + var placeholderID = placeholderData.codeVarEscaped; var placeholderValue = placeholderData.codeVarValue; - var placeholderInputWrapper = $('
'); - var placeholderInput = ``; - $(this).before(placeholderInputWrapper) - $(this).siblings('.code-input-wrapper').append(placeholderInput); - $(`input#${placeholderID}`).width(`${placeholderValue.length}ch`); - $(`input#${placeholderID}`).focus().select(); - $(this).css('opacity', 0); + const placeholderInput = document.createElement('input'); + placeholderInput.setAttribute('class', 'placeholder-edit'); + placeholderInput.setAttribute('data-id', placeholderID); + placeholderInput.setAttribute('data-code-var-escaped', placeholderID); + placeholderInput.setAttribute('value', placeholderValue); + placeholderInput.setAttribute('spellcheck', 'false'); + + placeholderInput.addEventListener('blur', function() { + submitPlaceholder($(this)); + } + ); + placeholderInput.addEventListener('input', function() { + updateInputWidth($(this)); + } + ); + placeholderInput.addEventListener('keydown', function(event) { + closeOnEnter($(this)[0], event); + } + ); + + const placeholderInputWrapper = $('
'); + $placeholder.before(placeholderInputWrapper) + $placeholder.siblings('.code-input-wrapper').append(placeholderInput); + $(`input[data-code-var-escaped="${placeholderID}"]`).width(`${placeholderValue.length}ch`); + document.querySelector(`input[data-code-var-escaped="${placeholderID}"]`).focus(); + document.querySelector(`input[data-code-var-escaped="${placeholderID}"]`).select(); + $placeholder.css('opacity', 0); }); } function submitPlaceholder(placeholderInput) { - var placeholderID = placeholderInput.attr('id'); + var placeholderID = placeholderInput.attr('data-code-var-escaped'); var placeholderValue = placeholderInput[0].value; - var placeholderInput = $(`input.placeholder-edit#${placeholderID}`); + placeholderInput = $(`input.placeholder-edit[data-id="${placeholderID}"]`); - $(`*[data-code-var='${placeholderID}']`).each(function() { + $(`*[data-code-var="${placeholderID}"]`).each(function() { $(this).attr('data-code-var-value', placeholderValue); $(this).html(placeholderValue + editIcon); $(this).css('opacity', 1); @@ -44,13 +66,7 @@ function closeOnEnter(input, event) { } } -function CodePlaceholder({element}) { - handleClick(element); -} - -$(function() { - const codePlaceholders = $(placeholderElement); - codePlaceholders.each(function() { - CodePlaceholder({element: this}); - }); -}); \ No newline at end of file +export default function CodePlaceholder({ component }) { + const $component = $(component); + handleClick($component); +} \ No newline at end of file diff --git a/assets/js/main.js b/assets/js/main.js index c1b95d1bc..57b92a837 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -39,6 +39,7 @@ import * as v3Wayfinding from './v3-wayfinding.js'; * The JavaScript is ideally a single-purpose module that exports a single default function to initialize the component and handle any component interactions. */ import AskAITrigger from './ask-ai-trigger.js'; +import CodePlaceholder from './code-placeholders.js'; import { CustomTimeTrigger } from './custom-timestamps.js'; import { SearchButton } from './search-button.js'; import { SidebarToggle } from './sidebar-toggle.js'; @@ -97,6 +98,10 @@ document.addEventListener('DOMContentLoaded', function () { AskAITrigger({ component }); window.influxdatadocs[componentName] = AskAITrigger; break; + case 'code-placeholder': + CodePlaceholder({ component }); + window.influxdatadocs[componentName] = CodePlaceholder; + break; case 'custom-time-trigger': CustomTimeTrigger({ component }); window.influxdatadocs[componentName] = CustomTimeTrigger; diff --git a/assets/styles/layouts/_homepage.scss b/assets/styles/layouts/_homepage.scss index 387c4b6be..a0583b4c9 100644 --- a/assets/styles/layouts/_homepage.scss +++ b/assets/styles/layouts/_homepage.scss @@ -120,9 +120,9 @@ } } - &.beta { + &.new { .product-info h3::after { - content: "beta"; + content: "New"; margin-left: .5rem; font-size: 1rem; padding: .25em .5em .25em .4em; diff --git a/assets/styles/layouts/_notifications.scss b/assets/styles/layouts/_notifications.scss index 00034186a..e7418ff82 100644 --- a/assets/styles/layouts/_notifications.scss +++ b/assets/styles/layouts/_notifications.scss @@ -99,6 +99,26 @@ pre { background: rgba($r-basalt, .35); } } + &.ga-announcement { + background-image: url('/svgs/influxdb3-ga-background.svg'); + background-size: cover; + a:hover { color: $br-dark-blue; } + code { color: $gr-gypsy; background: rgba($gr-gypsy, .25); } + pre { background: rgba($gr-gypsy, .25); } + + h3 {font-size: 1.4rem !important;} + .notification-slug { font-size: 1.15rem; + .btn { + display: inline-block; + background: $g20-white; + color: $br-dark-blue; + padding: .5rem 1rem; + border-radius: $radius * 2; + font-size: 1rem; + } + } + } + //////////// Basic HTML element styles for notification content //////////// h1,h2,h3,h4,h5,h6 { @@ -156,6 +176,16 @@ } .show::before {content: "Show more"} } + + .title-tag { + padding: .15rem .45rem; + text-transform: uppercase; + font-size: .85rem; + border-radius: $radius * 2; + font-family: $code; + background: $br-dark-blue; + } + .title-tag + h3 {margin-top: .75rem;} } } diff --git a/assets/styles/layouts/article/_blocks.scss b/assets/styles/layouts/article/_blocks.scss index 62b205491..090ee9560 100644 --- a/assets/styles/layouts/article/_blocks.scss +++ b/assets/styles/layouts/article/_blocks.scss @@ -96,5 +96,4 @@ blockquote { "blocks/tip", "blocks/important", "blocks/warning", - "blocks/caution", - "blocks/beta"; + "blocks/caution"; diff --git a/assets/styles/layouts/article/_feedback.scss b/assets/styles/layouts/article/_feedback.scss index 7578943ee..aba35b825 100644 --- a/assets/styles/layouts/article/_feedback.scss +++ b/assets/styles/layouts/article/_feedback.scss @@ -15,27 +15,48 @@ padding-right: 2rem; ul { - display: flex; - flex-wrap: wrap; margin-bottom: 1.25rem; padding: 0; list-style: none; - li {display: inline-block} - a { - margin-right: 1.5rem; color: $article-heading; + font-weight: $medium; + position: relative; + + &::after { + content: "\e90a"; + font-family: 'icomoon-v4'; + font-weight: bold; + font-size: 1.3rem; + display: inline-block; + position: absolute; + @include gradient($grad-burningDusk); + background-clip: text; + -webkit-text-fill-color: transparent; + right: 0; + transform: translateX(.25rem); + opacity: 0; + transition: transform .2s, opacity .2s; + } &:hover { - color: $article-link; - border-radius: calc($radius * 1.5); + &::after {transform: translateX(1.5rem); opacity: 1;} + } + + &.discord:before { + content: url('/svgs/discord.svg'); + display: inline-block; + height: 1.1rem; + width: 1.25rem; + vertical-align: top; + margin: 2px .65rem 0 0; } &.community:before { content: "\e900"; color: $article-heading; - margin: 0 .5rem 0 -.25rem; + margin-right: .75rem; font-size: 1.2rem; font-family: 'icomoon-v2'; vertical-align: middle; @@ -46,7 +67,16 @@ height: 1.1rem; width: 1.1rem; vertical-align: text-top; - margin-right: .5rem; + margin-right: .8rem; + } + + &.reddit:before { + content: url('/svgs/reddit.svg'); + display: inline-block; + height: 1.1rem; + width: 1.2rem; + vertical-align: top; + margin: 2px .75rem 0 0; } } } diff --git a/assets/styles/layouts/article/blocks/_beta.scss b/assets/styles/layouts/article/blocks/_beta.scss deleted file mode 100644 index 7c6636b94..000000000 --- a/assets/styles/layouts/article/blocks/_beta.scss +++ /dev/null @@ -1,105 +0,0 @@ -.block.beta { - @include gradient($grad-burningDusk); - padding: 4px; - border: none; - border-radius: 25px !important; - - .beta-content { - background: $article-bg; - border-radius: 21px; - padding: calc(1.65rem - 4px) calc(2rem - 4px) calc(.1rem + 4px) calc(2rem - 4px); - - h4 { - color: $article-heading; - } - - p {margin-bottom: 1rem;} - - .expand-wrapper { - border: none; - margin: .5rem 0 1.5rem; - } - .expand { - border: none; - padding: 0; - - .expand-content p { - margin-left: 2rem; - } - - ul { - - margin-top: -1rem; - - &.feedback-channels { - - padding: 0; - margin: -1rem 0 1.5rem 2rem; - list-style: none; - - a { - color: $article-heading; - font-weight: $medium; - position: relative; - - &.discord:before { - content: url('/svgs/discord.svg'); - display: inline-block; - height: 1.1rem; - width: 1.25rem; - vertical-align: top; - margin: 2px .65rem 0 0; - } - - &.community:before { - content: "\e900"; - color: $article-heading; - margin: 0 .65rem 0 0; - font-size: 1.2rem; - font-family: 'icomoon-v2'; - vertical-align: middle; - } - - &.slack:before { - content: url('/svgs/slack.svg'); - display: inline-block; - height: 1.1rem; - width: 1.1rem; - vertical-align: text-top; - margin-right: .65rem; - } - - &.reddit:before { - content: url('/svgs/reddit.svg'); - display: inline-block; - height: 1.1rem; - width: 1.2rem; - vertical-align: top; - margin: 2px .65rem 0 0; - } - - &::after { - content: "\e90a"; - font-family: 'icomoon-v4'; - font-weight: bold; - font-size: 1.3rem; - display: inline-block; - position: absolute; - @include gradient($grad-burningDusk); - background-clip: text; - -webkit-text-fill-color: transparent; - right: 0; - transform: translateX(.25rem); - opacity: 0; - transition: transform .2s, opacity .2s; - } - - &:hover { - &::after {transform: translateX(1.5rem); opacity: 1;} - } - } - } - } - } - } -} \ No newline at end of file diff --git a/compose.yaml b/compose.yaml index 1b51376e5..a2338c3b1 100644 --- a/compose.yaml +++ b/compose.yaml @@ -301,10 +301,11 @@ services: working_dir: /app influxdb3-core: container_name: influxdb3-core - image: quay.io/influxdb/influxdb3-core:latest + image: influxdb:3-core ports: - 8181:8181 command: + - influxdb3 - serve - --node-id=sensors_node0 - --log-filter=debug diff --git a/content/chronograf/v1/about_the_project/release-notes.md b/content/chronograf/v1/about_the_project/release-notes.md index ed15f4b61..5cc972a4f 100644 --- a/content/chronograf/v1/about_the_project/release-notes.md +++ b/content/chronograf/v1/about_the_project/release-notes.md @@ -10,6 +10,16 @@ aliases: - /chronograf/v1/about_the_project/release-notes-changelog/ --- +## v1.10.7 {date="2025-04-15"} + +### Bug Fixes + +- Fix Hosts page loading. + +### Dependency updates + +- Upgrade Go to 1.23.8. + ## v1.10.6 {date="2024-12-16"} ### Bug Fixes diff --git a/content/enterprise_influxdb/v1/tools/_index.md b/content/enterprise_influxdb/v1/tools/_index.md index 82327a722..08d66c4b6 100644 --- a/content/enterprise_influxdb/v1/tools/_index.md +++ b/content/enterprise_influxdb/v1/tools/_index.md @@ -6,6 +6,15 @@ menu: enterprise_influxdb_v1: name: Tools weight: 72 +aliases: + - /enterprise_influxdb/v1/tools/flux-vscode/ +prepend: | + > [!Important] + > #### Flux VS Code extension no longer available + > + > The `vsflux` extension is no longer available in the Visual Studio Marketplace. + > `vsflux` and the `flux-lsp` Flux Language Server Protocol plugin are no longer maintained. + > Their repositories have been archived and are no longer receiving updates. --- Use the following tools to work with InfluxDB Enterprise: diff --git a/content/enterprise_influxdb/v1/tools/flux-vscode.md b/content/enterprise_influxdb/v1/tools/flux-vscode.md index c9bd512c8..14e2abcfb 100644 --- a/content/enterprise_influxdb/v1/tools/flux-vscode.md +++ b/content/enterprise_influxdb/v1/tools/flux-vscode.md @@ -10,6 +10,14 @@ menu: enterprise_influxdb_v1: name: Flux VS Code extension parent: Tools +draft: true +prepend: | + > [!Important] + > #### Flux VS Code extension no longer available + > + > The `vsflux` extension is no longer available in the Visual Studio Marketplace. + > `vsflux` and the `flux-lsp` Flux Language Server Protocol plugin are no longer maintained. + > Their repositories have been archived and are no longer receiving updates. --- The [Flux Visual Studio Code (VS Code) extension](https://marketplace.visualstudio.com/items?itemName=influxdata.flux) diff --git a/content/influxdb/cloud/admin/buckets/delete-bucket.md b/content/influxdb/cloud/admin/buckets/delete-bucket.md index a898c378f..aac11e7a7 100644 --- a/content/influxdb/cloud/admin/buckets/delete-bucket.md +++ b/content/influxdb/cloud/admin/buckets/delete-bucket.md @@ -9,6 +9,8 @@ menu: weight: 203 aliases: - /influxdb/cloud/organizations/buckets/delete-bucket/ +source: /shared/influxdb-v2/admin/buckets/delete-bucket.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/admin/tokens/create-token.md b/content/influxdb/cloud/admin/tokens/create-token.md index 8caeabd03..e545f1b51 100644 --- a/content/influxdb/cloud/admin/tokens/create-token.md +++ b/content/influxdb/cloud/admin/tokens/create-token.md @@ -13,6 +13,8 @@ alt_links: cloud-serverless: /influxdb3/cloud-serverless/admin/tokens/create-token cloud-dedicated: /influxdb3/cloud-dedicated/admin/tokens/database/create clustered: /influxdb3/clustered/admin/tokens/database/create +source: /shared/influxdb-v2/admin/tokens/create-token.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/admin/tokens/delete-token.md b/content/influxdb/cloud/admin/tokens/delete-token.md index 57daf646a..9774b9ab5 100644 --- a/content/influxdb/cloud/admin/tokens/delete-token.md +++ b/content/influxdb/cloud/admin/tokens/delete-token.md @@ -9,6 +9,8 @@ menu: weight: 204 aliases: - /influxdb/cloud/security/tokens/delete-token/ +source: /shared/influxdb-v2/admin/tokens/delete-token.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/admin/tokens/update-tokens.md b/content/influxdb/cloud/admin/tokens/update-tokens.md index 0595c404d..ea793bde5 100644 --- a/content/influxdb/cloud/admin/tokens/update-tokens.md +++ b/content/influxdb/cloud/admin/tokens/update-tokens.md @@ -9,6 +9,8 @@ menu: weight: 203 aliases: - /influxdb/cloud/security/tokens/update-tokens/ +source: /shared/influxdb-v2/admin/tokens/update-tokens.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/admin/tokens/use-tokens.md b/content/influxdb/cloud/admin/tokens/use-tokens.md index cb9dbf9c9..6b537f18a 100644 --- a/content/influxdb/cloud/admin/tokens/use-tokens.md +++ b/content/influxdb/cloud/admin/tokens/use-tokens.md @@ -9,6 +9,8 @@ menu: weight: 204 aliases: - /influxdb/cloud/security/tokens/use-tokens/ +source: /shared/influxdb-v2/admin/tokens/use-tokens.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/admin/tokens/view-tokens.md b/content/influxdb/cloud/admin/tokens/view-tokens.md index f0fd83ae0..239ac46ee 100644 --- a/content/influxdb/cloud/admin/tokens/view-tokens.md +++ b/content/influxdb/cloud/admin/tokens/view-tokens.md @@ -10,6 +10,8 @@ weight: 202 aliases: - /influxdb/cloud/users/tokens/view-tokens - /influxdb/cloud/security/tokens/view-tokens/ +source: /shared/influxdb-v2/admin/tokens/view-tokens.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/api-guide/api_intro.md b/content/influxdb/cloud/api-guide/api_intro.md index e6c4aa518..93d5ed401 100644 --- a/content/influxdb/cloud/api-guide/api_intro.md +++ b/content/influxdb/cloud/api-guide/api_intro.md @@ -10,6 +10,8 @@ menu: aliases: - /influxdb/cloud/tools/api/ influxdb/cloud/tags: [api] +source: /shared/influxdb-v2/api-guide/api_intro.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/api-guide/client-libraries/_index.md b/content/influxdb/cloud/api-guide/client-libraries/_index.md index 1545cab52..dd7a3b1f8 100644 --- a/content/influxdb/cloud/api-guide/client-libraries/_index.md +++ b/content/influxdb/cloud/api-guide/client-libraries/_index.md @@ -14,6 +14,8 @@ menu: name: Client libraries parent: Develop with the API influxdb/cloud/tags: [client libraries] +source: /shared/influxdb-v2/api-guide/client-libraries/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/api-guide/client-libraries/arduino.md b/content/influxdb/cloud/api-guide/client-libraries/arduino.md index 5fda9bd52..acdf879f2 100644 --- a/content/influxdb/cloud/api-guide/client-libraries/arduino.md +++ b/content/influxdb/cloud/api-guide/client-libraries/arduino.md @@ -12,6 +12,8 @@ menu: params: url: https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/arduino.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/api-guide/client-libraries/browserjs.md b/content/influxdb/cloud/api-guide/client-libraries/browserjs.md index 0eeccbeba..d4f3992aa 100644 --- a/content/influxdb/cloud/api-guide/client-libraries/browserjs.md +++ b/content/influxdb/cloud/api-guide/client-libraries/browserjs.md @@ -18,6 +18,8 @@ aliases: related: - /influxdb/cloud/api-guide/client-libraries/nodejs/write/ - /influxdb/cloud/api-guide/client-libraries/nodejs/query/ +source: /shared/influxdb-v2/api-guide/client-libraries/browserjs.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/api-guide/client-libraries/csharp.md b/content/influxdb/cloud/api-guide/client-libraries/csharp.md index 93235f2e0..68b324bcb 100644 --- a/content/influxdb/cloud/api-guide/client-libraries/csharp.md +++ b/content/influxdb/cloud/api-guide/client-libraries/csharp.md @@ -11,6 +11,8 @@ menu: params: url: https://github.com/influxdata/influxdb-client-csharp weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/csharp.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/api-guide/client-libraries/dart.md b/content/influxdb/cloud/api-guide/client-libraries/dart.md index 082bac981..1e70b1c7e 100644 --- a/content/influxdb/cloud/api-guide/client-libraries/dart.md +++ b/content/influxdb/cloud/api-guide/client-libraries/dart.md @@ -11,6 +11,8 @@ menu: params: url: https://github.com/influxdata/influxdb-client-dart weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/dart.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/api-guide/client-libraries/go.md b/content/influxdb/cloud/api-guide/client-libraries/go.md index 89e86e1c4..c683e635e 100644 --- a/content/influxdb/cloud/api-guide/client-libraries/go.md +++ b/content/influxdb/cloud/api-guide/client-libraries/go.md @@ -13,6 +13,8 @@ weight: 201 aliases: - /influxdb/cloud/reference/api/client-libraries/go/ - /influxdb/cloud/tools/client-libraries/go/ +source: /shared/influxdb-v2/api-guide/client-libraries/go.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/api-guide/client-libraries/java.md b/content/influxdb/cloud/api-guide/client-libraries/java.md index 19d21f483..62b58a2f9 100644 --- a/content/influxdb/cloud/api-guide/client-libraries/java.md +++ b/content/influxdb/cloud/api-guide/client-libraries/java.md @@ -11,6 +11,8 @@ menu: params: url: https://github.com/influxdata/influxdb-client-java weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/java.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/api-guide/client-libraries/kotlin.md b/content/influxdb/cloud/api-guide/client-libraries/kotlin.md index 7abf1e9e7..db39c2c6d 100644 --- a/content/influxdb/cloud/api-guide/client-libraries/kotlin.md +++ b/content/influxdb/cloud/api-guide/client-libraries/kotlin.md @@ -11,6 +11,8 @@ menu: params: url: https://github.com/influxdata/influxdb-client-java/tree/master/client-kotlin weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/kotlin.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/api-guide/client-libraries/nodejs/_index.md b/content/influxdb/cloud/api-guide/client-libraries/nodejs/_index.md index 4c4d111d8..dd8f90b3b 100644 --- a/content/influxdb/cloud/api-guide/client-libraries/nodejs/_index.md +++ b/content/influxdb/cloud/api-guide/client-libraries/nodejs/_index.md @@ -14,6 +14,8 @@ aliases: - /influxdb/cloud/reference/api/client-libraries/js/ - /influxdb/cloud/reference/api/client-libraries/nodejs/ - /influxdb/cloud/tools/client-libraries/js/ +source: /shared/influxdb-v2/api-guide/client-libraries/nodejs/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/api-guide/client-libraries/nodejs/install.md b/content/influxdb/cloud/api-guide/client-libraries/nodejs/install.md index 16fe4f30c..0d45279f7 100644 --- a/content/influxdb/cloud/api-guide/client-libraries/nodejs/install.md +++ b/content/influxdb/cloud/api-guide/client-libraries/nodejs/install.md @@ -12,9 +12,11 @@ weight: 100 aliases: - /influxdb/cloud/reference/api/client-libraries/js/install - /influxdb/cloud/reference/api/client-libraries/nodejs/install +source: /shared/influxdb-v2/api-guide/client-libraries/nodejs/install.md --- -{{< duplicate-oss >}} + {{% note %}} The URL in the examples depends on your [InfluxDB Cloud region](/influxdb/cloud/reference/regions/). diff --git a/content/influxdb/cloud/api-guide/client-libraries/nodejs/query.md b/content/influxdb/cloud/api-guide/client-libraries/nodejs/query.md index 2e4505a9d..a522bcd77 100644 --- a/content/influxdb/cloud/api-guide/client-libraries/nodejs/query.md +++ b/content/influxdb/cloud/api-guide/client-libraries/nodejs/query.md @@ -11,6 +11,8 @@ weight: 201 aliases: - /influxdb/cloud/reference/api/client-libraries/js/query - /influxdb/cloud/reference/api/client-libraries/nodejs/query +source: /shared/influxdb-v2/api-guide/client-libraries/nodejs/query.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/api-guide/client-libraries/nodejs/write.md b/content/influxdb/cloud/api-guide/client-libraries/nodejs/write.md index e748b3893..7b3b0d1be 100644 --- a/content/influxdb/cloud/api-guide/client-libraries/nodejs/write.md +++ b/content/influxdb/cloud/api-guide/client-libraries/nodejs/write.md @@ -13,6 +13,8 @@ aliases: - /influxdb/cloud/reference/api/client-libraries/nodejs/write related: - /influxdb/cloud/write-data/troubleshoot/ +source: /shared/influxdb-v2/api-guide/client-libraries/nodejs/write.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/api-guide/client-libraries/php.md b/content/influxdb/cloud/api-guide/client-libraries/php.md index c0e78d0a4..14bfda2e1 100644 --- a/content/influxdb/cloud/api-guide/client-libraries/php.md +++ b/content/influxdb/cloud/api-guide/client-libraries/php.md @@ -11,6 +11,8 @@ menu: params: url: https://github.com/influxdata/influxdb-client-php weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/php.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/api-guide/client-libraries/python.md b/content/influxdb/cloud/api-guide/client-libraries/python.md index 601c48562..f1af070e4 100644 --- a/content/influxdb/cloud/api-guide/client-libraries/python.md +++ b/content/influxdb/cloud/api-guide/client-libraries/python.md @@ -14,6 +14,8 @@ aliases: - /influxdb/cloud/reference/api/client-libraries/python-cl-guide/ - /influxdb/cloud/tools/client-libraries/python/ weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/python.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/api-guide/client-libraries/r.md b/content/influxdb/cloud/api-guide/client-libraries/r.md index 526042d2c..d1787ebeb 100644 --- a/content/influxdb/cloud/api-guide/client-libraries/r.md +++ b/content/influxdb/cloud/api-guide/client-libraries/r.md @@ -11,6 +11,8 @@ menu: params: url: https://github.com/influxdata/influxdb-client-r weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/r.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/api-guide/client-libraries/ruby.md b/content/influxdb/cloud/api-guide/client-libraries/ruby.md index 5d58bad23..c56057fad 100644 --- a/content/influxdb/cloud/api-guide/client-libraries/ruby.md +++ b/content/influxdb/cloud/api-guide/client-libraries/ruby.md @@ -11,6 +11,8 @@ menu: params: url: https://github.com/influxdata/influxdb-client-ruby weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/ruby.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/api-guide/client-libraries/scala.md b/content/influxdb/cloud/api-guide/client-libraries/scala.md index f635b5f02..6650e3333 100644 --- a/content/influxdb/cloud/api-guide/client-libraries/scala.md +++ b/content/influxdb/cloud/api-guide/client-libraries/scala.md @@ -11,6 +11,8 @@ menu: params: url: https://github.com/influxdata/influxdb-client-java/tree/master/client-scala weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/scala.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/api-guide/client-libraries/swift.md b/content/influxdb/cloud/api-guide/client-libraries/swift.md index 8412bd973..b885c77fe 100644 --- a/content/influxdb/cloud/api-guide/client-libraries/swift.md +++ b/content/influxdb/cloud/api-guide/client-libraries/swift.md @@ -11,6 +11,8 @@ menu: params: url: https://github.com/influxdata/influxdb-client-swift weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/swift.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/api-guide/influxdb-1x/_index.md b/content/influxdb/cloud/api-guide/influxdb-1x/_index.md index cdc3b5ea4..5eeccf0f1 100644 --- a/content/influxdb/cloud/api-guide/influxdb-1x/_index.md +++ b/content/influxdb/cloud/api-guide/influxdb-1x/_index.md @@ -13,6 +13,8 @@ related: - /influxdb/cloud/query-data/influxql aliases: - /influxdb/cloud/reference/api/influxdb-1x/ +source: /shared/influxdb-v2/api-guide/influxdb-1x/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/api-guide/influxdb-1x/dbrp.md b/content/influxdb/cloud/api-guide/influxdb-1x/dbrp.md index 4c4645107..f395bc2fc 100644 --- a/content/influxdb/cloud/api-guide/influxdb-1x/dbrp.md +++ b/content/influxdb/cloud/api-guide/influxdb-1x/dbrp.md @@ -15,6 +15,8 @@ related: - /influxdb/cloud/query-data/influxql/ aliases: - /influxdb/cloud/reference/api/influxdb-1x/dbrp/ +source: /shared/influxdb-v2/api-guide/influxdb-1x/dbrp.md --- -{{% duplicate-oss %}} + diff --git a/content/influxdb/cloud/api-guide/influxdb-1x/query.md b/content/influxdb/cloud/api-guide/influxdb-1x/query.md index 284c74072..b6a1a31fd 100644 --- a/content/influxdb/cloud/api-guide/influxdb-1x/query.md +++ b/content/influxdb/cloud/api-guide/influxdb-1x/query.md @@ -17,6 +17,8 @@ related: - /influxdb/cloud/query-data/influxql aliases: - /influxdb/cloud/reference/api/influxdb-1x/query/ +source: /shared/influxdb-v2/api-guide/influxdb-1x/query.md --- -{{% duplicate-oss %}} + diff --git a/content/influxdb/cloud/api-guide/influxdb-1x/write.md b/content/influxdb/cloud/api-guide/influxdb-1x/write.md index 871b51017..8a4085656 100644 --- a/content/influxdb/cloud/api-guide/influxdb-1x/write.md +++ b/content/influxdb/cloud/api-guide/influxdb-1x/write.md @@ -18,6 +18,8 @@ related: - /influxdb/cloud/reference/syntax/line-protocol aliases: - /influxdb/cloud/reference/api/influxdb-1x/write/ +source: /shared/influxdb-v2/api-guide/influxdb-1x/write.md --- -{{% duplicate-oss %}} + diff --git a/content/influxdb/cloud/api-guide/tutorials/_index.md b/content/influxdb/cloud/api-guide/tutorials/_index.md index 8940a7620..af05643c3 100644 --- a/content/influxdb/cloud/api-guide/tutorials/_index.md +++ b/content/influxdb/cloud/api-guide/tutorials/_index.md @@ -8,6 +8,8 @@ menu: name: Client library tutorials parent: Develop with the API influxdb/cloud/tags: [api] +source: /shared/influxdb-v2/api-guide/tutorials/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/api-guide/tutorials/nodejs.md b/content/influxdb/cloud/api-guide/tutorials/nodejs.md index a2faed80c..5b2bb98ff 100644 --- a/content/influxdb/cloud/api-guide/tutorials/nodejs.md +++ b/content/influxdb/cloud/api-guide/tutorials/nodejs.md @@ -11,6 +11,8 @@ menu: name: JavaScript parent: Client library tutorials influxdb/cloud/tags: [api, javascript, nodejs] +source: /shared/influxdb-v2/api-guide/tutorials/nodejs.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/api-guide/tutorials/python.md b/content/influxdb/cloud/api-guide/tutorials/python.md index 34853caeb..eebced07b 100644 --- a/content/influxdb/cloud/api-guide/tutorials/python.md +++ b/content/influxdb/cloud/api-guide/tutorials/python.md @@ -12,6 +12,8 @@ menu: name: Python parent: Client library tutorials influxdb/cloud/tags: [api, python] +source: /shared/influxdb-v2/api-guide/tutorials/python.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/get-started/_index.md b/content/influxdb/cloud/get-started/_index.md index fb226c75c..677b242a1 100644 --- a/content/influxdb/cloud/get-started/_index.md +++ b/content/influxdb/cloud/get-started/_index.md @@ -62,8 +62,8 @@ The following are important definitions to understand when using InfluxDB: - **Point**: Single data record identified by its _measurement, tag keys, tag values, field key, and timestamp_. - **Series**: A group of points with the same - {{% oss-only %}}_measurement, tag keys, and tag values_.{{% /oss-only %}} - {{% cloud-only %}}_measurement, tag keys and values, and field key_.{{% /cloud-only %}} + {{% show-in "v2" %}}_measurement, tag keys, and tag values_.{{% /show-in %}} + {{% show-in "cloud,cloud-serverless" %}}_measurement, tag keys and values, and field key_.{{% /show-in %}} ##### Example InfluxDB query results @@ -81,13 +81,13 @@ InfluxDB {{< current-version >}}. Examples are provided for each of the followin ### InfluxDB user interface (UI) The InfluxDB UI provides a web-based visual interface for interacting with and managing InfluxDB. -{{% oss-only %}}The UI is packaged with InfluxDB and runs as part of the InfluxDB service. To access the UI, with InfluxDB running, visit [localhost:8086](http://localhost:8086) in your browser.{{% /oss-only %}} -{{% cloud-only %}}To access the InfluxDB Cloud UI, [log into your InfluxDB Cloud account](https://cloud2.influxdata.com).{{% /cloud-only %}} +{{% show-in "v2" %}}The UI is packaged with InfluxDB and runs as part of the InfluxDB service. To access the UI, with InfluxDB running, visit [localhost:8086](http://localhost:8086) in your browser.{{% /show-in %}} +{{% show-in "cloud,cloud-serverless" %}}To access the InfluxDB Cloud UI, [log into your InfluxDB Cloud account](https://cloud2.influxdata.com).{{% /show-in %}} ### `influx` CLI The `influx` CLI lets you interact with and manage InfluxDB {{< current-version >}} from a command line. -{{% oss-only %}}The CLI is packaged separately from InfluxDB and must be downloaded and installed separately.{{% /oss-only %}} +{{% show-in "v2" %}}The CLI is packaged separately from InfluxDB and must be downloaded and installed separately.{{% /show-in %}} For detailed CLI installation instructions, see [Use the influx CLI](/influxdb/cloud/tools/influx-cli/). diff --git a/content/influxdb/cloud/get-started/process.md b/content/influxdb/cloud/get-started/process.md index 8dfca5015..77f4b0cf9 100644 --- a/content/influxdb/cloud/get-started/process.md +++ b/content/influxdb/cloud/get-started/process.md @@ -17,6 +17,8 @@ related: - /influxdb/cloud/process-data/get-started/ - /flux/v0/get-started/ - /flux/v0/stdlib/ +source: /shared/influxdb-v2/get-started/process.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/get-started/query.md b/content/influxdb/cloud/get-started/query.md index f07a17be0..70724646c 100644 --- a/content/influxdb/cloud/get-started/query.md +++ b/content/influxdb/cloud/get-started/query.md @@ -14,6 +14,8 @@ weight: 102 metadata: [3 / 5] related: - /influxdb/cloud/query-data/ +source: /shared/influxdb-v2/get-started/query.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/get-started/visualize.md b/content/influxdb/cloud/get-started/visualize.md index 8969836b6..6949262ee 100644 --- a/content/influxdb/cloud/get-started/visualize.md +++ b/content/influxdb/cloud/get-started/visualize.md @@ -17,6 +17,8 @@ related: - /influxdb/cloud/visualize-data/visualization-types/ - /influxdb/cloud/tools/chronograf/ - /influxdb/cloud/tools/grafana/ +source: /shared/influxdb-v2/get-started/visualize.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/get-started/write.md b/content/influxdb/cloud/get-started/write.md index 26d737efa..d4be97a40 100644 --- a/content/influxdb/cloud/get-started/write.md +++ b/content/influxdb/cloud/get-started/write.md @@ -17,6 +17,8 @@ related: - /influxdb/cloud/write-data/best-practices/ - /influxdb/cloud/reference/syntax/line-protocol/ - /telegraf/v1/ +source: /shared/influxdb-v2/get-started/write.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/monitor-alert/_index.md b/content/influxdb/cloud/monitor-alert/_index.md index 08a7622c8..317702999 100644 --- a/content/influxdb/cloud/monitor-alert/_index.md +++ b/content/influxdb/cloud/monitor-alert/_index.md @@ -9,6 +9,8 @@ menu: name: Monitor & alert weight: 6 influxdb/cloud/tags: [monitor, alert, checks, notification, endpoints] +source: /shared/influxdb-v2/monitor-alert/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/monitor-alert/checks/create.md b/content/influxdb/cloud/monitor-alert/checks/create.md index 31e9362fc..98bb831c4 100644 --- a/content/influxdb/cloud/monitor-alert/checks/create.md +++ b/content/influxdb/cloud/monitor-alert/checks/create.md @@ -10,6 +10,8 @@ weight: 201 related: - /influxdb/cloud/monitor-alert/notification-rules/ - /influxdb/cloud/monitor-alert/notification-endpoints/ +source: /shared/influxdb-v2/monitor-alert/checks/create.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/monitor-alert/checks/delete.md b/content/influxdb/cloud/monitor-alert/checks/delete.md index 6688b5370..5295778ea 100644 --- a/content/influxdb/cloud/monitor-alert/checks/delete.md +++ b/content/influxdb/cloud/monitor-alert/checks/delete.md @@ -10,6 +10,8 @@ weight: 204 related: - /influxdb/cloud/monitor-alert/notification-rules/ - /influxdb/cloud/monitor-alert/notification-endpoints/ +source: /shared/influxdb-v2/monitor-alert/checks/delete.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/monitor-alert/checks/update.md b/content/influxdb/cloud/monitor-alert/checks/update.md index ba9f62f30..b4ddabfab 100644 --- a/content/influxdb/cloud/monitor-alert/checks/update.md +++ b/content/influxdb/cloud/monitor-alert/checks/update.md @@ -10,6 +10,8 @@ weight: 203 related: - /influxdb/cloud/monitor-alert/notification-rules/ - /influxdb/cloud/monitor-alert/notification-endpoints/ +source: /shared/influxdb-v2/monitor-alert/checks/update.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/monitor-alert/checks/view.md b/content/influxdb/cloud/monitor-alert/checks/view.md index cc678a791..d5a363710 100644 --- a/content/influxdb/cloud/monitor-alert/checks/view.md +++ b/content/influxdb/cloud/monitor-alert/checks/view.md @@ -10,6 +10,8 @@ weight: 202 related: - /influxdb/cloud/monitor-alert/notification-rules/ - /influxdb/cloud/monitor-alert/notification-endpoints/ +source: /shared/influxdb-v2/monitor-alert/checks/view.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/monitor-alert/custom-checks.md b/content/influxdb/cloud/monitor-alert/custom-checks.md index 1f58ab02d..593662b91 100644 --- a/content/influxdb/cloud/monitor-alert/custom-checks.md +++ b/content/influxdb/cloud/monitor-alert/custom-checks.md @@ -8,6 +8,8 @@ menu: parent: Monitor & alert weight: 201 influxdb/cloud/tags: [alerts, checks, tasks, Flux] +source: /shared/influxdb-v2/monitor-alert/custom-checks.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/monitor-alert/notification-endpoints/create.md b/content/influxdb/cloud/monitor-alert/notification-endpoints/create.md index 74e648000..9b9d46a4f 100644 --- a/content/influxdb/cloud/monitor-alert/notification-endpoints/create.md +++ b/content/influxdb/cloud/monitor-alert/notification-endpoints/create.md @@ -10,6 +10,8 @@ weight: 201 related: - /influxdb/cloud/monitor-alert/checks/ - /influxdb/cloud/monitor-alert/notification-rules/ +source: /shared/influxdb-v2/monitor-alert/notification-endpoints/create.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/monitor-alert/notification-endpoints/delete.md b/content/influxdb/cloud/monitor-alert/notification-endpoints/delete.md index ad16d9cc7..418f2afd5 100644 --- a/content/influxdb/cloud/monitor-alert/notification-endpoints/delete.md +++ b/content/influxdb/cloud/monitor-alert/notification-endpoints/delete.md @@ -10,6 +10,8 @@ weight: 204 related: - /influxdb/cloud/monitor-alert/checks/ - /influxdb/cloud/monitor-alert/notification-rules/ +source: /shared/influxdb-v2/monitor-alert/notification-endpoints/delete.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/monitor-alert/notification-endpoints/update.md b/content/influxdb/cloud/monitor-alert/notification-endpoints/update.md index 4cbef2187..cdaaa190c 100644 --- a/content/influxdb/cloud/monitor-alert/notification-endpoints/update.md +++ b/content/influxdb/cloud/monitor-alert/notification-endpoints/update.md @@ -10,6 +10,8 @@ weight: 203 related: - /influxdb/cloud/monitor-alert/checks/ - /influxdb/cloud/monitor-alert/notification-rules/ +source: /shared/influxdb-v2/monitor-alert/notification-endpoints/update.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/monitor-alert/notification-endpoints/view.md b/content/influxdb/cloud/monitor-alert/notification-endpoints/view.md index dea960bc8..95ae1f79b 100644 --- a/content/influxdb/cloud/monitor-alert/notification-endpoints/view.md +++ b/content/influxdb/cloud/monitor-alert/notification-endpoints/view.md @@ -11,6 +11,8 @@ weight: 202 related: - /influxdb/cloud/monitor-alert/checks/ - /influxdb/cloud/monitor-alert/notification-rules/ +source: /shared/influxdb-v2/monitor-alert/notification-endpoints/view.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/monitor-alert/notification-rules/create.md b/content/influxdb/cloud/monitor-alert/notification-rules/create.md index f1323057d..4fa4cf56b 100644 --- a/content/influxdb/cloud/monitor-alert/notification-rules/create.md +++ b/content/influxdb/cloud/monitor-alert/notification-rules/create.md @@ -9,6 +9,8 @@ menu: related: - /influxdb/cloud/monitor-alert/checks/ - /influxdb/cloud/monitor-alert/notification-endpoints/ +source: /shared/influxdb-v2/monitor-alert/notification-rules/create.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/monitor-alert/notification-rules/delete.md b/content/influxdb/cloud/monitor-alert/notification-rules/delete.md index e44e5ae58..f3aa8afa2 100644 --- a/content/influxdb/cloud/monitor-alert/notification-rules/delete.md +++ b/content/influxdb/cloud/monitor-alert/notification-rules/delete.md @@ -9,6 +9,8 @@ menu: related: - /influxdb/cloud/monitor-alert/checks/ - /influxdb/cloud/monitor-alert/notification-endpoints/ +source: /shared/influxdb-v2/monitor-alert/notification-rules/delete.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/monitor-alert/notification-rules/update.md b/content/influxdb/cloud/monitor-alert/notification-rules/update.md index 057091adf..342d76b69 100644 --- a/content/influxdb/cloud/monitor-alert/notification-rules/update.md +++ b/content/influxdb/cloud/monitor-alert/notification-rules/update.md @@ -9,6 +9,8 @@ menu: related: - /influxdb/cloud/monitor-alert/checks/ - /influxdb/cloud/monitor-alert/notification-endpoints/ +source: /shared/influxdb-v2/monitor-alert/notification-rules/update.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/monitor-alert/notification-rules/view.md b/content/influxdb/cloud/monitor-alert/notification-rules/view.md index cea864f3d..7d34466de 100644 --- a/content/influxdb/cloud/monitor-alert/notification-rules/view.md +++ b/content/influxdb/cloud/monitor-alert/notification-rules/view.md @@ -9,6 +9,8 @@ menu: related: - /influxdb/cloud/monitor-alert/checks/ - /influxdb/cloud/monitor-alert/notification-endpoints/ +source: /shared/influxdb-v2/monitor-alert/notification-rules/view.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/monitor-alert/send-email.md b/content/influxdb/cloud/monitor-alert/send-email.md index 8bfa768af..faa20ccc1 100644 --- a/content/influxdb/cloud/monitor-alert/send-email.md +++ b/content/influxdb/cloud/monitor-alert/send-email.md @@ -9,6 +9,8 @@ weight: 104 influxdb/cloud/tags: [alert, email, notifications, check] related: - /influxdb/cloud/monitor-alert/checks/ +source: /shared/influxdb-v2/monitor-alert/send-email.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/monitor-alert/templates/infrastructure/aws.md b/content/influxdb/cloud/monitor-alert/templates/infrastructure/aws.md index 5e68fda54..f52a361eb 100644 --- a/content/influxdb/cloud/monitor-alert/templates/infrastructure/aws.md +++ b/content/influxdb/cloud/monitor-alert/templates/infrastructure/aws.md @@ -7,6 +7,8 @@ menu: parent: Monitor infrastructure name: AWS CloudWatch weight: 201 +source: /shared/influxdb-v2/monitor-alert/templates/infrastructure/aws.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/monitor-alert/templates/infrastructure/docker.md b/content/influxdb/cloud/monitor-alert/templates/infrastructure/docker.md index a95abacfe..b1ab8a465 100644 --- a/content/influxdb/cloud/monitor-alert/templates/infrastructure/docker.md +++ b/content/influxdb/cloud/monitor-alert/templates/infrastructure/docker.md @@ -7,6 +7,8 @@ menu: parent: Monitor infrastructure name: Docker weight: 202 +source: /shared/influxdb-v2/monitor-alert/templates/infrastructure/docker.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/monitor-alert/templates/infrastructure/raspberry-pi.md b/content/influxdb/cloud/monitor-alert/templates/infrastructure/raspberry-pi.md index dfb9495db..1c7edb60f 100644 --- a/content/influxdb/cloud/monitor-alert/templates/infrastructure/raspberry-pi.md +++ b/content/influxdb/cloud/monitor-alert/templates/infrastructure/raspberry-pi.md @@ -7,6 +7,8 @@ menu: parent: Monitor infrastructure name: Raspberry Pi weight: 201 +source: /shared/influxdb-v2/monitor-alert/templates/infrastructure/raspberry-pi.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/monitor-alert/templates/infrastructure/vshpere.md b/content/influxdb/cloud/monitor-alert/templates/infrastructure/vshpere.md index 6f41de317..1f208a201 100644 --- a/content/influxdb/cloud/monitor-alert/templates/infrastructure/vshpere.md +++ b/content/influxdb/cloud/monitor-alert/templates/infrastructure/vshpere.md @@ -7,6 +7,8 @@ menu: parent: Monitor infrastructure name: vSphere weight: 206 +source: /shared/influxdb-v2/monitor-alert/templates/infrastructure/vshpere.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/monitor-alert/templates/infrastructure/windows.md b/content/influxdb/cloud/monitor-alert/templates/infrastructure/windows.md index 6a7251322..bbb6ed0d7 100644 --- a/content/influxdb/cloud/monitor-alert/templates/infrastructure/windows.md +++ b/content/influxdb/cloud/monitor-alert/templates/infrastructure/windows.md @@ -7,6 +7,8 @@ menu: parent: Monitor infrastructure name: Windows weight: 207 +source: /shared/influxdb-v2/monitor-alert/templates/infrastructure/windows.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/monitor-alert/templates/monitor.md b/content/influxdb/cloud/monitor-alert/templates/monitor.md index 4c4953ba5..6a22bddff 100644 --- a/content/influxdb/cloud/monitor-alert/templates/monitor.md +++ b/content/influxdb/cloud/monitor-alert/templates/monitor.md @@ -13,6 +13,8 @@ related: - /influxdb/v2/reference/cli/influx/apply/ - /influxdb/v2/reference/cli/influx/template/ - /influxdb/cloud/tools/influxdb-templates/monitor +source: /shared/influxdb-v2/monitor-alert/templates/monitor.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/monitor-alert/templates/networks/haproxy.md b/content/influxdb/cloud/monitor-alert/templates/networks/haproxy.md index d58675ca7..954e56511 100644 --- a/content/influxdb/cloud/monitor-alert/templates/networks/haproxy.md +++ b/content/influxdb/cloud/monitor-alert/templates/networks/haproxy.md @@ -7,6 +7,8 @@ menu: parent: Monitor networks name: HAproxy weight: 201 +source: /shared/influxdb-v2/monitor-alert/templates/networks/haproxy.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/process-data/get-started.md b/content/influxdb/cloud/process-data/get-started.md index 1e9ba1f5a..ada1ec0ca 100644 --- a/content/influxdb/cloud/process-data/get-started.md +++ b/content/influxdb/cloud/process-data/get-started.md @@ -16,6 +16,8 @@ related: - /influxdb/cloud/process-data/manage-tasks/ - /influxdb/cloud/process-data/manage-tasks/create-task/ - /resources/videos/influxdb-tasks/ +source: /shared/influxdb-v2/process-data/get-started.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/process-data/manage-tasks/create-task.md b/content/influxdb/cloud/process-data/manage-tasks/create-task.md index de1719a1c..980c02424 100644 --- a/content/influxdb/cloud/process-data/manage-tasks/create-task.md +++ b/content/influxdb/cloud/process-data/manage-tasks/create-task.md @@ -10,6 +10,8 @@ menu: weight: 201 related: - /influxdb/cloud/reference/cli/influx/task/create +source: /shared/influxdb-v2/process-data/manage-tasks/create-task.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/process-data/manage-tasks/delete-task.md b/content/influxdb/cloud/process-data/manage-tasks/delete-task.md index da49a8557..d1acf257d 100644 --- a/content/influxdb/cloud/process-data/manage-tasks/delete-task.md +++ b/content/influxdb/cloud/process-data/manage-tasks/delete-task.md @@ -10,6 +10,8 @@ menu: weight: 206 related: - /influxdb/cloud/reference/cli/influx/task/delete +source: /shared/influxdb-v2/process-data/manage-tasks/delete-task.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/process-data/manage-tasks/run-task.md b/content/influxdb/cloud/process-data/manage-tasks/run-task.md index b2d5f8256..3ec79cfcc 100644 --- a/content/influxdb/cloud/process-data/manage-tasks/run-task.md +++ b/content/influxdb/cloud/process-data/manage-tasks/run-task.md @@ -11,6 +11,8 @@ weight: 203 related: - /influxdb/cloud/reference/cli/influx/task/run - /influxdb/cloud/reference/cli/influx/task/retry +source: /shared/influxdb-v2/process-data/manage-tasks/run-task.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/process-data/manage-tasks/task-run-history.md b/content/influxdb/cloud/process-data/manage-tasks/task-run-history.md index 582d24589..b25680792 100644 --- a/content/influxdb/cloud/process-data/manage-tasks/task-run-history.md +++ b/content/influxdb/cloud/process-data/manage-tasks/task-run-history.md @@ -9,6 +9,8 @@ menu: weight: 203 related: - /influxdb/cloud/reference/cli/influx/task/run/find +source: /shared/influxdb-v2/process-data/manage-tasks/task-run-history.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/process-data/manage-tasks/update-task.md b/content/influxdb/cloud/process-data/manage-tasks/update-task.md index 4faa029ea..e52a47b9a 100644 --- a/content/influxdb/cloud/process-data/manage-tasks/update-task.md +++ b/content/influxdb/cloud/process-data/manage-tasks/update-task.md @@ -10,6 +10,8 @@ menu: weight: 204 related: - /influxdb/cloud/reference/cli/influx/task/update +source: /shared/influxdb-v2/process-data/manage-tasks/update-task.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/process-data/task-options.md b/content/influxdb/cloud/process-data/task-options.md index 95aff167f..22ed172fc 100644 --- a/content/influxdb/cloud/process-data/task-options.md +++ b/content/influxdb/cloud/process-data/task-options.md @@ -10,6 +10,8 @@ menu: parent: Process data weight: 105 influxdb/cloud/tags: [tasks, flux] +source: /shared/influxdb-v2/process-data/task-options.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/common-queries/_index.md b/content/influxdb/cloud/query-data/common-queries/_index.md index 47406fd7c..689361a41 100644 --- a/content/influxdb/cloud/query-data/common-queries/_index.md +++ b/content/influxdb/cloud/query-data/common-queries/_index.md @@ -9,6 +9,8 @@ menu: name: Common queries parent: Query data weight: 104 +source: /shared/influxdb-v2/query-data/common-queries/_index.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/common-queries/compare-values.md b/content/influxdb/cloud/query-data/common-queries/compare-values.md index 7f6fb05cd..6938112c6 100644 --- a/content/influxdb/cloud/query-data/common-queries/compare-values.md +++ b/content/influxdb/cloud/query-data/common-queries/compare-values.md @@ -9,6 +9,8 @@ menu: name: Compare values from different buckets parent: Common queries weight: 104 +source: /shared/influxdb-v2/query-data/common-queries/compare-values.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/common-queries/iot-common-queries.md b/content/influxdb/cloud/query-data/common-queries/iot-common-queries.md index 10de9f3a7..aa5cb832d 100644 --- a/content/influxdb/cloud/query-data/common-queries/iot-common-queries.md +++ b/content/influxdb/cloud/query-data/common-queries/iot-common-queries.md @@ -10,6 +10,8 @@ menu: weight: 205 related: - /resources/videos/iot-monitoring-with-influxdb/ +source: /shared/influxdb-v2/query-data/common-queries/iot-common-queries.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/common-queries/multiple-fields-in-calculations.md b/content/influxdb/cloud/query-data/common-queries/multiple-fields-in-calculations.md index 15197ee20..accd60c6d 100644 --- a/content/influxdb/cloud/query-data/common-queries/multiple-fields-in-calculations.md +++ b/content/influxdb/cloud/query-data/common-queries/multiple-fields-in-calculations.md @@ -8,6 +8,8 @@ menu: influxdb_cloud: parent: Common queries weight: 204 +source: /shared/influxdb-v2/query-data/common-queries/multiple-fields-in-calculations.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/common-queries/operate-on-columns.md b/content/influxdb/cloud/query-data/common-queries/operate-on-columns.md index 23a400b75..2486a3036 100644 --- a/content/influxdb/cloud/query-data/common-queries/operate-on-columns.md +++ b/content/influxdb/cloud/query-data/common-queries/operate-on-columns.md @@ -12,6 +12,8 @@ menu: name: Operate on columns parent: Common queries weight: 100 +source: /shared/influxdb-v2/query-data/common-queries/operate-on-columns.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/execute-queries/data-explorer.md b/content/influxdb/cloud/query-data/execute-queries/data-explorer.md index 7c2c3c9d3..ed86edb66 100644 --- a/content/influxdb/cloud/query-data/execute-queries/data-explorer.md +++ b/content/influxdb/cloud/query-data/execute-queries/data-explorer.md @@ -8,6 +8,8 @@ menu: name: Query with Data Explorer parent: Execute queries influxdb/cloud/tags: [query] +source: /shared/influxdb-v2/query-data/execute-queries/data-explorer.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/execute-queries/flux-repl.md b/content/influxdb/cloud/query-data/execute-queries/flux-repl.md index e7201c8c4..955081066 100644 --- a/content/influxdb/cloud/query-data/execute-queries/flux-repl.md +++ b/content/influxdb/cloud/query-data/execute-queries/flux-repl.md @@ -7,6 +7,8 @@ menu: name: Query in the Flux REPL parent: Execute queries influxdb/cloud/tags: [query] +source: /shared/influxdb-v2/query-data/execute-queries/flux-repl.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/execute-queries/influx-api.md b/content/influxdb/cloud/query-data/execute-queries/influx-api.md index 3973a99ca..6dff50a2c 100644 --- a/content/influxdb/cloud/query-data/execute-queries/influx-api.md +++ b/content/influxdb/cloud/query-data/execute-queries/influx-api.md @@ -7,6 +7,8 @@ menu: name: Query with the InfluxDB API parent: Execute queries influxdb/cloud/tags: [query] +source: /shared/influxdb-v2/query-data/execute-queries/influx-api.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/execute-queries/influx-query.md b/content/influxdb/cloud/query-data/execute-queries/influx-query.md index 5ad3f765a..4a0ad9b67 100644 --- a/content/influxdb/cloud/query-data/execute-queries/influx-query.md +++ b/content/influxdb/cloud/query-data/execute-queries/influx-query.md @@ -9,6 +9,8 @@ menu: influxdb/cloud/tags: [query] related: - /influxdb/cloud/reference/cli/influx/query/ +source: /shared/influxdb-v2/query-data/execute-queries/influx-query.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/_index.md b/content/influxdb/cloud/query-data/flux/_index.md index bc7b0aec1..dfb51ec0a 100644 --- a/content/influxdb/cloud/query-data/flux/_index.md +++ b/content/influxdb/cloud/query-data/flux/_index.md @@ -7,6 +7,8 @@ menu: influxdb_cloud: name: Query with Flux parent: Query data +source: /shared/influxdb-v2/query-data/flux/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/flux/calculate-percentages.md b/content/influxdb/cloud/query-data/flux/calculate-percentages.md index 144a36b55..396b33da4 100644 --- a/content/influxdb/cloud/query-data/flux/calculate-percentages.md +++ b/content/influxdb/cloud/query-data/flux/calculate-percentages.md @@ -16,6 +16,8 @@ related: - /flux/v0/stdlib/universe/pivot - /flux/v0/stdlib/universe/join list_query_example: percentages +source: /shared/influxdb-v2/query-data/flux/calculate-percentages.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/conditional-logic.md b/content/influxdb/cloud/query-data/flux/conditional-logic.md index 12e754569..1b0a8d9d3 100644 --- a/content/influxdb/cloud/query-data/flux/conditional-logic.md +++ b/content/influxdb/cloud/query-data/flux/conditional-logic.md @@ -20,6 +20,8 @@ list_code_example: | ```js if color == "green" then "008000" else "ffffff" ``` +source: /shared/influxdb-v2/query-data/flux/conditional-logic.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/cumulativesum.md b/content/influxdb/cloud/query-data/flux/cumulativesum.md index fb4035696..79e169eca 100644 --- a/content/influxdb/cloud/query-data/flux/cumulativesum.md +++ b/content/influxdb/cloud/query-data/flux/cumulativesum.md @@ -13,6 +13,8 @@ influxdb/cloud/tags: [query, cumulative sum] related: - /flux/v0/stdlib/universe/cumulativesum/ list_query_example: cumulative_sum +source: /shared/influxdb-v2/query-data/flux/cumulativesum.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/custom-functions/_index.md b/content/influxdb/cloud/query-data/flux/custom-functions/_index.md index 19bc72ffd..e45c95785 100644 --- a/content/influxdb/cloud/query-data/flux/custom-functions/_index.md +++ b/content/influxdb/cloud/query-data/flux/custom-functions/_index.md @@ -16,6 +16,8 @@ list_code_example: | data |> multByX(x: 2.0) ``` +source: /shared/influxdb-v2/query-data/flux/custom-functions/_index.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/custom-functions/custom-aggregate.md b/content/influxdb/cloud/query-data/flux/custom-functions/custom-aggregate.md index 63d92d432..5ea17d3cf 100644 --- a/content/influxdb/cloud/query-data/flux/custom-functions/custom-aggregate.md +++ b/content/influxdb/cloud/query-data/flux/custom-functions/custom-aggregate.md @@ -9,6 +9,8 @@ menu: weight: 301 related: - /flux/v0/stdlib/universe/reduce/ +source: /shared/influxdb-v2/query-data/flux/custom-functions/custom-aggregate.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/exists.md b/content/influxdb/cloud/query-data/flux/exists.md index ad5feae11..c496aedb7 100644 --- a/content/influxdb/cloud/query-data/flux/exists.md +++ b/content/influxdb/cloud/query-data/flux/exists.md @@ -20,6 +20,8 @@ list_code_example: | data |> filter(fn: (r) => exists r._value) ``` +source: /shared/influxdb-v2/query-data/flux/exists.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/explore-schema.md b/content/influxdb/cloud/query-data/flux/explore-schema.md index 4a03574a0..4d4010b8b 100644 --- a/content/influxdb/cloud/query-data/flux/explore-schema.md +++ b/content/influxdb/cloud/query-data/flux/explore-schema.md @@ -38,6 +38,8 @@ list_code_example: | // List tag values schema.tagValues(bucket: "example-bucket", tag: "example-tag") ``` +source: /shared/influxdb-v2/query-data/flux/explore-schema.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/fill.md b/content/influxdb/cloud/query-data/flux/fill.md index e20f15243..c78befb52 100644 --- a/content/influxdb/cloud/query-data/flux/fill.md +++ b/content/influxdb/cloud/query-data/flux/fill.md @@ -14,6 +14,8 @@ influxdb/cloud/tags: [query, fill] related: - /flux/v0/stdlib/universe/fill/ list_query_example: fill_null +source: /shared/influxdb-v2/query-data/flux/fill.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/first-last.md b/content/influxdb/cloud/query-data/flux/first-last.md index 1e1545ceb..9ad9b483d 100644 --- a/content/influxdb/cloud/query-data/flux/first-last.md +++ b/content/influxdb/cloud/query-data/flux/first-last.md @@ -16,6 +16,8 @@ related: - /flux/v0/stdlib/universe/first/ - /flux/v0/stdlib/universe/last/ list_query_example: first_last +source: /shared/influxdb-v2/query-data/flux/first-last.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/flux-version.md b/content/influxdb/cloud/query-data/flux/flux-version.md index 07c315d06..306161564 100644 --- a/content/influxdb/cloud/query-data/flux/flux-version.md +++ b/content/influxdb/cloud/query-data/flux/flux-version.md @@ -19,6 +19,8 @@ list_code_example: | array.from(rows: [{version: runtime.version()}]) ``` +source: /shared/influxdb-v2/query-data/flux/flux-version.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/flux/geo/_index.md b/content/influxdb/cloud/query-data/flux/geo/_index.md index f13d116c4..5ff74011d 100644 --- a/content/influxdb/cloud/query-data/flux/geo/_index.md +++ b/content/influxdb/cloud/query-data/flux/geo/_index.md @@ -18,6 +18,8 @@ list_code_example: | |> geo.filterRows(region: {lat: 30.04, lon: 31.23, radius: 200.0}) |> geo.groupByArea(newColumn: "geoArea", level: 5) ``` +source: /shared/influxdb-v2/query-data/flux/geo/_index.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/geo/filter-by-region.md b/content/influxdb/cloud/query-data/flux/geo/filter-by-region.md index d61484163..c1801354b 100644 --- a/content/influxdb/cloud/query-data/flux/geo/filter-by-region.md +++ b/content/influxdb/cloud/query-data/flux/geo/filter-by-region.md @@ -17,6 +17,8 @@ list_code_example: | sampleGeoData |> geo.filterRows(region: {lat: 30.04, lon: 31.23, radius: 200.0}, strict: true) ``` +source: /shared/influxdb-v2/query-data/flux/geo/filter-by-region.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/geo/group-geo-data.md b/content/influxdb/cloud/query-data/flux/geo/group-geo-data.md index 08a65f45b..d7222a22f 100644 --- a/content/influxdb/cloud/query-data/flux/geo/group-geo-data.md +++ b/content/influxdb/cloud/query-data/flux/geo/group-geo-data.md @@ -19,6 +19,8 @@ list_code_example: | |> geo.groupByArea(newColumn: "geoArea", level: 5) |> geo.asTracks(groupBy: ["id"],orderBy: ["_time"]) ``` +source: /shared/influxdb-v2/query-data/flux/geo/group-geo-data.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/geo/shape-geo-data.md b/content/influxdb/cloud/query-data/flux/geo/shape-geo-data.md index e3505ec49..6bf2fb0d0 100644 --- a/content/influxdb/cloud/query-data/flux/geo/shape-geo-data.md +++ b/content/influxdb/cloud/query-data/flux/geo/shape-geo-data.md @@ -29,6 +29,8 @@ list_code_example: | ) |> map(fn: (r) => ({r with s2_cell_id: geo.s2CellIDToken(point: {lon: r.lon, lat: r.lat}, level: 10)})) ``` +source: /shared/influxdb-v2/query-data/flux/geo/shape-geo-data.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/group-data.md b/content/influxdb/cloud/query-data/flux/group-data.md index fad6021ba..523002473 100644 --- a/content/influxdb/cloud/query-data/flux/group-data.md +++ b/content/influxdb/cloud/query-data/flux/group-data.md @@ -14,6 +14,8 @@ related: - /flux/v0/stdlib/universe/group - /flux/v0/stdlib/experimental/group list_query_example: group +source: /shared/influxdb-v2/query-data/flux/group-data.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/histograms.md b/content/influxdb/cloud/query-data/flux/histograms.md index 3be8bf190..ce62f627c 100644 --- a/content/influxdb/cloud/query-data/flux/histograms.md +++ b/content/influxdb/cloud/query-data/flux/histograms.md @@ -14,6 +14,8 @@ related: - /flux/v0/stdlib/universe/histogram - /flux/v0/prometheus/metric-types/histogram/, Work with Prometheus histograms in Flux list_query_example: histogram +source: /shared/influxdb-v2/query-data/flux/histograms.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/increase.md b/content/influxdb/cloud/query-data/flux/increase.md index 679bb2bb6..f533d45a9 100644 --- a/content/influxdb/cloud/query-data/flux/increase.md +++ b/content/influxdb/cloud/query-data/flux/increase.md @@ -16,6 +16,8 @@ influxdb/cloud/tags: [query, increase, counters] related: - /flux/v0/stdlib/universe/increase/ list_query_example: increase +source: /shared/influxdb-v2/query-data/flux/increase.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/join.md b/content/influxdb/cloud/query-data/flux/join.md index 005d5752e..d2846ae58 100644 --- a/content/influxdb/cloud/query-data/flux/join.md +++ b/content/influxdb/cloud/query-data/flux/join.md @@ -18,6 +18,8 @@ related: - /flux/v0/join-data/time/ - /flux/v0/stdlib/join/ list_query_example: join-new +source: /shared/influxdb-v2/query-data/flux/join.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/mathematic-operations.md b/content/influxdb/cloud/query-data/flux/mathematic-operations.md index 8a77c5b8b..9ba90ffa9 100644 --- a/content/influxdb/cloud/query-data/flux/mathematic-operations.md +++ b/content/influxdb/cloud/query-data/flux/mathematic-operations.md @@ -18,6 +18,8 @@ related: - /flux/v0/function-types#type-conversions, Flux type-conversion functions - /influxdb/cloud/query-data/flux/calculate-percentages/ list_query_example: map_math +source: /shared/influxdb-v2/query-data/flux/mathematic-operations.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/median.md b/content/influxdb/cloud/query-data/flux/median.md index d919bffcd..2fed82238 100644 --- a/content/influxdb/cloud/query-data/flux/median.md +++ b/content/influxdb/cloud/query-data/flux/median.md @@ -16,6 +16,8 @@ related: - /flux/v0/stdlib/universe/median/ - /flux/v0/stdlib/universe/quantile/ list_query_example: median +source: /shared/influxdb-v2/query-data/flux/median.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/monitor-states.md b/content/influxdb/cloud/query-data/flux/monitor-states.md index 538cd56eb..ee9b3def5 100644 --- a/content/influxdb/cloud/query-data/flux/monitor-states.md +++ b/content/influxdb/cloud/query-data/flux/monitor-states.md @@ -11,6 +11,8 @@ weight: 220 related: - /flux/v0/stdlib/universe/stateduration/ - /flux/v0/stdlib/universe/statecount/ +source: /shared/influxdb-v2/query-data/flux/monitor-states.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/moving-average.md b/content/influxdb/cloud/query-data/flux/moving-average.md index 14a2f491f..c16374791 100644 --- a/content/influxdb/cloud/query-data/flux/moving-average.md +++ b/content/influxdb/cloud/query-data/flux/moving-average.md @@ -16,6 +16,8 @@ related: - /flux/v0/stdlib/universe/movingaverage/ - /flux/v0/stdlib/universe/timedmovingaverage/ list_query_example: moving_average +source: /shared/influxdb-v2/query-data/flux/moving-average.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/operate-on-timestamps.md b/content/influxdb/cloud/query-data/flux/operate-on-timestamps.md index 5633e8a56..ac18fa6f1 100644 --- a/content/influxdb/cloud/query-data/flux/operate-on-timestamps.md +++ b/content/influxdb/cloud/query-data/flux/operate-on-timestamps.md @@ -20,8 +20,10 @@ related: - /flux/v0/stdlib/date/truncate/ - /flux/v0/stdlib/experimental/addduration/ - /flux/v0/stdlib/experimental/subduration/ +source: /shared/influxdb-v2/query-data/flux/operate-on-timestamps.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/flux/percentile-quantile.md b/content/influxdb/cloud/query-data/flux/percentile-quantile.md index 7d5cd20af..69b9ea1fa 100644 --- a/content/influxdb/cloud/query-data/flux/percentile-quantile.md +++ b/content/influxdb/cloud/query-data/flux/percentile-quantile.md @@ -15,6 +15,8 @@ related: - /influxdb/cloud/query-data/flux/query-median/ - /flux/v0/stdlib/universe/quantile/ list_query_example: quantile +source: /shared/influxdb-v2/query-data/flux/percentile-quantile.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/query-fields.md b/content/influxdb/cloud/query-data/flux/query-fields.md index adb3acb12..17873deee 100644 --- a/content/influxdb/cloud/query-data/flux/query-fields.md +++ b/content/influxdb/cloud/query-data/flux/query-fields.md @@ -20,6 +20,8 @@ list_code_example: | |> range(start: -1h) |> filter(fn: (r) => r._measurement == "example-measurement" and r._field == "example-field" and r.tag == "example-tag") ``` +source: /shared/influxdb-v2/query-data/flux/query-fields.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/rate.md b/content/influxdb/cloud/query-data/flux/rate.md index e6d3129fa..aef886f5c 100644 --- a/content/influxdb/cloud/query-data/flux/rate.md +++ b/content/influxdb/cloud/query-data/flux/rate.md @@ -19,6 +19,8 @@ related: - /flux/v0/stdlib/universe/derivative/ - /flux/v0/stdlib/experimental/aggregate/rate/ list_query_example: rate_of_change +source: /shared/influxdb-v2/query-data/flux/rate.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/regular-expressions.md b/content/influxdb/cloud/query-data/flux/regular-expressions.md index 3a82d2471..64eeba620 100644 --- a/content/influxdb/cloud/query-data/flux/regular-expressions.md +++ b/content/influxdb/cloud/query-data/flux/regular-expressions.md @@ -12,6 +12,8 @@ related: - /influxdb/cloud/query-data/flux/query-fields/ - /flux/v0/stdlib/regexp/ list_query_example: regular_expressions +source: /shared/influxdb-v2/query-data/flux/regular-expressions.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/scalar-values.md b/content/influxdb/cloud/query-data/flux/scalar-values.md index 3c49d5c58..0616f3cde 100644 --- a/content/influxdb/cloud/query-data/flux/scalar-values.md +++ b/content/influxdb/cloud/query-data/flux/scalar-values.md @@ -21,6 +21,8 @@ list_code_example: | return _record._value } ``` +source: /shared/influxdb-v2/query-data/flux/scalar-values.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/sort-limit.md b/content/influxdb/cloud/query-data/flux/sort-limit.md index d4f1e542e..a5e30288f 100644 --- a/content/influxdb/cloud/query-data/flux/sort-limit.md +++ b/content/influxdb/cloud/query-data/flux/sort-limit.md @@ -17,6 +17,8 @@ related: - /flux/v0/stdlib/universe/sort - /flux/v0/stdlib/universe/limit list_query_example: sort_limit +source: /shared/influxdb-v2/query-data/flux/sort-limit.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/sql.md b/content/influxdb/cloud/query-data/flux/sql.md index d9e799149..294f7b98c 100644 --- a/content/influxdb/cloud/query-data/flux/sql.md +++ b/content/influxdb/cloud/query-data/flux/sql.md @@ -24,6 +24,8 @@ list_code_example: | query: "SELECT * FROM example_table", ) ``` +source: /shared/influxdb-v2/query-data/flux/sql.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/flux/window-aggregate.md b/content/influxdb/cloud/query-data/flux/window-aggregate.md index 409febe89..3f71f90d7 100644 --- a/content/influxdb/cloud/query-data/flux/window-aggregate.md +++ b/content/influxdb/cloud/query-data/flux/window-aggregate.md @@ -17,6 +17,8 @@ related: - /flux/v0/function-types/#aggregates, Flux aggregate functions - /flux/v0/function-types/#selectors, Flux selector functions list_query_example: aggregate_window +source: /shared/influxdb-v2/query-data/flux/window-aggregate.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/get-started/_index.md b/content/influxdb/cloud/query-data/get-started/_index.md index 79b83200b..0f4119c1d 100644 --- a/content/influxdb/cloud/query-data/get-started/_index.md +++ b/content/influxdb/cloud/query-data/get-started/_index.md @@ -15,6 +15,8 @@ related: - /flux/v0/get-started/ - /flux/v0/ - /flux/v0/stdlib/ +source: /shared/influxdb-v2/query-data/get-started/_index.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/get-started/query-influxdb.md b/content/influxdb/cloud/query-data/get-started/query-influxdb.md index 3e45aaec5..9d1ba17a7 100644 --- a/content/influxdb/cloud/query-data/get-started/query-influxdb.md +++ b/content/influxdb/cloud/query-data/get-started/query-influxdb.md @@ -13,6 +13,8 @@ related: - /flux/v0/stdlib/influxdata/influxdb/from - /flux/v0/stdlib/universe/range - /flux/v0/stdlib/universe/filter +source: /shared/influxdb-v2/query-data/get-started/query-influxdb.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/get-started/transform-data.md b/content/influxdb/cloud/query-data/get-started/transform-data.md index 28117d78d..3eb85bf36 100644 --- a/content/influxdb/cloud/query-data/get-started/transform-data.md +++ b/content/influxdb/cloud/query-data/get-started/transform-data.md @@ -10,6 +10,8 @@ weight: 202 related: - /flux/v0/stdlib/universe/aggregatewindow - /flux/v0/stdlib/universe/window +source: /shared/influxdb-v2/query-data/get-started/transform-data.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/query-data/influxql/_index.md b/content/influxdb/cloud/query-data/influxql/_index.md index fc8f9210f..51e046640 100644 --- a/content/influxdb/cloud/query-data/influxql/_index.md +++ b/content/influxdb/cloud/query-data/influxql/_index.md @@ -14,6 +14,8 @@ related: - /influxdb/cloud/reference/api/influxdb-1x/query - /influxdb/cloud/reference/api/influxdb-1x/dbrp - /influxdb/cloud/tools/influxql-shell/ +source: /shared/influxdb-v2/query-data/influxql/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/influxql/dbrp.md b/content/influxdb/cloud/query-data/influxql/dbrp.md index 53a6cb679..ad9dac142 100644 --- a/content/influxdb/cloud/query-data/influxql/dbrp.md +++ b/content/influxdb/cloud/query-data/influxql/dbrp.md @@ -9,6 +9,8 @@ menu: parent: Query with InfluxQL weight: 201 influxdb/cloud/tags: [influxql, dbrp] +source: /shared/influxdb-v2/query-data/influxql/dbrp.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/influxql/explore-data/_index.md b/content/influxdb/cloud/query-data/influxql/explore-data/_index.md index 84cd7680e..0c94d7fb9 100644 --- a/content/influxdb/cloud/query-data/influxql/explore-data/_index.md +++ b/content/influxdb/cloud/query-data/influxql/explore-data/_index.md @@ -8,6 +8,8 @@ menu: name: Explore data parent: Query with InfluxQL weight: 202 +source: /shared/influxdb-v2/query-data/influxql/explore-data/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/influxql/explore-data/group-by.md b/content/influxdb/cloud/query-data/influxql/explore-data/group-by.md index b8f98ae47..0d6afd290 100644 --- a/content/influxdb/cloud/query-data/influxql/explore-data/group-by.md +++ b/content/influxdb/cloud/query-data/influxql/explore-data/group-by.md @@ -11,6 +11,8 @@ list_code_example: | ```sql SELECT_clause FROM_clause [WHERE_clause] GROUP BY [* | [,}} + diff --git a/content/influxdb/cloud/query-data/influxql/explore-data/limit-and-slimit.md b/content/influxdb/cloud/query-data/influxql/explore-data/limit-and-slimit.md index 6055eb786..6f157e9ea 100644 --- a/content/influxdb/cloud/query-data/influxql/explore-data/limit-and-slimit.md +++ b/content/influxdb/cloud/query-data/influxql/explore-data/limit-and-slimit.md @@ -11,6 +11,8 @@ list_code_example: | ```sql SELECT_clause FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] LIMIT ``` +source: /shared/influxdb-v2/query-data/influxql/explore-data/limit-and-slimit.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/influxql/explore-data/offset-and-soffset.md b/content/influxdb/cloud/query-data/influxql/explore-data/offset-and-soffset.md index 4ebf24efa..0dbb5d2cf 100644 --- a/content/influxdb/cloud/query-data/influxql/explore-data/offset-and-soffset.md +++ b/content/influxdb/cloud/query-data/influxql/explore-data/offset-and-soffset.md @@ -11,6 +11,8 @@ list_code_example: | ```sql SELECT_clause FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] LIMIT_clause OFFSET [SLIMIT_clause] ``` +source: /shared/influxdb-v2/query-data/influxql/explore-data/offset-and-soffset.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/influxql/explore-data/order-by.md b/content/influxdb/cloud/query-data/influxql/explore-data/order-by.md index b2f3e2281..a0aed85cf 100644 --- a/content/influxdb/cloud/query-data/influxql/explore-data/order-by.md +++ b/content/influxdb/cloud/query-data/influxql/explore-data/order-by.md @@ -12,6 +12,8 @@ list_code_example: | ```sql SELECT_clause FROM_clause [WHERE_clause] [GROUP_BY_clause] ORDER BY time DESC ``` +source: /shared/influxdb-v2/query-data/influxql/explore-data/order-by.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/influxql/explore-data/regular-expressions.md b/content/influxdb/cloud/query-data/influxql/explore-data/regular-expressions.md index 366f301fb..97d00c0d5 100644 --- a/content/influxdb/cloud/query-data/influxql/explore-data/regular-expressions.md +++ b/content/influxdb/cloud/query-data/influxql/explore-data/regular-expressions.md @@ -13,6 +13,8 @@ list_code_example: | ```sql SELECT // FROM // WHERE [ // | //] GROUP BY // ``` +source: /shared/influxdb-v2/query-data/influxql/explore-data/regular-expressions.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/influxql/explore-data/select.md b/content/influxdb/cloud/query-data/influxql/explore-data/select.md index d62fc5cc2..241d44bbc 100644 --- a/content/influxdb/cloud/query-data/influxql/explore-data/select.md +++ b/content/influxdb/cloud/query-data/influxql/explore-data/select.md @@ -12,6 +12,8 @@ list_code_example: | ```sql SELECT [,,] FROM [,] ``` +source: /shared/influxdb-v2/query-data/influxql/explore-data/select.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/influxql/explore-data/subqueries.md b/content/influxdb/cloud/query-data/influxql/explore-data/subqueries.md index 1118d319f..01fd44b4c 100644 --- a/content/influxdb/cloud/query-data/influxql/explore-data/subqueries.md +++ b/content/influxdb/cloud/query-data/influxql/explore-data/subqueries.md @@ -11,6 +11,8 @@ list_code_example: | ```sql SELECT_clause FROM ( SELECT_statement ) [...] ``` +source: /shared/influxdb-v2/query-data/influxql/explore-data/subqueries.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/influxql/explore-data/time-and-timezone.md b/content/influxdb/cloud/query-data/influxql/explore-data/time-and-timezone.md index 613987d3b..eb160fffc 100644 --- a/content/influxdb/cloud/query-data/influxql/explore-data/time-and-timezone.md +++ b/content/influxdb/cloud/query-data/influxql/explore-data/time-and-timezone.md @@ -12,6 +12,8 @@ list_code_example: | ```sql SELECT_clause FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] tz('') ``` +source: /shared/influxdb-v2/query-data/influxql/explore-data/time-and-timezone.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/influxql/explore-data/where.md b/content/influxdb/cloud/query-data/influxql/explore-data/where.md index f9560f3bb..91fa90bb9 100644 --- a/content/influxdb/cloud/query-data/influxql/explore-data/where.md +++ b/content/influxdb/cloud/query-data/influxql/explore-data/where.md @@ -12,6 +12,8 @@ list_code_example: | ```sql SELECT_clause FROM_clause WHERE [(AND|OR) [...]] ``` +source: /shared/influxdb-v2/query-data/influxql/explore-data/where.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/influxql/explore-schema.md b/content/influxdb/cloud/query-data/influxql/explore-schema.md index ae468c54f..a069134d9 100644 --- a/content/influxdb/cloud/query-data/influxql/explore-schema.md +++ b/content/influxdb/cloud/query-data/influxql/explore-schema.md @@ -8,6 +8,8 @@ menu: parent: Query with InfluxQL identifier: explore-schema-influxql weight: 202 +source: /shared/influxdb-v2/query-data/influxql/explore-schema.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/influxql/functions/_index.md b/content/influxdb/cloud/query-data/influxql/functions/_index.md index 9fdd4bd60..17ab86795 100644 --- a/content/influxdb/cloud/query-data/influxql/functions/_index.md +++ b/content/influxdb/cloud/query-data/influxql/functions/_index.md @@ -7,6 +7,8 @@ menu: name: InfluxQL functions parent: Query with InfluxQL weight: 203 +source: /shared/influxdb-v2/query-data/influxql/functions/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/influxql/functions/aggregates.md b/content/influxdb/cloud/query-data/influxql/functions/aggregates.md index f91ae7945..d19f42034 100644 --- a/content/influxdb/cloud/query-data/influxql/functions/aggregates.md +++ b/content/influxdb/cloud/query-data/influxql/functions/aggregates.md @@ -8,6 +8,8 @@ menu: name: Aggregates parent: InfluxQL functions weight: 205 +source: /shared/influxdb-v2/query-data/influxql/functions/aggregates.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/influxql/functions/selectors.md b/content/influxdb/cloud/query-data/influxql/functions/selectors.md index a81414b3b..d666c07d7 100644 --- a/content/influxdb/cloud/query-data/influxql/functions/selectors.md +++ b/content/influxdb/cloud/query-data/influxql/functions/selectors.md @@ -8,6 +8,8 @@ menu: name: Selectors parent: InfluxQL functions weight: 205 +source: /shared/influxdb-v2/query-data/influxql/functions/selectors.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/influxql/functions/technical-analysis.md b/content/influxdb/cloud/query-data/influxql/functions/technical-analysis.md index f6b358cda..89b28962a 100644 --- a/content/influxdb/cloud/query-data/influxql/functions/technical-analysis.md +++ b/content/influxdb/cloud/query-data/influxql/functions/technical-analysis.md @@ -8,6 +8,8 @@ menu: name: Technical analysis parent: InfluxQL functions weight: 205 +source: /shared/influxdb-v2/query-data/influxql/functions/technical-analysis.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/influxql/functions/transformations.md b/content/influxdb/cloud/query-data/influxql/functions/transformations.md index 979ecfc59..34636f54d 100644 --- a/content/influxdb/cloud/query-data/influxql/functions/transformations.md +++ b/content/influxdb/cloud/query-data/influxql/functions/transformations.md @@ -8,6 +8,8 @@ menu: name: Transformations parent: InfluxQL functions weight: 205 +source: /shared/influxdb-v2/query-data/influxql/functions/transformations.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/influxql/manage-data.md b/content/influxdb/cloud/query-data/influxql/manage-data.md index 9d3b36361..3c5ea691a 100644 --- a/content/influxdb/cloud/query-data/influxql/manage-data.md +++ b/content/influxdb/cloud/query-data/influxql/manage-data.md @@ -8,6 +8,8 @@ menu: parent: Query with InfluxQL identifier: manage-database weight: 204 +source: /shared/influxdb-v2/query-data/influxql/manage-data.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/influxql/math-operators.md b/content/influxdb/cloud/query-data/influxql/math-operators.md index 8bec44dbe..e25f578f3 100644 --- a/content/influxdb/cloud/query-data/influxql/math-operators.md +++ b/content/influxdb/cloud/query-data/influxql/math-operators.md @@ -8,6 +8,8 @@ menu: parent: Query with InfluxQL identifier: influxql-mathematical-operators weight: 209 +source: /shared/influxdb-v2/query-data/influxql/math-operators.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/query-data/optimize-queries.md b/content/influxdb/cloud/query-data/optimize-queries.md index d11c779b9..318fcda29 100644 --- a/content/influxdb/cloud/query-data/optimize-queries.md +++ b/content/influxdb/cloud/query-data/optimize-queries.md @@ -8,6 +8,8 @@ menu: name: Optimize queries parent: Query data influxdb/cloud/tags: [query] +source: /shared/influxdb-v2/query-data/optimize-queries.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/reference/api/_index.md b/content/influxdb/cloud/reference/api/_index.md index 5d876bcf4..16e3bdfbf 100644 --- a/content/influxdb/cloud/reference/api/_index.md +++ b/content/influxdb/cloud/reference/api/_index.md @@ -10,6 +10,8 @@ menu: name: InfluxDB HTTP API weight: 3 influxdb/cloud/tags: [api] +source: /shared/influxdb-v2/reference/api/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/_index.md b/content/influxdb/cloud/reference/cli/influx/_index.md index 600e88edd..1d31d5636 100644 --- a/content/influxdb/cloud/reference/cli/influx/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/_index.md @@ -12,6 +12,8 @@ weight: 101 influxdb/cloud/tags: [cli] related: - /influxdb/cloud/tools/clis/ +source: /shared/influxdb-v2/reference/cli/influx/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/apply/_index.md b/content/influxdb/cloud/reference/cli/influx/apply/_index.md index 5a929ec5f..2c4452f61 100644 --- a/content/influxdb/cloud/reference/cli/influx/apply/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/apply/_index.md @@ -13,6 +13,8 @@ related: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+] +source: /shared/influxdb-v2/reference/cli/influx/apply/_index.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/reference/cli/influx/auth/_index.md b/content/influxdb/cloud/reference/cli/influx/auth/_index.md index 126d9f464..3f4eb756e 100644 --- a/content/influxdb/cloud/reference/cli/influx/auth/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/auth/_index.md @@ -12,6 +12,8 @@ cascade: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+] +source: /shared/influxdb-v2/reference/cli/influx/auth/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/auth/active.md b/content/influxdb/cloud/reference/cli/influx/auth/active.md index 1fdb1cbb4..8a6e6a85c 100644 --- a/content/influxdb/cloud/reference/cli/influx/auth/active.md +++ b/content/influxdb/cloud/reference/cli/influx/auth/active.md @@ -7,6 +7,8 @@ menu: name: influx auth active parent: influx auth weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/auth/active.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/auth/create.md b/content/influxdb/cloud/reference/cli/influx/auth/create.md index 8092790c6..a6eeed4d4 100644 --- a/content/influxdb/cloud/reference/cli/influx/auth/create.md +++ b/content/influxdb/cloud/reference/cli/influx/auth/create.md @@ -7,6 +7,8 @@ menu: parent: influx auth weight: 201 updated_in: CLI v2.2.0 +source: /shared/influxdb-v2/reference/cli/influx/auth/create.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/auth/delete.md b/content/influxdb/cloud/reference/cli/influx/auth/delete.md index 5f4f0fc03..22f8cd5c3 100644 --- a/content/influxdb/cloud/reference/cli/influx/auth/delete.md +++ b/content/influxdb/cloud/reference/cli/influx/auth/delete.md @@ -6,6 +6,8 @@ menu: name: influx auth delete parent: influx auth weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/auth/delete.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/auth/inactive.md b/content/influxdb/cloud/reference/cli/influx/auth/inactive.md index 686d0f49a..9a2ed722a 100644 --- a/content/influxdb/cloud/reference/cli/influx/auth/inactive.md +++ b/content/influxdb/cloud/reference/cli/influx/auth/inactive.md @@ -6,6 +6,8 @@ menu: name: influx auth inactive parent: influx auth weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/auth/inactive.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/auth/list.md b/content/influxdb/cloud/reference/cli/influx/auth/list.md index f16e2600f..531bcf18b 100644 --- a/content/influxdb/cloud/reference/cli/influx/auth/list.md +++ b/content/influxdb/cloud/reference/cli/influx/auth/list.md @@ -6,6 +6,8 @@ menu: name: influx auth list parent: influx auth weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/auth/list.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/backup/_index.md b/content/influxdb/cloud/reference/cli/influx/backup/_index.md index b7954d545..2a00d15e1 100644 --- a/content/influxdb/cloud/reference/cli/influx/backup/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/backup/_index.md @@ -12,14 +12,15 @@ related: - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+, InfluxDB OSS only] updated_in: CLI v2.0.2 +prepend: | + > [!Note] + > #### Works with InfluxDB OSS 2.x + > + > The `influx backup` command works with **InfluxDB OSS 2.x**, but does not work with **InfluxDB Cloud**. + > For information about backing up data in InfluxDB Cloud, see + > [InfluxDB Cloud durability](/influxdb/cloud/reference/internals/durability/). +source: /shared/influxdb-v2/reference/cli/influx/backup/_index.md --- -{{% note %}} -#### Works with InfluxDB OSS 2.x - -The `influx backup` command works with **InfluxDB OSS 2.x**, but does not work with **InfluxDB Cloud**. -For information about backing up data in InfluxDB Cloud, see -[InfluxDB Cloud durability](/influxdb/cloud/reference/internals/durability/). -{{% /note %}} - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/bucket-schema/_index.md b/content/influxdb/cloud/reference/cli/influx/bucket-schema/_index.md index dcfaf83e5..9bea83387 100644 --- a/content/influxdb/cloud/reference/cli/influx/bucket-schema/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/bucket-schema/_index.md @@ -14,6 +14,8 @@ cascade: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.1.0+] +source: /shared/influxdb-v2/reference/cli/influx/bucket-schema/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/bucket-schema/create.md b/content/influxdb/cloud/reference/cli/influx/bucket-schema/create.md index 59129ca80..60fabb6c0 100644 --- a/content/influxdb/cloud/reference/cli/influx/bucket-schema/create.md +++ b/content/influxdb/cloud/reference/cli/influx/bucket-schema/create.md @@ -8,6 +8,8 @@ menu: weight: 201 related: - /influxdb/cloud/organizations/buckets/bucket-schema +source: /shared/influxdb-v2/reference/cli/influx/bucket-schema/create.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/bucket-schema/list.md b/content/influxdb/cloud/reference/cli/influx/bucket-schema/list.md index fb77977dd..88a016c18 100644 --- a/content/influxdb/cloud/reference/cli/influx/bucket-schema/list.md +++ b/content/influxdb/cloud/reference/cli/influx/bucket-schema/list.md @@ -8,6 +8,8 @@ menu: weight: 201 related: - /influxdb/cloud/organizations/buckets/bucket-schema +source: /shared/influxdb-v2/reference/cli/influx/bucket-schema/list.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/bucket-schema/update.md b/content/influxdb/cloud/reference/cli/influx/bucket-schema/update.md index 95db4076f..988002aa3 100644 --- a/content/influxdb/cloud/reference/cli/influx/bucket-schema/update.md +++ b/content/influxdb/cloud/reference/cli/influx/bucket-schema/update.md @@ -8,6 +8,8 @@ menu: weight: 201 related: - /influxdb/cloud/organizations/buckets/bucket-schema +source: /shared/influxdb-v2/reference/cli/influx/bucket-schema/update.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/bucket/_index.md b/content/influxdb/cloud/reference/cli/influx/bucket/_index.md index 482c9bfc9..4d000b906 100644 --- a/content/influxdb/cloud/reference/cli/influx/bucket/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/bucket/_index.md @@ -13,6 +13,8 @@ cascade: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+] +source: /shared/influxdb-v2/reference/cli/influx/bucket/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/bucket/create.md b/content/influxdb/cloud/reference/cli/influx/bucket/create.md index f2bc7a9e7..489a45cd3 100644 --- a/content/influxdb/cloud/reference/cli/influx/bucket/create.md +++ b/content/influxdb/cloud/reference/cli/influx/bucket/create.md @@ -13,6 +13,8 @@ related: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions updated_in: CLI v2.1.0 +source: /shared/influxdb-v2/reference/cli/influx/bucket/create.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/bucket/delete.md b/content/influxdb/cloud/reference/cli/influx/bucket/delete.md index 7445a8022..bdec5b03f 100644 --- a/content/influxdb/cloud/reference/cli/influx/bucket/delete.md +++ b/content/influxdb/cloud/reference/cli/influx/bucket/delete.md @@ -10,6 +10,8 @@ related: - /influxdb/cloud/organizations/buckets/delete-bucket/ - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions +source: /shared/influxdb-v2/reference/cli/influx/bucket/delete.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/bucket/list.md b/content/influxdb/cloud/reference/cli/influx/bucket/list.md index c400901cd..268d2fb8d 100644 --- a/content/influxdb/cloud/reference/cli/influx/bucket/list.md +++ b/content/influxdb/cloud/reference/cli/influx/bucket/list.md @@ -7,6 +7,8 @@ menu: parent: influx bucket weight: 201 updated_in: CLI v2.2.0 +source: /shared/influxdb-v2/reference/cli/influx/bucket/list.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/bucket/update.md b/content/influxdb/cloud/reference/cli/influx/bucket/update.md index 2125061d8..da8443f6d 100644 --- a/content/influxdb/cloud/reference/cli/influx/bucket/update.md +++ b/content/influxdb/cloud/reference/cli/influx/bucket/update.md @@ -6,6 +6,8 @@ menu: name: influx bucket update parent: influx bucket weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/bucket/update.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/completion/_index.md b/content/influxdb/cloud/reference/cli/influx/completion/_index.md index 91dacc695..39e82037f 100644 --- a/content/influxdb/cloud/reference/cli/influx/completion/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/completion/_index.md @@ -13,6 +13,8 @@ related: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+] +source: /shared/influxdb-v2/reference/cli/influx/completion/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/config/_index.md b/content/influxdb/cloud/reference/cli/influx/config/_index.md index 48f5b1c9b..7d7038e4e 100644 --- a/content/influxdb/cloud/reference/cli/influx/config/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/config/_index.md @@ -12,6 +12,8 @@ cascade: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+] +source: /shared/influxdb-v2/reference/cli/influx/config/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/config/create.md b/content/influxdb/cloud/reference/cli/influx/config/create.md index 9dc25abd7..8e31936fb 100644 --- a/content/influxdb/cloud/reference/cli/influx/config/create.md +++ b/content/influxdb/cloud/reference/cli/influx/config/create.md @@ -6,6 +6,8 @@ menu: name: influx config create parent: influx config weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/config/create.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/config/list.md b/content/influxdb/cloud/reference/cli/influx/config/list.md index 614b0d033..f16346787 100644 --- a/content/influxdb/cloud/reference/cli/influx/config/list.md +++ b/content/influxdb/cloud/reference/cli/influx/config/list.md @@ -6,6 +6,8 @@ menu: name: influx config list parent: influx config weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/config/list.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/config/rm.md b/content/influxdb/cloud/reference/cli/influx/config/rm.md index 93aeb7451..035cd9d32 100644 --- a/content/influxdb/cloud/reference/cli/influx/config/rm.md +++ b/content/influxdb/cloud/reference/cli/influx/config/rm.md @@ -6,6 +6,8 @@ menu: name: influx config rm parent: influx config weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/config/rm.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/config/set.md b/content/influxdb/cloud/reference/cli/influx/config/set.md index 71ca63833..5726bacb6 100644 --- a/content/influxdb/cloud/reference/cli/influx/config/set.md +++ b/content/influxdb/cloud/reference/cli/influx/config/set.md @@ -6,6 +6,8 @@ menu: name: influx config set parent: influx config weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/config/set.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/dashboards/_index.md b/content/influxdb/cloud/reference/cli/influx/dashboards/_index.md index 71c00be62..463a0abc6 100644 --- a/content/influxdb/cloud/reference/cli/influx/dashboards/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/dashboards/_index.md @@ -12,6 +12,8 @@ related: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+] +source: /shared/influxdb-v2/reference/cli/influx/dashboards/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/delete/_index.md b/content/influxdb/cloud/reference/cli/influx/delete/_index.md index 72c785a2e..8173d5eaa 100644 --- a/content/influxdb/cloud/reference/cli/influx/delete/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/delete/_index.md @@ -14,6 +14,8 @@ related: - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.3+] updated_in: CLI v2.2.0 +source: /shared/influxdb-v2/reference/cli/influx/delete/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/export/_index.md b/content/influxdb/cloud/reference/cli/influx/export/_index.md index 1864473a7..c26786a1b 100644 --- a/content/influxdb/cloud/reference/cli/influx/export/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/export/_index.md @@ -11,6 +11,8 @@ cascade: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+] +source: /shared/influxdb-v2/reference/cli/influx/export/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/export/all.md b/content/influxdb/cloud/reference/cli/influx/export/all.md index 91aae26ab..b451be5d0 100644 --- a/content/influxdb/cloud/reference/cli/influx/export/all.md +++ b/content/influxdb/cloud/reference/cli/influx/export/all.md @@ -10,6 +10,8 @@ related: - /influxdb/cloud/tools/influxdb-templates/create/ - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions +source: /shared/influxdb-v2/reference/cli/influx/export/all.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/export/stack.md b/content/influxdb/cloud/reference/cli/influx/export/stack.md index 075c549bd..ae1c8929e 100644 --- a/content/influxdb/cloud/reference/cli/influx/export/stack.md +++ b/content/influxdb/cloud/reference/cli/influx/export/stack.md @@ -6,6 +6,8 @@ menu: influxdb_cloud: parent: influx export weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/export/stack.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/help/_index.md b/content/influxdb/cloud/reference/cli/influx/help/_index.md index bc593e6d8..5a7fa1aee 100644 --- a/content/influxdb/cloud/reference/cli/influx/help/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/help/_index.md @@ -10,6 +10,8 @@ related: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+] +source: /shared/influxdb-v2/reference/cli/influx/help/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/org/_index.md b/content/influxdb/cloud/reference/cli/influx/org/_index.md index a7759722a..fc80754b7 100644 --- a/content/influxdb/cloud/reference/cli/influx/org/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/org/_index.md @@ -12,6 +12,8 @@ cascade: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+] +source: /shared/influxdb-v2/reference/cli/influx/org/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/org/create.md b/content/influxdb/cloud/reference/cli/influx/org/create.md index 90b56752a..2618c5ce5 100644 --- a/content/influxdb/cloud/reference/cli/influx/org/create.md +++ b/content/influxdb/cloud/reference/cli/influx/org/create.md @@ -7,14 +7,17 @@ menu: parent: influx org weight: 201 metadata: [influx CLI 2.0.0+, InfluxDB OSS only] +prepend: | + > [!NOTE] + > #### Works with InfluxDB OSS 2.x + > + > The `influx org create` command works with **InfluxDB OSS 2.x**, but does + > not work with **InfluxDB Cloud**. + > New organizations are created for each new InfluxDB account. + > For information about creating an InfluxDB Cloud account, see + > [sign up for InfluxDB Cloud](/influxdb/cloud/sign-up/). +source: /shared/influxdb-v2/reference/cli/influx/org/create.md --- -{{% note %}} -#### Works with InfluxDB OSS 2.x -The `influx org create` command works with **InfluxDB OSS 2.x**, but does not work with **InfluxDB Cloud**. -New organizations are created for each new InfluxDB account. -For information about creating an InfluxDB Cloud account, see -[sign up for InfluxDB Cloud](/influxdb/cloud/sign-up/). -{{% /note %}} - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/org/delete.md b/content/influxdb/cloud/reference/cli/influx/org/delete.md index 4f80dee86..ddf9e412f 100644 --- a/content/influxdb/cloud/reference/cli/influx/org/delete.md +++ b/content/influxdb/cloud/reference/cli/influx/org/delete.md @@ -7,14 +7,16 @@ menu: parent: influx org weight: 201 metadata: [influx CLI 2.0.0+, InfluxDB OSS only] +prepend: | + > [!NOTE] + > #### Works with InfluxDB OSS 2.x + > The `influx org delete` command works with **InfluxDB OSS 2.x**, but does + > not work with **InfluxDB Cloud**. + > An organization is associated with your InfluxDB account. + > For information about removing your InfluxDB Cloud account and its organization, + > see [Cancel your InfluxDB Cloud subscription](/influxdb/cloud/account-management/offboarding/). +source: /shared/influxdb-v2/reference/cli/influx/org/delete.md --- -{{% note %}} -#### Works with InfluxDB OSS 2.x -The `influx org delete` command works with **InfluxDB OSS 2.x**, but does not work with **InfluxDB Cloud**. -An organization is associated with your InfluxDB account. -For information about removing your InfluxDB Cloud account and its organization, -see [Cancel your InfluxDB Cloud subscription](/influxdb/cloud/account-management/offboarding/). -{{% /note %}} - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/org/list.md b/content/influxdb/cloud/reference/cli/influx/org/list.md index b62373fff..cf9ad880a 100644 --- a/content/influxdb/cloud/reference/cli/influx/org/list.md +++ b/content/influxdb/cloud/reference/cli/influx/org/list.md @@ -6,6 +6,8 @@ menu: name: influx org list parent: influx org weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/org/list.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/org/members/_index.md b/content/influxdb/cloud/reference/cli/influx/org/members/_index.md index 9bb07da5d..db75b42b1 100644 --- a/content/influxdb/cloud/reference/cli/influx/org/members/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/org/members/_index.md @@ -7,13 +7,15 @@ menu: parent: influx org weight: 201 metadata: [influx CLI 2.0.0+, InfluxDB OSS only] +prepend: | + > [!Note] + > #### Works with InfluxDB OSS 2.x + > The `influx org members` command works with **InfluxDB OSS 2.x**, but does + > not work with **InfluxDB Cloud**. + > For information about managing users in your InfluxDB Cloud organization, see + > [Manage users](/influxdb/cloud/admin/organizations/users/). +source: /shared/influxdb-v2/reference/cli/influx/org/members/_index.md --- -{{% note %}} -#### Works with InfluxDB OSS 2.x -The `influx org members` command works with **InfluxDB OSS 2.x**, but does not work with **InfluxDB Cloud**. -For information about managing users in your InfluxDB Cloud organization, see -[Manage users](/influxdb/cloud/admin/organizations/users/). -{{% /note %}} - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/org/members/add.md b/content/influxdb/cloud/reference/cli/influx/org/members/add.md index 47705c0ef..2c6c4acc4 100644 --- a/content/influxdb/cloud/reference/cli/influx/org/members/add.md +++ b/content/influxdb/cloud/reference/cli/influx/org/members/add.md @@ -8,14 +8,15 @@ menu: weight: 301 updated_in: CLI v2.4.0 metadata: [influx CLI 2.0.0+, InfluxDB OSS only] +prepend: | + > [!NOTE] + > #### Available with InfluxDB OSS 2.x only + > The `influx org members add` command adds members to organizations in **InfluxDB OSS 2.x**, + > but cannot add organization members to **InfluxDB Cloud**. + > For information about inviting users into your InfluxDB Cloud organization, see + > [Manage users](/influxdb/cloud/admin/organizations/users/). +source: /shared/influxdb-v2/reference/cli/influx/org/members/add.md --- -{{% note %}} -#### Available with InfluxDB OSS 2.x only -The `influx org members add` command adds members to organizations in **InfluxDB OSS 2.x**, -but cannot add organization members to **InfluxDB Cloud**. -For information about inviting users into your InfluxDB Cloud organization, see -[Manage users](/influxdb/cloud/admin/organizations/users/). -{{% /note %}} - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/org/members/list.md b/content/influxdb/cloud/reference/cli/influx/org/members/list.md index 26ef52333..e9e421090 100644 --- a/content/influxdb/cloud/reference/cli/influx/org/members/list.md +++ b/content/influxdb/cloud/reference/cli/influx/org/members/list.md @@ -6,6 +6,8 @@ menu: name: influx org members list parent: influx org members weight: 301 +source: /shared/influxdb-v2/reference/cli/influx/org/members/list.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/org/members/remove.md b/content/influxdb/cloud/reference/cli/influx/org/members/remove.md index 9acbc5538..fd949aab1 100644 --- a/content/influxdb/cloud/reference/cli/influx/org/members/remove.md +++ b/content/influxdb/cloud/reference/cli/influx/org/members/remove.md @@ -7,14 +7,15 @@ menu: parent: influx org members weight: 301 metadata: [influx CLI 2.0.0+, InfluxDB OSS only] +prepend: | + > [!NOTE] + > #### Available with InfluxDB OSS 2.x only + > The `influx org members remove` command removes organization members in **InfluxDB OSS 2.x**, + > but cannot remove organization members in **InfluxDB Cloud**. + > For information about removing a user from your InfluxDB Cloud organization, see + > [Remove a user](/influxdb/cloud/admin/organizations/users/#remove-a-user-from-your-organization/). +source: /shared/influxdb-v2/reference/cli/influx/org/members/remove.md --- -{{% note %}} -#### Available with InfluxDB OSS 2.x only -The `influx org members remove` command removes organization members in **InfluxDB OSS 2.x**, -but cannot remove organization members in **InfluxDB Cloud**. -For information about removing a user from your InfluxDB Cloud organization, see -[Remove a user](/influxdb/cloud/admin/organizations/users/#remove-a-user-from-your-organization/). -{{% /note %}} - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/org/update.md b/content/influxdb/cloud/reference/cli/influx/org/update.md index 6a671d7fa..437ce7109 100644 --- a/content/influxdb/cloud/reference/cli/influx/org/update.md +++ b/content/influxdb/cloud/reference/cli/influx/org/update.md @@ -6,6 +6,8 @@ menu: name: influx org update parent: influx org weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/org/update.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/ping/_index.md b/content/influxdb/cloud/reference/cli/influx/ping/_index.md index f880584b5..ee378b4ec 100644 --- a/content/influxdb/cloud/reference/cli/influx/ping/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/ping/_index.md @@ -13,11 +13,12 @@ related: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+, InfluxDB OSS only] +prepend: | + > [!Note] + > #### Works with InfluxDB OSS 2.x + > The `influx ping` command works with **InfluxDB OSS 2.x**, but does not work with **InfluxDB Cloud**. +source: /shared/influxdb-v2/reference/cli/influx/ping/_index.md --- -{{% note %}} -#### Works with InfluxDB OSS 2.x -The `influx ping` command works with **InfluxDB OSS 2.x**, but does not work with **InfluxDB Cloud**. -{{% /note %}} - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/query/_index.md b/content/influxdb/cloud/reference/cli/influx/query/_index.md index 2c608e590..7f4917c3f 100644 --- a/content/influxdb/cloud/reference/cli/influx/query/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/query/_index.md @@ -16,6 +16,8 @@ related: - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+] updated_in: CLI v2.0.5 +source: /shared/influxdb-v2/reference/cli/influx/query/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/remote/_index.md b/content/influxdb/cloud/reference/cli/influx/remote/_index.md index 5cba37667..8805136c3 100644 --- a/content/influxdb/cloud/reference/cli/influx/remote/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/remote/_index.md @@ -10,6 +10,8 @@ influxdb/cloud/tags: [write, replication] related: - /influxdb/cloud/reference/cli/influx/replication - /influxdb/cloud/write-data/replication +source: /shared/influxdb-v2/reference/cli/influx/remote/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/remote/create.md b/content/influxdb/cloud/reference/cli/influx/remote/create.md index c54a30cdd..550404e44 100644 --- a/content/influxdb/cloud/reference/cli/influx/remote/create.md +++ b/content/influxdb/cloud/reference/cli/influx/remote/create.md @@ -9,6 +9,8 @@ weight: 101 influxdb/cloud/tags: [write, replication] related: - /influxdb/cloud/reference/cli/influx/replication +source: /shared/influxdb-v2/reference/cli/influx/remote/create.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/remote/delete.md b/content/influxdb/cloud/reference/cli/influx/remote/delete.md index 767d28962..664a13b49 100644 --- a/content/influxdb/cloud/reference/cli/influx/remote/delete.md +++ b/content/influxdb/cloud/reference/cli/influx/remote/delete.md @@ -9,6 +9,8 @@ weight: 102 influxdb/cloud/tags: [write, replication] related: - /influxdb/cloud/reference/cli/influx/replication +source: /shared/influxdb-v2/reference/cli/influx/remote/delete.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/remote/list.md b/content/influxdb/cloud/reference/cli/influx/remote/list.md index 37b80c9f9..892be37c0 100644 --- a/content/influxdb/cloud/reference/cli/influx/remote/list.md +++ b/content/influxdb/cloud/reference/cli/influx/remote/list.md @@ -9,6 +9,8 @@ weight: 102 influxdb/cloud/tags: [write, replication] related: - /influxdb/cloud/reference/cli/influx/replication +source: /shared/influxdb-v2/reference/cli/influx/remote/list.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/remote/update.md b/content/influxdb/cloud/reference/cli/influx/remote/update.md index 92ecc929b..d8fdcd5ac 100644 --- a/content/influxdb/cloud/reference/cli/influx/remote/update.md +++ b/content/influxdb/cloud/reference/cli/influx/remote/update.md @@ -9,6 +9,8 @@ weight: 102 influxdb/cloud/tags: [write, replication] related: - /influxdb/cloud/reference/cli/influx/replication +source: /shared/influxdb-v2/reference/cli/influx/remote/update.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/replication/_index.md b/content/influxdb/cloud/reference/cli/influx/replication/_index.md index a5f12d612..d1badc76a 100644 --- a/content/influxdb/cloud/reference/cli/influx/replication/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/replication/_index.md @@ -11,6 +11,8 @@ cascade: related: - /influxdb/cloud/reference/cli/influx/remote - /influxdb/cloud/write-data/replication/replicate-data/ +source: /shared/influxdb-v2/reference/cli/influx/replication/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/replication/create.md b/content/influxdb/cloud/reference/cli/influx/replication/create.md index e1720e2cb..df0ef2b0a 100644 --- a/content/influxdb/cloud/reference/cli/influx/replication/create.md +++ b/content/influxdb/cloud/reference/cli/influx/replication/create.md @@ -7,6 +7,8 @@ menu: parent: influx replication weight: 101 influxdb/cloud/tags: [write] +source: /shared/influxdb-v2/reference/cli/influx/replication/create.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/replication/delete.md b/content/influxdb/cloud/reference/cli/influx/replication/delete.md index 1f9f4057b..766894f62 100644 --- a/content/influxdb/cloud/reference/cli/influx/replication/delete.md +++ b/content/influxdb/cloud/reference/cli/influx/replication/delete.md @@ -7,6 +7,8 @@ menu: parent: influx replication weight: 102 influxdb/cloud/tags: [write, replication] +source: /shared/influxdb-v2/reference/cli/influx/replication/delete.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/replication/list.md b/content/influxdb/cloud/reference/cli/influx/replication/list.md index 775019a49..5c73ba5f2 100644 --- a/content/influxdb/cloud/reference/cli/influx/replication/list.md +++ b/content/influxdb/cloud/reference/cli/influx/replication/list.md @@ -7,6 +7,8 @@ menu: parent: influx replication weight: 102 influxdb/cloud/tags: [write, replication] +source: /shared/influxdb-v2/reference/cli/influx/replication/list.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/replication/update.md b/content/influxdb/cloud/reference/cli/influx/replication/update.md index 9691f6877..016482336 100644 --- a/content/influxdb/cloud/reference/cli/influx/replication/update.md +++ b/content/influxdb/cloud/reference/cli/influx/replication/update.md @@ -7,6 +7,8 @@ menu: parent: influx replication weight: 102 influxdb/cloud/tags: [write, replication] +source: /shared/influxdb-v2/reference/cli/influx/replication/update.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/restore/index.md b/content/influxdb/cloud/reference/cli/influx/restore/index.md index 82f38ab5a..847b7b282 100644 --- a/content/influxdb/cloud/reference/cli/influx/restore/index.md +++ b/content/influxdb/cloud/reference/cli/influx/restore/index.md @@ -11,14 +11,13 @@ related: - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+] updated_in: CLI v2.0.7 +prepend: | + > [!NOTE] + > #### Works with InfluxDB OSS 2.x + > The `influx restore` command works with **InfluxDB OSS 2.x**, but does not work with **InfluxDB Cloud**. + > For information about restoring data in InfluxDB Cloud, see [InfluxDB Cloud durability](/influxdb/cloud/reference/internals/durability/) and contact [InfluxData Support](https://support.influxdata.com/). +source: /shared/influxdb-v2/reference/cli/influx/restore/index.md --- -{{% note %}} -#### Works with InfluxDB OSS 2.x -The `influx restore` command works with **InfluxDB OSS 2.x**, but does not work with **InfluxDB Cloud**. -For information about restoring data in InfluxDB Cloud, see -[InfluxDB Cloud durability](/influxdb/cloud/reference/internals/durability/) and -contact [InfluxData Support](https://support.influxdata.com/). -{{% /note %}} - -{{< duplicate-oss >}} \ No newline at end of file + diff --git a/content/influxdb/cloud/reference/cli/influx/scripts/_index.md b/content/influxdb/cloud/reference/cli/influx/scripts/_index.md index 6112b907c..499bd8b5a 100644 --- a/content/influxdb/cloud/reference/cli/influx/scripts/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/scripts/_index.md @@ -13,6 +13,8 @@ cascade: - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions - /influxdb/cloud/api-guide/api-invokable-scripts/ metadata: [influx CLI 2.4.0+, InfluxDB Cloud only] +source: /shared/influxdb-v2/reference/cli/influx/scripts/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/scripts/create.md b/content/influxdb/cloud/reference/cli/influx/scripts/create.md index a322e7340..85e26547d 100644 --- a/content/influxdb/cloud/reference/cli/influx/scripts/create.md +++ b/content/influxdb/cloud/reference/cli/influx/scripts/create.md @@ -6,6 +6,8 @@ menu: name: influx scripts create parent: influx scripts weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/scripts/create.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/scripts/delete.md b/content/influxdb/cloud/reference/cli/influx/scripts/delete.md index f126ad41c..4c7add75b 100644 --- a/content/influxdb/cloud/reference/cli/influx/scripts/delete.md +++ b/content/influxdb/cloud/reference/cli/influx/scripts/delete.md @@ -6,6 +6,8 @@ menu: name: influx scripts delete parent: influx scripts weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/scripts/delete.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/scripts/invoke.md b/content/influxdb/cloud/reference/cli/influx/scripts/invoke.md index 2dae895b2..02987dd22 100644 --- a/content/influxdb/cloud/reference/cli/influx/scripts/invoke.md +++ b/content/influxdb/cloud/reference/cli/influx/scripts/invoke.md @@ -6,6 +6,8 @@ menu: name: influx scripts invoke parent: influx scripts weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/scripts/invoke.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/scripts/list.md b/content/influxdb/cloud/reference/cli/influx/scripts/list.md index ce91368f5..6ff44513b 100644 --- a/content/influxdb/cloud/reference/cli/influx/scripts/list.md +++ b/content/influxdb/cloud/reference/cli/influx/scripts/list.md @@ -6,6 +6,8 @@ menu: name: influx scripts list parent: influx scripts weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/scripts/list.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/scripts/retrieve.md b/content/influxdb/cloud/reference/cli/influx/scripts/retrieve.md index 746cedf59..032226b51 100644 --- a/content/influxdb/cloud/reference/cli/influx/scripts/retrieve.md +++ b/content/influxdb/cloud/reference/cli/influx/scripts/retrieve.md @@ -6,6 +6,8 @@ menu: name: influx scripts retrieve parent: influx scripts weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/scripts/retrieve.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/scripts/update.md b/content/influxdb/cloud/reference/cli/influx/scripts/update.md index 18c7cd697..ba49bbfe6 100644 --- a/content/influxdb/cloud/reference/cli/influx/scripts/update.md +++ b/content/influxdb/cloud/reference/cli/influx/scripts/update.md @@ -6,6 +6,8 @@ menu: name: influx scripts update parent: influx scripts weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/scripts/update.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/secret/_index.md b/content/influxdb/cloud/reference/cli/influx/secret/_index.md index 3572fc378..97926fc0d 100644 --- a/content/influxdb/cloud/reference/cli/influx/secret/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/secret/_index.md @@ -13,6 +13,8 @@ cascade: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+] +source: /shared/influxdb-v2/reference/cli/influx/secret/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/secret/delete.md b/content/influxdb/cloud/reference/cli/influx/secret/delete.md index 4e9985b8b..742fa76b4 100644 --- a/content/influxdb/cloud/reference/cli/influx/secret/delete.md +++ b/content/influxdb/cloud/reference/cli/influx/secret/delete.md @@ -6,6 +6,8 @@ menu: name: influx secret delete parent: influx secret weight: 101 +source: /shared/influxdb-v2/reference/cli/influx/secret/delete.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/secret/list.md b/content/influxdb/cloud/reference/cli/influx/secret/list.md index 6e7788048..70a5cbd0c 100644 --- a/content/influxdb/cloud/reference/cli/influx/secret/list.md +++ b/content/influxdb/cloud/reference/cli/influx/secret/list.md @@ -6,6 +6,8 @@ menu: name: influx secret list parent: influx secret weight: 101 +source: /shared/influxdb-v2/reference/cli/influx/secret/list.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/secret/update.md b/content/influxdb/cloud/reference/cli/influx/secret/update.md index 7322cfb4a..20cde6375 100644 --- a/content/influxdb/cloud/reference/cli/influx/secret/update.md +++ b/content/influxdb/cloud/reference/cli/influx/secret/update.md @@ -6,6 +6,8 @@ menu: name: influx secret update parent: influx secret weight: 101 +source: /shared/influxdb-v2/reference/cli/influx/secret/update.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/setup/_index.md b/content/influxdb/cloud/reference/cli/influx/setup/_index.md index 8edabcf54..85aeaea20 100644 --- a/content/influxdb/cloud/reference/cli/influx/setup/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/setup/_index.md @@ -15,12 +15,13 @@ related: metadata: [influx CLI 2.0.0+, InfluxDB OSS only] updated_in: CLI v2.0.3 canonical: /influxdb/v2/reference/cli/influx/setup/ +prepend: | + > [!Note] + > #### Works with InfluxDB OSS 2.x + > The `influx setup` command initiates the setup process for **InfluxDB OSS 2.x** instances. + > The command does not work with **InfluxDB Cloud**. +source: /shared/influxdb-v2/reference/cli/influx/setup/_index.md --- -{{% note %}} -#### Works with InfluxDB OSS 2.x -The `influx setup` command initiates the setup process for **InfluxDB OSS 2.x** instances. -The command does not work with **InfluxDB Cloud**. -{{% /note %}} - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/stacks/_index.md b/content/influxdb/cloud/reference/cli/influx/stacks/_index.md index 73697adaa..e7fbbede7 100644 --- a/content/influxdb/cloud/reference/cli/influx/stacks/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/stacks/_index.md @@ -15,6 +15,8 @@ cascade: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.1+] +source: /shared/influxdb-v2/reference/cli/influx/stacks/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/stacks/init.md b/content/influxdb/cloud/reference/cli/influx/stacks/init.md index c4b1f7150..65b3bce28 100644 --- a/content/influxdb/cloud/reference/cli/influx/stacks/init.md +++ b/content/influxdb/cloud/reference/cli/influx/stacks/init.md @@ -7,6 +7,8 @@ menu: parent: influx stacks weight: 201 influxdb/cloud/tags: [templates] +source: /shared/influxdb-v2/reference/cli/influx/stacks/init.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/stacks/remove.md b/content/influxdb/cloud/reference/cli/influx/stacks/remove.md index de58721f7..5219b6a9b 100644 --- a/content/influxdb/cloud/reference/cli/influx/stacks/remove.md +++ b/content/influxdb/cloud/reference/cli/influx/stacks/remove.md @@ -9,6 +9,8 @@ weight: 201 aliases: - /influxdb/cloud/reference/cli/influx/pkg/stack/remove/ influxdb/cloud/tags: [templates] +source: /shared/influxdb-v2/reference/cli/influx/stacks/remove.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/stacks/update.md b/content/influxdb/cloud/reference/cli/influx/stacks/update.md index aa62f2f40..118055d0f 100644 --- a/content/influxdb/cloud/reference/cli/influx/stacks/update.md +++ b/content/influxdb/cloud/reference/cli/influx/stacks/update.md @@ -8,6 +8,8 @@ menu: weight: 201 influxdb/cloud/tags: [templates] updated_in: CLI v2.0.4 +source: /shared/influxdb-v2/reference/cli/influx/stacks/update.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/task/_index.md b/content/influxdb/cloud/reference/cli/influx/task/_index.md index ba6e3b7ff..a296ac7af 100644 --- a/content/influxdb/cloud/reference/cli/influx/task/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/task/_index.md @@ -13,6 +13,8 @@ cascade: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+] +source: /shared/influxdb-v2/reference/cli/influx/task/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/task/create.md b/content/influxdb/cloud/reference/cli/influx/task/create.md index 5f648d472..aeaace21b 100644 --- a/content/influxdb/cloud/reference/cli/influx/task/create.md +++ b/content/influxdb/cloud/reference/cli/influx/task/create.md @@ -6,6 +6,8 @@ menu: name: influx task create parent: influx task weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/task/create.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/task/delete.md b/content/influxdb/cloud/reference/cli/influx/task/delete.md index b3802cd58..e0c1c82f2 100644 --- a/content/influxdb/cloud/reference/cli/influx/task/delete.md +++ b/content/influxdb/cloud/reference/cli/influx/task/delete.md @@ -6,6 +6,8 @@ menu: name: influx task delete parent: influx task weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/task/delete.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/task/list.md b/content/influxdb/cloud/reference/cli/influx/task/list.md index 0641bace5..12e3222ed 100644 --- a/content/influxdb/cloud/reference/cli/influx/task/list.md +++ b/content/influxdb/cloud/reference/cli/influx/task/list.md @@ -6,6 +6,8 @@ menu: name: influx task list parent: influx task weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/task/list.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/task/log/_index.md b/content/influxdb/cloud/reference/cli/influx/task/log/_index.md index 1c47880b7..ddc0321da 100644 --- a/content/influxdb/cloud/reference/cli/influx/task/log/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/task/log/_index.md @@ -9,6 +9,8 @@ menu: parent: influx task weight: 201 influxdb/cloud/tags: [logs] +source: /shared/influxdb-v2/reference/cli/influx/task/log/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/task/log/list.md b/content/influxdb/cloud/reference/cli/influx/task/log/list.md index cddbfda89..cb6b44c6f 100644 --- a/content/influxdb/cloud/reference/cli/influx/task/log/list.md +++ b/content/influxdb/cloud/reference/cli/influx/task/log/list.md @@ -8,6 +8,8 @@ menu: weight: 301 aliases: - /influxdb/cloud/reference/cli/influx/task/log/list +source: /shared/influxdb-v2/reference/cli/influx/task/log/list.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/task/retry-failed.md b/content/influxdb/cloud/reference/cli/influx/task/retry-failed.md index 8e7393805..d705c9a4a 100644 --- a/content/influxdb/cloud/reference/cli/influx/task/retry-failed.md +++ b/content/influxdb/cloud/reference/cli/influx/task/retry-failed.md @@ -7,6 +7,8 @@ menu: parent: influx task weight: 201 metadata: [influx CLI 2.0.5+] +source: /shared/influxdb-v2/reference/cli/influx/task/retry-failed.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/task/run/_index.md b/content/influxdb/cloud/reference/cli/influx/task/run/_index.md index 43be3c742..8ba69f7ce 100644 --- a/content/influxdb/cloud/reference/cli/influx/task/run/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/task/run/_index.md @@ -8,6 +8,8 @@ menu: name: influx task run parent: influx task weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/task/run/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/task/run/list.md b/content/influxdb/cloud/reference/cli/influx/task/run/list.md index 4c3804b99..17fe70143 100644 --- a/content/influxdb/cloud/reference/cli/influx/task/run/list.md +++ b/content/influxdb/cloud/reference/cli/influx/task/run/list.md @@ -6,6 +6,8 @@ menu: name: influx task run list parent: influx task run weight: 301 +source: /shared/influxdb-v2/reference/cli/influx/task/run/list.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/task/run/retry.md b/content/influxdb/cloud/reference/cli/influx/task/run/retry.md index 0487f44a5..b3b60df9d 100644 --- a/content/influxdb/cloud/reference/cli/influx/task/run/retry.md +++ b/content/influxdb/cloud/reference/cli/influx/task/run/retry.md @@ -6,6 +6,8 @@ menu: name: influx task run retry parent: influx task run weight: 301 +source: /shared/influxdb-v2/reference/cli/influx/task/run/retry.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/task/update.md b/content/influxdb/cloud/reference/cli/influx/task/update.md index d04144548..600e18308 100644 --- a/content/influxdb/cloud/reference/cli/influx/task/update.md +++ b/content/influxdb/cloud/reference/cli/influx/task/update.md @@ -6,6 +6,8 @@ menu: name: influx task update parent: influx task weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/task/update.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/telegrafs/_index.md b/content/influxdb/cloud/reference/cli/influx/telegrafs/_index.md index e0a68da98..056dcc6db 100644 --- a/content/influxdb/cloud/reference/cli/influx/telegrafs/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/telegrafs/_index.md @@ -15,6 +15,8 @@ cascade: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+] +source: /shared/influxdb-v2/reference/cli/influx/telegrafs/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/telegrafs/create.md b/content/influxdb/cloud/reference/cli/influx/telegrafs/create.md index 90904ded9..56b9991fe 100644 --- a/content/influxdb/cloud/reference/cli/influx/telegrafs/create.md +++ b/content/influxdb/cloud/reference/cli/influx/telegrafs/create.md @@ -8,6 +8,8 @@ menu: name: influx telegrafs create parent: influx telegrafs weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/telegrafs/create.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/telegrafs/rm.md b/content/influxdb/cloud/reference/cli/influx/telegrafs/rm.md index 7a00fc6f8..12d6a8234 100644 --- a/content/influxdb/cloud/reference/cli/influx/telegrafs/rm.md +++ b/content/influxdb/cloud/reference/cli/influx/telegrafs/rm.md @@ -7,6 +7,8 @@ menu: name: influx telegrafs rm parent: influx telegrafs weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/telegrafs/rm.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/telegrafs/update.md b/content/influxdb/cloud/reference/cli/influx/telegrafs/update.md index 789bc5bc2..583c6577a 100644 --- a/content/influxdb/cloud/reference/cli/influx/telegrafs/update.md +++ b/content/influxdb/cloud/reference/cli/influx/telegrafs/update.md @@ -8,6 +8,8 @@ menu: name: influx telegrafs update parent: influx telegrafs weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/telegrafs/update.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/template/_index.md b/content/influxdb/cloud/reference/cli/influx/template/_index.md index adb0b8495..11f40b66f 100644 --- a/content/influxdb/cloud/reference/cli/influx/template/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/template/_index.md @@ -13,6 +13,8 @@ cascade: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.1+] +source: /shared/influxdb-v2/reference/cli/influx/template/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/template/validate.md b/content/influxdb/cloud/reference/cli/influx/template/validate.md index e92be201d..ac23a9b00 100644 --- a/content/influxdb/cloud/reference/cli/influx/template/validate.md +++ b/content/influxdb/cloud/reference/cli/influx/template/validate.md @@ -6,6 +6,8 @@ menu: influxdb_cloud: parent: influx template weight: 201 +source: /shared/influxdb-v2/reference/cli/influx/template/validate.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/transpile/_index.md b/content/influxdb/cloud/reference/cli/influx/transpile/_index.md index 167ba990e..72b7485fb 100644 --- a/content/influxdb/cloud/reference/cli/influx/transpile/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/transpile/_index.md @@ -6,17 +6,18 @@ related: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0 – 2.0.5] -prepend: - block: warn - content: | - ### Removed in influx CLI v2.0.5 - The `influx transpile` command was removed in **v2.0.5** of the `influx` CLI. - [Use InfluxQL to query InfluxDB](/influxdb/cloud/query-data/influxql/). - For information about manually converting InfluxQL queries to Flux, see: - - - [Get started with Flux](/flux/v0.x/get-started/) - - [Query data with Flux](/influxdb/cloud/query-data/flux/) - - [Migrate continuous queries to Flux tasks](/influxdb/cloud/upgrade/v1-to-cloud/migrate-cqs/) +prepend: | + > [!Warning] + > ### Removed in influx CLI v2.0.5 + > The `influx transpile` command was removed in **v2.0.5** of the `influx` CLI. + > [Use InfluxQL to query InfluxDB](/influxdb/cloud/query-data/influxql/). + > For information about manually converting InfluxQL queries to Flux, see: + > + > - [Get started with Flux](/flux/v0.x/get-started/) + > - [Query data with Flux](/influxdb/cloud/query-data/flux/) + > - [Migrate continuous queries to Flux tasks](/influxdb/cloud/upgrade/v1-to-cloud/migrate-cqs/) +source: /shared/influxdb-v2/reference/cli/influx/transpile/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/user/_index.md b/content/influxdb/cloud/reference/cli/influx/user/_index.md index 3c19da24a..3792fd981 100644 --- a/content/influxdb/cloud/reference/cli/influx/user/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/user/_index.md @@ -13,13 +13,14 @@ cascade: - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+, InfluxDB OSS only] canonical: /influxdb/v2/reference/cli/influx/user/ +prepend: | + > [!Note] + > #### Works with InfluxDB OSS 2.x + > The `influx user` command and its subcommands manage **InfluxDB OSS 2.x** users, + > but do not manage users in **InfluxDB Cloud**. + > Use the InfluxDB Cloud user interface to manage account information. +source: /shared/influxdb-v2/reference/cli/influx/user/_index.md --- -{{% note %}} -#### Works with InfluxDB OSS 2.x -The `influx user` command and its subcommands manage **InfluxDB OSS 2.x** users, -but do not manage users in **InfluxDB Cloud**. -Use the InfluxDB Cloud user interface to manage account information. -{{% /note %}} - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/user/create.md b/content/influxdb/cloud/reference/cli/influx/user/create.md index 5652bcc29..fda33eb10 100644 --- a/content/influxdb/cloud/reference/cli/influx/user/create.md +++ b/content/influxdb/cloud/reference/cli/influx/user/create.md @@ -7,14 +7,15 @@ menu: parent: influx user weight: 201 canonical: /influxdb/v2/reference/cli/influx/user/create/ +prepend: | + > [!NOTE] + > #### Works with InfluxDB OSS 2.x + > The `influx user create` command creates users in **InfluxDB OSS 2.x**, + > but does not create users in **InfluxDB Cloud**. + > For information about inviting users into your InfluxDB Cloud organization, see + > [Manage users](/influxdb/cloud/admin/organizations/users/). +source: /shared/influxdb-v2/reference/cli/influx/user/create.md --- -{{% note %}} -#### Works with InfluxDB OSS 2.x -The `influx user create` command creates users in **InfluxDB OSS 2.x**, -but does not create users in **InfluxDB Cloud**. -For information about inviting users into your InfluxDB Cloud organization, see -[Manage users](/influxdb/cloud/admin/organizations/users/). -{{% /note %}} - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/user/delete.md b/content/influxdb/cloud/reference/cli/influx/user/delete.md index c8eae6882..f4116837a 100644 --- a/content/influxdb/cloud/reference/cli/influx/user/delete.md +++ b/content/influxdb/cloud/reference/cli/influx/user/delete.md @@ -7,14 +7,15 @@ menu: parent: influx user weight: 201 canonical: /influxdb/v2/reference/cli/influx/user/delete/ +prepend: | + > [!Note] + > #### Works with InfluxDB OSS 2.x + > The `influx user delete` command deletes users from **InfluxDB OSS 2.x**, + > but does not delete users from **InfluxDB Cloud**. + > For information about removing a user from your InfluxDB Cloud organization, see + > [Remove a user](/influxdb/cloud/admin/organizations/users/#remove-a-user-from-your-organization). +source: /shared/influxdb-v2/reference/cli/influx/user/delete.md --- -{{% note %}} -#### Works with InfluxDB OSS 2.x -The `influx user delete` command deletes users from **InfluxDB OSS 2.x**, -but does not delete users from **InfluxDB Cloud**. -For information about removing a user from your InfluxDB Cloud organization, see -[Remove a user](/influxdb/cloud/admin/organizations/users/#remove-a-user-from-your-organization). -{{% /note %}} - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/user/list.md b/content/influxdb/cloud/reference/cli/influx/user/list.md index bf322a180..ca5c536ca 100644 --- a/content/influxdb/cloud/reference/cli/influx/user/list.md +++ b/content/influxdb/cloud/reference/cli/influx/user/list.md @@ -9,14 +9,15 @@ weight: 201 aliases: - /influxdb/cloud/reference/cli/influx/user/find canonical: /influxdb/v2/reference/cli/influx/user/list/ +prepend: | + > [!NOTE] + > #### Works with InfluxDB OSS 2.x + > The `influx user list` command lists users in **InfluxDB OSS 2.x**, + > but does not list users in **InfluxDB Cloud**. + > For information about managing InfluxDB Cloud users, see + > [Manage users](/influxdb/cloud/admin/organizations/users/). +source: /shared/influxdb-v2/reference/cli/influx/user/list.md --- -{{% note %}} -#### Works with InfluxDB OSS 2.x -The `influx user list` command lists users in **InfluxDB OSS 2.x**, -but does not list users in **InfluxDB Cloud**. -For information about managing InfluxDB Cloud users, see -[Manage users](/influxdb/cloud/admin/organizations/users/). -{{% /note %}} - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/user/password.md b/content/influxdb/cloud/reference/cli/influx/user/password.md index 142be5124..0b12f7308 100644 --- a/content/influxdb/cloud/reference/cli/influx/user/password.md +++ b/content/influxdb/cloud/reference/cli/influx/user/password.md @@ -11,14 +11,15 @@ related: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions canonical: /influxdb/v2/reference/cli/influx/user/password/ +prepend: | + > [!Note] + > #### Works with InfluxDB OSS 2.x + > The `influx user password` command updates passwords for **InfluxDB OSS 2.x** users, + > but does not update passwords for **InfluxDB Cloud** accounts. + > To change your InfluxDB Cloud account password, see + > [Change your password](/influxdb/cloud/account-management/change-password/). +source: /shared/influxdb-v2/reference/cli/influx/user/_index.md --- -{{% note %}} -#### Works with InfluxDB OSS 2.x -The `influx user password` command updates passwords for **InfluxDB OSS 2.x** users, -but does not update passwords for **InfluxDB Cloud** accounts. -To change your InfluxDB Cloud account password, see -[Change your password](/influxdb/cloud/account-management/change-password/). -{{% /note %}} - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/user/update.md b/content/influxdb/cloud/reference/cli/influx/user/update.md index 3e0b04904..fcc7f77b1 100644 --- a/content/influxdb/cloud/reference/cli/influx/user/update.md +++ b/content/influxdb/cloud/reference/cli/influx/user/update.md @@ -8,13 +8,14 @@ menu: parent: influx user weight: 201 canonical: /influxdb/v2/reference/cli/influx/user/update/ +prepend: | + > [!NOTE] + > #### Works with InfluxDB OSS 2.x + > The `influx user update` command updates users in **InfluxDB OSS 2.x**, + > but does not update users in **InfluxDB Cloud**. + > Use the InfluxDB Cloud user interface to update account information. +source: /shared/influxdb-v2/reference/cli/influx/user/update.md --- -{{% note %}} -#### Works with InfluxDB OSS 2.x -The `influx user update` command updates users in **InfluxDB OSS 2.x**, -but does not update users in **InfluxDB Cloud**. -Use the InfluxDB Cloud user interface to update account information. -{{% /note %}} - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/v1/_index.md b/content/influxdb/cloud/reference/cli/influx/v1/_index.md index f8521f028..a5dae5b8c 100644 --- a/content/influxdb/cloud/reference/cli/influx/v1/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/v1/_index.md @@ -12,6 +12,8 @@ cascade: - /influxdb/cloud/reference/cli/influx/#provide-required-authentication-credentials, influx CLI—Provide required authentication credentials - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+] +source: /shared/influxdb-v2/reference/cli/influx/v1/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/v1/auth/_index.md b/content/influxdb/cloud/reference/cli/influx/v1/auth/_index.md index 9896b4d02..c8bfa0527 100644 --- a/content/influxdb/cloud/reference/cli/influx/v1/auth/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/v1/auth/_index.md @@ -8,13 +8,14 @@ menu: parent: influx v1 weight: 101 influxdb/cloud/tags: [authorization] +prepend: | + > [!IMPORTANT] + > #### Not supported in InfluxDB Cloud + > + > **InfluxDB Cloud** does not support InfluxDB 1.x compatible authorizations. + > To authenticate with InfluxDB Cloud, use [InfluxDB token authentication](/influxdb/cloud/admin/tokens/). +source: /shared/influxdb-v2/reference/cli/influx/v1/auth/_index.md --- -> [!IMPORTANT] -> -> #### Not supported in InfluxDB Cloud -> -> **InfluxDB Cloud** does not support InfluxDB 1.x compatible authorizations. -> To authenticate with InfluxDB Cloud, use [InfluxDB token authentication](/influxdb/cloud/admin/tokens/). - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/v1/auth/create.md b/content/influxdb/cloud/reference/cli/influx/v1/auth/create.md index 6e49d59de..209b4f782 100644 --- a/content/influxdb/cloud/reference/cli/influx/v1/auth/create.md +++ b/content/influxdb/cloud/reference/cli/influx/v1/auth/create.md @@ -9,14 +9,16 @@ menu: weight: 101 influxdb/cloud/tags: [authorization] updated_in: CLI v2.0.3 +prepend: | + > [!Important] + > #### Not supported in InfluxDB Cloud Serverless + > + > **{{< product-name >}}** does not support InfluxDB 1.x compatible authorizations. + > Using the `influx v1 auth create` command with InfluxDB Cloud will result in an error. + > To authenticate with InfluxDB Cloud, use + > [InfluxDB token authentication](/influxdb3/cloud-serverless/admin/tokens/). +source: /shared/influxdb-v2/reference/cli/influx/v1/auth/create.md --- -> [!Important] -> #### Not supported in InfluxDB Cloud Serverless -> -> **{{< product-name >}}** does not support InfluxDB 1.x compatible authorizations. -> Using the `influx v1 auth create` command with InfluxDB Cloud will result in an error. -> To authenticate with InfluxDB Cloud, use -> [InfluxDB token authentication](/influxdb3/cloud-serverless/admin/tokens/). - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/v1/auth/delete.md b/content/influxdb/cloud/reference/cli/influx/v1/auth/delete.md index 706659be8..1bf7d05a1 100644 --- a/content/influxdb/cloud/reference/cli/influx/v1/auth/delete.md +++ b/content/influxdb/cloud/reference/cli/influx/v1/auth/delete.md @@ -8,13 +8,15 @@ menu: parent: influx v1 auth weight: 101 influxdb/cloud/tags: [authorization] +prepend: | + > [!Important] + > + > #### Not supported in InfluxDB Cloud + > **InfluxDB Cloud** does not support InfluxDB 1.x compatible authorizations. + > Using the `influx v1 auth delete` command with InfluxDB Cloud will result in an error. + > To authenticate with InfluxDB Cloud, use [InfluxDB token authentication](/influxdb/cloud/admin/tokens/). +source: /shared/influxdb-v2/reference/cli/influx/v1/auth/delete.md --- -> [!Important] -> -> #### Not supported in InfluxDB Cloud -> **InfluxDB Cloud** does not support InfluxDB 1.x compatible authorizations. -> Using the `influx v1 auth delete` command with InfluxDB Cloud will result in an error. -> To authenticate with InfluxDB Cloud, use [InfluxDB token authentication](/influxdb/cloud/admin/tokens/). - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/v1/auth/list.md b/content/influxdb/cloud/reference/cli/influx/v1/auth/list.md index c986596af..b6c39db55 100644 --- a/content/influxdb/cloud/reference/cli/influx/v1/auth/list.md +++ b/content/influxdb/cloud/reference/cli/influx/v1/auth/list.md @@ -8,13 +8,15 @@ menu: parent: influx v1 auth weight: 101 influxdb/cloud/tags: [authorization] +prepend: | + > [!Important] + > + > #### Not supported in InfluxDB Cloud + > **InfluxDB Cloud** does not support InfluxDB 1.x compatible authorizations. + > Using the `influx v1 auth list` command with InfluxDB Cloud will result in an error. + > To authenticate with InfluxDB Cloud, use [InfluxDB token authentication](/influxdb/cloud/admin/tokens/). +source: /shared/influxdb-v2/reference/cli/influx/v1/auth/list.md --- -> [!Important] -> -> #### Not supported in InfluxDB Cloud -> **InfluxDB Cloud** does not support InfluxDB 1.x compatible authorizations. -> Using the `influx v1 auth list` command with InfluxDB Cloud will result in an error. -> To authenticate with InfluxDB Cloud, use [InfluxDB token authentication](/influxdb/cloud/admin/tokens/). - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/v1/auth/set-active.md b/content/influxdb/cloud/reference/cli/influx/v1/auth/set-active.md index 9ff704995..1b86a7330 100644 --- a/content/influxdb/cloud/reference/cli/influx/v1/auth/set-active.md +++ b/content/influxdb/cloud/reference/cli/influx/v1/auth/set-active.md @@ -8,13 +8,15 @@ menu: parent: influx v1 auth weight: 101 influxdb/cloud/tags: [authorization] +prepend: | + > [!Important] + > + > #### Not supported in InfluxDB Cloud + > **InfluxDB Cloud** does not support InfluxDB 1.x compatible authorizations. + > Using the `influx v1 auth set-active` command with InfluxDB Cloud will result in an error. + > To authenticate with InfluxDB Cloud, use [InfluxDB token authentication](/influxdb/cloud/admin/tokens/). +source: /shared/influxdb-v2/reference/cli/influx/v1/auth/set-active.md --- -> [!Important] -> -> #### Not supported in InfluxDB Cloud -> **InfluxDB Cloud** does not support InfluxDB 1.x compatible authorizations. -> Using the `influx v1 auth set-active` command with InfluxDB Cloud will result in an error. -> To authenticate with InfluxDB Cloud, use [InfluxDB token authentication](/influxdb/cloud/admin/tokens/). - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/v1/auth/set-inactive.md b/content/influxdb/cloud/reference/cli/influx/v1/auth/set-inactive.md index 3b8e8779e..9131de6e5 100644 --- a/content/influxdb/cloud/reference/cli/influx/v1/auth/set-inactive.md +++ b/content/influxdb/cloud/reference/cli/influx/v1/auth/set-inactive.md @@ -8,13 +8,15 @@ menu: parent: influx v1 auth weight: 101 influxdb/cloud/tags: [authorization] +prepend: | + > [!Important] + > + > #### Not supported in InfluxDB Cloud + > **InfluxDB Cloud** does not support InfluxDB 1.x compatible authorizations. + > Using the `influx v1 auth set-inactive` command with InfluxDB Cloud will result in an error. + > To authenticate with InfluxDB Cloud, use [InfluxDB token authentication](/influxdb/cloud/admin/tokens/). +source: /shared/influxdb-v2/reference/cli/influx/v1/auth/set-inactive.md --- -> [!Important] -> -> #### Not supported in InfluxDB Cloud -> **InfluxDB Cloud** does not support InfluxDB 1.x compatible authorizations. -> Using the `influx v1 auth set-inactive` command with InfluxDB Cloud will result in an error. -> To authenticate with InfluxDB Cloud, use [InfluxDB token authentication](/influxdb/cloud/admin/tokens/). - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/v1/auth/set-password.md b/content/influxdb/cloud/reference/cli/influx/v1/auth/set-password.md index cbe7d63be..6b0f1859e 100644 --- a/content/influxdb/cloud/reference/cli/influx/v1/auth/set-password.md +++ b/content/influxdb/cloud/reference/cli/influx/v1/auth/set-password.md @@ -9,13 +9,15 @@ menu: weight: 101 influxdb/cloud/tags: [authorization] updated_in: CLI v2.0.3 +prepend: | + > [!Important] + > + > #### Not supported in InfluxDB Cloud + > **InfluxDB Cloud** does not support InfluxDB 1.x compatible authorizations. + > Using the `influx v1 auth set-password` command with InfluxDB Cloud will result in an error. + > To authenticate with InfluxDB Cloud, use [InfluxDB token authentication](/influxdb/cloud/admin/tokens/). +source: /shared/influxdb-v2/reference/cli/influx/v1/auth/set-password.md --- -> [!Important] -> -> #### Not supported in InfluxDB Cloud -> **InfluxDB Cloud** does not support InfluxDB 1.x compatible authorizations. -> Using the `influx v1 auth set-password` command with InfluxDB Cloud will result in an error. -> To authenticate with InfluxDB Cloud, use [InfluxDB token authentication](/influxdb/cloud/admin/tokens/). - -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/v1/dbrp/_index.md b/content/influxdb/cloud/reference/cli/influx/v1/dbrp/_index.md index 09fca198f..b7c00d25b 100644 --- a/content/influxdb/cloud/reference/cli/influx/v1/dbrp/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/v1/dbrp/_index.md @@ -10,6 +10,8 @@ weight: 101 influxdb/cloud/tags: [DBRP] cascade: metadata: [influx CLI 2.0.2+] +source: /shared/influxdb-v2/reference/cli/influx/v1/dbrp/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/v1/dbrp/create.md b/content/influxdb/cloud/reference/cli/influx/v1/dbrp/create.md index b16214572..3ee24a9bd 100644 --- a/content/influxdb/cloud/reference/cli/influx/v1/dbrp/create.md +++ b/content/influxdb/cloud/reference/cli/influx/v1/dbrp/create.md @@ -8,6 +8,8 @@ menu: parent: influx v1 dbrp weight: 101 influxdb/cloud/tags: [DBRP] +source: /shared/influxdb-v2/reference/cli/influx/v1/dbrp/create.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/reference/cli/influx/v1/dbrp/delete.md b/content/influxdb/cloud/reference/cli/influx/v1/dbrp/delete.md index 7d6ff3a64..fd0e7f404 100644 --- a/content/influxdb/cloud/reference/cli/influx/v1/dbrp/delete.md +++ b/content/influxdb/cloud/reference/cli/influx/v1/dbrp/delete.md @@ -8,6 +8,8 @@ menu: parent: influx v1 dbrp weight: 101 influxdb/cloud/tags: [DBRP] +source: /shared/influxdb-v2/reference/cli/influx/v1/dbrp/delete.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/reference/cli/influx/v1/dbrp/list.md b/content/influxdb/cloud/reference/cli/influx/v1/dbrp/list.md index 5375e9a71..d12a956a5 100644 --- a/content/influxdb/cloud/reference/cli/influx/v1/dbrp/list.md +++ b/content/influxdb/cloud/reference/cli/influx/v1/dbrp/list.md @@ -8,6 +8,8 @@ menu: parent: influx v1 dbrp weight: 101 influxdb/cloud/tags: [dbrp] +source: /shared/influxdb-v2/reference/cli/influx/v1/dbrp/list.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/reference/cli/influx/v1/dbrp/update.md b/content/influxdb/cloud/reference/cli/influx/v1/dbrp/update.md index dd6bbe521..985af0e66 100644 --- a/content/influxdb/cloud/reference/cli/influx/v1/dbrp/update.md +++ b/content/influxdb/cloud/reference/cli/influx/v1/dbrp/update.md @@ -8,6 +8,8 @@ menu: parent: influx v1 dbrp weight: 101 influxdb/cloud/tags: [DBRP] +source: /shared/influxdb-v2/reference/cli/influx/v1/dbrp/update.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/reference/cli/influx/v1/shell.md b/content/influxdb/cloud/reference/cli/influx/v1/shell.md index b7750bfeb..c161431c3 100644 --- a/content/influxdb/cloud/reference/cli/influx/v1/shell.md +++ b/content/influxdb/cloud/reference/cli/influx/v1/shell.md @@ -14,6 +14,8 @@ related: - /influxdb/cloud/query-data/influxql/ - /influxdb/v2/tools/influxql-shell/ metadata: [influx CLI 2.4.0+, InfluxDB Cloud] +source: /shared/influxdb-v2/reference/cli/influx/v1/shell.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/version/_index.md b/content/influxdb/cloud/reference/cli/influx/version/_index.md index bd363a761..a32cc94cd 100644 --- a/content/influxdb/cloud/reference/cli/influx/version/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/version/_index.md @@ -7,6 +7,8 @@ menu: parent: influx weight: 202 metadata: [influx CLI 2.0.0+] +source: /shared/influxdb-v2/reference/cli/influx/version/_index.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/reference/cli/influx/write/_index.md b/content/influxdb/cloud/reference/cli/influx/write/_index.md index b07cbd63d..1f38668f0 100644 --- a/content/influxdb/cloud/reference/cli/influx/write/_index.md +++ b/content/influxdb/cloud/reference/cli/influx/write/_index.md @@ -20,6 +20,8 @@ cascade: - /influxdb/cloud/reference/cli/influx/#flag-patterns-and-conventions, influx CLI—Flag patterns and conventions metadata: [influx CLI 2.0.0+] updated_in: CLI v2.0.5 +source: /shared/influxdb-v2/reference/cli/influx/write/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/cli/influx/write/dryrun.md b/content/influxdb/cloud/reference/cli/influx/write/dryrun.md index c03c39779..8228d38d5 100644 --- a/content/influxdb/cloud/reference/cli/influx/write/dryrun.md +++ b/content/influxdb/cloud/reference/cli/influx/write/dryrun.md @@ -15,6 +15,8 @@ related: - /influxdb/cloud/reference/syntax/line-protocol/ - /influxdb/cloud/reference/syntax/annotated-csv/ - /influxdb/cloud/reference/syntax/annotated-csv/extended/ +source: /shared/influxdb-v2/reference/cli/influx/write/dryrun.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/faq.md b/content/influxdb/cloud/reference/faq.md index b28b41513..d4925c94c 100644 --- a/content/influxdb/cloud/reference/faq.md +++ b/content/influxdb/cloud/reference/faq.md @@ -6,6 +6,8 @@ menu: name: Frequently asked questions parent: Reference weight: 9 +source: /shared/influxdb-v2/reference/faq.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/glossary.md b/content/influxdb/cloud/reference/glossary.md index 6a32151c4..4ae3a19b4 100644 --- a/content/influxdb/cloud/reference/glossary.md +++ b/content/influxdb/cloud/reference/glossary.md @@ -8,6 +8,8 @@ menu: name: Glossary parent: Reference influxdb/cloud/tags: [glossary] +source: /shared/influxdb-v2/reference/glossary.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/internals/system-buckets.md b/content/influxdb/cloud/reference/internals/system-buckets.md index 1d76e4af3..527dd742d 100644 --- a/content/influxdb/cloud/reference/internals/system-buckets.md +++ b/content/influxdb/cloud/reference/internals/system-buckets.md @@ -17,6 +17,8 @@ related: - /flux/v0/stdlib/influxdata/influxdb/monitor/from/ - /flux/v0/stdlib/influxdata/influxdb/monitor/logs/ - /flux/v0/stdlib/influxdata/influxdb/monitor/notify/ +source: /shared/influxdb-v2/reference/internals/system-buckets.md --- -{{% duplicate-oss %}} + diff --git a/content/influxdb/cloud/reference/key-concepts/data-elements.md b/content/influxdb/cloud/reference/key-concepts/data-elements.md index 4de2d02a1..2a0504a66 100644 --- a/content/influxdb/cloud/reference/key-concepts/data-elements.md +++ b/content/influxdb/cloud/reference/key-concepts/data-elements.md @@ -10,6 +10,8 @@ menu: influxdb/cloud/tags: [key concepts, schema] related: - /resources/videos/data-model-building-blocks/ +source: /shared/influxdb-v2/reference/key-concepts/data-elements.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/key-concepts/data-schema.md b/content/influxdb/cloud/reference/key-concepts/data-schema.md index 25cabf283..8913babc3 100644 --- a/content/influxdb/cloud/reference/key-concepts/data-schema.md +++ b/content/influxdb/cloud/reference/key-concepts/data-schema.md @@ -10,6 +10,8 @@ menu: parent: Key concepts name: Data schema influxdb/cloud/tags: [key concepts] +source: /shared/influxdb-v2/reference/key-concepts/data-schema.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/key-concepts/design-principles.md b/content/influxdb/cloud/reference/key-concepts/design-principles.md index e31a3e0d9..9b68ae8eb 100644 --- a/content/influxdb/cloud/reference/key-concepts/design-principles.md +++ b/content/influxdb/cloud/reference/key-concepts/design-principles.md @@ -8,6 +8,8 @@ menu: parent: Key concepts name: Design principles influxdb/cloud/tags: [key concepts, design principles] +source: /shared/influxdb-v2/reference/key-concepts/design-principles.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/prometheus-metrics.md b/content/influxdb/cloud/reference/prometheus-metrics.md index e4ad264c1..2c7a9009b 100644 --- a/content/influxdb/cloud/reference/prometheus-metrics.md +++ b/content/influxdb/cloud/reference/prometheus-metrics.md @@ -15,6 +15,8 @@ related: - /flux/v0/prometheus/, Work with Prometheus in Flux - /telegraf/v1/input-prometheus, Telegraf Prometheus input plugin - /flux/v0/stdlib/experimental/prometheus/scrape/ +source: /shared/influxdb-v2/reference/prometheus-metrics.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/reference/release-notes/cloud-updates.md b/content/influxdb/cloud/reference/release-notes/cloud-updates.md index 826f529a1..70a7ab533 100644 --- a/content/influxdb/cloud/reference/release-notes/cloud-updates.md +++ b/content/influxdb/cloud/reference/release-notes/cloud-updates.md @@ -14,6 +14,14 @@ aliases: InfluxDB Cloud updates occur frequently. Find a compilation of recent updates below. To find information about the latest Flux updates in InfluxDB Cloud, see [Flux release notes](/influxdb/cloud/reference/release-notes/flux/). +## April 2025 + +### Flux VS Code extension no longer maintained + +`vsflux` is no longer available in the Visual Studio Marketplace. +The `vsflux` Visual Studio Code extension and the `flux-lsp` Flux Language Server Protocol plugin are no longer maintained. +Their repositories have been archived and are no longer receiving updates. + ## October 2022 ### Custom data retention periods diff --git a/content/influxdb/cloud/reference/release-notes/influx-cli.md b/content/influxdb/cloud/reference/release-notes/influx-cli.md index d3db52db0..0c9e91249 100644 --- a/content/influxdb/cloud/reference/release-notes/influx-cli.md +++ b/content/influxdb/cloud/reference/release-notes/influx-cli.md @@ -6,6 +6,8 @@ menu: influxdb_cloud: parent: Release notes name: influx CLI +source: /shared/influxdb-v2/reference/release-notes/influx-cli.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/sample-data.md b/content/influxdb/cloud/reference/sample-data.md index 38449f226..79dee5c46 100644 --- a/content/influxdb/cloud/reference/sample-data.md +++ b/content/influxdb/cloud/reference/sample-data.md @@ -10,6 +10,8 @@ menu: influxdb_cloud: parent: Reference weight: 7 +source: /shared/influxdb-v2/reference/sample-data.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/syntax/_index.md b/content/influxdb/cloud/reference/syntax/_index.md index c669b4898..009b8395a 100644 --- a/content/influxdb/cloud/reference/syntax/_index.md +++ b/content/influxdb/cloud/reference/syntax/_index.md @@ -9,6 +9,8 @@ menu: name: Syntax parent: Reference influxdb/cloud/tags: [syntax] +source: /shared/influxdb-v2/reference/syntax/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/syntax/annotated-csv/_index.md b/content/influxdb/cloud/reference/syntax/annotated-csv/_index.md index 7c316bf73..507b0b3f3 100644 --- a/content/influxdb/cloud/reference/syntax/annotated-csv/_index.md +++ b/content/influxdb/cloud/reference/syntax/annotated-csv/_index.md @@ -12,6 +12,8 @@ influxdb/cloud/tags: [csv, syntax] related: - /influxdb/cloud/reference/flux/stdlib/csv/from/ - /influxdb/cloud/reference/syntax/annotated-csv/extended/ +source: /shared/influxdb-v2/reference/syntax/annotated-csv/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/syntax/annotated-csv/extended.md b/content/influxdb/cloud/reference/syntax/annotated-csv/extended.md index 225f0d94c..5b218b326 100644 --- a/content/influxdb/cloud/reference/syntax/annotated-csv/extended.md +++ b/content/influxdb/cloud/reference/syntax/annotated-csv/extended.md @@ -15,6 +15,8 @@ related: - /influxdb/cloud/reference/cli/influx/write/ - /influxdb/cloud/reference/syntax/line-protocol/ - /influxdb/cloud/reference/syntax/annotated-csv/ +source: /shared/influxdb-v2/reference/syntax/annotated-csv/extended.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/syntax/delete-predicate.md b/content/influxdb/cloud/reference/syntax/delete-predicate.md index 8a6d4e578..8d826916e 100644 --- a/content/influxdb/cloud/reference/syntax/delete-predicate.md +++ b/content/influxdb/cloud/reference/syntax/delete-predicate.md @@ -13,6 +13,8 @@ influxdb/cloud/tags: [syntax, delete] related: - /influxdb/cloud/write-data/delete-data/ - /influxdb/cloud/reference/cli/influx/delete/ +source: /shared/influxdb-v2/reference/syntax/delete-predicate.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/syntax/flux/_index.md b/content/influxdb/cloud/reference/syntax/flux/_index.md index de0aadfa8..ea4ef050e 100644 --- a/content/influxdb/cloud/reference/syntax/flux/_index.md +++ b/content/influxdb/cloud/reference/syntax/flux/_index.md @@ -10,6 +10,8 @@ menu: identifier: flux-syntax weight: 101 influxdb/cloud/tags: [syntax, flux] +source: /shared/influxdb-v2/reference/syntax/flux/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/syntax/flux/flux-vs-influxql.md b/content/influxdb/cloud/reference/syntax/flux/flux-vs-influxql.md index 7c4126419..6929610fe 100644 --- a/content/influxdb/cloud/reference/syntax/flux/flux-vs-influxql.md +++ b/content/influxdb/cloud/reference/syntax/flux/flux-vs-influxql.md @@ -10,6 +10,8 @@ menu: name: Flux vs InfluxQL parent: flux-syntax weight: 105 +source: /shared/influxdb-v2/reference/syntax/flux/flux-vs-influxql.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/reference/syntax/influxql/_index.md b/content/influxdb/cloud/reference/syntax/influxql/_index.md index ec6a21020..97f6bdd4d 100644 --- a/content/influxdb/cloud/reference/syntax/influxql/_index.md +++ b/content/influxdb/cloud/reference/syntax/influxql/_index.md @@ -8,6 +8,8 @@ menu: name: InfluxQL identifier: influxql-syntax weight: 101 +source: /shared/influxdb-v2/reference/syntax/influxql/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/syntax/influxql/internals.md b/content/influxdb/cloud/reference/syntax/influxql/internals.md index 9877ae7ed..6da8a790b 100644 --- a/content/influxdb/cloud/reference/syntax/influxql/internals.md +++ b/content/influxdb/cloud/reference/syntax/influxql/internals.md @@ -6,6 +6,8 @@ menu: name: InfluxQL internals parent: influxql-syntax weight: 106 +source: /shared/influxdb-v2/reference/syntax/influxql/internals.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/syntax/influxql/spec.md b/content/influxdb/cloud/reference/syntax/influxql/spec.md index bf9131ecc..b42382ff6 100644 --- a/content/influxdb/cloud/reference/syntax/influxql/spec.md +++ b/content/influxdb/cloud/reference/syntax/influxql/spec.md @@ -8,6 +8,8 @@ menu: aliases: - /influxdb/cloud/query_languages/spec/ weight: 103 +source: /shared/influxdb-v2/reference/syntax/influxql/spec.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/reference/syntax/line-protocol.md b/content/influxdb/cloud/reference/syntax/line-protocol.md index 3b19a9e67..d360736c5 100644 --- a/content/influxdb/cloud/reference/syntax/line-protocol.md +++ b/content/influxdb/cloud/reference/syntax/line-protocol.md @@ -10,6 +10,8 @@ weight: 102 influxdb/cloud/tags: [write, line protocol, syntax] related: - /influxdb/cloud/write-data/ +source: /shared/influxdb-v2/reference/syntax/line-protocol.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/sign-up.md b/content/influxdb/cloud/sign-up.md index cf556736e..7d48939dc 100644 --- a/content/influxdb/cloud/sign-up.md +++ b/content/influxdb/cloud/sign-up.md @@ -136,8 +136,8 @@ To see all available `influx` commands, type `influx -h` or check out [influx - Click one of the following buttons to download and install the `influx` CLI appropriate for your chipset. -influx CLI (amd64) -influx CLI (arm) +influx CLI (amd64) +influx CLI (arm) #### Step 2: Unpackage the influx binary @@ -145,7 +145,7 @@ Click one of the following buttons to download and install the `influx` CLI appr ```sh # Unpackage contents to the current working directory -tar xvfz influxdb2-client-{{< latest-cli >}}-linux-amd64.tar.gz +tar xvfz influxdb2-client-{{< latest-patch cli=true >}}-linux-amd64.tar.gz ``` #### Step 3: (Optional) Place the binary in your $PATH @@ -157,7 +157,7 @@ prefix the executable with `./` to run in place. If the binary is on your $PATH, ```sh # Copy the influx and influxd binary to your $PATH -sudo cp influxdb2-client-{{< latest-cli >}}-linux-amd64/influx /usr/local/bin/ +sudo cp influxdb2-client-{{< latest-patch cli=true >}}-linux-amd64/influx /usr/local/bin/ ``` {{% note %}} diff --git a/content/influxdb/cloud/tools/_index.md b/content/influxdb/cloud/tools/_index.md index ee4fee42f..764c4995b 100644 --- a/content/influxdb/cloud/tools/_index.md +++ b/content/influxdb/cloud/tools/_index.md @@ -6,6 +6,15 @@ weight: 13 menu: influxdb_cloud: name: Tools & integrations +aliases: + - /influxdb/cloud/tools/flux-vscode/ +prepend: | + > [!Important] + > #### Flux VS Code extension no longer available + > + > The `vsflux` extension is no longer available in the Visual Studio Marketplace. + > `vsflux` and the `flux-lsp` Flux Language Server Protocol plugin are no longer maintained. + > Their repositories have been archived and are no longer receiving updates. --- {{< children >}} diff --git a/content/influxdb/cloud/tools/chronograf.md b/content/influxdb/cloud/tools/chronograf.md index 132b93dfe..4126297d7 100644 --- a/content/influxdb/cloud/tools/chronograf.md +++ b/content/influxdb/cloud/tools/chronograf.md @@ -12,6 +12,8 @@ menu: weight: 121 related: - /chronograf/v1/ +source: /shared/influxdb-v2/tools/chronograf.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/tools/flux-repl.md b/content/influxdb/cloud/tools/flux-repl.md index 73e91475d..60cc2b19a 100644 --- a/content/influxdb/cloud/tools/flux-repl.md +++ b/content/influxdb/cloud/tools/flux-repl.md @@ -11,6 +11,8 @@ menu: weight: 111 aliases: - /influxdb/cloud/tools/repl/ +source: /shared/influxdb-v2/tools/flux-repl.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/tools/flux-vim-lsp.md b/content/influxdb/cloud/tools/flux-vim-lsp.md index c777acecf..8c5048274 100644 --- a/content/influxdb/cloud/tools/flux-vim-lsp.md +++ b/content/influxdb/cloud/tools/flux-vim-lsp.md @@ -8,6 +8,8 @@ menu: name: Flux LSP with Vim parent: Tools & integrations weight: 119 +source: /shared/influxdb-v2/tools/flux-vim-lsp.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/tools/flux-vscode.md b/content/influxdb/cloud/tools/flux-vscode.md index a815117fe..4e524025d 100644 --- a/content/influxdb/cloud/tools/flux-vscode.md +++ b/content/influxdb/cloud/tools/flux-vscode.md @@ -10,6 +10,9 @@ menu: influxdb_cloud: name: Flux VS Code extension parent: Tools & integrations +source: /shared/influxdb-v2/tools/flux-vscode.md +draft: true --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/tools/grafana.md b/content/influxdb/cloud/tools/grafana.md index a61cf37d7..898db072b 100644 --- a/content/influxdb/cloud/tools/grafana.md +++ b/content/influxdb/cloud/tools/grafana.md @@ -16,6 +16,8 @@ alt_links: cloud-serverless: /influxdb3/cloud-serverless/visualize-data/grafana/ cloud-dedicated: /influxdb3/cloud-dedicated/process-data/visualize/grafana/ clustered: /influxdb3/clustered/process-data/visualize/grafana/ +source: /shared/influxdb-v2/tools/grafana.md --- -{{< duplicate-oss >}} \ No newline at end of file + diff --git a/content/influxdb/cloud/tools/influx-cli.md b/content/influxdb/cloud/tools/influx-cli.md index e8f18f3dd..ef48f27fd 100644 --- a/content/influxdb/cloud/tools/influx-cli.md +++ b/content/influxdb/cloud/tools/influx-cli.md @@ -13,6 +13,8 @@ aliases: - /influxdb/cloud/tools/clis/ related: - /influxdb/cloud/reference/cli/influx/ +source: /shared/influxdb-v2/tools/influx-cli.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/tools/influxdb-templates/use.md b/content/influxdb/cloud/tools/influxdb-templates/use.md index 4b7220ca7..48646d52f 100644 --- a/content/influxdb/cloud/tools/influxdb-templates/use.md +++ b/content/influxdb/cloud/tools/influxdb-templates/use.md @@ -16,6 +16,8 @@ related: - /influxdb/cloud/reference/cli/influx/template/ - /influxdb/cloud/reference/cli/influx/template/validate/ - /influxdb/cloud/api/ +source: /shared/influxdb-v2/tools/influxdb-templates/use.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/tools/influxql-shell.md b/content/influxdb/cloud/tools/influxql-shell.md index bd07736b1..221d238c6 100644 --- a/content/influxdb/cloud/tools/influxql-shell.md +++ b/content/influxdb/cloud/tools/influxql-shell.md @@ -10,6 +10,8 @@ weight: 112 influxdb/cloud/tags: [InfluxQL] related: - /influxdb/cloud/reference/cli/influx/v1/shell/ +source: /shared/influxdb-v2/tools/influxql-shell.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/tools/kapacitor.md b/content/influxdb/cloud/tools/kapacitor.md index 567631898..5e291960f 100644 --- a/content/influxdb/cloud/tools/kapacitor.md +++ b/content/influxdb/cloud/tools/kapacitor.md @@ -11,6 +11,8 @@ menu: weight: 121 related: - /kapacitor/v1/ +source: /shared/influxdb-v2/tools/kapacitor.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/tools/notebooks/_index.md b/content/influxdb/cloud/tools/notebooks/_index.md index 5be4c03a3..c8dce6e5f 100644 --- a/content/influxdb/cloud/tools/notebooks/_index.md +++ b/content/influxdb/cloud/tools/notebooks/_index.md @@ -10,6 +10,8 @@ menu: weight: 102 aliases: - /influxdb/cloud/notebooks/ +source: /shared/influxdb-v2/tools/notebooks/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/tools/notebooks/clean-data.md b/content/influxdb/cloud/tools/notebooks/clean-data.md index c9e5a5216..c526c9352 100644 --- a/content/influxdb/cloud/tools/notebooks/clean-data.md +++ b/content/influxdb/cloud/tools/notebooks/clean-data.md @@ -11,6 +11,8 @@ menu: parent: Notebooks aliases: - /influxdb/cloud/notebooks/clean-data/ +source: /shared/influxdb-v2/tools/notebooks/clean-data.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/tools/notebooks/create-notebook.md b/content/influxdb/cloud/tools/notebooks/create-notebook.md index 25dd70432..1ea8973b0 100644 --- a/content/influxdb/cloud/tools/notebooks/create-notebook.md +++ b/content/influxdb/cloud/tools/notebooks/create-notebook.md @@ -10,5 +10,8 @@ menu: parent: Notebooks aliases: - /influxdb/cloud/notebooks/create-notebook/ +source: /shared/influxdb-v2/tools/notebooks/create-notebook.md --- -{{< duplicate-oss >}} + + diff --git a/content/influxdb/cloud/tools/notebooks/downsample.md b/content/influxdb/cloud/tools/notebooks/downsample.md index bf389d067..ff0acb45e 100644 --- a/content/influxdb/cloud/tools/notebooks/downsample.md +++ b/content/influxdb/cloud/tools/notebooks/downsample.md @@ -13,6 +13,8 @@ menu: parent: Notebooks aliases: - /influxdb/cloud/notebooks/downsample/ +source: /shared/influxdb-v2/tools/notebooks/downsample.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/tools/notebooks/manage-notebooks.md b/content/influxdb/cloud/tools/notebooks/manage-notebooks.md index 5b174f855..343faa6c6 100644 --- a/content/influxdb/cloud/tools/notebooks/manage-notebooks.md +++ b/content/influxdb/cloud/tools/notebooks/manage-notebooks.md @@ -9,6 +9,8 @@ menu: parent: Notebooks aliases: - /influxdb/cloud/notebooks/manage-notebooks/ +source: /shared/influxdb-v2/tools/notebooks/manage-notebooks.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/tools/notebooks/overview.md b/content/influxdb/cloud/tools/notebooks/overview.md index 86dad0f66..bc4e70c25 100644 --- a/content/influxdb/cloud/tools/notebooks/overview.md +++ b/content/influxdb/cloud/tools/notebooks/overview.md @@ -10,6 +10,8 @@ menu: parent: Notebooks aliases: - /influxdb/cloud/notebooks/overview/ +source: /shared/influxdb-v2/tools/notebooks/overview.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/tools/notebooks/troubleshoot-notebooks.md b/content/influxdb/cloud/tools/notebooks/troubleshoot-notebooks.md index 680ee9090..07b83d691 100644 --- a/content/influxdb/cloud/tools/notebooks/troubleshoot-notebooks.md +++ b/content/influxdb/cloud/tools/notebooks/troubleshoot-notebooks.md @@ -9,6 +9,8 @@ menu: parent: Notebooks aliases: - /influxdb/cloud/notebooks/troubleshoot-notebooks/ +source: /shared/influxdb-v2/tools/notebooks/troubleshoot-notebooks.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/tools/postman.md b/content/influxdb/cloud/tools/postman.md index ba9951e9b..8559eb0c2 100644 --- a/content/influxdb/cloud/tools/postman.md +++ b/content/influxdb/cloud/tools/postman.md @@ -12,6 +12,8 @@ influxdb/cloud/tags: [api, authentication] aliases: - /influxdb/cloud/reference/api/postman/ - /influxdb/cloud/api-guide/postman/ +source: /shared/influxdb-v2/tools/postman.md --- -{{% duplicate-oss %}} + diff --git a/content/influxdb/cloud/tools/telegraf-configs/_index.md b/content/influxdb/cloud/tools/telegraf-configs/_index.md index ac2edcc4c..99ad799b0 100644 --- a/content/influxdb/cloud/tools/telegraf-configs/_index.md +++ b/content/influxdb/cloud/tools/telegraf-configs/_index.md @@ -15,6 +15,8 @@ aliases: - /influxdb/cloud/telegraf-configs/ # alt_links: # cloud-serverless: /influxdb3/cloud-serverless/write-data/use-telegraf/telegraf-configs/ +source: /shared/influxdb-v2/tools/telegraf-configs/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/tools/telegraf-configs/clone.md b/content/influxdb/cloud/tools/telegraf-configs/clone.md index c70e6af26..12b880a3d 100644 --- a/content/influxdb/cloud/tools/telegraf-configs/clone.md +++ b/content/influxdb/cloud/tools/telegraf-configs/clone.md @@ -9,6 +9,8 @@ menu: parent: Telegraf configurations aliases: - /influxdb/cloud/telegraf-configs/clone/ +source: /shared/influxdb-v2/tools/telegraf-configs/clone.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/tools/telegraf-configs/create.md b/content/influxdb/cloud/tools/telegraf-configs/create.md index 26040e2c3..6fdf12fd9 100644 --- a/content/influxdb/cloud/tools/telegraf-configs/create.md +++ b/content/influxdb/cloud/tools/telegraf-configs/create.md @@ -16,6 +16,8 @@ aliases: - /influxdb/cloud/telegraf-configs/create/ # alt_links: # cloud-serverless: /influxdb3/cloud-serverless/write-data/use-telegraf/telegraf-configs/create/ +source: /shared/influxdb-v2/tools/telegraf-configs/create.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/tools/telegraf-configs/remove.md b/content/influxdb/cloud/tools/telegraf-configs/remove.md index 5ec449714..130185033 100644 --- a/content/influxdb/cloud/tools/telegraf-configs/remove.md +++ b/content/influxdb/cloud/tools/telegraf-configs/remove.md @@ -14,6 +14,8 @@ aliases: - /influxdb/cloud/telegraf-configs/remove/ # alt_links: # cloud-serverless: /influxdb3/cloud-serverless/write-data/use-telegraf/telegraf-configs/remove/ +source: /shared/influxdb-v2/tools/telegraf-configs/remove.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/tools/telegraf-configs/update.md b/content/influxdb/cloud/tools/telegraf-configs/update.md index 917a47b26..4c5d0d84a 100644 --- a/content/influxdb/cloud/tools/telegraf-configs/update.md +++ b/content/influxdb/cloud/tools/telegraf-configs/update.md @@ -12,6 +12,8 @@ aliases: - /influxdb/cloud/telegraf-configs/update/ # alt_links: # cloud-serverless: /influxdb3/cloud-serverless/write-data/use-telegraf/telegraf-configs/update/ +source: /shared/influxdb-v2/tools/telegraf-configs/update.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/tools/telegraf-configs/view.md b/content/influxdb/cloud/tools/telegraf-configs/view.md index cbba96dbe..4d1021af7 100644 --- a/content/influxdb/cloud/tools/telegraf-configs/view.md +++ b/content/influxdb/cloud/tools/telegraf-configs/view.md @@ -12,6 +12,8 @@ aliases: - /influxdb/cloud/telegraf-configs/view/ # alt_links: # cloud-serverless: /influxdb3/cloud-serverless/write-data/use-telegraf/telegraf-configs/view/ +source: /shared/influxdb-v2/tools/telegraf-configs/view.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/visualize-data/visualization-types/band.md b/content/influxdb/cloud/visualize-data/visualization-types/band.md index 18aa146b3..bc00fa1f1 100644 --- a/content/influxdb/cloud/visualize-data/visualization-types/band.md +++ b/content/influxdb/cloud/visualize-data/visualization-types/band.md @@ -8,6 +8,8 @@ menu: influxdb_cloud: name: Band parent: Visualization types +source: /shared/influxdb-v2/visualize-data/visualization-types/band.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/visualize-data/visualization-types/gauge.md b/content/influxdb/cloud/visualize-data/visualization-types/gauge.md index 06bd8c1fa..4bd621e6f 100644 --- a/content/influxdb/cloud/visualize-data/visualization-types/gauge.md +++ b/content/influxdb/cloud/visualize-data/visualization-types/gauge.md @@ -9,6 +9,8 @@ menu: influxdb_cloud: name: Gauge parent: Visualization types +source: /shared/influxdb-v2/visualize-data/visualization-types/gauge.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/visualize-data/visualization-types/graph-single-stat.md b/content/influxdb/cloud/visualize-data/visualization-types/graph-single-stat.md index b651e3ff6..95ff315b8 100644 --- a/content/influxdb/cloud/visualize-data/visualization-types/graph-single-stat.md +++ b/content/influxdb/cloud/visualize-data/visualization-types/graph-single-stat.md @@ -13,6 +13,8 @@ menu: related: - /influxdb/v2/visualize-data/visualization-types/graph - /influxdb/v2/visualize-data/visualization-types/single-stat +source: /shared/influxdb-v2/visualize-data/visualization-types/graph-single-stat.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/visualize-data/visualization-types/graph.md b/content/influxdb/cloud/visualize-data/visualization-types/graph.md index 79884d3b0..f954c3254 100644 --- a/content/influxdb/cloud/visualize-data/visualization-types/graph.md +++ b/content/influxdb/cloud/visualize-data/visualization-types/graph.md @@ -9,6 +9,8 @@ menu: influxdb_cloud: name: Graph parent: Visualization types +source: /shared/influxdb-v2/visualize-data/visualization-types/graph.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/visualize-data/visualization-types/heatmap.md b/content/influxdb/cloud/visualize-data/visualization-types/heatmap.md index a42c28a62..b77357916 100644 --- a/content/influxdb/cloud/visualize-data/visualization-types/heatmap.md +++ b/content/influxdb/cloud/visualize-data/visualization-types/heatmap.md @@ -12,6 +12,8 @@ menu: parent: Visualization types related: - /influxdb/cloud/visualize-data/visualization-types/scatter +source: /shared/influxdb-v2/visualize-data/visualization-types/heatmap.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/visualize-data/visualization-types/histogram.md b/content/influxdb/cloud/visualize-data/visualization-types/histogram.md index 91e6c701a..0738d3447 100644 --- a/content/influxdb/cloud/visualize-data/visualization-types/histogram.md +++ b/content/influxdb/cloud/visualize-data/visualization-types/histogram.md @@ -10,6 +10,8 @@ menu: influxdb_cloud: name: Histogram parent: Visualization types +source: /shared/influxdb-v2/visualize-data/visualization-types/histogram.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/visualize-data/visualization-types/mosaic.md b/content/influxdb/cloud/visualize-data/visualization-types/mosaic.md index 08c5c5e7a..a6293f137 100644 --- a/content/influxdb/cloud/visualize-data/visualization-types/mosaic.md +++ b/content/influxdb/cloud/visualize-data/visualization-types/mosaic.md @@ -10,6 +10,8 @@ menu: influxdb_cloud: name: Mosaic parent: Visualization types +source: /shared/influxdb-v2/visualize-data/visualization-types/mosaic.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/visualize-data/visualization-types/scatter.md b/content/influxdb/cloud/visualize-data/visualization-types/scatter.md index c128b4828..19429dd1d 100644 --- a/content/influxdb/cloud/visualize-data/visualization-types/scatter.md +++ b/content/influxdb/cloud/visualize-data/visualization-types/scatter.md @@ -11,6 +11,8 @@ menu: parent: Visualization types related: - /influxdb/cloud/visualize-data/visualization-types/heatmap +source: /shared/influxdb-v2/visualize-data/visualization-types/scatter.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/visualize-data/visualization-types/single-stat.md b/content/influxdb/cloud/visualize-data/visualization-types/single-stat.md index a42613029..5094615ef 100644 --- a/content/influxdb/cloud/visualize-data/visualization-types/single-stat.md +++ b/content/influxdb/cloud/visualize-data/visualization-types/single-stat.md @@ -9,6 +9,8 @@ menu: influxdb_cloud: name: Single Stat parent: Visualization types +source: /shared/influxdb-v2/visualize-data/visualization-types/single-stat.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/visualize-data/visualization-types/table.md b/content/influxdb/cloud/visualize-data/visualization-types/table.md index cf963629d..eb9f7eda8 100644 --- a/content/influxdb/cloud/visualize-data/visualization-types/table.md +++ b/content/influxdb/cloud/visualize-data/visualization-types/table.md @@ -10,6 +10,8 @@ menu: influxdb_cloud: name: Table parent: Visualization types +source: /shared/influxdb-v2/visualize-data/visualization-types/table.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/write-data/best-practices/resolve-high-cardinality.md b/content/influxdb/cloud/write-data/best-practices/resolve-high-cardinality.md index 927101c8c..80e1949b1 100644 --- a/content/influxdb/cloud/write-data/best-practices/resolve-high-cardinality.md +++ b/content/influxdb/cloud/write-data/best-practices/resolve-high-cardinality.md @@ -7,6 +7,8 @@ menu: name: Resolve high cardinality weight: 202 parent: write-best-practices +source: /shared/influxdb-v2/write-data/best-practices/resolve-high-cardinality.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/write-data/best-practices/schema-design.md b/content/influxdb/cloud/write-data/best-practices/schema-design.md index b7a71bebc..42c765c5a 100644 --- a/content/influxdb/cloud/write-data/best-practices/schema-design.md +++ b/content/influxdb/cloud/write-data/best-practices/schema-design.md @@ -9,6 +9,8 @@ menu: parent: write-best-practices related: - /resources/videos/data-model-building-blocks/ +source: /shared/influxdb-v2/write-data/best-practices/schema-design.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/write-data/delete-data.md b/content/influxdb/cloud/write-data/delete-data.md index da3e998e3..eeab557e9 100644 --- a/content/influxdb/cloud/write-data/delete-data.md +++ b/content/influxdb/cloud/write-data/delete-data.md @@ -13,6 +13,8 @@ influxdb/cloud/tags: [delete] related: - /influxdb/v2/reference/syntax/delete-predicate/ - /influxdb/v2/reference/cli/influx/delete/ +source: /shared/influxdb-v2/write-data/delete-data.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/write-data/developer-tools/csv.md b/content/influxdb/cloud/write-data/developer-tools/csv.md index f1335b062..3559ec769 100644 --- a/content/influxdb/cloud/write-data/developer-tools/csv.md +++ b/content/influxdb/cloud/write-data/developer-tools/csv.md @@ -17,6 +17,8 @@ alt_links: cloud-serverless: /influxdb3/cloud-serverless/write-data/csv/ cloud-dedicated: /influxdb3/cloud-dedicated/write-data/csv/ clustered: /influxdb3/clustered/write-data/csv/ +source: /shared/influxdb-v2/write-data/developer-tools/csv.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/write-data/developer-tools/scrape-prometheus-metrics.md b/content/influxdb/cloud/write-data/developer-tools/scrape-prometheus-metrics.md index 95f6b7a27..5ef7c1203 100644 --- a/content/influxdb/cloud/write-data/developer-tools/scrape-prometheus-metrics.md +++ b/content/influxdb/cloud/write-data/developer-tools/scrape-prometheus-metrics.md @@ -15,6 +15,8 @@ related: - /flux/v0/stdlib/experimental/prometheus/scrape/ - /flux/v0/prometheus/metric-types/ influxdb/cloud/tags: [prometheus] +source: /shared/influxdb-v2/write-data/developer-tools/scrape-prometheus-metrics.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/write-data/migrate-data/migrate-cloud-to-oss.md b/content/influxdb/cloud/write-data/migrate-data/migrate-cloud-to-oss.md index 5a0e20b0b..d9a6e7495 100644 --- a/content/influxdb/cloud/write-data/migrate-data/migrate-cloud-to-oss.md +++ b/content/influxdb/cloud/write-data/migrate-data/migrate-cloud-to-oss.md @@ -10,6 +10,8 @@ menu: aliases: - /influxdb/cloud/migrate-data/migrate-cloud-to-oss/ weight: 103 +source: /shared/influxdb-v2/write-data/migrate-data/migrate-cloud-to-oss.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/write-data/migrate-data/migrate-oss.md b/content/influxdb/cloud/write-data/migrate-data/migrate-oss.md index d49e04045..5d07a6276 100644 --- a/content/influxdb/cloud/write-data/migrate-data/migrate-oss.md +++ b/content/influxdb/cloud/write-data/migrate-data/migrate-oss.md @@ -10,6 +10,8 @@ menu: aliases: - /influxdb/cloud/migrate-data/migrate-oss/ weight: 101 +source: /shared/influxdb-v2/write-data/migrate-data/migrate-oss.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/write-data/no-code/load-data.md b/content/influxdb/cloud/write-data/no-code/load-data.md index 1ba0849e1..b074cd63f 100644 --- a/content/influxdb/cloud/write-data/no-code/load-data.md +++ b/content/influxdb/cloud/write-data/no-code/load-data.md @@ -11,6 +11,8 @@ menu: influxdb_cloud: name: Load data source in UI parent: Write data +source: /shared/influxdb-v2/write-data/no-code/load-data.md --- -{{< duplicate-oss >}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/cloud/write-data/no-code/use-telegraf/dual-write.md b/content/influxdb/cloud/write-data/no-code/use-telegraf/dual-write.md index f51a2a533..3597ac804 100644 --- a/content/influxdb/cloud/write-data/no-code/use-telegraf/dual-write.md +++ b/content/influxdb/cloud/write-data/no-code/use-telegraf/dual-write.md @@ -9,6 +9,8 @@ alt_links: cloud-serverless: /influxdb3/cloud-serverless/write-data/use-telegraf/dual-write/ cloud-dedicated: /influxdb3/cloud-dedicated/write-data/use-telegraf/dual-write/ clustered: /influxdb3/clustered/write-data/use-telegraf/dual-write/ +source: /shared/influxdb-v2/write-data/no-code/use-telegraf/dual-write.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/write-data/oss-to-cloud.md b/content/influxdb/cloud/write-data/oss-to-cloud.md index bf70bc504..851a63e41 100644 --- a/content/influxdb/cloud/write-data/oss-to-cloud.md +++ b/content/influxdb/cloud/write-data/oss-to-cloud.md @@ -9,6 +9,8 @@ menu: parent: Write data weight: 105 influxdb/cloud/tags: [write] +source: /shared/influxdb-v2/write-data/oss-to-cloud.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/write-data/replication/_index.md b/content/influxdb/cloud/write-data/replication/_index.md index 02aabd4ed..8b59865e7 100644 --- a/content/influxdb/cloud/write-data/replication/_index.md +++ b/content/influxdb/cloud/write-data/replication/_index.md @@ -8,6 +8,8 @@ menu: influxdb_cloud: name: Edge data replication parent: Write data +source: /shared/influxdb-v2/write-data/replication/_index.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/write-data/replication/replicate-data.md b/content/influxdb/cloud/write-data/replication/replicate-data.md index 9e8a2d272..5389bd4d4 100644 --- a/content/influxdb/cloud/write-data/replication/replicate-data.md +++ b/content/influxdb/cloud/write-data/replication/replicate-data.md @@ -12,6 +12,8 @@ influxdb/cloud/tags: [write, replication] related: - /influxdb/cloud/reference/cli/influx/remote - /influxdb/cloud/reference/cli/influx/replication +source: /shared/influxdb-v2/write-data/replication/replicate-data.md --- -{{< duplicate-oss >}} + diff --git a/content/influxdb/cloud/write-data/troubleshoot.md b/content/influxdb/cloud/write-data/troubleshoot.md index bfc30ea70..aaa93a1fc 100644 --- a/content/influxdb/cloud/write-data/troubleshoot.md +++ b/content/influxdb/cloud/write-data/troubleshoot.md @@ -15,6 +15,8 @@ related: - /influxdb/cloud/reference/internals - /influxdb/cloud/reference/cli/influx/write - influxdb/cloud/account-management/limits +source: /shared/influxdb-v2/write-data/troubleshoot.md --- -{{% duplicate-oss %}} \ No newline at end of file + \ No newline at end of file diff --git a/content/influxdb/v1/tools/_index.md b/content/influxdb/v1/tools/_index.md index f558effae..ea1d17495 100644 --- a/content/influxdb/v1/tools/_index.md +++ b/content/influxdb/v1/tools/_index.md @@ -4,12 +4,20 @@ description: Tools and utilities for interacting with InfluxDB. aliases: - /influxdb/v1/clients/ - /influxdb/v1/write_protocols/json/ + - /influxdb/v1/tools/flux-vscode/ menu: influxdb_v1: name: Tools weight: 60 alt_links: v2: /influxdb/v2/tools/ +prepend: | + > [!Important] + > #### Flux VS Code extension no longer available + > + > The `vsflux` extension is no longer available in the Visual Studio Marketplace. + > `vsflux` and the `flux-lsp` Flux Language Server Protocol plugin are no longer maintained. + > Their repositories have been archived and are no longer receiving updates. --- This section covers the available tools for interacting with InfluxDB. @@ -35,6 +43,7 @@ The list of [client libraries](/influxdb/v1/tools/api_client_libraries/) for int Use the [InfluxDB `inch` tool](/influxdb/v1/tools/inch/) to test InfluxDB performance. Adjust metrics such as the batch size, tag values, and concurrent write streams to test how ingesting different tag cardinalities and metrics affects performance. + ## Graphs and dashboards Use [Chronograf](/chronograf/v1/) or [Grafana](https://grafana.com/docs/grafana/latest/features/datasources/influxdb/) dashboards to visualize your time series data. @@ -60,3 +69,12 @@ SHOW TAG VALUES FROM "your.system"."host_info" WITH KEY = “host” ``` > **Note:** In Chronograf, you can also filter meta query results for a specified time range by [creating a `custom meta query` template variable](/chronograf/v1/guides/dashboard-template-variables/#create-custom-template-variables) and adding a time range filter. + +## Flux tools + +> [!NOTE] +> #### vsflux and Flux-LSP no longer maintained +> +> The `vsflux` Flux VS Code extension and the `flux-lsp` language server plugin for Vim are no longer maintained. +> Their repositories have been archived and are no longer receiving updates. +> `vsflux` is no longer available in the Visual Studio Marketplace. diff --git a/content/influxdb/v1/tools/flux-vscode.md b/content/influxdb/v1/tools/flux-vscode.md index 1718aa815..92067aa01 100644 --- a/content/influxdb/v1/tools/flux-vscode.md +++ b/content/influxdb/v1/tools/flux-vscode.md @@ -12,6 +12,14 @@ menu: parent: Tools alt_links: v2: /influxdb/v2/tools/flux-vscode/ +draft: true +prepend: | + > [!Important] + > #### Flux VS Code extension no longer available + > + > The `vsflux` extension is no longer available in the Visual Studio Marketplace. + > `vsflux` and the `flux-lsp` Flux Language Server Protocol plugin are no longer maintained. + > Their repositories have been archived and are no longer receiving updates. --- The [Flux Visual Studio Code (VS Code) extension](https://marketplace.visualstudio.com/items?itemName=influxdata.flux) diff --git a/content/influxdb/v2/admin/buckets/delete-bucket.md b/content/influxdb/v2/admin/buckets/delete-bucket.md index 1869e0b90..7a595a8db 100644 --- a/content/influxdb/v2/admin/buckets/delete-bucket.md +++ b/content/influxdb/v2/admin/buckets/delete-bucket.md @@ -9,66 +9,8 @@ menu: weight: 203 aliases: - /influxdb/v2/organizations/buckets/delete-bucket/ +source: /shared/influxdb-v2/admin/buckets/delete-bucket.md --- -Use the InfluxDB user interface (UI) or the `influx` command line interface (CLI) -to delete a bucket. - -## Delete a bucket in the InfluxDB UI - -{{% oss-only %}} - -1. In the navigation menu on the left, select **Data (Load Data)** > **Buckets**. - -{{< nav-icon "data" >}} - -2. Hover over the bucket you would like to delete. -3. Click the **{{< icon "delete" >}}** icon located far right of the bucket name. -4. Click **Delete** to delete the bucket. -{{% /oss-only %}} - -{{% cloud-only %}} - -1. In the navigation menu on the left, select **Load Data** > **Buckets**. - -{{< nav-icon "data" >}} - -2. Find the bucket that you would like to delete. -3. Click the **{{< icon "delete" >}}** icon located far right of the bucket name. -4. Click **{{< caps >}}Confirm{{< /caps >}}** to delete the bucket. - -{{% /cloud-only %}} - -## Delete a bucket using the influx CLI - -Use the [`influx bucket delete` command](/influxdb/v2/reference/cli/influx/bucket/delete) -to delete a bucket a bucket by name or ID. - -### Delete a bucket by name -**To delete a bucket by name, you need:** - -- Bucket name -- Bucket's organization name or ID - - -```sh -# Syntax -influx bucket delete -n -o - -# Example -influx bucket delete -n my-bucket -o my-org -``` - -### Delete a bucket by ID -**To delete a bucket by ID, you need:** - -- Bucket ID _(provided in the output of `influx bucket list`)_ - - -```sh -# Syntax -influx bucket delete -i - -# Example -influx bucket delete -i 034ad714fdd6f000 -``` + diff --git a/content/influxdb/v2/admin/tokens/create-token.md b/content/influxdb/v2/admin/tokens/create-token.md index 4d32004a9..25927974e 100644 --- a/content/influxdb/v2/admin/tokens/create-token.md +++ b/content/influxdb/v2/admin/tokens/create-token.md @@ -10,204 +10,8 @@ weight: 201 aliases: - /influxdb/v2/users/tokens/create-token/ - /influxdb/v2/security/tokens/create-token/ +source: /shared/influxdb-v2/admin/tokens/create-token.md --- -Create API tokens using the InfluxDB user interface (UI), the `influx` -command line interface (CLI), or the InfluxDB API. - -{{% note %}} - -To follow best practices for secure API token generation and retrieval, InfluxDB enforces access restrictions on API tokens. - -- Tokens are visible to the user who created the token. -- InfluxDB only allows access to the API token value immediately after the token is created. -- You can't change access (**read/write**) permissions for an API token after it's created. -- Tokens stop working when the user who created the token is deleted. - -**We recommend the following for managing your tokens:** - -- Create a generic user to create and manage tokens for writing data. -- Store your tokens in a secure password vault for future access. - -{{% /note %}} - -- [Manage tokens in the InfluxDB UI](#manage-tokens-in-the-influxdb-ui) -- [Create a token in the InfluxDB UI](#create-a-token-in-the-influxdb-ui) -- [Create a token using the influx CLI](#create-a-token-using-the-influx-cli) -- [Create a token using the InfluxDB API](#create-a-token-using-the-influxdb-api) - -## Manage tokens in the InfluxDB UI - -To manage InfluxDB API Tokens in the InfluxDB UI, navigate to the **API Tokens** management page. - -{{% oss-only %}} - -In the navigation menu on the left, select **Data (Load Data)** > **API Tokens**. - -{{% /oss-only %}} - -{{% cloud-only %}} - -In the navigation menu on the left, select **Load Data** > **API Tokens**. - -{{% /cloud-only %}} - -{{< nav-icon "load-data" >}} - -## Create a token in the InfluxDB UI - -{{% oss-only %}} - -1. From the [API Tokens management page](#manage-tokens-in-the-influxdb-ui), -click **{{< icon "plus" >}} Generate** and select a token type - (**Read/Write Token** or **All Access API Token**). -2. In the window that appears, enter a description for your token in the **Description** field. -3. If generating a **read/write token**: - - Search for and select buckets to read from in the **Read** pane. - - Search for and select buckets to write to in the **Write** pane. -4. Click **Save**. - -{{% /oss-only %}} - - -{{% cloud-only %}} - -### Create an All Access token - -1. From the [API Tokens management page](#manage-tokens-in-the-influxdb-ui), -click the **{{< icon "plus" >}} {{< caps >}}Generate API Token{{< /caps >}}** button. -2. Select **All Access API Token**. - -### Create a custom token - -1. From the [API Tokens management page](#manage-tokens-in-the-influxdb-ui), -click the **{{< icon "plus" >}} {{< caps >}}Generate API Token{{< /caps >}}** button. -2. Select **Custom API Token**. -3. When the **Generate a Personal API Token** window appears, enter a description. If you don't provide a description for the token, InfluxDB will generate a description from the permissions you assign. - For example, if you select **Read** for a bucket named "\_monitoring" and **Write** for a bucket named "\_tasks", InfluxDB will generate the description "Read buckets \_monitoring Write buckets \_tasks". -4. Select the check boxes in the **Read** and **Write** columns to assign access permissions for the token. You can enable access to all buckets, individual buckets, Telegraf configurations, and other InfluxDB resources. By default, the new token has no access permissions. -5. When you're finished, click **{{< caps >}}Generate{{< /caps >}}**. -6. When InfluxDB displays the token value, click **{{< caps >}}Copy to Clipboard{{< /caps >}}**. This is your only chance to access and copy the token value from InfluxDB. -7. (Optional) Store the API token value in a secure password vault. - -### Clone a token - -To create a token with the same authorizations as an existing token, clone the existing token. - -1. From the [API Tokens management page](#manage-tokens-in-the-influxdb-ui), -find the token you want to clone and click the **{{< icon "settings" >}}** icon located far right of the token description. -3. Select **Clone**. -3. When InfluxDB UI displays the created token, click **{{< caps >}}Copy to Clipboard{{< /caps >}}**. This is your only chance to access and copy the token value from InfluxDB. -4. (Optional) Store the API token value in a secure password vault. - -{{% /cloud-only %}} - -## Create a token using the influx CLI - -Use the [`influx auth create` command](/influxdb/v2/reference/cli/influx/auth/create) to create a token. -Include flags with the command to grant specific permissions to the token. -See the [available flags](/influxdb/v2/reference/cli/influx/auth/create#flags). -Only tokens with the `write: authorizations` permission can create tokens. - -```sh -# Syntax -influx auth create -o [permission-flags] -``` - -### Examples -#### Create an All Access token - -Create an All Access token to grant permissions to all resources in an organization. - -```sh -influx auth create \ - --org my-org \ - --all-access -``` - -{{% oss-only %}} - -#### Create an operator token - -Create an operator token to grant permissions to all resources in all organizations. - -```sh -influx auth create \ - --org my-org \ - --operator -``` - -{{% note %}} -To [view or create an operator token](/influxdb/v2/admin/tokens/create-token/) with the InfluxDB UI, `api/v2` API, or `influx` CLI after the setup process is completed, you must use an existing operator token. - -To create a new operator token without using an existing one, see how to use the [`influxd recovery auth`](/influxdb/v2/reference/cli/influxd/recovery/auth/) CLI. -{{% /note %}} -{{% /oss-only %}} - -#### Create a token with specified permissions - -##### Create a token with specified read permissions - -```sh -influx auth create \ - --org my-org \ - --read-bucket 03a2bbf46309a000 \ - --read-bucket 3a87c03ace269000 \ - --read-dashboards \ - --read-tasks \ - --read-telegrafs \ - --read-user -``` - -##### Create a token scoped to a user and with specified read and write permissions - -```sh -influx auth create \ - --org ORG_NAME \ - --user USERNAME \ - --read-authorizations \ - --write-authorizations \ - --read-buckets \ - --write-buckets \ - --read-dashboards \ - --write-dashboards \ - --read-tasks \ - --write-tasks \ - --read-telegrafs \ - --write-telegrafs \ - --read-users \ - --write-users -``` - -See the [`influx auth create` documentation](/influxdb/v2/reference/cli/influx/auth/create) for information about other available flags. - -## Create a token using the InfluxDB API - -Use the `/api/v2/authorizations` InfluxDB API endpoint to create a token. - -{{< api-endpoint method="POST" endpoint="http://localhost:8086/api/v2/authorizations" api-ref="/influxdb/v2/api/#operation/PostAuthorizations" >}} - -Include the following in your request: - -| Requirement | Include by | -|:----------- |:---------- | -| API token with the [`write: authorizations`](/influxdb/v2/api/#operation/PostAuthorizations) permission | Use the `Authorization` header and the {{% oss-only %}}`Bearer` or {{% /oss-only %}}`Token` scheme. | -| Organization | Pass as `orgID` in the request body. -| Permissions list | Pass as a `permissions` array in the request body. - -```sh -{{% get-shared-text "api/v2.0/auth/oss/token-create.sh" %}} -``` - -### Create a token scoped to a user - -To scope a token to a user other than the token creator, pass the `userID` property in the request -body. - -```sh -{{% get-shared-text "api/v2.0/auth/oss/tokens-create-with-user.sh" %}} -``` - -See the -[`POST /api/v2/authorizations` documentation](/influxdb/v2/api/#operation/PostAuthorizations) -for more information about options. + diff --git a/content/influxdb/v2/admin/tokens/delete-token.md b/content/influxdb/v2/admin/tokens/delete-token.md index 869fd2035..f335f216b 100644 --- a/content/influxdb/v2/admin/tokens/delete-token.md +++ b/content/influxdb/v2/admin/tokens/delete-token.md @@ -10,79 +10,8 @@ weight: 204 aliases: - /influxdb/v2/users/tokens/delete-token - /influxdb/v2/security/tokens/delete-token/ +source: /shared/influxdb-v2/admin/tokens/delete-token.md --- -Delete API tokens from the InfluxDB user interface (UI) or the `influx` command line interface (CLI). -Once deleted, all users and external integrations using the API token will no longer -have access to your InfluxDB instance. - -- [Delete tokens in the InfluxDB UI](#delete-tokens-in-the-influxdb-ui) -- [Delete a token using the influx CLI](#delete-a-token-using-the-influx-cli) -- [Delete a token using the InfluxDB API](#delete-a-token-using-the-influxdb-api) - -## Delete tokens in the InfluxDB UI - -{{% oss-only %}} - -1. In the navigation menu on the left, select **Data (Load Data)** > **API Tokens**. - -{{< nav-icon "load-data" >}} - -2. Hover over the token you want to delete. -3. Click the **{{< icon "delete" >}}** icon located far right of the token description. -3. Click **Delete** to delete the token. - -{{% /oss-only %}} - -{{% cloud-only %}} - -1. In the navigation menu on the left, select **Load Data** > **API Tokens**. - -{{< nav-icon "data" >}} - -2. Find the token that you would like to delete. -3. Click the **{{< icon "delete" >}}** icon located far right of the token description. -4. Click **{{< caps >}}Confirm{{< /caps >}}** to delete the token. - -{{% /cloud-only %}} - -## Delete a token using the influx CLI - -Use the [`influx auth delete` command](/influxdb/v2/reference/cli/influx/auth/delete) -to delete a token. - -_This command requires an auth ID, which is available in the output of `influx auth find`._ - -```sh -# Syntax -influx auth delete -i - -# Example -influx auth delete -i 03a2bee5a9c9a000 -``` - -## Delete a token using the InfluxDB API - -Use the `/api/v2/authorizations` InfluxDB API endpoint to delete a token. - -{{< api-endpoint method="DELETE" endpoint="http://localhost:8086/api/v2/authorizations/AUTH_ID" api-ref="/influxdb/v2/api/#operation/DeleteAuthorizationsID" >}} - -Include the following in your request: - -| Requirement | Include by | -|:----------- |:---------- | -| API token with the [`write: authorizations`](/influxdb/v2/api/#operation/PostAuthorizations) permission | Use the `Authorization: Token YOUR_API_TOKEN` header. | -| Authorization ID | URL path parameter. | - -```sh -# Delete the first authorization listed for the user. -curl --request GET \ - "http://localhost:8086/api/v2/authorizations?user=user2" \ - --header "Authorization: Token ${INFLUX_OP_TOKEN}" \ - --header 'Content-type: application/json' \ -| jq .authorizations[0].id \ -| xargs -I authid curl --request DELETE \ - http://localhost:8086/api/v2/authorizations/authid \ - --header "Authorization: Token ${INFLUX_OP_TOKEN}" \ - --header 'Content-type: application/json' -``` + diff --git a/content/influxdb/v2/admin/tokens/update-tokens.md b/content/influxdb/v2/admin/tokens/update-tokens.md index 24d18e36f..99991b0a2 100644 --- a/content/influxdb/v2/admin/tokens/update-tokens.md +++ b/content/influxdb/v2/admin/tokens/update-tokens.md @@ -10,121 +10,8 @@ weight: 203 aliases: - /influxdb/v2/users/tokens/update-tokens - /influxdb/v2/security/tokens/update-tokens/ +source: /shared/influxdb-v2/admin/tokens/update-tokens.md --- -Update an API token's description and status. -using the InfluxDB user interface (UI). - -- [Update a token in the InfluxDB UI](#update-a-token-in-the-influxdb-ui) -- [Enable or disable a token in the InfluxDB UI](#enable-or-disable-a-token-in-the-influxdb-ui) -- [Enable a token using the influx CLI](#enable-a-token-using-the-influx-cli) -- [Disable a token using the influx CLI](#disable-a-token-using-the-influx-cli) -- [Update a token using the InfluxDB API](#update-a-token-using-the-influxdb-api) - -## Update a token in the InfluxDB UI - -1. In the navigation menu on the left, select **Data (Load Data)** > **API Tokens**. - -{{< nav-icon "load-data" >}} - -2. Click the pencil icon {{< icon "pencil" >}} next to the token's name in the **Description** column. -3. Update the token description, then click anywhere else to save. - -## Enable or disable a token in the InfluxDB UI - -{{% oss-only %}} - -1. In the navigation menu on the left, select **Data (Load Data)** > **API Tokens**. - -{{< nav-icon "load-data" >}} - -2. Click the **{{< icon "toggle" >}} Status** toggle. - -{{% /oss-only %}} - -{{% cloud-only %}} - -1. In the navigation menu on the left, select **Load Data** > **API Tokens**. - - {{< nav-icon "data" >}} - -2. Find the token that you would like to enable or disable. -3. Click the token description. -4. Click the **{{< icon "toggle-blue" >}} Status** toggle. - -{{% /cloud-only %}} - -## Enable a token using the influx CLI - -Use the [`influx auth active` command](/influxdb/v2/reference/cli/influx/auth/active) -to activate a token. - -_This command requires an authorization ID, which is available in the output of `influx auth find`._ - -```sh -# Syntax -influx auth active -i - -# Example -influx auth active -i 0804f74142bbf000 -``` -To get the current status of a token, use the JSON output of the [`influx auth list` command](/influxdb/v2/reference/cli/influx/auth/list). - -```sh -influx auth find --json -``` - -### Disable a token using the influx CLI - -Use the [`influx auth inactive` command](/influxdb/v2/reference/cli/influx/auth/active) -to deactivate a token. - -_This command requires an authorization ID, which is available in the output of `influx auth find`._ - -```sh -# Syntax -influx auth inactive -i - -# Example -influx auth inactive -i 0804f74142bbf000 -``` - -To get the current status of a token, use the JSON output of the [`influx auth list` command](/influxdb/v2/reference/cli/influx/auth/list). - -```sh -influx auth find --json -``` - -## Update a token using the InfluxDB API - -Use the `/api/v2/authorizations` InfluxDB API endpoint to update the description and status of a token. - -{{< api-endpoint method="PATCH" endpoint="http://localhost:8086/api/v2/authorizations/AUTH_ID" api-ref="/influxdb/v2/api/#operation/PatchAuthorizationsID" >}} - -Include the following in your request: - -| Requirement | Include by | -|:----------- |:---------- | -| API token with the [`write: authorizations`](/influxdb/v2/api/#operation/PostAuthorizations) permission | Use the `Authorization: Token YOUR_API_TOKEN` header. | -| Authorization ID | URL path parameter. | -| Description and/or Status | Pass as `description`, `status` in the request body. | - -### Disable a token - -```sh -# Update the description and status of the first authorization listed for the user. - -curl --request GET \ - "http://localhost:8086/api/v2/authorizations?user=user2" \ - --header "Authorization: Token ${INFLUX_TOKEN}" \ - --header 'Content-type: application/json' \ -| jq .authorizations[0].id \ -| xargs -I authid curl --request PATCH \ - http://localhost:8086/api/v2/authorizations/authid \ - --header "Authorization: Token ${INFLUX_TOKEN}" \ - --header 'Content-type: application/json' \ - --data '{ - "description": "deactivated_auth", - "status": "inactive" - }' | jq . -``` + diff --git a/content/influxdb/v2/admin/tokens/use-tokens.md b/content/influxdb/v2/admin/tokens/use-tokens.md index 271deb130..410f5708d 100644 --- a/content/influxdb/v2/admin/tokens/use-tokens.md +++ b/content/influxdb/v2/admin/tokens/use-tokens.md @@ -10,36 +10,8 @@ weight: 204 aliases: - /influxdb/v2/users/tokens/use-tokens - /influxdb/v2/security/tokens/use-tokens/ +source: /shared/influxdb-v2/admin/tokens/use-tokens.md --- -Use tokens to authenticate requests to InfluxDB, including requests to write, query, and manage data and resources. -Authenticate requests using the [`influx` CLI](/influxdb/v2/reference/cli/influx/), API requests made with client libraries, and tools like `curl`. - -### Add a token to a CLI request - -```sh -influx write -t -b BUCKET -o org-name -``` - -``` -export INFLUX_TOKEN=my-token -influx write -t $INFLUX_TOKEN -b my-bucket -o my-org "measurement field=1" -``` - -{{% note %}} -See [here](/influxdb/v2/write-data/no-code/use-telegraf/auto-config/#configure-your-token-as-an-environment-variable) -to configure environment variables on Windows. -(Click on the **Windows** tab.) -{{% /note %}} - -### Use CLI configurations - -Automatically manage and use tokens from the CLI using [`influx config`](/influxdb/v2/reference/cli/influx/config/). - -### Use a token in an API request - -Use tokens in [API requests](/influxdb/v2/api-guide/api_intro/#authentication). - -### Use a token in Postman - -Make authenticated requests with tokens [using Postman](/influxdb/v2/tools/postman/). + diff --git a/content/influxdb/v2/admin/tokens/view-tokens.md b/content/influxdb/v2/admin/tokens/view-tokens.md index f846df95a..e8a093081 100644 --- a/content/influxdb/v2/admin/tokens/view-tokens.md +++ b/content/influxdb/v2/admin/tokens/view-tokens.md @@ -10,103 +10,8 @@ weight: 202 aliases: - /influxdb/v2/users/tokens/view-tokens - /influxdb/v2/security/tokens/view-tokens/ +source: /shared/influxdb-v2/admin/tokens/view-tokens.md --- -View API tokens and permissions using the InfluxDB user interface (UI), -the `influx` command line interface (CLI), or the InfluxDB API. - -{{% note %}} - -{{% oss-only %}}Tokens are visible to the user who created the token. Users who own a token with operator permissions also have access to all tokens. Tokens stop working when the user who created the token is deleted. - -In the InfluxDB UI, full tokens are only visible immediately after the token is created. - -**We recommend creating a generic user to create and manage tokens for writing data.** -{{% /oss-only %}} - -{{% cloud-only %}} -To follow best practices for secure API token generation and retrieval, InfluxDB Cloud enforces access restrictions on API tokens. - - InfluxDB Cloud UI only allows access to the API token value immediately after the token is created. - - You can't change access (**read/write**) permissions for an API token after it's created. - - Tokens stop working when the user who created the token is deleted. - -We recommend the following for managing your tokens: -- Create a generic user to create and manage tokens for writing data. -- Store your tokens in a secure password vault for future access. -{{% /cloud-only %}} -{{% /note %}} - -## View tokens in the InfluxDB UI - -{{% oss-only %}} - -1. In the navigation menu on the left, select **Data (Load Data)** > **API Tokens**. - -{{< nav-icon "load-data" >}} - -2. Click a token name in the list to view the token status and a summary of access permissions. - -{{% /oss-only %}} - -{{% cloud-only %}} - -1. In the navigation menu on the left, select **Load Data** > **API Tokens**. - -{{< nav-icon "load-data" >}} - -2. Click a token description in the list to view the token status and a list of access permissions. - -{{% /cloud-only %}} - -## View tokens using the influx CLI - -Use the [`influx auth list` command](/influxdb/v2/reference/cli/influx/auth/list) -to view tokens. - -```sh -influx auth list -``` - -Filtering options such as filtering by authorization ID, username, or user ID are available. -See the [`influx auth list` documentation](/influxdb/v2/reference/cli/influx/auth/list) -for information about other available flags. - -## View tokens using the InfluxDB API - -Use the `/api/v2/authorizations` InfluxDB API endpoint to view tokens and permissions. - -{{< api-endpoint method="GET" endpoint="/api/v2/authorizations" api-ref="/influxdb/v2/api/#operation/GetAuthorizations" >}} - -Include the following in your request: - -| Requirement | Include by | -|:----------- |:---------- | -| API token with the [`read: authorizations`](/influxdb/v2/api/#operation/PostAuthorizations) permission | Use the `Authorization: Token YOUR_API_TOKEN` header. | - -```sh -{{% get-shared-text "api/v2.0/auth/oss/tokens-view.sh" %}} -``` - -### View a single token - -To view a specific authorization and token, include the authorization ID in the URL path. - -{{% api-endpoint method="GET" endpoint="/api/v2/authorizations/{authID}" api-ref="/influxdb/v2/api/#operation/GetAuthorizationsID" %}} - -### Filter the token list - -InfluxDB returns authorizations from the same organization as the token used in the request. -To filter tokens by user, include `userID` as a query parameter in your request. - -```sh -{{% get-shared-text "api/v2.0/auth/oss/tokens-view-filter.sh" %}} -``` - -{{% oss-only %}} - -[***Operator tokens***](/influxdb/v2/admin/tokens/#operator-token) have access to all organizations' authorizations. -To filter authorizations by organization when using an operator token, include an `org` or `orgID` query parameter in your request. - -{{% /oss-only %}} - -See the [`/authorizations` endpoint documentation](/influxdb/v2/api/#tag/Authorizations-(API-tokens)) for more information about available parameters. + diff --git a/content/influxdb/v2/api-guide/api_intro.md b/content/influxdb/v2/api-guide/api_intro.md index b02bb0496..bc12a32b4 100644 --- a/content/influxdb/v2/api-guide/api_intro.md +++ b/content/influxdb/v2/api-guide/api_intro.md @@ -10,66 +10,8 @@ menu: aliases: - /influxdb/v2/tools/api/ influxdb/cloud/tags: [api] +source: /shared/influxdb-v2/api-guide/api_intro.md --- -InfluxDB offers a rich API and [client libraries](/influxdb/v2/api-guide/client-libraries) ready to integrate with your application. Use popular tools like Curl and [Postman](/influxdb/v2/api-guide/postman) for rapidly testing API requests. - -This section guides you through the most commonly used API methods. - -For detailed documentation on the entire API, see the [InfluxDB v2 API Reference](/influxdb/v2/reference/api/#influxdb-v2-api-documentation). - -{{% note %}} -If you need to use InfluxDB {{< current-version >}} with **InfluxDB 1.x** API clients and integrations, see the [1.x compatibility API](/influxdb/v2/reference/api/#influxdb-v1-compatibility-api-reference-documentation). -{{% /note %}} - -## Bootstrap your application - -With most API requests, you'll need to provide a minimum of your InfluxDB URL and Authorization Token (API Token). - -[Install InfluxDB OSS v2.x](/influxdb/v2/install/) or upgrade to -an [InfluxDB Cloud account](/influxdb/cloud/sign-up). - -### Authentication - -InfluxDB uses [API tokens](/influxdb/v2/admin/tokens/) to authorize API requests. - -1. Before exploring the API, use the InfluxDB UI to -[create an initial API token](/influxdb/v2/admin/tokens/create-token/) for your application. - -2. Include your API token in an `Authorization: Token YOUR_API_TOKEN` HTTP header with each request. - -{{< code-tabs-wrapper >}} -{{% code-tabs %}} -[curl](#curl) -[Node.js](#nodejs) -{{% /code-tabs %}} -{{% code-tab-content %}} -```sh -{{% get-shared-text "api/v2.0/auth/oss/token-auth.sh" %}} -``` -{{% /code-tab-content %}} -{{% code-tab-content %}} -```js -{{% get-shared-text "api/v2.0/auth/oss/token-auth.js" %}} -``` -{{% /code-tab-content %}} -{{< /code-tabs-wrapper >}} - -Postman is another popular tool for exploring APIs. See how to [send authenticated requests with Postman](/influxdb/v2/tools/postman/#send-authenticated-api-requests-with-postman). - -## Buckets API - -Before writing data you'll need to create a Bucket in InfluxDB. -[Create a bucket](/influxdb/v2/admin/buckets/create-bucket/#create-a-bucket-using-the-influxdb-api) using an HTTP request to the InfluxDB API `/buckets` endpoint. - -```sh -{{% get-shared-text "api/v2.0/buckets/oss/create.sh" %}} -``` - -## Write API - -[Write data to InfluxDB](/influxdb/v2/write-data/developer-tools/api/) using an HTTP request to the InfluxDB API `/api/v2/write` endpoint. - -## Query API - -[Query from InfluxDB](/influxdb/v2/query-data/execute-queries/influx-api/) using an HTTP request to the `/api/v2/query` endpoint. + diff --git a/content/influxdb/v2/api-guide/client-libraries/_index.md b/content/influxdb/v2/api-guide/client-libraries/_index.md index fed8999ef..d2687fb14 100644 --- a/content/influxdb/v2/api-guide/client-libraries/_index.md +++ b/content/influxdb/v2/api-guide/client-libraries/_index.md @@ -14,9 +14,8 @@ menu: name: Client libraries parent: Develop with the API influxdb/v2/tags: [client libraries] +source: /shared/influxdb-v2/api-guide/client-libraries/_index.md --- -InfluxDB client libraries are language-specific packages that integrate with the InfluxDB v2 API. -The following **InfluxDB v2** client libraries are available: - -{{< children type="list" >}} + diff --git a/content/influxdb/v2/api-guide/client-libraries/arduino.md b/content/influxdb/v2/api-guide/client-libraries/arduino.md index 1078814a1..2edb12bc7 100644 --- a/content/influxdb/v2/api-guide/client-libraries/arduino.md +++ b/content/influxdb/v2/api-guide/client-libraries/arduino.md @@ -12,10 +12,8 @@ menu: params: url: https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/arduino.md --- -Arduino is an open source hardware and software platform used for building electronics projects. - -The documentation for this client library is available on GitHub. - -Arduino InfluxDB client + diff --git a/content/influxdb/v2/api-guide/client-libraries/browserjs.md b/content/influxdb/v2/api-guide/client-libraries/browserjs.md index fa26ad990..5d9d1768a 100644 --- a/content/influxdb/v2/api-guide/client-libraries/browserjs.md +++ b/content/influxdb/v2/api-guide/client-libraries/browserjs.md @@ -18,100 +18,8 @@ aliases: related: - /influxdb/v2/api-guide/client-libraries/nodejs/write/ - /influxdb/v2/api-guide/client-libraries/nodejs/query/ +source: /shared/influxdb-v2/api-guide/client-libraries/browserjs.md --- -Use the [InfluxDB JavaScript client library](https://github.com/influxdata/influxdb-client-js) to interact with the InfluxDB v2 API in browsers and front-end clients. This library supports both front-end and server-side environments and provides the following distributions: -* ECMAScript modules (ESM) and CommonJS modules (CJS) -* Bundled ESM -* Bundled UMD - -This guide presumes some familiarity with JavaScript, browser environments, and InfluxDB. -If you're just getting started with InfluxDB, see [Get started with InfluxDB](/influxdb/v2/get-started/). - -{{% warn %}} -### Tokens in production applications -{{% api/browser-token-warning %}} -{{% /warn %}} - -* [Before you begin](#before-you-begin) -* [Use with module bundlers](#use-with-module-bundlers) -* [Use bundled distributions with browsers and module loaders](#use-bundled-distributions-with-browsers-and-module-loaders) -* [Get started with the example app](#get-started-with-the-example-app) - -## Before you begin - -1. Install [Node.js](https://nodejs.org/en/download/package-manager/) to serve your front-end app. - -2. Ensure that InfluxDB is running and you can connect to it. - For information about what URL to use to connect to InfluxDB OSS or InfluxDB Cloud, see [InfluxDB URLs](/influxdb/v2/reference/urls/). - -## Use with module bundlers - -If you use a module bundler like Webpack or Parcel, install `@influxdata/influxdb-client-browser`. -For more information and examples, see [Node.js](/influxdb/v2/api-guide/client-libraries/nodejs/). - -## Use bundled distributions with browsers and module loaders - -1. Configure InfluxDB properties for your script. - - ```html - - ``` - -2. Import modules from the latest client library browser distribution. -`@influxdata/influxdb-client-browser` exports bundled ESM and UMD syntaxes. - - {{< code-tabs-wrapper >}} - {{% code-tabs %}} - [ESM](#import-esm) - [UMD](#import-umd) - {{% /code-tabs %}} - {{% code-tab-content %}} - ```html - - ``` - {{% /code-tab-content %}} - {{% code-tab-content %}} - ```html - - - ``` - {{% /code-tab-content %}} - {{< /code-tabs-wrapper >}} - -After you've imported the client library, you're ready to [write data](/influxdb/v2/api-guide/client-libraries/nodejs/write/?t=nodejs) to InfluxDB. - -## Get started with the example app - -This library includes an example browser app that queries from and writes to your InfluxDB instance. - -1. Clone the [influxdb-client-js](https://github.com/influxdata/influxdb-client-js) repo. - -2. Navigate to the `examples` directory: - ```js - cd examples - ``` - -3. Update `./env_browser.js` with your InfluxDB [url](/influxdb/v2/reference/urls/), [bucket](/influxdb/v2/admin/buckets/), [organization](/influxdb/v2/admin/organizations/), and [token](/influxdb/v2/admin/tokens/) - -4. Run the following command to start the application at [http://localhost:3001/examples/index.html]() - - ```sh - npm run browser - ``` - - `index.html` loads the `env_browser.js` configuration, the client library ESM modules, and the application in your browser. + diff --git a/content/influxdb/v2/api-guide/client-libraries/csharp.md b/content/influxdb/v2/api-guide/client-libraries/csharp.md index c9de682c1..c138e666a 100644 --- a/content/influxdb/v2/api-guide/client-libraries/csharp.md +++ b/content/influxdb/v2/api-guide/client-libraries/csharp.md @@ -11,10 +11,8 @@ menu: params: url: https://github.com/influxdata/influxdb-client-csharp weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/csharp.md --- -C# is a general-purpose object-oriented programming language. - -The documentation for this client library is available on GitHub. - -C# InfluxDB client \ No newline at end of file + diff --git a/content/influxdb/v2/api-guide/client-libraries/dart.md b/content/influxdb/v2/api-guide/client-libraries/dart.md index 3178d11da..9efa0582f 100644 --- a/content/influxdb/v2/api-guide/client-libraries/dart.md +++ b/content/influxdb/v2/api-guide/client-libraries/dart.md @@ -11,10 +11,8 @@ menu: params: url: https://github.com/influxdata/influxdb-client-dart weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/dart.md --- -Dart is a programming language created for quick application development for both web and mobile apps. - -The documentation for this client library is available on GitHub. - -Dart InfluxDB client \ No newline at end of file + diff --git a/content/influxdb/v2/api-guide/client-libraries/go.md b/content/influxdb/v2/api-guide/client-libraries/go.md index 84ac58555..6421b478a 100644 --- a/content/influxdb/v2/api-guide/client-libraries/go.md +++ b/content/influxdb/v2/api-guide/client-libraries/go.md @@ -13,194 +13,8 @@ weight: 201 aliases: - /influxdb/v2/reference/api/client-libraries/go/ - /influxdb/v2/tools/client-libraries/go/ +source: /shared/influxdb-v2/api-guide/client-libraries/go.md --- -Use the [InfluxDB Go client library](https://github.com/influxdata/influxdb-client-go) to integrate InfluxDB into Go scripts and applications. - -This guide presumes some familiarity with Go and InfluxDB. -If just getting started, see [Get started with InfluxDB](/influxdb/v2/get-started/). - -## Before you begin - -1. [Install Go 1.13 or later](https://golang.org/doc/install). -2. Add the client package your to your project dependencies. - - ```sh - # Add InfluxDB Go client package to your project go.mod - go get github.com/influxdata/influxdb-client-go/v2 - ``` -3. Ensure that InfluxDB is running and you can connect to it. - For information about what URL to use to connect to InfluxDB OSS or InfluxDB Cloud, see [InfluxDB URLs](/influxdb/v2/reference/urls/). - -## Boilerplate for the InfluxDB Go Client Library - -Use the Go library to write and query data from InfluxDB. - -1. In your Go program, import the necessary packages and specify the entry point of your executable program. - - ```go - package main - - import ( - "context" - "fmt" - "time" - - "github.com/influxdata/influxdb-client-go/v2" - ) - ``` - -2. Define variables for your InfluxDB [bucket](/influxdb/v2/admin/buckets/), [organization](/influxdb/v2/admin/organizations/), and [token](/influxdb/v2/admin/tokens/). - - ```go - bucket := "example-bucket" - org := "example-org" - token := "example-token" - // Store the URL of your InfluxDB instance - url := "http://localhost:8086" - ``` - -3. Create the the InfluxDB Go client and pass in the `url` and `token` parameters. - - ```go - client := influxdb2.NewClient(url, token) - ``` - -4. Create a **write client** with the `WriteAPIBlocking` method and pass in the `org` and `bucket` parameters. - - ```go - writeAPI := client.WriteAPIBlocking(org, bucket) - ``` - -5. To query data, create an InfluxDB **query client** and pass in your InfluxDB `org`. - - ```go - queryAPI := client.QueryAPI(org) - ``` - -## Write data to InfluxDB with Go - -Use the Go library to write data to InfluxDB. - -1. Create a [point](/influxdb/v2/reference/glossary/#point) and write it to InfluxDB using the `WritePoint` method of the API writer struct. - -2. Close the client to flush all pending writes and finish. - - ```go - p := influxdb2.NewPoint("stat", - map[string]string{"unit": "temperature"}, - map[string]interface{}{"avg": 24.5, "max": 45}, - time.Now()) - writeAPI.WritePoint(context.Background(), p) - client.Close() - ``` - -### Complete example write script - -```go -func main() { - bucket := "example-bucket" - org := "example-org" - token := "example-token" - // Store the URL of your InfluxDB instance - url := "http://localhost:8086" - // Create new client with default option for server url authenticate by token - client := influxdb2.NewClient(url, token) - // User blocking write client for writes to desired bucket - writeAPI := client.WriteAPIBlocking(org, bucket) - // Create point using full params constructor - p := influxdb2.NewPoint("stat", - map[string]string{"unit": "temperature"}, - map[string]interface{}{"avg": 24.5, "max": 45}, - time.Now()) - // Write point immediately - writeAPI.WritePoint(context.Background(), p) - // Ensures background processes finishes - client.Close() -} -``` -## Query data from InfluxDB with Go -Use the Go library to query data stored in InfluxDB. - -1. Create a Flux query and pass the `bucket` parameter with your bucket name. - - ```js - from(bucket:"") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "stat") - ``` - - The query client sends the Flux query to InfluxDB and returns the results as a FluxRecord object with a table structure. - -**The query client includes the following methods:** - -- `Query`: Sends the Flux query to InfluxDB. -- `Next`: Iterates over the query response. -- `TableChanged`: Identifies when the group key changes. -- `Record`: Returns the last parsed FluxRecord and gives access to value and row properties. -- `Value`: Returns the actual field value. - -```go -result, err := queryAPI.Query(context.Background(), `from(bucket:"") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "stat")`) -if err == nil { - for result.Next() { - if result.TableChanged() { - fmt.Printf("table: %s\n", result.TableMetadata().String()) - } - fmt.Printf("value: %v\n", result.Record().Value()) - } - if result.Err() != nil { - fmt.Printf("query parsing error: %s\n", result.Err().Error()) - } -} else { - panic(err) -} -``` - -**The FluxRecord object includes the following methods for accessing your data:** - -- `Table()`: Returns the index of the table the record belongs to. -- `Start()`: Returns the inclusive lower time bound of all records in the current table. -- `Stop()`: Returns the exclusive upper time bound of all records in the current table. -- `Time()`: Returns the time of the record. -- `Value() `: Returns the actual field value. -- `Field()`: Returns the field name. -- `Measurement()`: Returns the measurement name of the record. -- `Values()`: Returns a map of column values. -- `ValueByKey()`: Returns a value from the record for given column key. - -### Complete example query script - -```go - func main() { - // Create client - client := influxdb2.NewClient(url, token) - // Get query client - queryAPI := client.QueryAPI(org) - // Get QueryTableResult - result, err := queryAPI.Query(context.Background(), `from(bucket:"my-bucket")|> range(start: -1h) |> filter(fn: (r) => r._measurement == "stat")`) - if err == nil { - // Iterate over query response - for result.Next() { - // Notice when group key has changed - if result.TableChanged() { - fmt.Printf("table: %s\n", result.TableMetadata().String()) - } - // Access data - fmt.Printf("value: %v\n", result.Record().Value()) - } - // Check for an error - if result.Err() != nil { - fmt.Printf("query parsing error: %s\n", result.Err().Error()) - } - } else { - panic(err) - } - // Ensures background processes finishes - client.Close() -} -``` - -For more information, see the [Go client README on GitHub](https://github.com/influxdata/influxdb-client-go). + diff --git a/content/influxdb/v2/api-guide/client-libraries/java.md b/content/influxdb/v2/api-guide/client-libraries/java.md index 9d0dfa7e8..332590b2c 100644 --- a/content/influxdb/v2/api-guide/client-libraries/java.md +++ b/content/influxdb/v2/api-guide/client-libraries/java.md @@ -11,10 +11,8 @@ menu: params: url: https://github.com/influxdata/influxdb-client-java weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/java.md --- -Java is one of the oldest and most popular class-based, object-oriented programming languages. - -The documentation for this client library is available on GitHub. - -Java InfluxDB client \ No newline at end of file + diff --git a/content/influxdb/v2/api-guide/client-libraries/kotlin.md b/content/influxdb/v2/api-guide/client-libraries/kotlin.md index 5e1f8ae59..89aae4b58 100644 --- a/content/influxdb/v2/api-guide/client-libraries/kotlin.md +++ b/content/influxdb/v2/api-guide/client-libraries/kotlin.md @@ -11,10 +11,8 @@ menu: params: url: https://github.com/influxdata/influxdb-client-java/tree/master/client-kotlin weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/kotlin.md --- -Kotlin is an open source programming language that runs on the Java Virtual Machine (JVM). - -The documentation for this client library is available on GitHub. - -Kotlin InfluxDB client + diff --git a/content/influxdb/v2/api-guide/client-libraries/nodejs/_index.md b/content/influxdb/v2/api-guide/client-libraries/nodejs/_index.md index d728132be..19a12f82a 100644 --- a/content/influxdb/v2/api-guide/client-libraries/nodejs/_index.md +++ b/content/influxdb/v2/api-guide/client-libraries/nodejs/_index.md @@ -12,12 +12,9 @@ influxdb/v2/tags: [client libraries, JavaScript] weight: 201 aliases: - /influxdb/v2/reference/api/client-libraries/nodejs/ - - /influxdb/v2/reference/api/client-libraries/js/ + - /influxdb/v2/reference/api/client-libraries/js/ +source: /shared/influxdb-v2/api-guide/client-libraries/nodejs/_index.md --- -Use the [InfluxDB JavaScript client library](https://github.com/influxdata/influxdb-client-js) to integrate InfluxDB into your Node.js application. -In this guide, you'll start a Node.js project from scratch and code some simple API operations. - -{{< children >}} - -{{% api/v2dot0/nodejs/learn-more %}} + diff --git a/content/influxdb/v2/api-guide/client-libraries/nodejs/install.md b/content/influxdb/v2/api-guide/client-libraries/nodejs/install.md index 4d7fd0e7f..068f9963f 100644 --- a/content/influxdb/v2/api-guide/client-libraries/nodejs/install.md +++ b/content/influxdb/v2/api-guide/client-libraries/nodejs/install.md @@ -11,105 +11,8 @@ influxdb/v2/tags: [client libraries, JavaScript] weight: 100 aliases: - /influxdb/v2/reference/api/client-libraries/nodejs/install +source: /shared/influxdb-v2/api-guide/client-libraries/nodejs/install.md --- - -## Install Node.js - -1. Install [Node.js](https://nodejs.org/en/download/package-manager/). - -2. Ensure that InfluxDB is running and you can connect to it. - For information about what URL to use to connect to InfluxDB OSS or InfluxDB Cloud, see [InfluxDB URLs](/influxdb/v2/reference/urls/). - -3. Create a directory for your new Node.js project, and then change to the - directory--for example, enter the following command into your terminal: - - ```sh - mkdir influx-node-app && cd influx-node-app - ``` - -4. Enter the following command to generate an npm package for your project. - - - `npm`: the package manager included with Node.js - - `-y`: uses defaults for the package and bypasses prompts - - ```sh - npm init -y - ``` - -## Install TypeScript - -Many of the client library examples use [TypeScript](https://www.typescriptlang.org/). -Follow these steps to initialize the TypeScript project: - -1. Install TypeScript and type definitions for Node.js. - - ```sh - npm i -g typescript && npm i --save-dev @types/node - ``` - -2. Enter the following command to create a TypeScript configuration - (`tsconfig.json`) with default values: - - ```sh - tsc --init - ``` - -3. Run the TypeScript compiler. - To recompile your code automatically as you make changes, pass the `--watch, -w` flag to the compiler. - - - - ```sh - tsc --watch - ``` - -## Install dependencies - -The JavaScript client library contains two packages: `@influxdata/influxdb-client` and `@influxdata/influxdb-client-apis`. -Add both as dependencies of your project. - -1. Open a new terminal window and install `@influxdata/influxdb-client` for querying and writing data: - - ```sh - npm install --save @influxdata/influxdb-client - ``` - -3. Install `@influxdata/influxdb-client-apis` for access to the InfluxDB management APIs: - - ```sh - npm install --save @influxdata/influxdb-client-apis - ``` - -## Next steps - -Once you've installed the JavaScript client library, you're ready to [write data](/influxdb/v2/api-guide/client-libraries/nodejs/write/) to InfluxDB or [get started](#get-started-with-examples) with other examples from the client library. - -## Get started with examples - -{{% note %}} -The client examples include an [`env`](https://github.com/influxdata/influxdb-client-js/blob/master/examples/env.mjs) module for accessing your InfluxDB properties from environment variables or from `env.mjs`. -The examples use these properties to interact with the InfluxDB API. -{{% /note %}} - -1. Set environment variables or update `env.mjs` with your InfluxDB [bucket](/influxdb/v2/admin/buckets/), [organization](/influxdb/v2/admin/organizations/), [token](/influxdb/v2/admin/tokens/), and [URL](/influxdb/v2/reference/urls/). - - ```sh - export INFLUX_URL=http://localhost:8086 - export INFLUX_TOKEN=YOUR_API_TOKEN - export INFLUX_ORG=YOUR_ORG - export INFLUX_BUCKET=YOUR_BUCKET - ``` - Replace the following: - - *`YOUR_API_TOKEN`*: InfluxDB API token - - *`YOUR_ORG`*: InfluxDB organization ID - - *`YOUR_BUCKET`*: InfluxDB bucket name - -2. Run one of the [`influxdb-client-js` example scripts](https://github.com/influxdata/influxdb-client-js/tree/master/examples/). - - - - ```sh - query.ts - ``` -{{% api/v2dot0/nodejs/learn-more %}} + diff --git a/content/influxdb/v2/api-guide/client-libraries/nodejs/query.md b/content/influxdb/v2/api-guide/client-libraries/nodejs/query.md index bb91a1eeb..fa7331d20 100644 --- a/content/influxdb/v2/api-guide/client-libraries/nodejs/query.md +++ b/content/influxdb/v2/api-guide/client-libraries/nodejs/query.md @@ -10,85 +10,8 @@ influxdb/v2/tags: [client libraries, JavaScript] weight: 201 aliases: - /influxdb/v2/reference/api/client-libraries/nodejs/query +source: /shared/influxdb-v2/api-guide/client-libraries/nodejs/query.md --- -Use the [InfluxDB JavaScript client library](https://github.com/influxdata/influxdb-client-js) in a Node.js environment to query InfluxDB. - -The following example sends a Flux query to an InfluxDB bucket and outputs rows from an observable table. - -## Before you begin - -- [Install the client library and other dependencies](/influxdb/v2/api-guide/client-libraries/nodejs/install/). - -## Query InfluxDB - -1. Change to your new project directory and create a file for your query module. - - ```sh - cd influx-node-app && touch query.js - ``` - -2. Instantiate an `InfluxDB` client. Provide your InfluxDB URL and API token. - Use the `getQueryApi()` method of the client. - Provide your InfluxDB organization ID to create a configured **query client**. - - ```js - import { InfluxDB, Point } from '@influxdata/influxdb-client' - - const queryApi = new InfluxDB({YOUR_URL, YOUR_API_TOKEN}).getQueryApi(YOUR_ORG) - ``` - - Replace the following: - - *`YOUR_URL`*: InfluxDB URL - - *`YOUR_API_TOKEN`*: InfluxDB API token - - *`YOUR_ORG`*: InfluxDB organization ID - -3. Create a Flux query for your InfluxDB bucket. Store the query as a string variable. - {{% warn %}} - To prevent SQL injection attacks, avoid concatenating unsafe user input with queries. - {{% /warn %}} - - ```js - const fluxQuery = - 'from(bucket: "YOUR_BUCKET") - |> range(start: 0) - |> filter(fn: (r) => r._measurement == "temperature")' - ``` - Replace *`YOUR_BUCKET`* with the name of your InfluxDB bucket. - -4. Use the `queryRows()` method of the query client to query InfluxDB. - `queryRows()` takes a Flux query and an [RxJS **Observer**](http://reactivex.io/rxjs/manual/overview.html#observer) object. - The client returns [table](/influxdb/v2/reference/syntax/annotated-csv/#tables) metadata and rows as an [RxJS **Observable**](http://reactivex.io/rxjs/manual/overview.html#observable). - `queryRows()` subscribes your observer to the observable. - Finally, the observer logs the rows from the response to the terminal. - - ```js - const observer = { - next(row, tableMeta) { - const o = tableMeta.toObject(row) - console.log( - `${o._time} ${o._measurement} in '${o.location}' (${o.sensor_id}): ${o._field}=${o._value}` - ) - } - } - - queryApi.queryRows(fluxQuery, observer) - - ``` - -### Complete example - -```js -{{% get-shared-text "api/v2.0/query/query.mjs" %}} -``` - -To run the example from a file, set your InfluxDB environment variables and use `node` to execute the JavaScript file. - -```sh -export INFLUX_URL=http://localhost:8086 && \ -export INFLUX_TOKEN=YOUR_API_TOKEN && \ -export INFLUX_ORG=YOUR_ORG && \ -node query.js -``` - -{{% api/v2dot0/nodejs/learn-more %}} + diff --git a/content/influxdb/v2/api-guide/client-libraries/nodejs/write.md b/content/influxdb/v2/api-guide/client-libraries/nodejs/write.md index 4c78e3470..667e420c3 100644 --- a/content/influxdb/v2/api-guide/client-libraries/nodejs/write.md +++ b/content/influxdb/v2/api-guide/client-libraries/nodejs/write.md @@ -12,106 +12,8 @@ aliases: - /influxdb/v2/reference/api/client-libraries/nodejs/write related: - /influxdb/v2/write-data/troubleshoot/ +source: /shared/influxdb-v2/api-guide/client-libraries/nodejs/write.md --- -Use the [InfluxDB JavaScript client library](https://github.com/influxdata/influxdb-client-js) to write data from a Node.js environment to InfluxDB. - -The JavaScript client library includes the following convenient features for writing data to InfluxDB: -- Apply default tags to data points. -- Buffer points into batches to optimize data transfer. -- Automatically retry requests on failure. -- Set an optional HTTP proxy address for your network. - -### Before you begin - -- [Install the client library and other dependencies](/influxdb/v2/api-guide/client-libraries/nodejs/install/). -### Write data with the client library - -1. Instantiate an `InfluxDB` client. Provide your InfluxDB URL and API token. - - ```js - import {InfluxDB, Point} from '@influxdata/influxdb-client' - - const influxDB = new InfluxDB({YOUR_URL, YOUR_API_TOKEN}) - ``` - Replace the following: - - *`YOUR_URL`*: InfluxDB URL - - *`YOUR_API_TOKEN`*: InfluxDB API token - -2. Use the `getWriteApi()` method of the client to create a **write client**. - Provide your InfluxDB organization ID and bucket name. - - ```js - const writeApi = influxDB.getWriteApi(YOUR_ORG, YOUR_BUCKET) - ``` - Replace the following: - - *`YOUR_ORG`*: InfluxDB organization ID - - *`YOUR_BUCKET`*: InfluxDB bucket name - -3. To apply one or more [tags](/influxdb/v2/reference/glossary/#tag) to all points, use the `useDefaultTags()` method. - Provide tags as an object of key/value pairs. - - ```js - writeApi.useDefaultTags({region: 'west'}) - ``` - -4. Use the `Point()` constructor to create a [point](/influxdb/v2/reference/glossary/#point). - 1. Call the constructor and provide a [measurement](/influxdb/v2/reference/glossary/#measurement). - 2. To add one or more tags, chain the `tag()` method to the constructor. - Provide a `name` and `value`. - 3. To add a field of type `float`, chain the `floatField()` method to the constructor. - Provide a `name` and `value`. - - ```js - const point1 = new Point('temperature') - .tag('sensor_id', 'TLM010') - .floatField('value', 24) - ``` - -5. Use the `writePoint()` method to write the point to your InfluxDB bucket. - Finally, use the `close()` method to flush all pending writes. - The example logs the new data point followed by "WRITE FINISHED" to stdout. - - ```js - writeApi.writePoint(point1) - - writeApi.close().then(() => { - console.log('WRITE FINISHED') - }) - ``` - -### Complete example - -{{< code-tabs-wrapper >}} -{{% code-tabs %}} -[Curl](#curl) -[Node.js](#nodejs) -{{% /code-tabs %}} -{{% code-tab-content %}} - -```sh -{{< get-shared-text "api/v2.0/write/write.sh" >}} -``` -{{% /code-tab-content %}} -{{% code-tab-content %}} - -```js -{{< get-shared-text "api/v2.0/write/write.mjs" >}} -``` - -{{% /code-tab-content %}} -{{< /code-tabs-wrapper >}} - -To run the example from a file, set your InfluxDB environment variables and use `node` to execute the JavaScript file. - -```sh -export INFLUX_URL=http://localhost:8086 && \ -export INFLUX_TOKEN=YOUR_API_TOKEN && \ -export INFLUX_ORG=YOUR_ORG && \ -export INFLUX_BUCKET=YOUR_BUCKET && \ -node write.js -``` - -### Response codes -_For information about **InfluxDB API response codes**, see -[InfluxDB API Write documentation](/influxdb/cloud/api/#operation/PostWrite)._ + diff --git a/content/influxdb/v2/api-guide/client-libraries/php.md b/content/influxdb/v2/api-guide/client-libraries/php.md index 2b826c87f..a6c6c2fe5 100644 --- a/content/influxdb/v2/api-guide/client-libraries/php.md +++ b/content/influxdb/v2/api-guide/client-libraries/php.md @@ -11,10 +11,8 @@ menu: params: url: https://github.com/influxdata/influxdb-client-php weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/php.md --- -PHP is a popular general-purpose scripting language primarily used for web development. - -The documentation for this client library is available on GitHub. - -PHP InfluxDB client \ No newline at end of file + diff --git a/content/influxdb/v2/api-guide/client-libraries/python.md b/content/influxdb/v2/api-guide/client-libraries/python.md index 51b6a1d42..23b837ff2 100644 --- a/content/influxdb/v2/api-guide/client-libraries/python.md +++ b/content/influxdb/v2/api-guide/client-libraries/python.md @@ -14,180 +14,8 @@ aliases: - /influxdb/v2/reference/api/client-libraries/python-cl-guide/ - /influxdb/v2/tools/client-libraries/python/ weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/python.md --- -Use the [InfluxDB Python client library](https://github.com/influxdata/influxdb-client-python) to integrate InfluxDB into Python scripts and applications. - -This guide presumes some familiarity with Python and InfluxDB. -If just getting started, see [Get started with InfluxDB](/influxdb/v2/get-started/). - -## Before you begin - -1. Install the InfluxDB Python library: - - ```sh - pip install influxdb-client - ``` - -2. Ensure that InfluxDB is running. - If running InfluxDB locally, visit http://localhost:8086. - (If using InfluxDB Cloud, visit the URL of your InfluxDB Cloud UI. - For example: https://us-west-2-1.aws.cloud2.influxdata.com.) - -## Write data to InfluxDB with Python - -We are going to write some data in [line protocol](/influxdb/v2/reference/syntax/line-protocol/) using the Python library. - -1. In your Python program, import the InfluxDB client library and use it to write data to InfluxDB. - - ```python - import influxdb_client - from influxdb_client.client.write_api import SYNCHRONOUS - ``` - -2. Define a few variables with the name of your [bucket](/influxdb/v2/admin/buckets/), [organization](/influxdb/v2/admin/organizations/), and [token](/influxdb/v2/admin/tokens/). - - ```python - bucket = "" - org = "" - token = "" - # Store the URL of your InfluxDB instance - url="http://localhost:8086" - ``` - -3. Instantiate the client. The `InfluxDBClient` object takes three named parameters: `url`, `org`, and `token`. Pass in the named parameters. - - ```python - client = influxdb_client.InfluxDBClient( - url=url, - token=token, - org=org - ) - ``` - The `InfluxDBClient` object has a `write_api` method used for configuration. - -4. Instantiate a **write client** using the `client` object and the `write_api` method. Use the `write_api` method to configure the writer object. - - ```python - write_api = client.write_api(write_options=SYNCHRONOUS) - ``` - -5. Create a [point](/influxdb/v2/reference/glossary/#point) object and write it to InfluxDB using the `write` method of the API writer object. The write method requires three parameters: `bucket`, `org`, and `record`. - - ```python - p = influxdb_client.Point("my_measurement").tag("location", "Prague").field("temperature", 25.3) - write_api.write(bucket=bucket, org=org, record=p) - ``` - -### Complete example write script - -```python -import influxdb_client -from influxdb_client.client.write_api import SYNCHRONOUS - -bucket = "" -org = "" -token = "" -# Store the URL of your InfluxDB instance -url="http://localhost:8086" - -client = influxdb_client.InfluxDBClient( - url=url, - token=token, - org=org -) - -# Write script -write_api = client.write_api(write_options=SYNCHRONOUS) - -p = influxdb_client.Point("my_measurement").tag("location", "Prague").field("temperature", 25.3) -write_api.write(bucket=bucket, org=org, record=p) -``` -## Query data from InfluxDB with Python - -1. Instantiate the **query client**. - - ```python - query_api = client.query_api() - ``` - -2. Create a Flux query, and then format it as a Python string. - - ```python - query = 'from(bucket:"my-bucket")\ - |> range(start: -10m)\ - |> filter(fn:(r) => r._measurement == "my_measurement")\ - |> filter(fn:(r) => r.location == "Prague")\ - |> filter(fn:(r) => r._field == "temperature")' - ``` - - The query client sends the Flux query to InfluxDB and returns a Flux object with a table structure. - -3. Pass the `query()` method two named parameters:`org` and `query`. - - ```python - result = query_api.query(org=org, query=query) - ``` - -4. Iterate through the tables and records in the Flux object. - - Use the `get_value()` method to return values. - - Use the `get_field()` method to return fields. - - ```python - results = [] - for table in result: - for record in table.records: - results.append((record.get_field(), record.get_value())) - - print(results) - [(temperature, 25.3)] - ``` - -**The Flux object provides the following methods for accessing your data:** - -- `get_measurement()`: Returns the measurement name of the record. -- `get_field()`: Returns the field name. -- `get_value()`: Returns the actual field value. -- `values`: Returns a map of column values. -- `values.get("")`: Returns a value from the record for given column. -- `get_time()`: Returns the time of the record. -- `get_start()`: Returns the inclusive lower time bound of all records in the current table. -- `get_stop()`: Returns the exclusive upper time bound of all records in the current table. - - -### Complete example query script - -```python -import influxdb_client -from influxdb_client.client.write_api import SYNCHRONOUS - -bucket = "" -org = "" -token = "" -# Store the URL of your InfluxDB instance -url="http://localhost:8086" - -client = influxdb_client.InfluxDBClient( - url=url, - token=token, - org=org -) - -# Query script -query_api = client.query_api() -query = 'from(bucket:"my-bucket")\ -|> range(start: -10m)\ -|> filter(fn:(r) => r._measurement == "my_measurement")\ -|> filter(fn:(r) => r.location == "Prague")\ -|> filter(fn:(r) => r._field == "temperature")' -result = query_api.query(org=org, query=query) -results = [] -for table in result: - for record in table.records: - results.append((record.get_field(), record.get_value())) - -print(results) -[(temperature, 25.3)] -``` - -For more information, see the [Python client README on GitHub](https://github.com/influxdata/influxdb-client-python). + diff --git a/content/influxdb/v2/api-guide/client-libraries/r.md b/content/influxdb/v2/api-guide/client-libraries/r.md index ee309ca64..578554c4b 100644 --- a/content/influxdb/v2/api-guide/client-libraries/r.md +++ b/content/influxdb/v2/api-guide/client-libraries/r.md @@ -11,10 +11,8 @@ menu: params: url: https://github.com/influxdata/influxdb-client-r weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/r.md --- -R is a programming language and software environment for statistical analysis, reporting, and graphical representation primarily used in data science. - -The documentation for this client library is available on GitHub. - -R InfluxDB client \ No newline at end of file + diff --git a/content/influxdb/v2/api-guide/client-libraries/ruby.md b/content/influxdb/v2/api-guide/client-libraries/ruby.md index 83909490b..1d108af2e 100644 --- a/content/influxdb/v2/api-guide/client-libraries/ruby.md +++ b/content/influxdb/v2/api-guide/client-libraries/ruby.md @@ -11,10 +11,8 @@ menu: params: url: https://github.com/influxdata/influxdb-client-ruby weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/ruby.md --- -Ruby is a highly flexible, open-source, object-oriented programming language. - -The documentation for this client library is available on GitHub. - -Ruby InfluxDB client \ No newline at end of file + diff --git a/content/influxdb/v2/api-guide/client-libraries/scala.md b/content/influxdb/v2/api-guide/client-libraries/scala.md index 7a0a3c198..5185ba9ba 100644 --- a/content/influxdb/v2/api-guide/client-libraries/scala.md +++ b/content/influxdb/v2/api-guide/client-libraries/scala.md @@ -11,10 +11,8 @@ menu: params: url: https://github.com/influxdata/influxdb-client-java/tree/master/client-scala weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/scala.md --- -Scala is a general-purpose programming language that supports both object-oriented and functional programming. - -The documentation for this client library is available on GitHub. - -Scala InfluxDB client \ No newline at end of file + diff --git a/content/influxdb/v2/api-guide/client-libraries/swift.md b/content/influxdb/v2/api-guide/client-libraries/swift.md index 354bb2b4b..f0a17f545 100644 --- a/content/influxdb/v2/api-guide/client-libraries/swift.md +++ b/content/influxdb/v2/api-guide/client-libraries/swift.md @@ -11,10 +11,8 @@ menu: params: url: https://github.com/influxdata/influxdb-client-swift weight: 201 +source: /shared/influxdb-v2/api-guide/client-libraries/swift.md --- -Swift is a programming language created by Apple for building applications across multiple Apple platforms. - -The documentation for this client library is available on GitHub. - -Swift InfluxDB client \ No newline at end of file + diff --git a/content/influxdb/v2/api-guide/influxdb-1x/_index.md b/content/influxdb/v2/api-guide/influxdb-1x/_index.md index ac40b92ba..021dbb523 100644 --- a/content/influxdb/v2/api-guide/influxdb-1x/_index.md +++ b/content/influxdb/v2/api-guide/influxdb-1x/_index.md @@ -14,277 +14,8 @@ related: - /influxdb/v2/install/upgrade/v1-to-v2/ aliases: - /influxdb/v2/reference/api/influxdb-1x/ +source: /shared/influxdb-v2/api-guide/influxdb-1x/_index.md --- -The InfluxDB v2 API includes InfluxDB 1.x compatibility endpoints that work with -InfluxDB 1.x client libraries and third-party integrations like [Grafana](https://grafana.com) and others. - -View full v1 compatibility API documentation - -## Authentication - -InfluxDB 1.x compatibility endpoints require all query and write requests to be authenticated with an -[API token](/influxdb/v2/admin/tokens/) or 1.x-compatible -credentials. - -* [Authenticate with the Token scheme](#authenticate-with-the-token-scheme) -* [Authenticate with a 1.x username and password scheme](#authenticate-with-a-username-and-password-scheme) - -### Authenticate with the Token scheme -Token authentication requires the following credential: - -- **token**: InfluxDB [API token](/influxdb/v2/admin/tokens/) - -Use the `Authorization` header with the `Token` scheme to provide your token to InfluxDB. -The `Token` scheme is the word `Token`, a space, and your token (all case-sensitive). - -#### Syntax - -```http -Authorization: Token INFLUX_API_TOKEN -``` - -#### Example - -{{< code-tabs-wrapper >}} -{{% code-tabs %}} -[curl](#curl) -[Node.js](#nodejs) -{{% /code-tabs %}} -{{% code-tab-content %}} - - - -```sh -{{% get-shared-text "api/v1-compat/auth/oss/token-auth.sh" %}} -``` -{{% /code-tab-content %}} -{{% code-tab-content %}} -```js -{{% get-shared-text "api/v1-compat/auth/oss/token-auth.js" %}} -``` -{{% /code-tab-content %}} -{{< /code-tabs-wrapper >}} - -### Authenticate with a username and password scheme - -Use the following authentication schemes with clients that support the InfluxDB 1.x convention of `username` and `password` (that don't support the `Authorization: Token` scheme): - -- [Basic authentication](#basic-authentication) -- [Query string authentication](#query-string-authentication) - -#### Manage credentials - -{{% oss-only %}} - -Username and password schemes require the following credentials: -- **username**: 1.x username (this is separate from the UI login username) -- **password**: 1.x password or InfluxDB API token. - -{{% note %}} -#### Password or Token - -If you have [set a password](/influxdb/v2/install/upgrade/v1-to-v2/manual-upgrade/#1x-compatible-authorizations) for the 1.x-compatible username, provide the 1.x-compatible password. -If you haven't set a password for the 1.x-compatible username, provide the InfluxDB [authentication token](/influxdb/v2/admin/tokens/) as the password. -{{% /note %}} - -For more information, see how to create and manage -[1.x-compatible authorizations](/influxdb/v2/install/upgrade/v1-to-v2/manual-upgrade/#1x-compatible-authorizations) -when manually upgrading from InfluxDB v1 to v2. - -{{% /oss-only %}} - -{{% cloud-only %}} - -- **username**: InfluxDB Cloud username - (Use the email address you signed up with as your username--for example, `exampleuser@influxdata.com`.) -- **password**: InfluxDB Cloud [API token](/influxdb/cloud/admin/tokens/) - -{{% /cloud-only %}} - -#### Basic authentication - -Use the `Authorization` header with the `Basic` scheme to provide username and -password credentials to InfluxDB. - -{{% api/v1-compat/basic-auth-syntax %}} - -##### Syntax - -{{% oss-only %}} - -```http -Authorization: Basic INFLUX_USERNAME:INFLUX_PASSWORD_OR_TOKEN -``` - -{{% /oss-only %}} - - -{{% cloud-only %}} - -```http -Authorization: Basic exampleuser@influxdata.com:INFLUX_API_TOKEN -``` - -{{% /cloud-only %}} - -##### Example - -{{% code-placeholders "INFLUX_(USERNAME|PASSWORD_OR_TOKEN|API_TOKEN)|exampleuser@influxdata.com" %}} - -{{% oss-only %}} - -{{< code-tabs-wrapper >}} -{{% code-tabs %}} -[curl](#curl) -[Node.js](#nodejs) -{{% /code-tabs %}} -{{% code-tab-content %}} - - - -```sh -{{% get-shared-text "api/v1-compat/auth/oss/basic-auth.sh" %}} -``` -{{% /code-tab-content %}} -{{% code-tab-content %}} -```js -{{% get-shared-text "api/v1-compat/auth/oss/basic-auth.js" %}} -``` -{{% /code-tab-content %}} -{{< /code-tabs-wrapper >}} - -{{% /oss-only %}} - - -{{% cloud-only %}} - -{{< code-tabs-wrapper >}} -{{% code-tabs %}} -[curl](#curl) -[Node.js](#nodejs) -{{% /code-tabs %}} -{{% code-tab-content %}} - - - -```sh -{{% get-shared-text "api/v1-compat/auth/cloud/basic-auth.sh" %}} -``` -{{% /code-tab-content %}} - -{{% code-tab-content %}} -```js -{{% get-shared-text "api/v1-compat/auth/cloud/basic-auth.js" %}} -``` -{{% /code-tab-content %}} -{{< /code-tabs-wrapper >}} - -Replace the following: -- {{% code-placeholder-key %}}`exampleuser@influxdata.com`{{% /code-placeholder-key %}}: the email address that you signed up with -- {{% code-placeholder-key %}}`INFLUX_API_TOKEN`{{% /code-placeholder-key %}}: your [InfluxDB API token](/influxdb/cloud/reference/glossary/#token) - -{{% /cloud-only %}} - -#### Query string authentication -Use InfluxDB 1.x API parameters to provide credentials through the query string. - -{{% note %}} -##### Consider when using query string parameters - -- URL-encode query parameters that may contain whitespace or other special characters. -- Be aware of the [risks](https://owasp.org/www-community/vulnerabilities/Information_exposure_through_query_strings_in_url) when exposing sensitive data through URLs. -{{% /note %}} - -##### Syntax - -{{% oss-only %}} - -```http - /query/?u=INFLUX_USERNAME&p=INFLUX_PASSWORD_OR_TOKEN - /write/?u=INFLUX_USERNAME&p=INFLUX_PASSWORD_OR_TOKEN - ``` - -{{% /oss-only %}} - -{{% cloud-only %}} - -```http -/query/?u=INFLUX_USERNAME&p=INFLUX_API_TOKEN -/write/?u=INFLUX_USERNAME&p=INFLUX_API_TOKEN -``` - -{{% /cloud-only %}} - -##### Example - -{{% oss-only %}} -{{< code-tabs-wrapper >}} -{{% code-tabs %}} -[curl](#curl) -[Node.js](#nodejs) -{{% /code-tabs %}} -{{% code-tab-content %}} - - - -```sh -{{< get-shared-text "api/v1-compat/auth/oss/querystring-auth.sh" >}} -``` -{{% /code-tab-content %}} -{{% code-tab-content %}} -```js -{{< get-shared-text "api/v1-compat/auth/oss/querystring-auth.js" >}} -``` -{{% /code-tab-content %}} -{{< /code-tabs-wrapper >}} - -Replace the following: -- {{% code-placeholder-key %}}`INFLUX_USERNAME`{{% /code-placeholder-key %}}: [InfluxDB 1.x username](#manage-credentials) -- {{% code-placeholder-key %}}`INFLUX_PASSWORD_OR_TOKEN`{{% /code-placeholder-key %}}: [InfluxDB 1.x password or InfluxDB API token](#manage-credentials) - -{{% /oss-only %}} - -{{% cloud-only %}} - -{{< code-tabs-wrapper >}} -{{% code-tabs %}} -[curl](#curl) -[Node.js](#nodejs) -{{% /code-tabs %}} -{{% code-tab-content %}} - - - -```sh -{{% get-shared-text "api/v1-compat/auth/cloud/basic-auth.sh" %}} -``` -{{% /code-tab-content %}} - -{{% code-tab-content %}} -```js -{{% get-shared-text "api/v1-compat/auth/cloud/basic-auth.js" %}} -``` -{{% /code-tab-content %}} -{{< /code-tabs-wrapper >}} - -{{% /code-placeholders %}} - -Replace the following: -- {{% code-placeholder-key %}}`exampleuser@influxdata.com`{{% /code-placeholder-key %}}: the email address that you signed up with -- {{% code-placeholder-key %}}`INFLUX_API_TOKEN`{{% /code-placeholder-key %}}: your [InfluxDB API token](/influxdb/cloud/reference/glossary/#token) - -{{% /cloud-only %}} - -##### InfluxQL support - -The compatibility API supports InfluxQL, with the following caveats: - -- The `INTO` clause (for example, `SELECT ... INTO ...`) is not supported. -- With the exception of [`DELETE`](/influxdb/v1/query_language/manage-database/#delete-series-with-delete) and - [`DROP MEASUREMENT`](/influxdb/v1/query_language/manage-database/#delete-measurements-with-drop-measurement) queries, which are still allowed, - InfluxQL database management commands are not supported. - -## Compatibility endpoints - -{{< children readmore=true >}} + diff --git a/content/influxdb/v2/api-guide/influxdb-1x/dbrp.md b/content/influxdb/v2/api-guide/influxdb-1x/dbrp.md index 86a0136b3..a211d7fd1 100644 --- a/content/influxdb/v2/api-guide/influxdb-1x/dbrp.md +++ b/content/influxdb/v2/api-guide/influxdb-1x/dbrp.md @@ -28,7 +28,7 @@ databases and retention policies are mapped to buckets using the The DBRP mapping service uses the **database** and **retention policy** specified in [1.x compatibility API](/influxdb/v2/reference/api/influxdb-1x/) requests to route operations to a bucket. -{{% cloud-only %}} +{{% show-in "cloud,cloud-serverless" %}} {{% note %}} To query data in InfluxQL that was written using the `api/v2/write` API, @@ -36,7 +36,7 @@ you must **manually create a DBRP mapping** to map a bucket to a database and re For more information, see [Create DBRP mappings](/influxdb/v2/query-data/influxql/dbrp/#create-dbrp-mappings). {{% /note %}} -{{% /cloud-only %}} +{{% /show-in %}} ### Default retention policies @@ -46,7 +46,7 @@ the default retention policy for the specified database. Use the `influx` CLI or the InfluxDB API to set a retention policy as the default retention policy for a database. -{{% oss-only %}} +{{% show-in "v2" %}} ### When creating a bucket @@ -63,20 +63,20 @@ Virtual DBRP mappings are those that are created on your behalf. mapping uses the bucket name as the database and `autogen` as the retention policy. The `autogen` retention policy is set as the default retention policy. -{{% /oss-only %}} +{{% /show-in %}} ### When writing data -{{% oss-only %}} +{{% show-in "v2" %}} When writing data using the [`/write` compatibility endpoint](/influxdb/v2/reference/api/influxdb-1x/write/), the DBRP mapping service uses the database and retention policy specified in the request to write the data to the appropriate bucket. -{{% /oss-only %}} +{{% /show-in %}} -{{% cloud-only %}} +{{% show-in "cloud,cloud-serverless" %}} When writing data using the [`/write` compatibility endpoint](/influxdb/v2/reference/api/influxdb-1x/write/), @@ -91,11 +91,11 @@ the DBRP mapping service checks for a bucket mapped to the database and retentio database retention policy is used, a DBRP mapping is added to the bucket, and data is written to the bucket. -{{% /cloud-only %}} +{{% /show-in %}} ### When querying data -{{% oss-only %}} +{{% show-in "v2" %}} When querying data from InfluxDB {{< current-version >}} using the [`/query` compatibility endpoint](/influxdb/v2/reference/api/influxdb-1x/query/), @@ -103,9 +103,9 @@ the DBRP mapping service uses the database and retention policy specified in the request to query data from the appropriate bucket. If no retention policy is specified, the database's default retention policy is used. -{{% /oss-only %}} +{{% /show-in %}} -{{% cloud-only %}} +{{% show-in "cloud,cloud-serverless" %}} When querying data from InfluxDB {{< current-version >}} using the [`/query` compatibility endpoint](/influxdb/v2/reference/api/influxdb-1x/query/), @@ -118,7 +118,7 @@ the DBRP mapping service checks for the specified database and retention policy _For more information on the DBRP mapping API, see the [`/api/v2/dbrps` endpoint documentation](/influxdb/v2/api/#tag/DBRPs)._ -{{% /cloud-only %}} +{{% /show-in %}} {{% note %}} #### A DBRP combination can only be mapped to a single bucket diff --git a/content/influxdb/v2/api-guide/influxdb-1x/query.md b/content/influxdb/v2/api-guide/influxdb-1x/query.md index de5da77ae..284ebd6e2 100644 --- a/content/influxdb/v2/api-guide/influxdb-1x/query.md +++ b/content/influxdb/v2/api-guide/influxdb-1x/query.md @@ -30,7 +30,7 @@ The `/query` compatibility endpoint uses the **database** and **retention policy specified in the query request to map the request to an InfluxDB bucket. For more information, see [Database and retention policy mapping](/influxdb/v2/reference/api/influxdb-1x/dbrp). -{{% cloud-only %}} +{{% show-in "cloud,cloud-serverless" %}} {{% note %}} If you have an existing bucket that doesn't follow the **database/retention-policy** naming convention, @@ -38,7 +38,7 @@ you **must** [manually create a database and retention policy mapping](/influxdb to query that bucket with the `/query` compatibility API. {{% /note %}} -{{% /cloud-only %}} +{{% /show-in %}} ## Authentication @@ -98,7 +98,7 @@ The following precisions are available: ##### Query using basic authentication -{{% oss-only %}} +{{% show-in "v2" %}} {{< code-tabs-wrapper >}} {{% code-tabs %}} @@ -120,9 +120,9 @@ The following precisions are available: {{% /code-tab-content %}} {{< /code-tabs-wrapper >}} -{{% /oss-only %}} +{{% /show-in %}} -{{% cloud-only %}} +{{% show-in "cloud,cloud-serverless" %}} {{< code-tabs-wrapper >}} {{% code-tabs %}} @@ -145,7 +145,7 @@ The following precisions are available: {{< /code-tabs-wrapper >}} -{{% /cloud-only %}} +{{% /show-in %}} ##### Query a non-default retention policy diff --git a/content/influxdb/v2/api-guide/influxdb-1x/write.md b/content/influxdb/v2/api-guide/influxdb-1x/write.md index 8e626383e..9790f7aea 100644 --- a/content/influxdb/v2/api-guide/influxdb-1x/write.md +++ b/content/influxdb/v2/api-guide/influxdb-1x/write.md @@ -29,7 +29,7 @@ to the `/write` endpoint. POST http://localhost:8086/write -{{% cloud-only %}} +{{% show-in "cloud,cloud-serverless" %}} {{% note %}} If you have an existing bucket that doesn't follow the `database/retention-policy` naming convention, @@ -37,11 +37,11 @@ you _must_ [manually create a database and retention policy mapping](/influxdb/v to write data to that bucket with the `/write` compatibility API. {{% /note %}} -{{% /cloud-only %}} +{{% /show-in %}} ## Authentication -{{% oss-only %}} +{{% show-in "v2" %}} Use one of the following authentication methods: - **token authentication** @@ -50,13 +50,13 @@ Use one of the following authentication methods: _For more information, see [Authentication](/influxdb/v2/reference/api/influxdb-1x/#authentication)._ -{{% /oss-only %}} +{{% /show-in %}} -{{% cloud-only %}} +{{% show-in "cloud,cloud-serverless" %}} {{% api/v1-compat/cloud/authentication %}} -{{% /cloud-only %}} +{{% /show-in %}} ## Request body Include your line protocol in the request body. @@ -66,7 +66,7 @@ encode the line protocol. ## Query string parameters -{{% oss-only %}} +{{% show-in "v2" %}} ### u (Optional) The 1.x **username** to authenticate the request. @@ -76,9 +76,9 @@ _See [query string authentication](/influxdb/v2/reference/api/influxdb-1x/#query (Optional) The 1.x **password** to authenticate the request. _See [query string authentication](/influxdb/v2/reference/api/influxdb-1x/#query-string-authentication)._ -{{% /oss-only %}} +{{% /show-in %}} -{{% cloud-only %}} +{{% show-in "cloud,cloud-serverless" %}} ### u (Optional) The InfluxDB Cloud **username** to authenticate the request. @@ -88,7 +88,7 @@ _See [query string authentication](/influxdb/cloud/reference/api/influxdb-1x/#qu (Optional) The InfluxDB Cloud **API token** to authenticate the request. _See [query string authentication](/influxdb/cloud/reference/api/influxdb-1x/#query-string-authentication)._ -{{% /cloud-only %}} +{{% /show-in %}} ### db ({{< req >}}) The **database** to write data to. @@ -134,7 +134,7 @@ influx setup \ ``` --> -{{% oss-only %}} +{{% show-in "v2" %}} {{% code-placeholders "DATABASE_NAME|USERNAME|PASSWORD_OR_TOKEN|API_TOKEN|exampleuser@influxdata.com" %}} ```sh @@ -144,9 +144,9 @@ curl --request POST http://localhost:8086/write?db=DATABASE_NAME \ ``` {{% /code-placeholders %}} -{{% /oss-only %}} +{{% /show-in %}} -{{% cloud-only %}} +{{% show-in "cloud,cloud-serverless" %}} {{% code-placeholders "DATABASE_NAME|USERNAME|PASSWORD_OR_TOKEN|API_TOKEN|exampleuser@influxdata.com" %}} ```sh curl --request POST https://cloud2.influxdata.com/write?db=DATABASE_NAME \ @@ -155,7 +155,7 @@ curl --request POST https://cloud2.influxdata.com/write?db=DATABASE_NAME \ ``` {{% /code-placeholders %}} -{{% /cloud-only %}} +{{% /show-in %}} ##### Write data using token authentication @@ -209,7 +209,7 @@ curl --request POST http://localhost:8086/write?db=DATABASE_NAME \ ``` {{% /code-placeholders %}} -{{% oss-only %}} +{{% show-in "v2" %}} Replace the following: @@ -218,9 +218,9 @@ Replace the following: - {{% code-placeholder-key %}}`PASSWORD_OR_TOKEN`{{% /code-placeholder-key %}}: your [InfluxDB 1.x password or InfluxDB API token](/influxdb/v2/reference/api/influxdb-1x/#manage-credentials) - {{% code-placeholder-key %}}`API_TOKEN`{{% /code-placeholder-key %}}: your [InfluxDB API token](/influxdb/v2/admin/tokens/) -{{% /oss-only %}} +{{% /show-in %}} -{{% cloud-only %}} +{{% show-in "cloud,cloud-serverless" %}} Replace the following: @@ -228,4 +228,4 @@ Replace the following: - {{% code-placeholder-key %}}}`exampleuser@influxdata.com`{{% /code-placeholder-key %}}: the email address that you signed up with - {{% code-placeholder-key %}}`API_TOKEN`{{% /code-placeholder-key %}}: your [InfluxDB API token](/influxdb/v2/admin/tokens/) -{{% /cloud-only %}} +{{% /show-in %}} diff --git a/content/influxdb/v2/api-guide/tutorials/_index.md b/content/influxdb/v2/api-guide/tutorials/_index.md index ffe0ab820..b9fb91f28 100644 --- a/content/influxdb/v2/api-guide/tutorials/_index.md +++ b/content/influxdb/v2/api-guide/tutorials/_index.md @@ -8,23 +8,8 @@ menu: name: Client library tutorials parent: Develop with the API influxdb/v2/tags: [api] +source: /shared/influxdb-v2/api-guide/tutorials/_index.md --- -Follow step-by-step tutorials to build an Internet-of-Things (IoT) application with InfluxData client libraries and your favorite framework or language. -InfluxData and the user community maintain client libraries for developers who want to take advantage of: - -- Idioms for InfluxDB requests, responses, and errors. -- Common patterns in a familiar programming language. -- Faster development and less boilerplate code. - -In these tutorials, you'll use the InfluxDB API and -client libraries to build a modern application, and learn the following: - -- InfluxDB core concepts. -- How the application interacts with devices and InfluxDB. -- How to authenticate apps and devices to the API. -- How to install a client library. -- How to write and query data in InfluxDB. -- How to use the InfluxData UI libraries to format data and create visualizations. - -{{< children >}} + diff --git a/content/influxdb/v2/api-guide/tutorials/nodejs.md b/content/influxdb/v2/api-guide/tutorials/nodejs.md index 8424f60a9..2907183ad 100644 --- a/content/influxdb/v2/api-guide/tutorials/nodejs.md +++ b/content/influxdb/v2/api-guide/tutorials/nodejs.md @@ -11,513 +11,8 @@ menu: name: JavaScript parent: Client library tutorials influxdb/v2/tags: [api, javascript, nodejs] +source: /shared/influxdb-v2/api-guide/tutorials/nodejs.md --- -{{% api/iot-starter-intro %}} - -## Contents - -- [Contents](#contents) -- [Set up InfluxDB](#set-up-influxdb) -- [Introducing IoT Starter](#introducing-iot-starter) -- [Install Yarn](#install-yarn) -- [Create the application](#create-the-application) -- [Install InfluxDB client library](#install-influxdb-client-library) -- [Configure the client library](#configure-the-client-library) -- [Build the API](#build-the-api) -- [Create the API to list devices](#create-the-api-to-list-devices) - - [Handle requests for device information](#handle-requests-for-device-information) - - [Retrieve and list devices](#retrieve-and-list-devices) -- [Create the API to register devices](#create-the-api-to-register-devices) - - [Create an authorization for the device](#create-an-authorization-for-the-device) - - [Write the device authorization to a bucket](#write-the-device-authorization-to-a-bucket) -- [Install and run the UI](#install-and-run-the-ui) - -## Set up InfluxDB - -If you haven't already, [create an InfluxDB Cloud account](https://www.influxdata.com/products/influxdb-cloud/) or [install InfluxDB OSS](https://www.influxdata.com/products/influxdb/). - -The IoT Starter example app assumes the following prerequisites: - -- An InfluxDB [org ID](/influxdb/v2/admin/organizations/view-orgs/) -- An [API token](/influxdb/v2/admin/tokens/create-token/) (for example, an **All Access token**) that has read and write permissions for the buckets -- A [bucket](/influxdb/v2/admin/buckets/create-bucket/#create-a-bucket-using-the-influxdb-api) named `iot_center` for storing time series data from devices -- A [bucket](/influxdb/v2/admin/buckets/create-bucket/#create-a-bucket-using-the-influxdb-api) named `iot_center_devices` for storing device metadata and API token IDs - -{{% note %}} - -#### Use restricted tokens for production apps - -For a production application, create and use a -{{% cloud-only %}}custom{{% /cloud-only %}}{{% oss-only %}}read-write{{% /oss-only %}} -token with minimal permissions and only use it with a single client or application. - -{{% /note %}} - -## Introducing IoT Starter - -The application architecture has four layers: - -- **InfluxDB API**: InfluxDB v2 API. -- **IoT device**: Virtual or physical devices write IoT data to the InfluxDB API. -- **UI**: Sends requests to the server and renders views in the browser. -- **API**: Receives requests from the UI, sends requests to InfluxDB, and processes responses from InfluxDB. - -{{% note %}} -For the complete code referenced in this tutorial, see the [influxdata/iot-api-js repository](https://github.com/influxdata/iot-api-js). -{{% /note %}} - -## Install Yarn - -If you haven't already installed `yarn`, follow the [Yarn package manager installation instructions](https://yarnpkg.com/getting-started/install#nodejs-1610-1) for your version of Node.js. - -- To check the installed `yarn` version, enter the following code into your terminal: - - ```bash - yarn --version - ``` - -## Create the application - -Create a directory that will contain your `iot-api` projects. -The following example code creates an `iot-api` directory in your home directory -and changes to the new directory: - -```bash -mkdir ~/iot-api-apps -cd ~/iot-api-apps -``` - -Follow these steps to create a JavaScript application with [Next.js](https://nextjs.org/): - -1. In your `~/iot-api-apps` directory, open a terminal and enter the following commands to create the `iot-api-js` app from the NextJS [learn-starter template](https://github.com/vercel/next-learn/tree/master/basics/learn-starter): - - ```bash - yarn create-next-app iot-api-js --example "https://github.com/vercel/next-learn/tree/master/basics/learn-starter" - ``` - -2. After the installation completes, enter the following commands in your terminal to go into your `./iot-api-js` directory and start the development server: - - ```bash - cd iot-api-js - yarn dev -p 3001 - ``` - -To view the application, visit in your browser. - -## Install InfluxDB client library - -The InfluxDB client library provides the following InfluxDB API interactions: - -- Query data with the Flux language. -- Write data to InfluxDB. -- Batch data in the background. -- Retry requests automatically on failure. - -1. Enter the following command into your terminal to install the client library: - - ```bash - yarn add @influxdata/influxdb-client - ``` - -2. Enter the following command into your terminal to install `@influxdata/influxdb-client-apis`, the _management APIs_ that create, modify, and delete authorizations, buckets, tasks, and other InfluxDB resources: - - ```bash - yarn add @influxdata/influxdb-client-apis - ``` - -For more information about the client library, see the [influxdata/influxdb-client-js repo](https://github.com/influxdata/influxdb-client-js). - -## Configure the client library - -InfluxDB client libraries require configuration properties from your InfluxDB environment. -Typically, you'll provide the following properties as environment variables for your application: - -- `INFLUX_URL` -- `INFLUX_TOKEN` -- `INFLUX_ORG` -- `INFLUX_BUCKET` -- `INFLUX_BUCKET_AUTH` - -Next.js uses the `env` module to provide environment variables to your application. - -The `./.env.development` file is versioned and contains non-secret default settings for your _development_ environment. - -```bash -# .env.development - -INFLUX_URL=http://localhost:8086 -INFLUX_BUCKET=iot_center -INFLUX_BUCKET_AUTH=iot_center_devices -``` - -To configure secrets and settings that aren't added to version control, -create a `./.env.local` file and set the variables--for example, set your InfluxDB token and organization: - -```sh -# .env.local - -# INFLUX_TOKEN -# InfluxDB API token used by the application server to send requests to InfluxDB. -# For convenience in development, use an **All Access** token. - -INFLUX_TOKEN=29Xx1KH9VkASPR2DSfRfFd82OwGD... - -# INFLUX_ORG -# InfluxDB organization ID you want to use in development. - -INFLUX_ORG=48c88459ee424a04 -``` - -Enter the following commands into your terminal to restart and load the `.env` files: - - 1. `CONTROL+C` to stop the application. - 2. `yarn dev` to start the application. - -Next.js sets variables that you can access in the `process.env` object--for example: - -```ts -console.log(process.env.INFLUX_ORG) -``` - -## Build the API - -Your application API provides server-side HTTP endpoints that process requests from the UI. -Each API endpoint is responsible for the following: - -1. Listen for HTTP requests (from the UI). -2. Translate requests into InfluxDB API requests. -3. Process InfluxDB API responses and handle errors. -4. Respond with status and data (for the UI). - -## Create the API to list devices - -Add the `/api/devices` API endpoint that retrieves, processes, and lists devices. -`/api/devices` uses the `/api/v2/query` InfluxDB API endpoint to query `INFLUX_BUCKET_AUTH` for a registered device. - -### Handle requests for device information - -1. Create a `./pages/api/devices/[[...deviceParams]].js` file to handle requests for `/api/devices` and `/api/devices//measurements/`. - -2. In the file, export a Next.js request `handler` function. -[See the example](https://github.com/influxdata/iot-api-js/blob/18d34bcd59b93ad545c5cd9311164c77f6d1995a/pages/api/devices/%5B%5B...deviceParams%5D%5D.js). - - {{% note %}} -In Next.js, the filename pattern `[[...param]].js` creates a _catch-all_ API route. -To learn more, see [Next.js dynamic API routes](https://nextjs.org/docs/api-routes/dynamic-api-routes). - {{% /note %}} - -### Retrieve and list devices - -Retrieve registered devices in `INFLUX_BUCKET_AUTH` and process the query results. - -1. Create a Flux query that gets the last row of each [series](/influxdb/v2/reference/glossary#series) that contains a `deviceauth` measurement. - The example query below returns rows that contain the `key` field (authorization ID) and excludes rows that contain a `token` field (to avoid exposing tokens to the UI). - - ```js - // Flux query finds devices - from(bucket:`${INFLUX_BUCKET_AUTH}`) - |> range(start: 0) - |> filter(fn: (r) => r._measurement == "deviceauth" and r._field != "token") - |> last() - ``` - -2. Use the `QueryApi` client to send the Flux query to the `POST /api/v2/query` InfluxDB API endpoint. - -Create a `./pages/api/devices/_devices.js` file that contains the following: - -{{< code-tabs-wrapper >}} -{{% code-tabs %}} -[Node.js](#nodejs) -{{% /code-tabs %}} -{{% code-tab-content %}} - -{{% truncate %}} - -```ts -import { InfluxDB } from '@influxdata/influxdb-client' -import { flux } from '@influxdata/influxdb-client' - -const INFLUX_ORG = process.env.INFLUX_ORG -const INFLUX_BUCKET_AUTH = process.env.INFLUX_BUCKET_AUTH -const influxdb = new InfluxDB({url: process.env.INFLUX_URL, token: process.env.INFLUX_TOKEN}) - -/** - * Gets devices or a particular device when deviceId is specified. Tokens - * are not returned unless deviceId is specified. It can also return devices - * with empty/unknown key, such devices can be ignored (InfluxDB authorization is not associated). - * @param deviceId optional deviceId - * @returns promise with an Record. - */ - export async function getDevices(deviceId) { - const queryApi = influxdb.getQueryApi(INFLUX_ORG) - const deviceFilter = - deviceId !== undefined - ? flux` and r.deviceId == "${deviceId}"` - : flux` and r._field != "token"` - const fluxQuery = flux`from(bucket:${INFLUX_BUCKET_AUTH}) - |> range(start: 0) - |> filter(fn: (r) => r._measurement == "deviceauth"${deviceFilter}) - |> last()` - const devices = {} - - return await new Promise((resolve, reject) => { - queryApi.queryRows(fluxQuery, { - next(row, tableMeta) { - const o = tableMeta.toObject(row) - const deviceId = o.deviceId - if (!deviceId) { - return - } - const device = devices[deviceId] || (devices[deviceId] = {deviceId}) - device[o._field] = o._value - if (!device.updatedAt || device.updatedAt < o._time) { - device.updatedAt = o._time - } - }, - error: reject, - complete() { - resolve(devices) - }, - }) - }) -} -``` - -{{% /truncate %}} - -{{% caption %}}[iot-api-js/pages/api/devices/_devices.js getDevices(deviceId)](https://github.com/influxdata/iot-api-js/blob/18d34bcd59b93ad545c5cd9311164c77f6d1995a/pages/api/devices/_devices.js){{% /caption %}} - -{{% /code-tab-content %}} -{{< /code-tabs-wrapper >}} - -The `_devices` module exports a `getDevices(deviceId)` function that queries -for registered devices, processes the data, and returns a Promise with the result. -If you invoke the function as `getDevices()` (without a _`deviceId`_), -it retrieves all `deviceauth` points and returns a Promise with `{ DEVICE_ID: ROW_DATA }`. - -To send the query and process results, the `getDevices(deviceId)` function uses the `QueryAPI queryRows(query, consumer)` method. -`queryRows` executes the `query` and provides the Annotated CSV result as an Observable to the `consumer`. -`queryRows` has the following TypeScript signature: - -```ts -queryRows( - query: string | ParameterizedQuery, - consumer: FluxResultObserver -): void -``` - -{{% caption %}}[@influxdata/influxdb-client-js QueryAPI](https://github.com/influxdata/influxdb-client-js/blob/3db2942432b993048d152e0d0e8ec8499eedfa60/packages/core/src/QueryApi.ts){{% /caption %}} - -The `consumer` that you provide must implement the [`FluxResultObserver` interface](https://github.com/influxdata/influxdb-client-js/blob/3db2942432b993048d152e0d0e8ec8499eedfa60/packages/core/src/results/FluxResultObserver.ts) and provide the following callback functions: - -- `next(row, tableMeta)`: processes the next row and table metadata--for example, to prepare the response. -- `error(error)`: receives and handles errors--for example, by rejecting the Promise. -- `complete()`: signals when all rows have been consumed--for example, by resolving the Promise. - -To learn more about Observers, see the [RxJS Guide](https://rxjs.dev/guide/observer). - -## Create the API to register devices - -In this application, a _registered device_ is a point that contains your device ID, authorization ID, and API token. -The API token and authorization permissions allow the device to query and write to `INFLUX_BUCKET`. -In this section, you add the API endpoint that handles requests from the UI, creates an authorization in InfluxDB, -and writes the registered device to the `INFLUX_BUCKET_AUTH` bucket. -To learn more about API tokens and authorizations, see [Manage API tokens](/influxdb/v2/admin/tokens/) - -The application API uses the following `/api/v2` InfluxDB API endpoints: - -- `POST /api/v2/query`: to query `INFLUX_BUCKET_AUTH` for a registered device. -- `GET /api/v2/buckets`: to get the bucket ID for `INFLUX_BUCKET`. -- `POST /api/v2/authorizations`: to create an authorization for the device. -- `POST /api/v2/write`: to write the device authorization to `INFLUX_BUCKET_AUTH`. - -1. Add a `./pages/api/devices/create.js` file to handle requests for `/api/devices/create`. -2. In the file, export a Next.js request `handler` function that does the following: - - 1. Accept a device ID in the request body. - 2. Query `INFLUX_BUCKET_AUTH` and respond with an error if an authorization exists for the device. - 3. [Create an authorization for the device](#create-an-authorization-for-the-device). - 4. [Write the device ID and authorization to `INFLUX_BUCKET_AUTH`](#write-the-device-authorization-to-a-bucket). - 5. Respond with `HTTP 200` when the write request completes. - -[See the example](https://github.com/influxdata/iot-api-js/blob/25b38c94a1f04ea71f2ef4b9fcba5350d691cb9d/pages/api/devices/create.js). - -### Create an authorization for the device - -In this section, you create an authorization with _read_-_write_ permission to `INFLUX_BUCKET` and receive an API token for the device. -The example below uses the following steps to create the authorization: - -1. Instantiate the `AuthorizationsAPI` client and `BucketsAPI` client with the configuration. -2. Retrieve the bucket ID. -3. Use the client library to send a `POST` request to the `/api/v2/authorizations` InfluxDB API endpoint. - -In `./api/devices/create.js`, add the following `createAuthorization(deviceId)` function: - -{{< code-tabs-wrapper >}} -{{% code-tabs %}} -[Node.js](#nodejs) -{{% /code-tabs %}} -{{% code-tab-content %}} - -{{% truncate %}} - -```js -import { InfluxDB } from '@influxdata/influxdb-client' -import { getDevices } from './_devices' -import { AuthorizationsAPI, BucketsAPI } from '@influxdata/influxdb-client-apis' -import { Point } from '@influxdata/influxdb-client' - -const INFLUX_ORG = process.env.INFLUX_ORG -const INFLUX_BUCKET_AUTH = process.env.INFLUX_BUCKET_AUTH -const INFLUX_BUCKET = process.env.INFLUX_BUCKET - -const influxdb = new InfluxDB({url: process.env.INFLUX_URL, token: process.env.INFLUX_TOKEN}) - -/** - * Creates an authorization for a supplied deviceId - * @param {string} deviceId client identifier - * @returns {import('@influxdata/influxdb-client-apis').Authorization} promise with authorization or an error - */ -async function createAuthorization(deviceId) { - const authorizationsAPI = new AuthorizationsAPI(influxdb) - const bucketsAPI = new BucketsAPI(influxdb) - const DESC_PREFIX = 'IoTCenterDevice: ' - - const buckets = await bucketsAPI.getBuckets({name: INFLUX_BUCKET, orgID: INFLUX_ORG}) - const bucketId = buckets.buckets[0]?.id - - return await authorizationsAPI.postAuthorizations( - { - body: { - orgID: INFLUX_ORG, - description: DESC_PREFIX + deviceId, - permissions: [ - { - action: 'read', - resource: {type: 'buckets', id: bucketId, orgID: INFLUX_ORG}, - }, - { - action: 'write', - resource: {type: 'buckets', id: bucketId, orgID: INFLUX_ORG}, - }, - ], - }, - } - ) - -} -``` - -{{% /truncate %}} -{{% caption %}}[iot-api-js/pages/api/devices/create.js](https://github.com/influxdata/iot-api-js/blob/42a37d683b5e4df601422f85d2c22f5e9d592e68/pages/api/devices/create.js){{% /caption %}} - -{{% /code-tab-content %}} -{{< /code-tabs-wrapper >}} - -To create an authorization that has _read_-_write_ permission to `INFLUX_BUCKET`, you need the bucket ID. -To retrieve the bucket ID, -`createAuthorization(deviceId)` calls the `BucketsAPI getBuckets` function that sends a `GET` request to -the `/api/v2/buckets` InfluxDB API endpoint. -`createAuthorization(deviceId)` then passes a new authorization in the request body with the following: - -- Bucket ID. -- Organization ID. -- Description: `IoTCenterDevice: DEVICE_ID`. -- List of permissions to the bucket. - -To learn more about API tokens and authorizations, see [Manage API tokens](/influxdb/v2/admin/tokens/). - -Next, [write the device authorization to a bucket](#write-the-device-authorization-to-a-bucket). - -### Write the device authorization to a bucket - -With a device authorization in InfluxDB, write a point for the device and authorization details to `INFLUX_BUCKET_AUTH`. -Storing the device authorization in a bucket allows you to do the following: - -- Report device authorization history. -- Manage devices with and without tokens. -- Assign the same token to multiple devices. -- Refresh tokens. - -To write a point to InfluxDB, use the InfluxDB client library to send a `POST` request to the `/api/v2/write` InfluxDB API endpoint. -In `./pages/api/devices/create.js`, add the following `createDevice(deviceId)` function: - -{{< code-tabs-wrapper >}} -{{% code-tabs %}} -[Node.js](#nodejs) -{{% /code-tabs %}} -{{% code-tab-content %}} - -```ts -/** Creates an authorization for a deviceId and writes it to a bucket */ -async function createDevice(deviceId) { - let device = (await getDevices(deviceId)) || {} - let authorizationValid = !!Object.values(device)[0]?.key - if(authorizationValid) { - console.log(JSON.stringify(device)) - return Promise.reject('This device ID is already registered and has an authorization.') - } else { - console.log(`createDeviceAuthorization: deviceId=${deviceId}`) - const authorization = await createAuthorization(deviceId) - const writeApi = influxdb.getWriteApi(INFLUX_ORG, INFLUX_BUCKET_AUTH, 'ms', { - batchSize: 2, - }) - const point = new Point('deviceauth') - .tag('deviceId', deviceId) - .stringField('key', authorization.id) - .stringField('token', authorization.token) - writeApi.writePoint(point) - await writeApi.close() - return - } -} -``` - -{{% caption %}}[iot-api-js/pages/api/devices/create.js](https://github.com/influxdata/iot-api-js/blob/25b38c94a1f04ea71f2ef4b9fcba5350d691cb9d/pages/api/devices/create.js){{% /caption %}} - -{{% /code-tab-content %}} -{{< /code-tabs-wrapper >}} - -`createDevice(device_id)` takes a _`device_id`_ and writes data to `INFLUX_BUCKET_AUTH` in the following steps: - -1. Initialize `InfluxDBClient()` with `url`, `token`, and `org` values from the configuration. -2. Initialize a `WriteAPI` client for writing data to an InfluxDB bucket. -3. Create a `Point`. -4. Use `writeApi.writePoint(point)` to write the `Point` to the bucket. - -The function writes a point with the following elements: - -| Element | Name | Value | -|:------------|:-----------|:--------------------------| -| measurement | | `deviceauth` | -| tag | `deviceId` | device ID | -| field | `key` | authorization ID | -| field | `token` | authorization (API) token | - -## Install and run the UI - -`influxdata/iot-api-ui` is a standalone [Next.js React](https://nextjs.org/docs/basic-features/pages) UI that uses your application API to write and query data in InfluxDB. -`iot-api-ui` uses Next.js _[rewrites](https://nextjs.org/docs/api-reference/next.config.js/rewrites)_ to route all requests in the `/api/` path to your API. - -To install and run the UI, do the following: - -1. In your `~/iot-api-apps` directory, clone the [`influxdata/iot-api-ui` repo](https://github.com/influxdata/iot-api-ui) and go into the `iot-api-ui` directory--for example: - - ```bash - cd ~/iot-api-apps - git clone git@github.com:influxdata/iot-api-ui.git - cd ./iot-app-ui - ``` - -2. The `./.env.development` file contains default configuration settings that you can - edit or override (with a `./.env.local` file). -3. To start the UI, enter the following command into your terminal: - - ```bash - yarn dev - ``` - - To view the list and register devices, visit in your browser. - -To learn more about the UI components, see [`influxdata/iot-api-ui`](https://github.com/influxdata/iot-api-ui). + diff --git a/content/influxdb/v2/api-guide/tutorials/python.md b/content/influxdb/v2/api-guide/tutorials/python.md index e8aa3cc72..5d36ffb19 100644 --- a/content/influxdb/v2/api-guide/tutorials/python.md +++ b/content/influxdb/v2/api-guide/tutorials/python.md @@ -12,508 +12,8 @@ menu: name: Python parent: Client library tutorials influxdb/v2/tags: [api, python] +source: /shared/influxdb-v2/api-guide/tutorials/python.md --- -{{% api/iot-starter-intro %}} -- How to use the InfluxData UI libraries to format data and create visualizations. - -## Contents - -- [Contents](#contents) -- [Set up InfluxDB](#set-up-influxdb) -- [Introducing IoT Starter](#introducing-iot-starter) -- [Create the application](#create-the-application) -- [Install InfluxDB client library](#install-influxdb-client-library) -- [Configure the client library](#configure-the-client-library) -- [Build the API](#build-the-api) -- [Create the API to register devices](#create-the-api-to-register-devices) - - [Create an authorization for the device](#create-an-authorization-for-the-device) - - [Write the device authorization to a bucket](#write-the-device-authorization-to-a-bucket) -- [Create the API to list devices](#create-the-api-to-list-devices) -- [Create IoT virtual device](#create-iot-virtual-device) -- [Write telemetry data](#write-telemetry-data) -- [Query telemetry data](#query-telemetry-data) -- [Define API responses](#define-api-responses) -- [Install and run the UI](#install-and-run-the-ui) - -## Set up InfluxDB - -If you haven't already, [create an InfluxDB Cloud account](https://www.influxdata.com/products/influxdb-cloud/) or [install InfluxDB OSS](https://www.influxdata.com/products/influxdb/). - -The IoT Starter example app assumes the following prerequisites: - -- An InfluxDB [org ID](/influxdb/v2/admin/organizations/view-orgs/) -- An [API token](/influxdb/v2/admin/tokens/create-token/) (for example, an **All Access token**) that has read and write permissions for the buckets -- A [bucket](/influxdb/v2/admin/buckets/create-bucket/#create-a-bucket-using-the-influxdb-api) named `iot_center` for storing time series data from devices -- A [bucket](/influxdb/v2/admin/buckets/create-bucket/#create-a-bucket-using-the-influxdb-api) named `iot_center_devices` for storing device metadata and API token IDs - -## Introducing IoT Starter - -The application architecture has four layers: - -- **InfluxDB API**: InfluxDB v2 API. -- **IoT device**: Virtual or physical devices write IoT data to the InfluxDB API. -- **UI**: Sends requests to the server and renders views in the browser. -- **API**: Receives requests from the UI, sends requests to InfluxDB, - and processes responses from InfluxDB. - -{{% note %}} -For the complete code referenced in this tutorial, see the [influxdata/iot-api-python repository](https://github.com/influxdata/iot-api-python). -{{% /note %}} - -## Create the application - -Create a directory that will contain your `iot-api` projects. -The following example code creates an `iot-api` directory in your home directory -and changes to the new directory: - -```bash -mkdir ~/iot-api-apps -cd ~/iot-api-apps -``` - -Use [Flask](https://flask.palletsprojects.com/), a lightweight Python web -framework, -to create your application. - -1. In your `~/iot-api-apps` directory, open a terminal and enter the following commands to create and navigate into a new project directory: - - ```bash - mkdir iot-api-python && cd $_ - ``` - -2. Enter the following commands in your terminal to create and activate a Python virtual environment for the project: - - ```bash - # Create a new virtual environment named "virtualenv" - # Python 3.8+ - python -m venv virtualenv - - # Activate the virtualenv (OS X & Linux) - source virtualenv/bin/activate - ``` - -3. After activation completes, enter the following commands in your terminal to install Flask with the `pip` package installer (included with Python): - - ```bash - pip install Flask - ``` - -4. In your project, create a `app.py` file that: - - 1. Imports the Flask package. - 2. Instantiates a Flask application. - 3. Provides a route to execute the application. - - ```python - from flask import Flask - app = Flask(__name__) - - @app.route("/") - def hello(): - return "Hello World!" - ``` - - {{% caption %}}[influxdata/iot-api-python app.py](https://github.com/influxdata/iot-api-python/blob/main/app.py){{% /caption %}} - - Start your application. - The following example code starts the application - on `http://localhost:3001` with debugging and hot-reloading enabled: - - ```bash - export FLASK_ENV=development - flask run -h localhost -p 3001 - ``` - - In your browser, visit to view the “Hello World!” response. - -## Install InfluxDB client library - -The InfluxDB client library provides the following InfluxDB API interactions: - -- Query data with the Flux language. -- Write data to InfluxDB. -- Batch data in the background. -- Retry requests automatically on failure. - -Enter the following command into your terminal to install the client library: - -```bash -pip install influxdb-client -``` - -For more information about the client library, see the [influxdata/influxdb-client-python repo](https://github.com/influxdata/influxdb-client-python). - -## Configure the client library - -InfluxDB client libraries require configuration properties from your InfluxDB environment. -Typically, you'll provide the following properties as environment variables for your application: - -- `INFLUX_URL` -- `INFLUX_TOKEN` -- `INFLUX_ORG` -- `INFLUX_BUCKET` -- `INFLUX_BUCKET_AUTH` - -To set up the client configuration, create a `config.ini` in your project's top -level directory and paste the following to provide the necessary InfluxDB credentials: - -```ini -[APP] -INFLUX_URL = -INFLUX_TOKEN = -INFLUX_ORG = -INFLUX_BUCKET = iot_center -INFLUX_BUCKET_AUTH = iot_center_devices -``` - -{{% caption %}}[/iot-api-python/config.ini](https://github.com/influxdata/iot-api-python/blob/main/config.ini){{% /caption %}} - -Replace the following: - -- **``**: your InfluxDB instance URL. -- **``**: your InfluxDB [API token](#authorization) with permission to query (_read_) buckets -and create (_write_) authorizations for devices. -- **``**: your InfluxDB organization ID. - -## Build the API - -Your application API provides server-side HTTP endpoints that process requests from the UI. -Each API endpoint is responsible for the following: - -1. Listen for HTTP requests (from the UI). -2. Translate requests into InfluxDB API requests. -3. Process InfluxDB API responses and handle errors. -4. Respond with status and data (for the UI). - -## Create the API to register devices - -In this application, a _registered device_ is a point that contains your device ID, authorization ID, and API token. -The API token and authorization permissions allow the device to query and write to `INFLUX_BUCKET`. -In this section, you add the API endpoint that handles requests from the UI, creates an authorization in InfluxDB, -and writes the registered device to the `INFLUX_BUCKET_AUTH` bucket. -To learn more about API tokens and authorizations, see [Manage API tokens](/influxdb/v2/admin/tokens/) - -The application API uses the following `/api/v2` InfluxDB API endpoints: - -- `POST /api/v2/query`: to query `INFLUX_BUCKET_AUTH` for a registered device. -- `GET /api/v2/buckets`: to get the bucket ID for `INFLUX_BUCKET`. -- `POST /api/v2/authorizations`: to create an authorization for the device. -- `POST /api/v2/write`: to write the device authorization to `INFLUX_BUCKET_AUTH`. - -### Create an authorization for the device - -In this section, you create an authorization with _read_-_write_ permission to `INFLUX_BUCKET` and receive an API token for the device. -The example below uses the following steps to create the authorization: - -1. Instantiate the `AuthorizationsAPI` client and `BucketsAPI` client with the configuration. -2. Retrieve the bucket ID. -3. Use the client library to send a `POST` request to the `/api/v2/authorizations` InfluxDB API endpoint. - -Create a `./api/devices.py` file that contains the following: - -{{% truncate %}} - -```python -# Import the dependencies. -import configparser -from datetime import datetime -from uuid import uuid4 - -# Import client library classes. -from influxdb_client import Authorization, InfluxDBClient, Permission, PermissionResource, Point, WriteOptions -from influxdb_client.client.authorizations_api import AuthorizationsApi -from influxdb_client.client.bucket_api import BucketsApi -from influxdb_client.client.query_api import QueryApi -from influxdb_client.client.write_api import SYNCHRONOUS - -from api.sensor import Sensor - -# Get the configuration key-value pairs. - -config = configparser.ConfigParser() -config.read('config.ini') - -def create_authorization(device_id) -> Authorization: - influxdb_client = InfluxDBClient(url=config.get('APP', 'INFLUX_URL'), - token=os.environ.get('INFLUX_TOKEN'), - org=os.environ.get('INFLUX_ORG')) - - authorization_api = AuthorizationsApi(influxdb_client) - # get bucket_id from bucket - buckets_api = BucketsApi(influxdb_client) - buckets = buckets_api.find_bucket_by_name(config.get('APP', 'INFLUX_BUCKET')) # function returns only 1 bucket - bucket_id = buckets.id - org_id = buckets.org_id - desc_prefix = f'IoTCenterDevice: {device_id}' - org_resource = PermissionResource(org_id=org_id, id=bucket_id, type="buckets") - read = Permission(action="read", resource=org_resource) - write = Permission(action="write", resource=org_resource) - permissions = [read, write] - authorization = Authorization(org_id=org_id, permissions=permissions, description=desc_prefix) - request = authorization_api.create_authorization(authorization=authorization) - return request -``` - -{{% /truncate %}} -{{% caption %}}[iot-api-python/api/devices.py](https://github.com/influxdata/iot-api-python/blob/d389a0e072c7a03dfea99e5663bdc32be94966bb/api/devices.py#L145){{% /caption %}} - -To create an authorization that has _read_-_write_ permission to `INFLUX_BUCKET`, you need the bucket ID. -To retrieve the bucket ID, `create_authorization(deviceId)` calls the -`BucketsAPI find_bucket_by_name` function that sends a `GET` request to -the `/api/v2/buckets` InfluxDB API endpoint. -`create_authorization(deviceId)` then passes a new authorization in the request body with the following: - -- Bucket ID. -- Organization ID. -- Description: `IoTCenterDevice: DEVICE_ID`. -- List of permissions to the bucket. - -To learn more about API tokens and authorizations, see [Manage API tokens](/influxdb/v2/admin/tokens/). - -Next, [write the device authorization to a bucket](#write-the-device-authorization-to-a-bucket). - -### Write the device authorization to a bucket - -With a device authorization in InfluxDB, write a point for the device and authorization details to `INFLUX_BUCKET_AUTH`. -Storing the device authorization in a bucket allows you to do the following: - -- Report device authorization history. -- Manage devices with and without tokens. -- Assign the same token to multiple devices. -- Refresh tokens. - -To write a point to InfluxDB, use the InfluxDB client library to send a `POST` request to the `/api/v2/write` InfluxDB API endpoint. -In `./api/devices.py`, add the following `create_device(device_id)` function: - -```python -def create_device(device_id=None): - influxdb_client = InfluxDBClient(url=config.get('APP', 'INFLUX_URL'), - token=config.get('APP', 'INFLUX_TOKEN'), - org=config.get('APP', 'INFLUX_ORG')) - if device_id is None: - device_id = str(uuid4()) - write_api = influxdb_client.write_api(write_options=SYNCHRONOUS) - point = Point('deviceauth') \ - .tag("deviceId", device_id) \ - .field('key', f'fake_auth_id_{device_id}') \ - .field('token', f'fake_auth_token_{device_id}') - client_response = write_api.write(bucket=config.get('APP', 'INFLUX_BUCKET_AUTH'), record=point) - # write() returns None on success - if client_response is None: - return device_id - # Return None on failure - return None -``` - -{{% caption %}}[iot-api-python/api/devices.py](https://github.com/influxdata/iot-api-python/blob/f354941c80b6bac643ca29efe408fde1deebdc96/api/devices.py#L47){{% /caption %}} - -`create_device(device_id)` takes a _`device_id`_ and writes data to `INFLUX_BUCKET_AUTH` in the following steps: - -1. Initialize `InfluxDBClient()` with `url`, `token`, and `org` values from the configuration. -2. Initialize a `WriteAPI` client for writing data to an InfluxDB bucket. -3. Create a `Point`. -4. Use `write_api.write()` to write the `Point` to the bucket. -5. Check for failures--if the write was successful, `write_api` returns `None`. -6. Return _`device_id`_ if successful; `None` otherwise. - -The function writes a point with the following elements: - -| Element | Name | Value | -|:------------|:-----------|:--------------------------| -| measurement | | `deviceauth` | -| tag | `deviceId` | device ID | -| field | `key` | authorization ID | -| field | `token` | authorization (API) token | - -Next, [create the API to list devices](#create-the-api-to-list-devices). - -## Create the API to list devices - -Add the `/api/devices` API endpoint that retrieves, processes, and lists registered devices. - -1. Create a Flux query that gets the last row of each [series](/influxdb/v2/reference/glossary#series) that contains a `deviceauth` measurement. - The example query below returns rows that contain the `key` field (authorization ID) and excludes rows that contain a `token` field (to avoid exposing tokens to the UI). - - ```js - // Flux query finds devices - from(bucket:`${INFLUX_BUCKET_AUTH}`) - |> range(start: 0) - |> filter(fn: (r) => r._measurement == "deviceauth" and r._field != "token") - |> last() - ``` - -2. Use the `QueryApi` client to send the Flux query to the `POST /api/v2/query` InfluxDB API endpoint. - - In `./api/devices.py`, add the following: - - ```python - def get_device(device_id=None) -> {}: - influxdb_client = InfluxDBClient(url=config.get('APP', 'INFLUX_URL'), - token=os.environ.get('INFLUX_TOKEN'), - org=os.environ.get('INFLUX_ORG')) - # Queries must be formatted with single and double quotes correctly - query_api = QueryApi(influxdb_client) - device_filter = '' - if device_id: - device_id = str(device_id) - device_filter = f'r.deviceId == "{device_id}" and r._field != "token"' - else: - device_filter = f'r._field != "token"' - - flux_query = f'from(bucket: "{config.get("APP", "INFLUX_BUCKET_AUTH")}") ' \ - f'|> range(start: 0) ' \ - f'|> filter(fn: (r) => r._measurement == "deviceauth" and {device_filter}) ' \ - f'|> last()' - - response = query_api.query(flux_query) - result = [] - for table in response: - for record in table.records: - try: - 'updatedAt' in record - except KeyError: - record['updatedAt'] = record.get_time() - record[record.get_field()] = record.get_value() - result.append(record.values) - return result - ``` - - {{% caption %}}[iot-api-python/api/devices.py get_device()](https://github.com/influxdata/iot-api-python/blob/9bf44a659424a27eb937d545dc0455754354aef5/api/devices.py#L30){{% /caption %}} - - The `get_device(device_id)` function does the following: - - 1. Instantiates a `QueryApi` client and sends the Flux query to InfluxDB. - 2. Iterates over the `FluxTable` in the response and returns a list of tuples. - -## Create IoT virtual device - -Create a `./api/sensor.py` file that generates simulated weather telemetry data. -Follow the [example code](https://github.com/influxdata/iot-api-python/blob/f354941c80b6bac643ca29efe408fde1deebdc96/api/sensor.py) to create the IoT virtual device. - -Next, generate data for virtual devices and [write the data to InfluxDB](#write-telemetry-data). - -## Write telemetry data - -In this section, you write telemetry data to an InfluxDB bucket. -To write data, use the InfluxDB client library to send a `POST` request to the `/api/v2/write` InfluxDB API endpoint. - -The example below uses the following steps to generate data and then write it to InfluxDB: - -1. Initialize a `WriteAPI` instance. -2. Create a `Point` with the `environment` measurement and data fields for temperature, humidity, pressure, latitude, and longitude. -3. Use the `WriteAPI write` method to send the point to InfluxDB. - -In `./api/devices.py`, add the following `write_measurements(device_id)` function: - -```python -def write_measurements(device_id): - influxdb_client = InfluxDBClient(url=config.get('APP', 'INFLUX_URL'), - token=config.get('APP', 'INFLUX_TOKEN'), - org=config.get('APP', 'INFLUX_ORG')) - write_api = influxdb_client.write_api(write_options=SYNCHRONOUS) - virtual_device = Sensor() - coord = virtual_device.geo() - point = Point("environment") \ - .tag("device", device_id) \ - .tag("TemperatureSensor", "virtual_bme280") \ - .tag("HumiditySensor", "virtual_bme280") \ - .tag("PressureSensor", "virtual_bme280") \ - .field("Temperature", virtual_device.generate_measurement()) \ - .field("Humidity", virtual_device.generate_measurement()) \ - .field("Pressure", virtual_device.generate_measurement()) \ - .field("Lat", coord['latitude']) \ - .field("Lon", coord['latitude']) \ - .time(datetime.utcnow()) - print(f"Writing: {point.to_line_protocol()}") - client_response = write_api.write(bucket=config.get('APP', 'INFLUX_BUCKET'), record=point) - # write() returns None on success - if client_response is None: - # TODO Maybe also return the data that was written - return device_id - # Return None on failure - return None -``` - -{{% caption %}}[iot-api-python/api/devices.py write_measurement()](https://github.com/influxdata/iot-api-python/blob/f354941c80b6bac643ca29efe408fde1deebdc96/api/devices.py){{% /caption %}} - -## Query telemetry data - -In this section, you retrieve telemetry data from an InfluxDB bucket. -To retrieve data, use the InfluxDB client library to send a `POST` request to the `/api/v2/query` InfluxDB API endpoint. -The example below uses the following steps to retrieve and process telemetry data: - - 1. Query `environment` measurements in `INFLUX_BUCKET`. - 2. Filter results by `device_id`. - 3. Return CSV data that the [`influxdata/giraffe` UI library](https://github.com/influxdata/giraffe) can process. - -In `./api/devices.py`, add the following `get_measurements(device_id)` function: - -```python -def get_measurements(query): - influxdb_client = InfluxDBClient(url=config.get('APP', 'INFLUX_URL'), - token=os.environ.get('INFLUX_TOKEN'), org=os.environ.get('INFLUX_ORG')) - query_api = QueryApi(influxdb_client) - result = query_api.query_csv(query, - dialect=Dialect( - header=True, - delimiter=",", - comment_prefix="#", - annotations=['group', 'datatype', 'default'], - date_time_format="RFC3339")) - response = '' - for row in result: - response += (',').join(row) + ('\n') - return response -``` - -{{% caption %}}[iot-api-python/api/devices.py get_measurements()](https://github.com/influxdata/iot-api-python/blob/9bf44a659424a27eb937d545dc0455754354aef5/api/devices.py#L122){{% /caption %}} - -## Define API responses - -In `app.py`, add API endpoints that match incoming requests and respond with the results of your modules. -In the following `/api/devices/` route example, `app.py` retrieves _`device_id`_ from `GET` and `POST` requests, passes it to the `get_device(device_id)` method and returns the result as JSON data with CORS `allow-` headers. - -```python -@app.route('/api/devices/', methods=['GET', 'POST']) -def api_get_device(device_id): - if request.method == "OPTIONS": # CORS preflight - return _build_cors_preflight_response() - return _corsify_actual_response(jsonify(devices.get_device(device_id))) -``` - -{{% caption %}}[iot-api-python/app.py](https://github.com/influxdata/iot-api-python/blob/9bf44a659424a27eb937d545dc0455754354aef5/app.py){{% /caption %}} - -Enter the following commands into your terminal to restart the application: - - 1. `CONTROL+C` to stop the application. - 2. `flask run -h localhost -p 3001` to start the application. - -To retrieve devices data from your API, visit in your browser. - -## Install and run the UI - -`influxdata/iot-api-ui` is a standalone [Next.js React](https://nextjs.org/docs/basic-features/pages) UI that uses your application API to write and query data in InfluxDB. -`iot-api-ui` uses Next.js _[rewrites](https://nextjs.org/docs/api-reference/next.config.js/rewrites)_ to route all requests in the `/api/` path to your API. - -To install and run the UI, do the following: - -1. In your `~/iot-api-apps` directory, clone the [`influxdata/iot-api-ui` repo](https://github.com/influxdata/iot-api-ui) and go into the `iot-api-ui` directory--for example: - - ```bash - cd ~/iot-api-apps - git clone git@github.com:influxdata/iot-api-ui.git - cd ./iot-app-ui - ``` - -2. The `./.env.development` file contains default configuration settings that you can - edit or override (with a `./.env.local` file). -3. To start the UI, enter the following command into your terminal: - - ```bash - yarn dev - ``` - - To view the list and register devices, visit in your browser. - -To learn more about the UI components, see [`influxdata/iot-api-ui`](https://github.com/influxdata/iot-api-ui). + diff --git a/content/influxdb/v2/get-started/_index.md b/content/influxdb/v2/get-started/_index.md index b05dead17..1cb90099c 100644 --- a/content/influxdb/v2/get-started/_index.md +++ b/content/influxdb/v2/get-started/_index.md @@ -63,8 +63,8 @@ The following are important definitions to understand when using InfluxDB: - **Point**: Single data record identified by its _measurement, tag keys, tag values, field key, and timestamp_. - **Series**: A group of points with the same - {{% oss-only %}}_measurement, tag keys, and tag values_.{{% /oss-only %}} - {{% cloud-only %}}_measurement, tag keys and values, and field key_.{{% /cloud-only %}} + {{% show-in "v2" %}}_measurement, tag keys, and tag values_.{{% /show-in %}} + {{% show-in "cloud,cloud-serverless" %}}_measurement, tag keys and values, and field key_.{{% /show-in %}} ##### Example InfluxDB query results @@ -82,13 +82,13 @@ InfluxDB {{< current-version >}}. Examples are provided for each of the followin ### InfluxDB user interface (UI) The InfluxDB UI provides a web-based visual interface for interacting with and managing InfluxDB. -{{% oss-only %}}The UI is packaged with InfluxDB and runs as part of the InfluxDB service. To access the UI, with InfluxDB running, visit [localhost:8086](http://localhost:8086) in your browser.{{% /oss-only %}} -{{% cloud-only %}}To access the InfluxDB Cloud UI, [log into your InfluxDB Cloud account](https://cloud2.influxdata.com).{{% /cloud-only %}} +{{% show-in "v2" %}}The UI is packaged with InfluxDB and runs as part of the InfluxDB service. To access the UI, with InfluxDB running, visit [localhost:8086](http://localhost:8086) in your browser.{{% /show-in %}} +{{% show-in "cloud,cloud-serverless" %}}To access the InfluxDB Cloud UI, [log into your InfluxDB Cloud account](https://cloud2.influxdata.com).{{% /show-in %}} ### `influx` CLI The `influx` CLI lets you interact with and manage InfluxDB {{< current-version >}} from a command line. -{{% oss-only %}}The CLI is packaged separately from InfluxDB and must be downloaded and installed separately.{{% /oss-only %}} +{{% show-in "v2" %}}The CLI is packaged separately from InfluxDB and must be downloaded and installed separately.{{% /show-in %}} For detailed CLI installation instructions, see [Use the influx CLI](/influxdb/v2/tools/influx-cli/). diff --git a/content/influxdb/v2/get-started/process.md b/content/influxdb/v2/get-started/process.md index 96b9c7727..c47724a06 100644 --- a/content/influxdb/v2/get-started/process.md +++ b/content/influxdb/v2/get-started/process.md @@ -17,1259 +17,8 @@ related: - /influxdb/v2/process-data/get-started/ - /flux/v0/get-started/ - /flux/v0/stdlib/ +source: /shared/influxdb-v2/get-started/process.md --- -Now that you know the [basics of querying data from InfluxDB](/influxdb/v2/get-started/query/), -let's go beyond a basic query and begin to process the queried data. -"Processing" data could mean transforming, aggregating, downsampling, or alerting -on data. This tutorial covers the following data processing use cases: - -- [Remap or assign values in your data](#remap-or-assign-values-in-your-data) -- [Group data](#group-data) -- [Aggregate or select specific data](#aggregate-or-select-specific-data) -- [Pivot data into a relational schema](#pivot-data-into-a-relational-schema) -- [Downsample data](#downsample-data) -- [Automate processing with InfluxDB tasks](#automate-processing-with-influxdb-tasks) - -{{% note %}} -Most data processing operations require manually editing Flux queries. -If you're using the **InfluxDB Data Explorer**, switch to the **Script Editor** -instead of using the **Query Builder.** -{{% /note %}} - -## Remap or assign values in your data - -Use the [`map()` function](/flux/v0/stdlib/universe/map/) to -iterate over each row in your data and update the values in that row. -`map()` is one of the most useful functions in Flux and will help you accomplish -many of they data processing operations you need to perform. - -{{< expand-wrapper >}} -{{% expand "Learn more about how `map()` works" %}} - -`map()` takes a single parameter, `fn`. -`fn` takes an anonymous function that reads each row as a -[record](/flux/v0/data-types/composite/record/) named `r`. -In the `r` record, each key-value pair represents a column and its value. -For example: - -```js -r = { - _time: 2020-01-01T00:00:00Z, - _measurement: "home", - room: "Kitchen", - _field: "temp", - _value: 21.0, -} -``` - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :------ | :----- | :----- | -| 2020-01-01T00:00:00Z | home | Kitchen | temp | 21.0 | - -The `fn` function modifies the `r` record in any way you need and returns a new -record for the row. For example, using the record above: - -```js -(r) => ({ _time: r._time, _field: "temp_F", _value: (r._value * 1.8) + 32.0}) - -// Returns: {_time: 2020-01-01T00:00:00Z, _field: "temp_F", _value: 69.8} -``` - -| _time | _field | _value | -| :------------------- | :----- | -----: | -| 2020-01-01T00:00:00Z | temp_F | 69.8 | - -Notice that some of the columns were dropped from the original row record. -This is because the `fn` function explicitly mapped the `_time`, `_field`, and `_value` columns. -To retain existing columns and only update or add specific columns, use the -`with` operator to extend your row record. -For example, using the record above: - -```js -(r) => ({r with _value: (r._value * 1.8) + 32.0, degrees: "F"}) - -// Returns: -// { -// _time: 2020-01-01T00:00:00Z, -// _measurement: "home", -// room: "Kitchen", -// _field: "temp", -// _value: 69.8, -// degrees: "F", -// } -``` - -| _time | _measurement | room | _field | _value | degrees | -| :------------------- | :----------- | :------ | :----- | -----: | :------ | -| 2020-01-01T00:00:00Z | home | Kitchen | temp | 69.8 | F | - -{{% /expand %}} -{{< /expand-wrapper >}} - -```js -from(bucket: "get-started") - |> range(start: 2022-01-01T08:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field == "hum") - |> map(fn: (r) => ({r with _value: r._value / 100.0})) -``` - -### Map examples - -{{< expand-wrapper >}} - -{{% expand "Perform mathematical operations" %}} - -`map()` lets your perform mathematical operations on your data. -For example, using the [data written in "Get started writing to InfluxDB"](/influxdb/v2/get-started/write/#view-the-written-data): - -1. Query the `temp` field to return room temperatures in °C. -2. Use `map()` to iterate over each row and convert the °C temperatures in the - `_value` column to °F using the equation: `°F = (°C * 1.8) + 32.0`. - -```js -from(bucket: "get-started") - |> range(start: 2022-01-01T14:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field == "temp") - |> map(fn: (r) => ({r with _value: (r._value * 1.8) + 32.0})) -``` - -{{< tabs-wrapper >}} -{{% tabs "small" %}} -[Input](#) -[Output](#) -Click to view output -{{% /tabs %}} -{{% tab-content %}} - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Kitchen | temp | 22.8 | -| 2022-01-01T15:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T16:00:00Z | home | Kitchen | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T18:00:00Z | home | Kitchen | temp | 23.3 | -| 2022-01-01T19:00:00Z | home | Kitchen | temp | 23.1 | -| 2022-01-01T20:00:00Z | home | Kitchen | temp | 22.7 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T15:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T16:00:00Z | home | Living Room | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Living Room | temp | 22.6 | -| 2022-01-01T18:00:00Z | home | Living Room | temp | 22.8 | -| 2022-01-01T19:00:00Z | home | Living Room | temp | 22.5 | -| 2022-01-01T20:00:00Z | home | Living Room | temp | 22.2 | - -{{% /tab-content %}} -{{% tab-content %}} - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :------ | :----- | ----------------: | -| 2022-01-01T14:00:00Z | home | Kitchen | temp | 73.03999999999999 | -| 2022-01-01T15:00:00Z | home | Kitchen | temp | 72.86 | -| 2022-01-01T16:00:00Z | home | Kitchen | temp | 72.32 | -| 2022-01-01T17:00:00Z | home | Kitchen | temp | 72.86 | -| 2022-01-01T18:00:00Z | home | Kitchen | temp | 73.94 | -| 2022-01-01T19:00:00Z | home | Kitchen | temp | 73.58000000000001 | -| 2022-01-01T20:00:00Z | home | Kitchen | temp | 72.86 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | ----------------: | -| 2022-01-01T14:00:00Z | home | Living Room | temp | 72.14 | -| 2022-01-01T15:00:00Z | home | Living Room | temp | 72.14 | -| 2022-01-01T16:00:00Z | home | Living Room | temp | 72.32 | -| 2022-01-01T17:00:00Z | home | Living Room | temp | 72.68 | -| 2022-01-01T18:00:00Z | home | Living Room | temp | 73.03999999999999 | -| 2022-01-01T19:00:00Z | home | Living Room | temp | 72.5 | -| 2022-01-01T20:00:00Z | home | Living Room | temp | 71.96000000000001 | - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -{{% /expand %}} - -{{% expand "Conditionally assign a state" %}} - -Within a `map()` function, you can use [conditional expressions](/flux/v0/spec/expressions/#conditional-expressions) (if/then/else) to conditionally assign values. -For example, using the [data written in "Get started writing to InfluxDB"](/influxdb/v2/get-started/write/#view-the-written-data): - -1. Query the `co` field to return carbon monoxide parts per million (ppm) readings in each room. -2. Use `map()` to iterate over each row, evaluate the value in the `_value` - column, and then conditionally assign a state: - - - If the carbon monoxide is less than 10 ppm, assign the state: **ok**. - - Otherwise, assign the state: **warning**. - - Store the state in a **state** column. - -```js -from(bucket: "get-started") - |> range(start: 2022-01-01T14:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field == "co") - |> map(fn: (r) => ({r with state: if r._value < 10 then "ok" else "warning"})) -``` - -{{< tabs-wrapper >}} -{{% tabs "small" %}} -[Input](#) -[Output](#) -Click to view output -{{% /tabs %}} -{{% tab-content %}} - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :------ | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Kitchen | co | 1 | -| 2022-01-01T15:00:00Z | home | Kitchen | co | 3 | -| 2022-01-01T16:00:00Z | home | Kitchen | co | 7 | -| 2022-01-01T17:00:00Z | home | Kitchen | co | 9 | -| 2022-01-01T18:00:00Z | home | Kitchen | co | 18 | -| 2022-01-01T19:00:00Z | home | Kitchen | co | 22 | -| 2022-01-01T20:00:00Z | home | Kitchen | co | 26 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Living Room | co | 1 | -| 2022-01-01T15:00:00Z | home | Living Room | co | 1 | -| 2022-01-01T16:00:00Z | home | Living Room | co | 4 | -| 2022-01-01T17:00:00Z | home | Living Room | co | 5 | -| 2022-01-01T18:00:00Z | home | Living Room | co | 9 | -| 2022-01-01T19:00:00Z | home | Living Room | co | 14 | -| 2022-01-01T20:00:00Z | home | Living Room | co | 17 | - -{{% /tab-content %}} -{{% tab-content %}} - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _time | _measurement | room | _field | _value | state | -| :------------------- | :----------- | :------ | :----- | -----: | :------ | -| 2022-01-01T14:00:00Z | home | Kitchen | co | 1 | ok | -| 2022-01-01T15:00:00Z | home | Kitchen | co | 3 | ok | -| 2022-01-01T16:00:00Z | home | Kitchen | co | 7 | ok | -| 2022-01-01T17:00:00Z | home | Kitchen | co | 9 | ok | -| 2022-01-01T18:00:00Z | home | Kitchen | co | 18 | warning | -| 2022-01-01T19:00:00Z | home | Kitchen | co | 22 | warning | -| 2022-01-01T20:00:00Z | home | Kitchen | co | 26 | warning | - -| _time | _measurement | room | _field | _value | state | -| :------------------- | :----------- | :---------- | :----- | -----: | :------ | -| 2022-01-01T14:00:00Z | home | Living Room | co | 1 | ok | -| 2022-01-01T15:00:00Z | home | Living Room | co | 1 | ok | -| 2022-01-01T16:00:00Z | home | Living Room | co | 4 | ok | -| 2022-01-01T17:00:00Z | home | Living Room | co | 5 | ok | -| 2022-01-01T18:00:00Z | home | Living Room | co | 9 | ok | -| 2022-01-01T19:00:00Z | home | Living Room | co | 14 | warning | -| 2022-01-01T20:00:00Z | home | Living Room | co | 17 | warning | - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -{{% /expand %}} - -{{% expand "Alert on data" %}} - -`map()` lets you execute more complex operations on a per row basis. -Using a [Flux block (`{}`)](/flux/v0/spec/blocks/) in the `fn` function, -you can create scoped variables and execute other functions within the context -of each row. For example, you can send a message to [Slack](https://slack.com). - -{{% note %}} -For this example to actually send messages to Slack, you need to -[set up a Slack app that can send and receive messages](https://api.slack.com/messaging/sending). -{{% /note %}} - -For example, using the [data written in "Get started writing to InfluxDB"](/influxdb/v2/get-started/write/#view-the-written-data): - -1. Import the [`slack` package](/flux/v0/stdlib/slack/). -2. Query the `co` field to return carbon monoxide parts per million (ppm) readings in each room. -3. Use `map()` to iterate over each row, evaluate the value in the `_value` - column, and then conditionally assign a state: - - - If the carbon monoxide is less than 10 ppm, assign the state: **ok**. - - Otherwise, assign the state: **warning**. - - Store the state in a **state** column. -4. Use [`filter()`](/flux/v0/stdlib/universe/filter/) to return - only rows with **warning** in the state column. -5. Use `map()` to iterate over each row. - In your `fn` function, use a [Flux block (`{}`)](/flux/v0/spec/blocks/) to: - - 1. Create a `responseCode` variable that uses [`slack.message()`](/flux/v0/stdlib/slack/message/) - to send a message to Slack using data from the input row. - `slack.message()` returns the response code of the Slack API request as an integer. - 2. Use a `return` statement to return a new row record. - The new row should extend the input row with a new column, **sent**, with - a boolean value determined by the `responseCode` variable. - -`map()` sends a message to Slack for each row piped forward into the function. - -```js -import "slack" - -from(bucket: "get-started") - |> range(start: 2022-01-01T14:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field == "co") - |> map(fn: (r) => ({r with state: if r._value < 10 then "ok" else "warning"})) - |> filter(fn: (r) => r.state == "warning") - |> map( - fn: (r) => { - responseCode = - slack.message( - token: "mYSlacK70k3n", - color: "#ff0000", - channel: "#alerts", - text: "Carbon monoxide is at dangerous levels in the ${r.room}: ${r._value} ppm.", - ) - - return {r with sent: responseCode == 200} - }, - ) -``` - -{{< tabs-wrapper >}} -{{% tabs "small" %}} -[Input](#) -[Output](#) -Click to view output -{{% /tabs %}} -{{% tab-content %}} - -The following input represents the data filtered by the **warning** state. - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _time | _measurement | room | _field | _value | state | -| :------------------- | :----------- | :------ | :----- | -----: | :------ | -| 2022-01-01T18:00:00Z | home | Kitchen | co | 18 | warning | -| 2022-01-01T19:00:00Z | home | Kitchen | co | 22 | warning | -| 2022-01-01T20:00:00Z | home | Kitchen | co | 26 | warning | - -| _time | _measurement | room | _field | _value | state | -| :------------------- | :----------- | :---------- | :----- | -----: | :------ | -| 2022-01-01T19:00:00Z | home | Living Room | co | 14 | warning | -| 2022-01-01T20:00:00Z | home | Living Room | co | 17 | warning | - -{{% /tab-content %}} -{{% tab-content %}} - -The output includes a **sent** column indicating the if the message was sent. - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _time | _measurement | room | _field | _value | state | sent | -| :------------------- | :----------- | :------ | :----- | -----: | :------ | :--- | -| 2022-01-01T18:00:00Z | home | Kitchen | co | 18 | warning | true | -| 2022-01-01T19:00:00Z | home | Kitchen | co | 22 | warning | true | -| 2022-01-01T20:00:00Z | home | Kitchen | co | 26 | warning | true | - -| _time | _measurement | room | _field | _value | state | sent | -| :------------------- | :----------- | :---------- | :----- | -----: | :------ | :--- | -| 2022-01-01T19:00:00Z | home | Living Room | co | 14 | warning | true | -| 2022-01-01T20:00:00Z | home | Living Room | co | 17 | warning | true | - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -With the results above, you would receive the following messages in Slack: - -> Carbon monoxide is at dangerous levels in the Kitchen: 18 ppm. -> Carbon monoxide is at dangerous levels in the Kitchen: 22 ppm. -> Carbon monoxide is at dangerous levels in the Living Room: 14 ppm. -> Carbon monoxide is at dangerous levels in the Kitchen: 26 ppm. -> Carbon monoxide is at dangerous levels in the Living Room: 17 ppm. - -{{% note %}} -You can also use the [InfluxDB checks and notifications system](/influxdb/v2/monitor-alert/) -as a user interface for configuring checks and alerting on data. -{{% /note %}} - -{{% /expand %}} -{{< /expand-wrapper >}} - -## Group data - -Use the [`group()` function](/flux/v0/stdlib/universe/group/) to -regroup your data by specific column values in preparation for further processing. - -```js -from(bucket: "get-started") - |> range(start: 2022-01-01T08:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> group(columns: ["room", "_field"]) -``` - -{{% note %}} -Understanding data grouping and why it matters is important, but may be too much -for this "getting started" tutorial. -For more information about how data is grouped and why it matters, see the -[Flux data model](/flux/v0/get-started/data-model/) documentation. -{{% /note %}} - -By default, `from()` returns data queried from InfluxDB grouped by series -(measurement, tags, and field key). -Each table in the returned stream of tables represents a group. -Each table contains the same values for the columns that data is grouped by. -This grouping is important as you [aggregate data](#aggregate-or-select-specific-data). - -### Group examples - -{{< expand-wrapper >}} -{{% expand "Group data by specific columns" %}} - -Using the [data written in "Get started writing to InfluxDB"](/influxdb/v2/get-started/write/#view-the-written-data): - -1. Query the `temp` and `hum` fields. -2. Use `group()` to group by only the `_field` column. - -```js -from(bucket: "get-started") - |> range(start: 2022-01-01T08:00:00Z, stop: 2022-01-01T10:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field == "temp" or r._field == "hum") - |> group(columns: ["_field"]) -``` - -{{< tabs-wrapper >}} -{{% tabs "small" %}} -[Input](#) -[Output](#) -Click to view output -{{% /tabs %}} -{{% tab-content %}} - -The following data is output from the last `filter()` and piped forward into `group()`: - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -{{% flux/group-key "[_measurement=home, room=Kitchen, _field=hum]" true %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | :----- | -| 2022-01-01T08:00:00Z | home | Kitchen | hum | 35.9 | -| 2022-01-01T09:00:00Z | home | Kitchen | hum | 36.2 | -| 2022-01-01T10:00:00Z | home | Kitchen | hum | 36.1 | - -{{% flux/group-key "[_measurement=home, room=Living Room, _field=hum]" true %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | :----- | -| 2022-01-01T08:00:00Z | home | Living Room | hum | 35.9 | -| 2022-01-01T09:00:00Z | home | Living Room | hum | 35.9 | -| 2022-01-01T10:00:00Z | home | Living Room | hum | 36 | - -{{% flux/group-key "[_measurement=home, room=Kitchen, _field=temp]" true %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | :----- | -| 2022-01-01T08:00:00Z | home | Kitchen | temp | 21 | -| 2022-01-01T09:00:00Z | home | Kitchen | temp | 23 | -| 2022-01-01T10:00:00Z | home | Kitchen | temp | 22.7 | - -{{% flux/group-key "[_measurement=home, room=Living Room, _field=temp]" true %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | :----- | -| 2022-01-01T08:00:00Z | home | Living Room | temp | 21.1 | -| 2022-01-01T09:00:00Z | home | Living Room | temp | 21.4 | -| 2022-01-01T10:00:00Z | home | Living Room | temp | 21.8 | - -{{% /tab-content %}} -{{% tab-content %}} - -When grouped by `_field`, all rows with the `temp` field will be in one table -and all the rows with the `hum` field will be in another. -`_measurement` and `room` columns no longer affect how rows are grouped. - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -{{% flux/group-key "[_field=hum]" true %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | :----- | -| 2022-01-01T08:00:00Z | home | Kitchen | hum | 35.9 | -| 2022-01-01T09:00:00Z | home | Kitchen | hum | 36.2 | -| 2022-01-01T10:00:00Z | home | Kitchen | hum | 36.1 | -| 2022-01-01T08:00:00Z | home | Living Room | hum | 35.9 | -| 2022-01-01T09:00:00Z | home | Living Room | hum | 35.9 | -| 2022-01-01T10:00:00Z | home | Living Room | hum | 36 | - -{{% flux/group-key "[_field=temp]" true %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | :----- | -| 2022-01-01T08:00:00Z | home | Kitchen | temp | 21 | -| 2022-01-01T09:00:00Z | home | Kitchen | temp | 23 | -| 2022-01-01T10:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T08:00:00Z | home | Living Room | temp | 21.1 | -| 2022-01-01T09:00:00Z | home | Living Room | temp | 21.4 | -| 2022-01-01T10:00:00Z | home | Living Room | temp | 21.8 | - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -{{% /expand %}} - -{{% expand "Ungroup data" %}} - -Using the [data written in "Get started writing to InfluxDB"](/influxdb/v2/get-started/write/#view-the-written-data): - -1. Query the `temp` and `hum` fields. -2. Use `group()` without any parameters to "ungroup" data or group by no columns. - The default value of the `columns` parameter is an empty array (`[]`). - -```js -from(bucket: "get-started") - |> range(start: 2022-01-01T08:00:00Z, stop: 2022-01-01T10:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field == "temp" or r._field == "hum") - |> group() -``` - -{{< tabs-wrapper >}} -{{% tabs "small" %}} -[Input](#) -[Output](#) -Click to view output -{{% /tabs %}} -{{% tab-content %}} - -The following data is output from the last `filter()` and piped forward into `group()`: - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -{{% flux/group-key "[_measurement=home, room=Kitchen, _field=hum]" true %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | :----- | -| 2022-01-01T08:00:00Z | home | Kitchen | hum | 35.9 | -| 2022-01-01T09:00:00Z | home | Kitchen | hum | 36.2 | -| 2022-01-01T10:00:00Z | home | Kitchen | hum | 36.1 | - -{{% flux/group-key "[_measurement=home, room=Living Room, _field=hum]" true %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | :----- | -| 2022-01-01T08:00:00Z | home | Living Room | hum | 35.9 | -| 2022-01-01T09:00:00Z | home | Living Room | hum | 35.9 | -| 2022-01-01T10:00:00Z | home | Living Room | hum | 36 | - -{{% flux/group-key "[_measurement=home, room=Kitchen, _field=temp]" true %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | :----- | -| 2022-01-01T08:00:00Z | home | Kitchen | temp | 21 | -| 2022-01-01T09:00:00Z | home | Kitchen | temp | 23 | -| 2022-01-01T10:00:00Z | home | Kitchen | temp | 22.7 | - -{{% flux/group-key "[_measurement=home, room=Living Room, _field=temp]" true %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | :----- | -| 2022-01-01T08:00:00Z | home | Living Room | temp | 21.1 | -| 2022-01-01T09:00:00Z | home | Living Room | temp | 21.4 | -| 2022-01-01T10:00:00Z | home | Living Room | temp | 21.8 | - -{{% /tab-content %}} -{{% tab-content %}} - -When ungrouped, a data is returned in a single table. - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -{{% flux/group-key "[]" true %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T08:00:00Z | home | Kitchen | hum | 35.9 | -| 2022-01-01T09:00:00Z | home | Kitchen | hum | 36.2 | -| 2022-01-01T10:00:00Z | home | Kitchen | hum | 36.1 | -| 2022-01-01T08:00:00Z | home | Kitchen | temp | 21 | -| 2022-01-01T09:00:00Z | home | Kitchen | temp | 23 | -| 2022-01-01T10:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T08:00:00Z | home | Living Room | hum | 35.9 | -| 2022-01-01T09:00:00Z | home | Living Room | hum | 35.9 | -| 2022-01-01T10:00:00Z | home | Living Room | hum | 36 | -| 2022-01-01T08:00:00Z | home | Living Room | temp | 21.1 | -| 2022-01-01T09:00:00Z | home | Living Room | temp | 21.4 | -| 2022-01-01T10:00:00Z | home | Living Room | temp | 21.8 | - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -{{% /expand %}} -{{< /expand-wrapper >}} - -## Aggregate or select specific data - -Use Flux [aggregate](/flux/v0/function-types/#aggregates) -or [selector](/flux/v0/function-types/#selectors) functions to -return aggregate or selected values from **each** input table. - -```js -from(bucket: "get-started") - |> range(start: 2022-01-01T08:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field == "co" or r._field == "hum" or r._field == "temp") - |> mean() -``` - -{{% note %}} -#### Aggregate over time - -If you want to query aggregate values over time, this is a form of -[downsampling](#downsample-data). -{{% /note %}} - -### Aggregate functions - -[Aggregate functions](/flux/v0/function-types/#aggregates) drop -columns that are **not** in the [group key](/flux/v0/get-started/data-model/#group-key) -and return a single row for each input table with the aggregate value of that table. - -#### Aggregate examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the average temperature for each room" %}} - -Using the [data written in "Get started writing to InfluxDB"](/influxdb/v2/get-started/write/#view-the-written-data): - -1. Query the `temp` field. By default, `from()` returns the data grouped by - `_measurement`, `room` and `_field`, so each table represents a room. -2. Use `mean()` to return the average temperature from each room. - -```js -from(bucket: "get-started") - |> range(start: 2022-01-01T14:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field == "temp") - |> mean() -``` - -{{< tabs-wrapper >}} -{{% tabs "small" %}} -[Input](#) -[Output](#) -Click to view output -{{% /tabs %}} -{{% tab-content %}} - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Kitchen | temp | 22.8 | -| 2022-01-01T15:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T16:00:00Z | home | Kitchen | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T18:00:00Z | home | Kitchen | temp | 23.3 | -| 2022-01-01T19:00:00Z | home | Kitchen | temp | 23.1 | -| 2022-01-01T20:00:00Z | home | Kitchen | temp | 22.7 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T15:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T16:00:00Z | home | Living Room | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Living Room | temp | 22.6 | -| 2022-01-01T18:00:00Z | home | Living Room | temp | 22.8 | -| 2022-01-01T19:00:00Z | home | Living Room | temp | 22.5 | -| 2022-01-01T20:00:00Z | home | Living Room | temp | 22.2 | - -{{% /tab-content %}} -{{% tab-content %}} - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _measurement | room | _field | _value | -| :----------- | :------ | :----- | -----------------: | -| home | Kitchen | temp | 22.814285714285713 | - -| _measurement | room | _field | _value | -| :----------- | :---------- | :----- | ----------------: | -| home | Living Room | temp | 22.44285714285714 | - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -{{% /expand %}} - -{{% expand "Calculate the overall average temperature of all rooms" %}} - -Using the [data written in "Get started writing to InfluxDB"](/influxdb/v2/get-started/write/#view-the-written-data): - -1. Query the `temp` field. -2. Use `group()` to **ungroup** the data into a single table. By default, - `from()` returns the data grouped by`_measurement`, `room` and `_field`. - To get the overall average, you need to structure all results as a single table. -3. Use `mean()` to return the average temperature. - -```js -from(bucket: "get-started") - |> range(start: 2022-01-01T14:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field == "temp") - |> group() - |> mean() -``` - -{{< tabs-wrapper >}} -{{% tabs "small" %}} -[Input](#) -[Output](#) -Click to view output -{{% /tabs %}} -{{% tab-content %}} - -The following input data represents the ungrouped data that is piped forward -into `mean()`. - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Kitchen | temp | 22.8 | -| 2022-01-01T15:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T16:00:00Z | home | Kitchen | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T18:00:00Z | home | Kitchen | temp | 23.3 | -| 2022-01-01T19:00:00Z | home | Kitchen | temp | 23.1 | -| 2022-01-01T20:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T14:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T15:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T16:00:00Z | home | Living Room | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Living Room | temp | 22.6 | -| 2022-01-01T18:00:00Z | home | Living Room | temp | 22.8 | -| 2022-01-01T19:00:00Z | home | Living Room | temp | 22.5 | -| 2022-01-01T20:00:00Z | home | Living Room | temp | 22.2 | - -{{% /tab-content %}} -{{% tab-content %}} - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _value | -| -----------------: | -| 22.628571428571426 | - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -{{% /expand %}} - -{{% expand "Count the number of points reported per room across all fields" %}} - -Using the [data written in "Get started writing to InfluxDB"](/influxdb/v2/get-started/write/#view-the-written-data): - -1. Query all fields by simply filtering by the `home` measurement. -2. The fields in the `home` measurement are different types. - Use `toFloat()` to cast all field values to floats. -3. Use `group()` to group the data by `room`. -4. Use `count()` to return the number of rows in each input table. - -```js -from(bucket: "get-started") - |> range(start: 2022-01-01T14:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> toFloat() - |> group(columns: ["room"]) - |> count() -``` - -##### Output - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| room | _value | -| :------ | -----: | -| Kitchen | 21 | - -| room | _value | -| :---------- | -----: | -| Living Room | 21 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -{{% note %}} -#### Assign a new aggregate timestamp - -`_time` is generally not part of the group key and will be dropped when using -aggregate functions. To assign a new timestamp to aggregate points, duplicate -the `_start` or `_stop` column, which represent the query bounds, as the -new `_time` column. - -```js -from(bucket: "get-started") - |> range(start: 2022-01-01T14:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field == "temp") - |> mean() - |> duplicate(column: "_stop", as: "_time") -``` -{{% /note %}} - -### Selector functions - -[Selector functions](/flux/v0/function-types/#selectors) return -one or more columns from each input table and retain all columns and their values. - -#### Selector examples - -{{< expand-wrapper >}} - -{{% expand "Return the first temperature from each room" %}} - -Using the [data written in "Get started writing to InfluxDB"](/influxdb/v2/get-started/write/#view-the-written-data): - -1. Query the `temp` field. -2. Use [`first()`](/flux/v0/stdlib/universe/first/) to return the - first row from each table. - -```js -from(bucket: "get-started") - |> range(start: 2022-01-01T14:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field == "temp") - |> first() -``` - -{{< tabs-wrapper >}} -{{% tabs "small" %}} -[Input](#) -[Output](#) -Click to view output -{{% /tabs %}} -{{% tab-content %}} - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Kitchen | temp | 22.8 | -| 2022-01-01T15:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T16:00:00Z | home | Kitchen | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T18:00:00Z | home | Kitchen | temp | 23.3 | -| 2022-01-01T19:00:00Z | home | Kitchen | temp | 23.1 | -| 2022-01-01T20:00:00Z | home | Kitchen | temp | 22.7 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T15:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T16:00:00Z | home | Living Room | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Living Room | temp | 22.6 | -| 2022-01-01T18:00:00Z | home | Living Room | temp | 22.8 | -| 2022-01-01T19:00:00Z | home | Living Room | temp | 22.5 | -| 2022-01-01T20:00:00Z | home | Living Room | temp | 22.2 | - -{{% /tab-content %}} -{{% tab-content %}} - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Kitchen | temp | 22.8 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Living Room | temp | 22.3 | - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -{{% /expand %}} - -{{% expand "Return the last temperature from each room" %}} - -Using the [data written in "Get started writing to InfluxDB"](/influxdb/v2/get-started/write/#view-the-written-data): - -1. Query the `temp` field. -2. Use [`last()`](/flux/v0/stdlib/universe/last/) to return the - last row from each table. - -```js -from(bucket: "get-started") - |> range(start: 2022-01-01T14:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field == "temp") - |> last() -``` - -{{< tabs-wrapper >}} -{{% tabs "small" %}} -[Input](#) -[Output](#) -Click to view output -{{% /tabs %}} -{{% tab-content %}} - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Kitchen | temp | 22.8 | -| 2022-01-01T15:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T16:00:00Z | home | Kitchen | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T18:00:00Z | home | Kitchen | temp | 23.3 | -| 2022-01-01T19:00:00Z | home | Kitchen | temp | 23.1 | -| 2022-01-01T20:00:00Z | home | Kitchen | temp | 22.7 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T15:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T16:00:00Z | home | Living Room | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Living Room | temp | 22.6 | -| 2022-01-01T18:00:00Z | home | Living Room | temp | 22.8 | -| 2022-01-01T19:00:00Z | home | Living Room | temp | 22.5 | -| 2022-01-01T20:00:00Z | home | Living Room | temp | 22.2 | - -{{% /tab-content %}} -{{% tab-content %}} - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T20:00:00Z | home | Kitchen | temp | 22.7 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T20:00:00Z | home | Living Room | temp | 22.2 | - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -{{% /expand %}} - -{{% expand "Return the maximum temperature from each room" %}} - -Using the [data written in "Get started writing to InfluxDB"](/influxdb/v2/get-started/write/#view-the-written-data): - -1. Query the `temp` field. -2. Use [`max()`](/flux/v0/stdlib/universe/max/) to return the row - with the highest value in the `_value` column from each table. - -```js -from(bucket: "get-started") - |> range(start: 2022-01-01T14:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field == "temp") - |> max() -``` - -{{< tabs-wrapper >}} -{{% tabs "small" %}} -[Input](#) -[Output](#) -Click to view output -{{% /tabs %}} -{{% tab-content %}} - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Kitchen | temp | 22.8 | -| 2022-01-01T15:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T16:00:00Z | home | Kitchen | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T18:00:00Z | home | Kitchen | temp | 23.3 | -| 2022-01-01T19:00:00Z | home | Kitchen | temp | 23.1 | -| 2022-01-01T20:00:00Z | home | Kitchen | temp | 22.7 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T15:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T16:00:00Z | home | Living Room | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Living Room | temp | 22.6 | -| 2022-01-01T18:00:00Z | home | Living Room | temp | 22.8 | -| 2022-01-01T19:00:00Z | home | Living Room | temp | 22.5 | -| 2022-01-01T20:00:00Z | home | Living Room | temp | 22.2 | - -{{% /tab-content %}} -{{% tab-content %}} - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Kitchen | temp | 22.8 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T18:00:00Z | home | Living Room | temp | 22.8 | - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## Pivot data into a relational schema - -If coming from relational SQL or SQL-like query languages, such as InfluxQL, -the data model that Flux uses is different than what you're used to. -Flux returns multiple tables where each table contains a different field. -A "relational" schema structures each field as a column in each row. - -Use the [`pivot()` function](/flux/v0/stdlib/universe/pivot/) to -pivot data into a "relational" schema based on timestamps. - -```js -from(bucket: "get-started") - |> range(start: 2022-01-01T14:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field == "co" or r._field == "hum" or r._field == "temp") - |> filter(fn: (r) => r.room == "Kitchen") - |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value") -``` - -{{< expand-wrapper >}} -{{% expand "View input and pivoted output" %}} - -{{< tabs-wrapper >}} -{{% tabs "small" %}} -[Input](#) -[Output](#) -Click to view output -{{% /tabs %}} -{{% tab-content %}} - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :------ | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Kitchen | co | 1 | -| 2022-01-01T15:00:00Z | home | Kitchen | co | 3 | -| 2022-01-01T16:00:00Z | home | Kitchen | co | 7 | -| 2022-01-01T17:00:00Z | home | Kitchen | co | 9 | -| 2022-01-01T18:00:00Z | home | Kitchen | co | 18 | -| 2022-01-01T19:00:00Z | home | Kitchen | co | 22 | -| 2022-01-01T20:00:00Z | home | Kitchen | co | 26 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :------ | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Kitchen | hum | 36.3 | -| 2022-01-01T15:00:00Z | home | Kitchen | hum | 36.2 | -| 2022-01-01T16:00:00Z | home | Kitchen | hum | 36 | -| 2022-01-01T17:00:00Z | home | Kitchen | hum | 36 | -| 2022-01-01T18:00:00Z | home | Kitchen | hum | 36.9 | -| 2022-01-01T19:00:00Z | home | Kitchen | hum | 36.6 | -| 2022-01-01T20:00:00Z | home | Kitchen | hum | 36.5 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :------ | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Kitchen | temp | 22.8 | -| 2022-01-01T15:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T16:00:00Z | home | Kitchen | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T18:00:00Z | home | Kitchen | temp | 23.3 | -| 2022-01-01T19:00:00Z | home | Kitchen | temp | 23.1 | -| 2022-01-01T20:00:00Z | home | Kitchen | temp | 22.7 | - -{{% /tab-content %}} -{{% tab-content %}} - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _time | _measurement | room | co | hum | temp | -| :------------------- | :----------- | :------ | --: | ---: | ---: | -| 2022-01-01T14:00:00Z | home | Kitchen | 1 | 36.3 | 22.8 | -| 2022-01-01T15:00:00Z | home | Kitchen | 3 | 36.2 | 22.7 | -| 2022-01-01T16:00:00Z | home | Kitchen | 7 | 36 | 22.4 | -| 2022-01-01T17:00:00Z | home | Kitchen | 9 | 36 | 22.7 | -| 2022-01-01T18:00:00Z | home | Kitchen | 18 | 36.9 | 23.3 | -| 2022-01-01T19:00:00Z | home | Kitchen | 22 | 36.6 | 23.1 | -| 2022-01-01T20:00:00Z | home | Kitchen | 26 | 36.5 | 22.7 | - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -{{% /expand %}} -{{< /expand-wrapper >}} - -## Downsample data - -Downsampling data is a strategy that improve performance at query time and also -optimizes long-term data storage. Simply put, downsampling reduces the number of -points returned by a query without losing the general trends in the data. - -_For more information about downsampling data, see -[Downsample data](/influxdb/v2/process-data/common-tasks/downsample-data/)._ - -The most common way to downsample data is by time intervals or "windows." -For example, you may want to query the last hour of data and return the average -value for every five minute window. - -Use [`aggregateWindow()`](/flux/v0/stdlib/universe/aggregatewindow/) -to downsample data by specified time intervals: - -- Use the `every` parameter to specify the duration of each window. -- Use the `fn` parameter to specify what [aggregate](/flux/v0/function-types/#aggregates) - or [selector](/flux/v0/function-types/#selectors) function - to apply to each window. -- _(Optional)_ Use the `timeSrc` parameter to specify which column value to - use to create the new aggregate timestamp for each window. - The default is `_stop`. - -```js -from(bucket: "get-started") - |> range(start: 2022-01-01T14:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field == "temp") - |> aggregateWindow(every: 2h, fn: mean) -``` - -{{< expand-wrapper >}} -{{% expand "View input and downsampled output" %}} - -{{< tabs-wrapper >}} -{{% tabs "small" %}} -[Input](#) -[Output](#) -Click to view output -{{% /tabs %}} -{{% tab-content %}} - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Kitchen | temp | 22.8 | -| 2022-01-01T15:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T16:00:00Z | home | Kitchen | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T18:00:00Z | home | Kitchen | temp | 23.3 | -| 2022-01-01T19:00:00Z | home | Kitchen | temp | 23.1 | -| 2022-01-01T20:00:00Z | home | Kitchen | temp | 22.7 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T14:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T15:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T16:00:00Z | home | Living Room | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Living Room | temp | 22.6 | -| 2022-01-01T18:00:00Z | home | Living Room | temp | 22.8 | -| 2022-01-01T19:00:00Z | home | Living Room | temp | 22.5 | -| 2022-01-01T20:00:00Z | home | Living Room | temp | 22.2 | - -{{% /tab-content %}} -{{% tab-content %}} - -{{% note %}} -`_start` and `_stop` columns have been omitted. -{{% /note %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----------------: | -| 2022-01-01T16:00:00Z | home | Kitchen | temp | 22.75 | -| 2022-01-01T18:00:00Z | home | Kitchen | temp | 22.549999999999997 | -| 2022-01-01T20:00:00Z | home | Kitchen | temp | 23.200000000000003 | -| 2022-01-01T20:00:01Z | home | Kitchen | temp | 22.7 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----------------: | -| 2022-01-01T16:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T18:00:00Z | home | Living Room | temp | 22.5 | -| 2022-01-01T20:00:00Z | home | Living Room | temp | 22.65 | -| 2022-01-01T20:00:01Z | home | Living Room | temp | 22.2 | - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -{{% /expand %}} -{{< /expand-wrapper >}} - -## Automate processing with InfluxDB tasks - -[InfluxDB tasks](/influxdb/v2/process-data/get-started/) are scheduled queries -that can perform any of the data processing operations described above. -Generally tasks then use the [`to()` function](/flux/v0/stdlib/influxdata/influxdb/to/) -to write the processed result back to InfluxDB. - -_For more information about creating and configuring tasks, see -[Get started with InfluxDB tasks](/influxdb/v2/process-data/get-started/)._ - -#### Example downsampling task - -```js -option task = { - name: "Example task" - every: 1d, -} - -from(bucket: "get-started-downsampled") - |> range(start: -task.every) - |> filter(fn: (r) => r._measurement == "home") - |> aggregateWindow(every: 2h, fn: mean) -``` -{{< page-nav prev="/influxdb/v2/get-started/query/" next="/influxdb/v2/get-started/visualize/" keepTab=true >}} + diff --git a/content/influxdb/v2/get-started/query.md b/content/influxdb/v2/get-started/query.md index bb276e000..d132f2cd0 100644 --- a/content/influxdb/v2/get-started/query.md +++ b/content/influxdb/v2/get-started/query.md @@ -14,590 +14,8 @@ weight: 102 metadata: [3 / 5] related: - /influxdb/v2/query-data/ +source: /shared/influxdb-v2/get-started/query.md --- -InfluxDB supports many different tools for querying data, including: - -- InfluxDB user interface (UI) -- [InfluxDB HTTP API](/influxdb/v2/reference/api/) -- [`influx` CLI](/influxdb/v2/tools/influx-cli/) -- [Chronograf](/chronograf/v1/) -- [Grafana](/influxdb/v2/tools/grafana/) -- [InfluxDB client libraries](/influxdb/v2/api-guide/client-libraries/) - -This tutorial walks you through the fundamentals of querying data in InfluxDB and -focuses primarily on the two languages you can use to query your time series data: - -- **Flux**: A functional scripting language designed to query and process data - from InfluxDB and other data sources. -- **InfluxQL**: A SQL-like query language designed to query time series data from - InfluxDB. - -{{% note %}} -The examples in this section of the tutorial query the data from written in the -[Get started writing data](/influxdb/v2/get-started/write/#write-line-protocol-to-influxdb) section. -{{% /note %}} - -###### On this page: -- [Query data with Flux](#query-data-with-flux) - - [Flux query basics](#flux-query-basics) - - [Execute a Flux query](#execute-a-flux-query) -- [Query data with InfluxQL](#query-data-with-influxql) - - [InfluxQL query basics](#influxql-query-basics) - - [Execute an InfluxQL query](#execute-an-influxql-query) - ---- - -## Query data with Flux - -Flux is a functional scripting language that lets you query and process data -from InfluxDB and [other data sources](/flux/v0/query-data/). - -{{% note %}} -This is a brief introduction to writing Flux queries. -For a more in-depth introduction, see [Get started with Flux](/flux/v0/get-started/). -{{% /note %}} - -### Flux query basics - -When querying InfluxDB with Flux, there are three primary functions you use: - -- [from()](/flux/v0/stdlib/influxdata/influxdb/from/): - Queries data from an InfluxDB bucket. -- [range()](/flux/v0/stdlib/universe/range/): - Filters data based on time bounds. Flux requires "bounded" queries—queries - limited to a specific time range. -- [filter()](/flux/v0/stdlib/universe/filter/): - Filters data based on column values. Each row is represented by `r` - and each column is represented by a property of `r`. - You can apply multiple subsequent filters. - - To see how `from()` structures data into rows and tables when returned from InfluxDB, - [view the data written in Get started writing to InfluxDB](/influxdb/v2/get-started/write/#view-the-written-data). - - {{< expand-wrapper >}} -{{% expand "Learn more about how `filter()` works" %}} - -[`filter()`](/flux/v0/stdlib/universe/filter/) reads each row as a -[record](/flux/v0/data-types/composite/record/) named `r`. -In the `r` record, each key-value pair represents a column and its value. -For example: - -```js -r = { - _time: 2020-01-01T00:00:00Z, - _measurement: "home", - room: "Kitchen", - _field: "temp", - _value: 21.0, -} -``` - -To filter rows, use [predicate expressions](/flux/v0/get-started/syntax-basics/#predicate-expressions) -to evaluate the values of columns. Given the row record above: - -```javascript -(r) => r._measurement == "home" // Returns true -(r) => r.room == "Kitchen" // Returns true -(r) => r._field == "co" // Returns false -(r) => r._field == "co" or r._field == "temp" // Returns true -(r) => r._value <= 20.0 // Returns false -``` - -Rows that evaluate to `true` are included in the `filter()` output. -Rows that evaluate to `false` are dropped from the `filter()` output. - {{% /expand %}} - {{< /expand-wrapper >}} - -#### Pipe-forward operator - -Flux uses the pipe-forward operator (`|>`) to pipe the output of one function as -input the next function as input. - -#### Query the example data - -The following Flux query returns the **co**, **hum**, and **temp** fields stored in -the **home** measurement with timestamps **between 2022-01-01T08:00:00Z and 2022-01-01T20:00:01Z**. - -```js -from(bucket: "get-started") - |> range(start: 2022-01-01T08:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field== "co" or r._field == "hum" or r._field == "temp") -``` - -### Execute a Flux query - -Use the **InfluxDB UI**, **`influx` CLI**, or **InfluxDB API** to execute Flux queries. - -{{< tabs-wrapper >}} -{{% tabs %}} -[InfluxDB UI](#) -[influx CLI](#) -[InfluxDB API](#) -{{% /tabs %}} - -{{% tab-content %}} - - -1. Visit - {{% oss-only %}}[localhost:8086](http://localhost:8086){{% /oss-only %}} - {{% cloud-only %}}[cloud2.influxdata.com](https://cloud2.influxdata.com){{% /cloud-only %}} - in a browser to log in and access the InfluxDB UI. - -2. In the left navigation bar, click **Data Explorer**. - -{{< nav-icon "data-explorer" "v4" >}} - -3. The InfluxDB Data Explorer provides two options for querying data with Flux: - - - [Query Builder](#query-builder) _(default)_: - Visual query builder that lets you select the time range, - measurement, tags, and fields to query. - - [Script Editor](#script-editor): - In-browser code editor for composing and running Flux scripts. - - --- - - #### Query builder - - **To build and execute a Flux query with the query builder**: - - 1. In the **{{% caps %}}FROM{{% /caps %}}** column, select the bucket to query. For this tutorial, - select the **get-started** bucket. - 2. In the next **filter** column, select **_measurement** from the - column dropdown menu, and then select the **home** measurement. - 3. _(Optional)_ To query a specific field or fields, in the next **filter** - column, select **_field** from the column dropdown menu, and then - select the fields to query. In this tutorial, there are three - fields: **co**, **hum**, and **temp**. - 4. _(Optional)_ To query by specific tag values, in the next **filter** - column, select then tag column from the column dropdown menu, and then - select the tag values to filter by. In this tutorial, the tag only - tag column is **room**. - 5. _(Optional)_ In the **{{% caps %}}Aggregate Function{{% /caps %}}** pane, - select an aggregate or selector function to use to downsample the data. - The default aggregate function is `mean`. - 6. In the time range dropdown menu, select **Custom Time Range**, and - select the following dates from the date selectors: - - - **Start**: 2022-01-01 08:00:00 - - **Stop**: 2022-01-01 20:00:01 - - _Note the addition of one second to the stop time. In Flux, stop - times are exclusive and will exclude points with that timestamp. - By adding one second, the query will include all points to - 2022-01-01 20:00:00_. - - 7. Click **{{% caps %}}Submit{{% /caps %}}** to execute the query with the - selected filters and operations and display the result. - - --- - - #### Script editor - - **To write and execute a Flux query with the query builder**: - - 1. In the Data Explorer, click **{{% caps %}}Script Editor{{% /caps %}}**. - 2. Write your Flux query in the Script Editor text field. - - _**Note**: You can either hand-write the functions or you can use the function list - to the right of the script editor to search for and inject functions._ - - 1. Use `from()` and specify the bucket to query with the `bucket` parameter. - For this tutorial, query the **get-started** bucket. - 2. Use `range()` to specify the time range to query. The `start` - parameter defines the earliest time to include in results. - The `stop` parameter specifies the latest time (exclusively) to - include in results. - - - **start**: 2022-01-01T08:00:00Z - - **stop**: 2022-01-01T20:00:01Z - - _Note the addition of one second to the stop time. In Flux, stop - times are exclusive and will exclude points with that timestamp. - By adding one second, the query will include all points to - 2022-01-01 20:00:00_. - - If you want to use the start and stop times selected in the time - selection dropdown menu, use `v.timeRangeStart` and `v.timeRangeStop` - as the values for the `start` and `stop` parameters. - - 3. Use `filter()` to filter results by the **home** measurement. - 4. _(Optional)_ Use `filter()` to filter results by a specific field. - In this tutorial, there are three fields: **co**, **hum**, and **temp**. - 5. _(Optional)_ Use `filter()` to filter results by specific - tag values. In this tutorial, there is one tag, **room**, with two - potential values: **Living Room** or **Kitchen**. - - ```js - from(bucket: "get-started") - |> range(start: 2022-01-01T08:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field== "co" or r._field == "hum" or r._field == "temp") - ``` - - 3. Click **{{% caps %}}Submit{{% /caps %}}** to execute the query with the - selected filters and operations and display the result. - - -{{% /tab-content %}} -{{% tab-content %}} - - -1. If you haven't already, [download, install, and configure the `influx` CLI](/influxdb/v2/tools/influx-cli/). -2. Use the [`influx query` command](/influxdb/v2/reference/cli/influx/query/) - to query InfluxDB using Flux. - - **Provide the following**: - - - String-encoded Flux query. - - [Connection and authentication credentials](/influxdb/v2/get-started/setup/?t=influx+CLI#configure-authentication-credentials) - -```sh -influx query ' -from(bucket: "get-started") - |> range(start: 2022-01-01T08:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field== "co" or r._field == "hum" or r._field == "temp") -' -``` - - -{{% /tab-content %}} -{{% tab-content %}} - - -To query data from InfluxDB using Flux and the InfluxDB HTTP API, send a request -to the InfluxDB API [`/api/v2/query` endpoint](/influxdb/v2/api/#operation/PostQuery) -using the `POST` request method. - -{{< api-endpoint endpoint="http://localhost:8086/api/v2/query" method="post" api-ref="/influxdb/v2/api/#operation/PostQuery" >}} - -Include the following with your request: - -- **Headers**: - - **Authorization**: Token - - **Content-Type**: application/vnd.flux - - **Accept**: application/csv - - _(Optional)_ **Accept-Encoding**: gzip -- **Query parameters**: - - **org**: InfluxDB organization name -- **Request body**: Flux query as plain text - -The following example uses cURL and the InfluxDB API to query data with Flux: - -```sh -curl --request POST \ -"$INFLUX_HOST/api/v2/query?org=$INFLUX_ORG&bucket=get-started" \ - --header "Authorization: Token $INFLUX_TOKEN" \ - --header "Content-Type: application/vnd.flux" \ - --header "Accept: application/csv" \ - --data 'from(bucket: "get-started") - |> range(start: 2022-01-01T08:00:00Z, stop: 2022-01-01T20:00:01Z) - |> filter(fn: (r) => r._measurement == "home") - |> filter(fn: (r) => r._field== "co" or r._field == "hum" or r._field == "temp") - ' -``` - -{{% note %}} -The InfluxDB `/api/v2/query` endpoint returns query results in -[annotated CSV](/influxdb/v2/reference/syntax/annotated-csv/). -{{% /note %}} - - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -### Flux query results - -{{< expand-wrapper >}} -{{% expand "View Flux query results" %}} - -{{% note %}} -`_start` and `_stop` columns have been omitted. -These columns, by default, represent the query time bounds and are added by `range()`. -{{% /note %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :------ | :----- | -----: | -| 2022-01-01T08:00:00Z | home | Kitchen | co | 0 | -| 2022-01-01T09:00:00Z | home | Kitchen | co | 0 | -| 2022-01-01T10:00:00Z | home | Kitchen | co | 0 | -| 2022-01-01T11:00:00Z | home | Kitchen | co | 0 | -| 2022-01-01T12:00:00Z | home | Kitchen | co | 0 | -| 2022-01-01T13:00:00Z | home | Kitchen | co | 1 | -| 2022-01-01T14:00:00Z | home | Kitchen | co | 1 | -| 2022-01-01T15:00:00Z | home | Kitchen | co | 3 | -| 2022-01-01T16:00:00Z | home | Kitchen | co | 7 | -| 2022-01-01T17:00:00Z | home | Kitchen | co | 9 | -| 2022-01-01T18:00:00Z | home | Kitchen | co | 18 | -| 2022-01-01T19:00:00Z | home | Kitchen | co | 22 | -| 2022-01-01T20:00:00Z | home | Kitchen | co | 26 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :------ | :----- | -----: | -| 2022-01-01T08:00:00Z | home | Kitchen | hum | 35.9 | -| 2022-01-01T09:00:00Z | home | Kitchen | hum | 36.2 | -| 2022-01-01T10:00:00Z | home | Kitchen | hum | 36.1 | -| 2022-01-01T11:00:00Z | home | Kitchen | hum | 36 | -| 2022-01-01T12:00:00Z | home | Kitchen | hum | 36 | -| 2022-01-01T13:00:00Z | home | Kitchen | hum | 36.5 | -| 2022-01-01T14:00:00Z | home | Kitchen | hum | 36.3 | -| 2022-01-01T15:00:00Z | home | Kitchen | hum | 36.2 | -| 2022-01-01T16:00:00Z | home | Kitchen | hum | 36 | -| 2022-01-01T17:00:00Z | home | Kitchen | hum | 36 | -| 2022-01-01T18:00:00Z | home | Kitchen | hum | 36.9 | -| 2022-01-01T19:00:00Z | home | Kitchen | hum | 36.6 | -| 2022-01-01T20:00:00Z | home | Kitchen | hum | 36.5 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :------ | :----- | -----: | -| 2022-01-01T08:00:00Z | home | Kitchen | temp | 21 | -| 2022-01-01T09:00:00Z | home | Kitchen | temp | 23 | -| 2022-01-01T10:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T11:00:00Z | home | Kitchen | temp | 22.4 | -| 2022-01-01T12:00:00Z | home | Kitchen | temp | 22.5 | -| 2022-01-01T13:00:00Z | home | Kitchen | temp | 22.8 | -| 2022-01-01T14:00:00Z | home | Kitchen | temp | 22.8 | -| 2022-01-01T15:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T16:00:00Z | home | Kitchen | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T18:00:00Z | home | Kitchen | temp | 23.3 | -| 2022-01-01T19:00:00Z | home | Kitchen | temp | 23.1 | -| 2022-01-01T20:00:00Z | home | Kitchen | temp | 22.7 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T08:00:00Z | home | Living Room | co | 0 | -| 2022-01-01T09:00:00Z | home | Living Room | co | 0 | -| 2022-01-01T10:00:00Z | home | Living Room | co | 0 | -| 2022-01-01T11:00:00Z | home | Living Room | co | 0 | -| 2022-01-01T12:00:00Z | home | Living Room | co | 0 | -| 2022-01-01T13:00:00Z | home | Living Room | co | 0 | -| 2022-01-01T14:00:00Z | home | Living Room | co | 0 | -| 2022-01-01T15:00:00Z | home | Living Room | co | 1 | -| 2022-01-01T16:00:00Z | home | Living Room | co | 4 | -| 2022-01-01T17:00:00Z | home | Living Room | co | 5 | -| 2022-01-01T18:00:00Z | home | Living Room | co | 9 | -| 2022-01-01T19:00:00Z | home | Living Room | co | 14 | -| 2022-01-01T20:00:00Z | home | Living Room | co | 17 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T08:00:00Z | home | Living Room | hum | 35.9 | -| 2022-01-01T09:00:00Z | home | Living Room | hum | 35.9 | -| 2022-01-01T10:00:00Z | home | Living Room | hum | 36 | -| 2022-01-01T11:00:00Z | home | Living Room | hum | 36 | -| 2022-01-01T12:00:00Z | home | Living Room | hum | 35.9 | -| 2022-01-01T13:00:00Z | home | Living Room | hum | 36 | -| 2022-01-01T14:00:00Z | home | Living Room | hum | 36.1 | -| 2022-01-01T15:00:00Z | home | Living Room | hum | 36.1 | -| 2022-01-01T16:00:00Z | home | Living Room | hum | 36 | -| 2022-01-01T17:00:00Z | home | Living Room | hum | 35.9 | -| 2022-01-01T18:00:00Z | home | Living Room | hum | 36.2 | -| 2022-01-01T19:00:00Z | home | Living Room | hum | 36.3 | -| 2022-01-01T20:00:00Z | home | Living Room | hum | 36.4 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T08:00:00Z | home | Living Room | temp | 21.1 | -| 2022-01-01T09:00:00Z | home | Living Room | temp | 21.4 | -| 2022-01-01T10:00:00Z | home | Living Room | temp | 21.8 | -| 2022-01-01T11:00:00Z | home | Living Room | temp | 22.2 | -| 2022-01-01T12:00:00Z | home | Living Room | temp | 22.2 | -| 2022-01-01T13:00:00Z | home | Living Room | temp | 22.4 | -| 2022-01-01T14:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T15:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T16:00:00Z | home | Living Room | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Living Room | temp | 22.6 | -| 2022-01-01T18:00:00Z | home | Living Room | temp | 22.8 | -| 2022-01-01T19:00:00Z | home | Living Room | temp | 22.5 | -| 2022-01-01T20:00:00Z | home | Living Room | temp | 22.2 | - -{{% /expand %}} -{{< /expand-wrapper >}} - -## Query data with InfluxQL - -InfluxQL is a SQL-like query language similar to most SQL languages, but -specifically designed to query time series data from InfluxDB 0.x and 1.x. - -{{% note %}} -#### Map databases and retention policies to buckets - -Because InfluxQL was developed for earlier versions of InfluxDB, it depends on -**databases and retention policies** (DBRP) which have been replaced by -[buckets](/influxdb/v2/get-started/#data-organization) in InfluxDB {{< current-version >}}. -To use InfluxQL with InfluxDB {{< current-version >}}, first -[map database and retention policy (DBRP) combinations to an InfluxDB bucket](/influxdb/v2/query-data/influxql/dbrp/). -{{% /note %}} - -### InfluxQL query basics - -When querying InfluxDB with InfluxQL, the most basic query includes the following -statements and clauses: - -- `SELECT`: Specify which fields and tags to query. -- `FROM`: Specify the measurement to query. - Use the measurement name or a fully-qualified measurement name which includes - the database and retention policy. For example: `db.rp.measurement`. -- `WHERE`: _(Optional)_ Filter data based on fields, tags, and time. - -The following InfluxQL query returns the **co**, **hum**, and **temp** fields and -the **room** tag stored in the **home** measurement with timestamps -**between 2022-01-01T08:00:00Z and 2022-01-01T20:00:00Z**. - -```sql -SELECT co,hum,temp,room FROM "get-started".autogen.home WHERE time >= '2022-01-01T08:00:00Z' AND time <= '2022-01-01T20:00:00Z' -``` - -{{% note %}} -These are just the fundamentals of the InfluxQL syntax. -For more in-depth information, see the [InfluxQL documentation](/influxdb/v2/query-data/influxql/). -{{% /note %}} - -### Execute an InfluxQL query - -Use the **`influx` CLI**, or **InfluxDB API** to execute InfluxQL queries. - -{{< tabs-wrapper >}} -{{% tabs %}} -[InfluxDB UI](#) -[influx CLI](#) -[InfluxDB API](#) -{{% /tabs %}} - -{{% tab-content %}} - - -{{% note %}} -#### The influxdb UI does not support InfluxQL - -The InfluxDB {{< current-version >}} UI does not provide a way to query data with InfluxQL. -For a user interface that builds and executes InfluxQL queries, consider using -[Chronograf](/influxdb/v2/tools/chronograf/) or -[Grafana](/influxdb/v2/tools/grafana/) with InfluxDB {{< current-version >}}. -{{% /note %}} - - -{{% /tab-content %}} -{{% tab-content %}} - - -{{< cli/influx-creds-note >}} - -1. If you haven't already, [download, install, and configure the `influx` CLI](/influxdb/v2/tools/influx-cli/). -2. Use the [`influx v1 shell` command](/influxdb/v2/reference/cli/influx/v1/shell/) - to start an InfluxQL shell and query InfluxDB using InfluxQL. - Provide the following: - - - [Connection and authentication credentials](/influxdb/v2/get-started/setup/?t=influx+CLI#configure-authentication-credentials) - - ```sh - influx v1 shell - ``` - -3. Enter an InfluxQL query and press {{< keybind mac="return" other="Enter ↵" >}}. - - ```sql - SELECT co,hum,temp,room FROM "get-started".autogen.home WHERE time >= '2022-01-01T08:00:00Z' AND time <= '2022-01-01T20:00:00Z' - ``` - - -{{% /tab-content %}} -{{% tab-content %}} - - -To query data from InfluxDB using InfluxQL and the InfluxDB HTTP API, send a request -to the InfluxDB API [`/query` 1.X compatibility endpoint](/influxdb/v2/reference/api/influxdb-1x/query/) -using the `POST` request method. - -{{< api-endpoint endpoint="http://localhost:8086/query" method="post" api-ref="/influxdb/v2/api/v1-compatibility/#operation/PostQueryV1" >}} - -Include the following with your request: - -- **Headers**: - - **Authorization**: Token - - **Accept**: application/json - - _(Optional)_ **Accept-Encoding**: gzip -- **Query parameters**: - - **db**: Database to query. - - **rp**: Retention policy to query data from. - - **q**: InfluxQL query to execute. - - **epoch**: _(Optional)_ Return results with - [Unix timestamps](/influxdb/v2/reference/glossary/#unix-timestamp) of a - specified precision instead of [RFC3339 timestamps](/influxdb/v2/reference/glossary/#rfc3339-timestamp). The following precisions are available: - - - `ns` - nanoseconds - - `u` or `µ` - microseconds - - `ms` - milliseconds - - `s` - seconds - - `m` - minutes - - `h` - hours - -- **Request body**: Flux query as plain text - -The following example uses cURL and the InfluxDB API to query data with InfluxQL: - -```sh -curl --get "$INFLUX_HOST/query?org=$INFLUX_ORG&bucket=get-started" \ - --header "Authorization: Token $INFLUX_TOKEN" \ - --data-urlencode "db=get-started" \ - --data-urlencode "rp=autogen" \ - --data-urlencode "q=SELECT co,hum,temp,room FROM home WHERE time >= '2022-01-01T08:00:00Z' AND time <= '2022-01-01T20:00:00Z'" -``` - -{{% note %}} -The InfluxDB `/write` 1.x compatibility endpoint returns query results in JSON format. -{{% /note %}} - - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -### InfluxQL query results - -{{< expand-wrapper >}} -{{% expand "View InfluxQL query results" %}} - -| time | room | co | hum | temp | -| :------------------- | :---------- | --: | ---: | ---: | -| 2022-01-01T08:00:00Z | Kitchen | 0 | 35.9 | 21 | -| 2022-01-01T08:00:00Z | Living Room | 0 | 35.9 | 21.1 | -| 2022-01-01T09:00:00Z | Kitchen | 0 | 36.2 | 23 | -| 2022-01-01T09:00:00Z | Living Room | 0 | 35.9 | 21.4 | -| 2022-01-01T10:00:00Z | Kitchen | 0 | 36.1 | 22.7 | -| 2022-01-01T10:00:00Z | Living Room | 0 | 36 | 21.8 | -| 2022-01-01T11:00:00Z | Kitchen | 0 | 36 | 22.4 | -| 2022-01-01T11:00:00Z | Living Room | 0 | 36 | 22.2 | -| 2022-01-01T12:00:00Z | Kitchen | 0 | 36 | 22.5 | -| 2022-01-01T12:00:00Z | Living Room | 0 | 35.9 | 22.2 | -| 2022-01-01T13:00:00Z | Kitchen | 1 | 36.5 | 22.8 | -| 2022-01-01T13:00:00Z | Living Room | 0 | 36 | 22.4 | -| 2022-01-01T14:00:00Z | Kitchen | 1 | 36.3 | 22.8 | -| 2022-01-01T14:00:00Z | Living Room | 0 | 36.1 | 22.3 | -| 2022-01-01T15:00:00Z | Kitchen | 3 | 36.2 | 22.7 | -| 2022-01-01T15:00:00Z | Living Room | 1 | 36.1 | 22.3 | -| 2022-01-01T16:00:00Z | Kitchen | 7 | 36 | 22.4 | -| 2022-01-01T16:00:00Z | Living Room | 4 | 36 | 22.4 | -| 2022-01-01T17:00:00Z | Kitchen | 9 | 36 | 22.7 | -| 2022-01-01T17:00:00Z | Living Room | 5 | 35.9 | 22.6 | -| 2022-01-01T18:00:00Z | Kitchen | 18 | 36.9 | 23.3 | -| 2022-01-01T18:00:00Z | Living Room | 9 | 36.2 | 22.8 | -| 2022-01-01T19:00:00Z | Kitchen | 22 | 36.6 | 23.1 | -| 2022-01-01T19:00:00Z | Living Room | 14 | 36.3 | 22.5 | -| 2022-01-01T20:00:00Z | Kitchen | 26 | 36.5 | 22.7 | -| 2022-01-01T20:00:00Z | Living Room | 17 | 36.4 | 22.2 | - -{{% /expand %}} -{{< /expand-wrapper >}} - -**Congratulations!** You've learned the basics of querying data in InfluxDB. -For a deep dive into all the ways you can query InfluxDB, see the -[Query data in InfluxDB](/influxdb/v2/query-data/) section of documentation. - -Let's move on to more advanced data processing queries and automating queries -with InfluxDB tasks. - -{{< page-nav prev="/influxdb/v2/get-started/write/" next="/influxdb/v2/get-started/process/" keepTab=true >}} + diff --git a/content/influxdb/v2/get-started/setup.md b/content/influxdb/v2/get-started/setup.md index 444a10a10..a577e848d 100644 --- a/content/influxdb/v2/get-started/setup.md +++ b/content/influxdb/v2/get-started/setup.md @@ -223,8 +223,8 @@ For more options and details, see the [`POST /api/v2/setup` API endpoint documen 1. Visit - {{% oss-only %}}[localhost:8086](http://localhost:8086){{% /oss-only %}} - {{% cloud-only %}}[cloud2.influxdata.com](https://cloud2.influxdata.com){{% /cloud-only %}} + {{% show-in "v2" %}}[localhost:8086](http://localhost:8086){{% /show-in %}} + {{% show-in "cloud,cloud-serverless" %}}[cloud2.influxdata.com](https://cloud2.influxdata.com){{% /show-in %}} in a browser to log in and access the InfluxDB UI. 2. Navigate to **Load Data** > **API Tokens** using the left navigation bar. @@ -564,8 +564,8 @@ Replace the following: 1. Visit - {{% oss-only %}}[localhost:8086](http://localhost:8086){{% /oss-only %}} - {{% cloud-only %}}[cloud2.influxdata.com](https://cloud2.influxdata.com){{% /cloud-only %}} + {{% show-in "v2" %}}[localhost:8086](http://localhost:8086){{% /show-in %}} + {{% show-in "cloud,cloud-serverless" %}}[cloud2.influxdata.com](https://cloud2.influxdata.com){{% /show-in %}} in a browser to log in and access the InfluxDB UI. 2. Navigate to **Load Data** > **Buckets** using the left navigation bar. diff --git a/content/influxdb/v2/get-started/visualize.md b/content/influxdb/v2/get-started/visualize.md index 29a294579..1e3154106 100644 --- a/content/influxdb/v2/get-started/visualize.md +++ b/content/influxdb/v2/get-started/visualize.md @@ -17,169 +17,8 @@ related: - /influxdb/v2/visualize-data/visualization-types/ - /influxdb/v2/tools/chronograf/ - /influxdb/v2/tools/grafana/ +source: /shared/influxdb-v2/get-started/visualize.md --- -There are many tools you can use to visualize your time series data including the -InfluxDB user interface (UI), [Chronograf](/influxdb/v2/tools/chronograf/), and -[Grafana](/influxdb/v2/tools/grafana/). -This tutorial walks you through using the **InfluxDB UI** to create a simple dashboard. - -Dashboards are a powerful way of displaying time series data and can help to -identify trends and anomalies. A dashboard is comprised of one or more -dashboard cells. A **dashboard cell** visualizes the results of a query using -one of the available [visualization types](/influxdb/v2/visualize-data/visualization-types/). - -- [Create a dashboard](#create-a-dashboard) -- [Create dashboard cells](#create-dashboard-cells) -- [Create and use dashboard variables](#create-and-use-dashboard-variables) - - [Create a custom dashboard variable](#create-a-custom-dashboard-variable) - - [Use a custom dashboard variable](#use-a-custom-dashboard-variable) - -## Create a dashboard - -1. With InfluxDB running, visit [localhost:8086](http://localhost:8086) in your - browser to access the InfluxDB UI. -2. Log in and select **Dashboards** in the left navigation bar. - - {{< nav-icon "dashboards" >}} - -3. Click **+ {{% caps %}}Create Dashboard{{% /caps %}}** and select **New Dashboard**. -4. Click _**Name this Dashboard**_ and provide a name for the dashboard. - For this tutorial, we'll use **"Getting Started Dashboard"**. - -## Create dashboard cells - -With your new dashboard created and named, add a new dashboard cell: - -1. Click **{{< icon "add-cell" >}} {{% caps %}}Add Cell{{% /caps %}}**. -2. Click _**Name this Cell**_ and provide a name for the cell. - For this tutorial, we'll use **"Room temperature"**. -3. _(Optional)_ Select the visualization type from the visualization drop-down menu. - There are many different [visualization types](/influxdb/v2/visualize-data/visualization-types/) - available. - For this tutorial, use the default **Graph** visualization. -4. Use the query time range selector to select an absolute time range that - covers includes the time range of the - [data written in "Get started writing to InfluxDB"](/influxdb/v2/get-started/write/#view-the-written-data): - **2022-01-01T08:00:00Z** to **2022-01-01T20:00:01Z**. - - 1. The query time range selector defaults to querying data from the last hour - (**{{< icon "clock" >}} Past 1h**). - Click the time range selector drop-down menu and select **Custom Time Range**. - - {{< expand-wrapper >}} - {{% expand "View time range selector" %}} -{{< img-hd src="/img/influxdb/2-4-get-started-visualize-time-range.png" alt="InfluxDB time range selector" />}} - {{% /expand %}} - {{< /expand-wrapper >}} - - 2. Use the date picker to select the stop and stop date and time or manually - enter the following start and stop times: - - - **Start**: 2022-01-01 08:00:00 - - **Stop**: 2022-01-01 20:00:01 - - 3. Click **{{% caps %}}Apply Time Range{{% /caps %}}**. - -5. Use the **Query Builder** to select the measurement, fields, and tags to query: - - 1. In the **{{% caps %}}From{{% /caps %}}** column, select the **get-started** bucket. - 2. In the **Filter** column, select the **home** measurement. - 3. In the next **Filter** column, select the **temp** field. - 4. In the next **Filter** column, select the **room** tag and the **Kitchen** tag value. - -6. Click **{{% caps %}}Submit{{% /caps %}}** to run the query and visualize the - results. - - {{< img-hd src="/img/influxdb/2-4-get-started-visualize-query-builder.png" alt="InfluxDB Query Builder" />}} - -7. Click **{{< icon "check" >}}** to save the cell and return to the dashboard. - -## Create and use dashboard variables - -InfluxDB dashboard cells use **dashboard variables** to dynamically change -specific parts of cell queries. -The query builder automatically builds queries using the following -[predefined dashboard variables](/influxdb/v2/visualize-data/variables/#predefined-dashboard-variables), -each controlled by selections in your dashboard: - -- `v.timeRangeStart`: Start time of the queried time range specified by the time range selector. -- `v.timeRangeStop`: Stop time of the queried time range specified by the time range selector. -- `v.windowPeriod`: Window period used downsample data to one point per pixel in - a cell visualization. The value of this variable is determined by the pixel-width of the cell. - -### Create a custom dashboard variable - -Let's create a custom dashboard variable that we can use to change the field -displayed by your dashboard cell. - -1. Select **Settings > Variables** in the left navigation bar. - - {{< nav-icon "settings" >}} - -2. Click **+ {{% caps %}}Create Variable{{% /caps %}}** and select **New Variable**. -3. Name your variable. For this tutorial, name the variable, **"room"**. -4. Select the default **Query** dashboard variable type. - This variable type uses the results of a query to populate the list of potential - variable values. _For information about the other dashboard variable types, - see [Variable types](/influxdb/v2/visualize-data/variables/variable-types/)._ -5. Enter the following Flux query to return all the different `room` tag values - in your `get-started` bucket from the [Unix epoch](/influxdb/v2/reference/glossary/#unix-timestamp). - - ```js - import "influxdata/influxdb/schema" - - schema.tagValues(bucket: "get-started", tag: "room", start: time(v: 0)) - ``` - -6. Click **{{% caps %}}Create Variable{{% /caps %}}**. - -### Use a custom dashboard variable - -1. Navigate to your **Getting Started Dashboard** by clicking **Dashboards** in - the left navigation bar and the clicking on the name of your dashboard. - - {{< nav-icon "dashboards" >}} - -2. Click the **{{< icon "gear" >}}** on the **Room temperature** cell and select - **{{< icon "pencil" >}} Configure**. -3. Click **{{% caps %}}Script Editor{{% /caps %}}** to edit the Flux query - directly. -4. On line 5 of the Flux query, replace `"Kitchen"` with `v.room` to use the - selected value of the `room` dashboard variable. - - ```js - from(bucket: "get-started") - |> range(start: v.timeRangeStart, stop: v.timeRangeStop) - |> filter(fn: (r) => r["_measurement"] == "home") - |> filter(fn: (r) => r["_field"] == "temp") - |> filter(fn: (r) => r["room"] == v.room) - |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false) - |> yield(name: "mean") - ``` -5. Click **{{< icon "check" >}}** to save the cell and return to the dashboard. -6. Refresh the browser to reload the dashboard. -7. Use the **room variable** drop-down menu to select the room to display - recorded temperatures from. - - {{< img-hd src="/img/influxdb/2-4-get-started-visualize-variable-select.png" alt="InfluxDB dashboard variable selection" />}} - -_For more information about creating custom dashboard variables, see -[Use and manage dashboard variables](/influxdb/v2/visualize-data/variables/)._ - -{{< page-nav prev="/influxdb/v2/get-started/process/" >}} - ---- - -## Congratulations! - -You have walked through the -[basics of setting up, writing, querying, processing, and visualizing](/influxdb/v2/get-started/) -data with InfluxDB {{< current-version >}}. -Feel free to dive in deeper to each of these topics: - -- [Write data to InfluxDB](/influxdb/v2/write-data/) -- [Query data in InfluxDB](/influxdb/v2/query-data/) -- [Process data with InfluxDB](/influxdb/v2/process-data/) -- [Visualize data with the InfluxDB UI](/influxdb/v2/visualize-data/) - + diff --git a/content/influxdb/v2/get-started/write.md b/content/influxdb/v2/get-started/write.md index cef8288bf..f59ee56e2 100644 --- a/content/influxdb/v2/get-started/write.md +++ b/content/influxdb/v2/get-started/write.md @@ -17,377 +17,8 @@ related: - /influxdb/v2/write-data/best-practices/ - /influxdb/v2/reference/syntax/line-protocol/ - /telegraf/v1/ +source: /shared/influxdb-v2/get-started/write.md --- -InfluxDB provides many different options for ingesting or writing data, including -the following: - -- Influx user interface (UI) -- [InfluxDB HTTP API](/influxdb/v2/reference/api/) -- [`influx` CLI](/influxdb/v2/tools/influx-cli/) -- [Telegraf](/telegraf/v1/) -- [InfluxDB client libraries](/influxdb/v2/api-guide/client-libraries/) - -This tutorial walks you through the fundamental of using **line protocol** to write -data to InfluxDB. If using tools like Telegraf or InfluxDB client libraries, they will -build the line protocol for you, but it's good to understand how line protocol works. - -## Line protocol - -All data written to InfluxDB is written using **line protocol**, a text-based -format that lets you provide the necessary information to write a data point to InfluxDB. -_This tutorial covers the basics of line protocol, but for detailed information, -see the [Line protocol reference](/influxdb/v2/reference/syntax/line-protocol/)._ - -### Line protocol elements - -Each line of line protocol contains the following elements: - -{{< req type="key" >}} - -- {{< req "\*" >}} **measurement**: String that identifies the [measurement]() to store the data in. -- **tag set**: Comma-delimited list of key value pairs, each representing a tag. - Tag keys and values are unquoted strings. _Spaces, commas, and equal characters must be escaped._ -- {{< req "\*" >}} **field set**: Comma-delimited list key value pairs, each representing a field. - Field keys are unquoted strings. _Spaces and commas must be escaped._ - Field values can be [strings](/influxdb/v2/reference/syntax/line-protocol/#string) (quoted), - [floats](/influxdb/v2/reference/syntax/line-protocol/#float), - [integers](/influxdb/v2/reference/syntax/line-protocol/#integer), - [unsigned integers](/influxdb/v2/reference/syntax/line-protocol/#uinteger), - or [booleans](/influxdb/v2/reference/syntax/line-protocol/#boolean). -- **timestamp**: [Unix timestamp](/influxdb/v2/reference/syntax/line-protocol/#unix-timestamp) - associated with the data. InfluxDB supports up to nanosecond precision. - _If the precision of the timestamp is not in nanoseconds, you must specify the - precision when writing the data to InfluxDB._ - -#### Line protocol element parsing - -- **measurement**: Everything before the _first unescaped comma before the first whitespace_. -- **tag set**: Key-value pairs between the _first unescaped comma_ and the _first unescaped whitespace_. -- **field set**: Key-value pairs between the _first and second unescaped whitespaces_. -- **timestamp**: Integer value after the _second unescaped whitespace_. -- Lines are separated by the newline character (`\n`). - Line protocol is whitespace sensitive. - ---- - -{{< influxdb/line-protocol >}} - ---- - -_For schema design recommendations, see [InfluxDB schema design](/influxdb/v2/write-data/best-practices/schema-design/)._ - -## Construct line protocol - -With a basic understanding of line protocol, you can now construct line protocol -and write data to InfluxDB. -Consider a use case where you collect data from sensors in your home. -Each sensor collects temperature, humidity, and carbon monoxide readings. -To collect this data, use the following schema: - -- **measurement**: `home` - - **tags** - - `room`: Living Room or Kitchen - - **fields** - - `temp`: temperature in °C (float) - - `hum`: percent humidity (float) - - `co`: carbon monoxide in parts per million (integer) - - **timestamp**: Unix timestamp in _second_ precision - -Data is collected hourly beginning at 2022-01-01T08:00:00Z (UTC) until 2022-01-01T20:00:00Z (UTC). -The resulting line protocol would look something like the following: - -##### Home sensor data line protocol -```sh -home,room=Living\ Room temp=21.1,hum=35.9,co=0i 1641024000 -home,room=Kitchen temp=21.0,hum=35.9,co=0i 1641024000 -home,room=Living\ Room temp=21.4,hum=35.9,co=0i 1641027600 -home,room=Kitchen temp=23.0,hum=36.2,co=0i 1641027600 -home,room=Living\ Room temp=21.8,hum=36.0,co=0i 1641031200 -home,room=Kitchen temp=22.7,hum=36.1,co=0i 1641031200 -home,room=Living\ Room temp=22.2,hum=36.0,co=0i 1641034800 -home,room=Kitchen temp=22.4,hum=36.0,co=0i 1641034800 -home,room=Living\ Room temp=22.2,hum=35.9,co=0i 1641038400 -home,room=Kitchen temp=22.5,hum=36.0,co=0i 1641038400 -home,room=Living\ Room temp=22.4,hum=36.0,co=0i 1641042000 -home,room=Kitchen temp=22.8,hum=36.5,co=1i 1641042000 -home,room=Living\ Room temp=22.3,hum=36.1,co=0i 1641045600 -home,room=Kitchen temp=22.8,hum=36.3,co=1i 1641045600 -home,room=Living\ Room temp=22.3,hum=36.1,co=1i 1641049200 -home,room=Kitchen temp=22.7,hum=36.2,co=3i 1641049200 -home,room=Living\ Room temp=22.4,hum=36.0,co=4i 1641052800 -home,room=Kitchen temp=22.4,hum=36.0,co=7i 1641052800 -home,room=Living\ Room temp=22.6,hum=35.9,co=5i 1641056400 -home,room=Kitchen temp=22.7,hum=36.0,co=9i 1641056400 -home,room=Living\ Room temp=22.8,hum=36.2,co=9i 1641060000 -home,room=Kitchen temp=23.3,hum=36.9,co=18i 1641060000 -home,room=Living\ Room temp=22.5,hum=36.3,co=14i 1641063600 -home,room=Kitchen temp=23.1,hum=36.6,co=22i 1641063600 -home,room=Living\ Room temp=22.2,hum=36.4,co=17i 1641067200 -home,room=Kitchen temp=22.7,hum=36.5,co=26i 1641067200 -``` - -## Write line protocol to InfluxDB - -Use the **InfluxDB UI**, **`influx` CLI**, or **InfluxDB API** to write the -line protocol above to InfluxDB. - -{{< tabs-wrapper >}} -{{% tabs %}} -[InfluxDB UI](#) -[influx CLI](#) -[InfluxDB API](#) -{{% /tabs %}} - -{{% tab-content %}} - - -1. Visit - {{% oss-only %}}[localhost:8086](http://localhost:8086){{% /oss-only %}} - {{% cloud-only %}}[cloud2.influxdata.com](https://cloud2.influxdata.com){{% /cloud-only %}} - in a browser to log in and access the InfluxDB UI. - -2. Navigate to **Load Data** > **Buckets** using the left navigation bar. - -{{< nav-icon "load data" >}} - -3. Click **{{< icon "plus" >}} {{< caps >}}Add Data{{< /caps >}}** on the bucket - you want to write the data to and select **Line Protocol**. -4. Select **{{< caps >}}Enter Manually{{< /caps >}}**. -5. {{< req "Important" >}} In the **Precision** drop-down menu above the line - protocol text field, select **Seconds** (to match to precision of the - timestamps in the line protocol). -6. Copy the [line protocol above](#home-sensor-data-line-protocol) and paste it - into the line protocol text field. -7. Click **{{< caps >}}Write Data{{< /caps >}}**. - -The UI will confirm that the data has been written successfully. - - -{{% /tab-content %}} -{{% tab-content %}} - - -1. If you haven't already, [download, install, and configure the `influx` CLI](/influxdb/v2/tools/influx-cli/). -2. Use the [`influx write` command](/influxdb/v2/reference/cli/influx/write/) - to write the [line protocol above](#home-sensor-data-line-protocol) to InfluxDB. - - **Provide the following**: - - - `-b, --bucket` or `--bucket-id` flag with the bucket name or ID to write do. - - `-p, --precision` flag with the timestamp precision (`s`). - - String-encoded line protocol. - - [Connection and authentication credentials](/influxdb/v2/get-started/setup/?t=influx+CLI#configure-authentication-credentials) - - ```sh - influx write \ - --bucket get-started \ - --precision s " - home,room=Living\ Room temp=21.1,hum=35.9,co=0i 1641024000 - home,room=Kitchen temp=21.0,hum=35.9,co=0i 1641024000 - home,room=Living\ Room temp=21.4,hum=35.9,co=0i 1641027600 - home,room=Kitchen temp=23.0,hum=36.2,co=0i 1641027600 - home,room=Living\ Room temp=21.8,hum=36.0,co=0i 1641031200 - home,room=Kitchen temp=22.7,hum=36.1,co=0i 1641031200 - home,room=Living\ Room temp=22.2,hum=36.0,co=0i 1641034800 - home,room=Kitchen temp=22.4,hum=36.0,co=0i 1641034800 - home,room=Living\ Room temp=22.2,hum=35.9,co=0i 1641038400 - home,room=Kitchen temp=22.5,hum=36.0,co=0i 1641038400 - home,room=Living\ Room temp=22.4,hum=36.0,co=0i 1641042000 - home,room=Kitchen temp=22.8,hum=36.5,co=1i 1641042000 - home,room=Living\ Room temp=22.3,hum=36.1,co=0i 1641045600 - home,room=Kitchen temp=22.8,hum=36.3,co=1i 1641045600 - home,room=Living\ Room temp=22.3,hum=36.1,co=1i 1641049200 - home,room=Kitchen temp=22.7,hum=36.2,co=3i 1641049200 - home,room=Living\ Room temp=22.4,hum=36.0,co=4i 1641052800 - home,room=Kitchen temp=22.4,hum=36.0,co=7i 1641052800 - home,room=Living\ Room temp=22.6,hum=35.9,co=5i 1641056400 - home,room=Kitchen temp=22.7,hum=36.0,co=9i 1641056400 - home,room=Living\ Room temp=22.8,hum=36.2,co=9i 1641060000 - home,room=Kitchen temp=23.3,hum=36.9,co=18i 1641060000 - home,room=Living\ Room temp=22.5,hum=36.3,co=14i 1641063600 - home,room=Kitchen temp=23.1,hum=36.6,co=22i 1641063600 - home,room=Living\ Room temp=22.2,hum=36.4,co=17i 1641067200 - home,room=Kitchen temp=22.7,hum=36.5,co=26i 1641067200 - " - ``` - - -{{% /tab-content %}} -{{% tab-content %}} - - -To write data to InfluxDB using the InfluxDB HTTP API, send a request to -the InfluxDB API `/api/v2/write` endpoint using the `POST` request method. - -{{< api-endpoint endpoint="http://localhost:8086/api/v2/write" method="post" api-ref="/influxdb/v2/api/#operation/PostWrite" >}} - -Include the following with your request: - -- **Headers**: - - **Authorization**: Token - - **Content-Type**: text/plain; charset=utf-8 - - **Accept**: application/json -- **Query parameters**: - - **org**: InfluxDB organization name - - **bucket**: InfluxDB bucket name - - **precision**: timestamp precision (default is `ns`) -- **Request body**: Line protocol as plain text - -The following example uses cURL and the InfluxDB API to write line protocol -to InfluxDB: - -```sh -export INFLUX_HOST=http://localhost:8086 -export INFLUX_ORG= -export INFLUX_TOKEN= - -curl --request POST \ -"$INFLUX_HOST/api/v2/write?org=$INFLUX_ORG&bucket=get-started&precision=s" \ - --header "Authorization: Token $INFLUX_TOKEN" \ - --header "Content-Type: text/plain; charset=utf-8" \ - --header "Accept: application/json" \ - --data-binary " -home,room=Living\ Room temp=21.1,hum=35.9,co=0i 1641024000 -home,room=Kitchen temp=21.0,hum=35.9,co=0i 1641024000 -home,room=Living\ Room temp=21.4,hum=35.9,co=0i 1641027600 -home,room=Kitchen temp=23.0,hum=36.2,co=0i 1641027600 -home,room=Living\ Room temp=21.8,hum=36.0,co=0i 1641031200 -home,room=Kitchen temp=22.7,hum=36.1,co=0i 1641031200 -home,room=Living\ Room temp=22.2,hum=36.0,co=0i 1641034800 -home,room=Kitchen temp=22.4,hum=36.0,co=0i 1641034800 -home,room=Living\ Room temp=22.2,hum=35.9,co=0i 1641038400 -home,room=Kitchen temp=22.5,hum=36.0,co=0i 1641038400 -home,room=Living\ Room temp=22.4,hum=36.0,co=0i 1641042000 -home,room=Kitchen temp=22.8,hum=36.5,co=1i 1641042000 -home,room=Living\ Room temp=22.3,hum=36.1,co=0i 1641045600 -home,room=Kitchen temp=22.8,hum=36.3,co=1i 1641045600 -home,room=Living\ Room temp=22.3,hum=36.1,co=1i 1641049200 -home,room=Kitchen temp=22.7,hum=36.2,co=3i 1641049200 -home,room=Living\ Room temp=22.4,hum=36.0,co=4i 1641052800 -home,room=Kitchen temp=22.4,hum=36.0,co=7i 1641052800 -home,room=Living\ Room temp=22.6,hum=35.9,co=5i 1641056400 -home,room=Kitchen temp=22.7,hum=36.0,co=9i 1641056400 -home,room=Living\ Room temp=22.8,hum=36.2,co=9i 1641060000 -home,room=Kitchen temp=23.3,hum=36.9,co=18i 1641060000 -home,room=Living\ Room temp=22.5,hum=36.3,co=14i 1641063600 -home,room=Kitchen temp=23.1,hum=36.6,co=22i 1641063600 -home,room=Living\ Room temp=22.2,hum=36.4,co=17i 1641067200 -home,room=Kitchen temp=22.7,hum=36.5,co=26i 1641067200 -" -``` - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -{{< expand-wrapper >}} -{{% expand "View the written data" %}} - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :------ | :----- | -----: | -| 2022-01-01T08:00:00Z | home | Kitchen | co | 0 | -| 2022-01-01T09:00:00Z | home | Kitchen | co | 0 | -| 2022-01-01T10:00:00Z | home | Kitchen | co | 0 | -| 2022-01-01T11:00:00Z | home | Kitchen | co | 0 | -| 2022-01-01T12:00:00Z | home | Kitchen | co | 0 | -| 2022-01-01T13:00:00Z | home | Kitchen | co | 1 | -| 2022-01-01T14:00:00Z | home | Kitchen | co | 1 | -| 2022-01-01T15:00:00Z | home | Kitchen | co | 3 | -| 2022-01-01T16:00:00Z | home | Kitchen | co | 7 | -| 2022-01-01T17:00:00Z | home | Kitchen | co | 9 | -| 2022-01-01T18:00:00Z | home | Kitchen | co | 18 | -| 2022-01-01T19:00:00Z | home | Kitchen | co | 22 | -| 2022-01-01T20:00:00Z | home | Kitchen | co | 26 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :------ | :----- | -----: | -| 2022-01-01T08:00:00Z | home | Kitchen | hum | 35.9 | -| 2022-01-01T09:00:00Z | home | Kitchen | hum | 36.2 | -| 2022-01-01T10:00:00Z | home | Kitchen | hum | 36.1 | -| 2022-01-01T11:00:00Z | home | Kitchen | hum | 36 | -| 2022-01-01T12:00:00Z | home | Kitchen | hum | 36 | -| 2022-01-01T13:00:00Z | home | Kitchen | hum | 36.5 | -| 2022-01-01T14:00:00Z | home | Kitchen | hum | 36.3 | -| 2022-01-01T15:00:00Z | home | Kitchen | hum | 36.2 | -| 2022-01-01T16:00:00Z | home | Kitchen | hum | 36 | -| 2022-01-01T17:00:00Z | home | Kitchen | hum | 36 | -| 2022-01-01T18:00:00Z | home | Kitchen | hum | 36.9 | -| 2022-01-01T19:00:00Z | home | Kitchen | hum | 36.6 | -| 2022-01-01T20:00:00Z | home | Kitchen | hum | 36.5 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :------ | :----- | -----: | -| 2022-01-01T08:00:00Z | home | Kitchen | temp | 21 | -| 2022-01-01T09:00:00Z | home | Kitchen | temp | 23 | -| 2022-01-01T10:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T11:00:00Z | home | Kitchen | temp | 22.4 | -| 2022-01-01T12:00:00Z | home | Kitchen | temp | 22.5 | -| 2022-01-01T13:00:00Z | home | Kitchen | temp | 22.8 | -| 2022-01-01T14:00:00Z | home | Kitchen | temp | 22.8 | -| 2022-01-01T15:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T16:00:00Z | home | Kitchen | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Kitchen | temp | 22.7 | -| 2022-01-01T18:00:00Z | home | Kitchen | temp | 23.3 | -| 2022-01-01T19:00:00Z | home | Kitchen | temp | 23.1 | -| 2022-01-01T20:00:00Z | home | Kitchen | temp | 22.7 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T08:00:00Z | home | Living Room | co | 0 | -| 2022-01-01T09:00:00Z | home | Living Room | co | 0 | -| 2022-01-01T10:00:00Z | home | Living Room | co | 0 | -| 2022-01-01T11:00:00Z | home | Living Room | co | 0 | -| 2022-01-01T12:00:00Z | home | Living Room | co | 0 | -| 2022-01-01T13:00:00Z | home | Living Room | co | 0 | -| 2022-01-01T14:00:00Z | home | Living Room | co | 0 | -| 2022-01-01T15:00:00Z | home | Living Room | co | 1 | -| 2022-01-01T16:00:00Z | home | Living Room | co | 4 | -| 2022-01-01T17:00:00Z | home | Living Room | co | 5 | -| 2022-01-01T18:00:00Z | home | Living Room | co | 9 | -| 2022-01-01T19:00:00Z | home | Living Room | co | 14 | -| 2022-01-01T20:00:00Z | home | Living Room | co | 17 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T08:00:00Z | home | Living Room | hum | 35.9 | -| 2022-01-01T09:00:00Z | home | Living Room | hum | 35.9 | -| 2022-01-01T10:00:00Z | home | Living Room | hum | 36 | -| 2022-01-01T11:00:00Z | home | Living Room | hum | 36 | -| 2022-01-01T12:00:00Z | home | Living Room | hum | 35.9 | -| 2022-01-01T13:00:00Z | home | Living Room | hum | 36 | -| 2022-01-01T14:00:00Z | home | Living Room | hum | 36.1 | -| 2022-01-01T15:00:00Z | home | Living Room | hum | 36.1 | -| 2022-01-01T16:00:00Z | home | Living Room | hum | 36 | -| 2022-01-01T17:00:00Z | home | Living Room | hum | 35.9 | -| 2022-01-01T18:00:00Z | home | Living Room | hum | 36.2 | -| 2022-01-01T19:00:00Z | home | Living Room | hum | 36.3 | -| 2022-01-01T20:00:00Z | home | Living Room | hum | 36.4 | - -| _time | _measurement | room | _field | _value | -| :------------------- | :----------- | :---------- | :----- | -----: | -| 2022-01-01T08:00:00Z | home | Living Room | temp | 21.1 | -| 2022-01-01T09:00:00Z | home | Living Room | temp | 21.4 | -| 2022-01-01T10:00:00Z | home | Living Room | temp | 21.8 | -| 2022-01-01T11:00:00Z | home | Living Room | temp | 22.2 | -| 2022-01-01T12:00:00Z | home | Living Room | temp | 22.2 | -| 2022-01-01T13:00:00Z | home | Living Room | temp | 22.4 | -| 2022-01-01T14:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T15:00:00Z | home | Living Room | temp | 22.3 | -| 2022-01-01T16:00:00Z | home | Living Room | temp | 22.4 | -| 2022-01-01T17:00:00Z | home | Living Room | temp | 22.6 | -| 2022-01-01T18:00:00Z | home | Living Room | temp | 22.8 | -| 2022-01-01T19:00:00Z | home | Living Room | temp | 22.5 | -| 2022-01-01T20:00:00Z | home | Living Room | temp | 22.2 | - -{{% /expand %}} -{{< /expand-wrapper >}} - -**Congratulations!** You have written data to InfluxDB. The method described -above is the manual way of writing data, but there are other options available: - -- [Write data to InfluxDB using no-code solutions](/influxdb/v2/write-data/no-code/) -- [Write data to InfluxDB using developer tools](/influxdb/v2/write-data/developer-tools/) - -With data now stored in InfluxDB, let's query it. - -{{< page-nav prev="/influxdb/v2/get-started/setup/" next="/influxdb/v2/get-started/query/" keepTab=true >}} + diff --git a/content/influxdb/v2/monitor-alert/_index.md b/content/influxdb/v2/monitor-alert/_index.md index ec1c9aed8..b3f26cc27 100644 --- a/content/influxdb/v2/monitor-alert/_index.md +++ b/content/influxdb/v2/monitor-alert/_index.md @@ -9,30 +9,8 @@ menu: name: Monitor & alert weight: 7 influxdb/v2/tags: [monitor, alert, checks, notification, endpoints] +source: /shared/influxdb-v2/monitor-alert/_index.md --- -Monitor your time series data and send alerts by creating checks, notification -rules, and notification endpoints. Or use [community templates to monitor](/influxdb/v2/monitor-alert/templates/) supported environments. - -## Overview - -1. A [check](/influxdb/v2/reference/glossary/#check) in InfluxDB queries data and assigns a status with a `_level` based on specific conditions. -2. InfluxDB stores the output of a check in the `statuses` measurement in the `_monitoring` system bucket. -3. [Notification rules](/influxdb/v2/reference/glossary/#notification-rule) check data in the `statuses` - measurement and, based on conditions set in the notification rule, send a message - to a [notification endpoint](/influxdb/v2/reference/glossary/#notification-endpoint). -4. InfluxDB stores notifications in the `notifications` measurement in the `_monitoring` system bucket. - -## Create an alert - -To get started, do the following: - -1. [Create checks](/influxdb/v2/monitor-alert/checks/create/) to monitor data and assign a status. -2. [Add notification endpoints](/influxdb/v2/monitor-alert/notification-endpoints/create/) - to send notifications to third parties. -3. [Create notification rules](/influxdb/v2/monitor-alert/notification-rules/create) to check - statuses and send notifications to your notifications endpoints. - -## Manage your monitoring and alerting pipeline - -{{< children >}} + diff --git a/content/influxdb/v2/monitor-alert/checks/create.md b/content/influxdb/v2/monitor-alert/checks/create.md index b59e3a158..a1808b022 100644 --- a/content/influxdb/v2/monitor-alert/checks/create.md +++ b/content/influxdb/v2/monitor-alert/checks/create.md @@ -10,141 +10,8 @@ weight: 201 related: - /influxdb/v2/monitor-alert/notification-rules/ - /influxdb/v2/monitor-alert/notification-endpoints/ +source: /shared/influxdb-v2/monitor-alert/checks/create.md --- -Create a check in the InfluxDB user interface (UI). -Checks query data and apply a status to each point based on specified conditions. - -## Parts of a check -A check consists of two parts – a query and check configuration. - -#### Check query -- Specifies the dataset to monitor. -- May include tags to narrow results. - -#### Check configuration -- Defines check properties, including the check interval and status message. -- Evaluates specified conditions and applies a status (if applicable) to each data point: - - `crit` - - `warn` - - `info` - - `ok` -- Stores status in the `_level` column. - -## Check types -There are two types of checks: - -- [threshold](#threshold-check) -- [deadman](#deadman-check) - -#### Threshold check -A threshold check assigns a status based on a value being above, below, -inside, or outside of defined thresholds. - -#### Deadman check -A deadman check assigns a status to data when a series or group doesn't report -in a specified amount of time. - -## Create a check -1. In the navigation menu on the left, select **Alerts > Alerts**. - - {{< nav-icon "alerts" >}} - -2. Click **{{< caps >}}{{< icon "plus" >}} Create{{< /caps >}}** and select the [type of check](#check-types) to create. -3. Click **Name this check** in the top left corner and provide a unique name for the check, and then do the following: - - [Configure the check query](#configure-the-check-query) - - [Configure the check](#configure-the-check) -4. _(Optional)_ In the **Name this check** field at the top, enter a unique name for the check. - -#### Configure the check query -1. Select the **bucket**, **measurement**, **field** and **tag sets** to query. -2. If creating a threshold check, select an **aggregate function**. - Aggregate functions aggregate data between the specified check intervals and - return a single value for the check to process. - - In the **Aggregate functions** column, select an interval from the interval drop-down list - (for example, "Every 5 minutes") and an aggregate function from the list of functions. -3. Click **{{< caps >}}Submit{{< /caps >}}** to run the query and preview the results. - To see the raw query results, click the **View Raw Data {{< icon "toggle" >}}** toggle. - -#### Configure the check -1. Click **{{< caps >}}2. Configure Check{{< /caps >}}** near the top of the window. -2. In the **{{< caps >}}Properties{{< /caps >}}** column, configure the following: - - ##### Schedule Every - Select the interval to run the check (for example, "Every 5 minutes"). - This interval matches the aggregate function interval for the check query. - _Changing the interval here will update the aggregate function interval._ - - ##### Offset - Delay the execution of a task to account for any late data. - Offset queries do not change the queried time range. - - {{% note %}}Your offset must be shorter than your [check interval](#schedule-every). - {{% /note %}} - - ##### Tags - Add custom tags to the query output. - Each custom tag appends a new column to each row in the query output. - The column label is the tag key and the column value is the tag value. - - Use custom tags to associate additional metadata with the check. - Common metadata tags across different checks lets you easily group and organize checks. - You can also use custom tags in [notification rules](/influxdb/v2/monitor-alert/notification-rules/create/). - -3. In the **{{< caps >}}Status Message Template{{< /caps >}}** column, enter - the status message template for the check. - Use [Flux string interpolation](/flux/v0/data-types/basic/string/#interpolate-strings) - to populate the message with data from the query. - - Check data is represented as a record, `r`. - Access specific column values using dot notation: `r.columnName`. - - Use data from the following columns: - - - columns included in the query output - - [custom tags](#tags) added to the query output - - `_check_id` - - `_check_name` - - `_level` - - `_source_measurement` - - `_type` - - ###### Example status message template - ``` - From ${r._check_name}: - ${r._field} is ${r._level}. - Its value is ${string(v: r.field_name)}. - ``` - - When a check generates a status, it stores the message in the `_message` column. - -4. Define check conditions that assign statuses to points. - Condition options depend on your check type. - - ##### Configure a threshold check - 1. In the **{{< caps >}}Thresholds{{< /caps >}}** column, click the status name (CRIT, WARN, INFO, or OK) - to define conditions for that specific status. - 2. From the **When value** drop-down list, select a threshold: is above, is below, - is inside of, is outside of. - 3. Enter a value or values for the threshold. - You can also use the threshold sliders in the data visualization to define threshold values. - - ##### Configure a deadman check - 1. In the **{{< caps >}}Deadman{{< /caps >}}** column, enter a duration for the deadman check in the **for** field. - For example, `90s`, `5m`, `2h30m`, etc. - 2. Use the **set status to** drop-down list to select a status to set on a dead series. - 3. In the **And stop checking after** field, enter the time to stop monitoring the series. - For example, `30m`, `2h`, `3h15m`, etc. - -5. Click the green **{{< icon "check" >}}** in the top right corner to save the check. - -## Clone a check -Create a new check by cloning an existing check. - -1. Go to **Alerts > Alerts** in the navigation on the left. - - {{< nav-icon "alerts" >}} - -2. Click the **{{< icon "gear" >}}** icon next to the check you want to clone - and then click **Clone**. + diff --git a/content/influxdb/v2/monitor-alert/checks/delete.md b/content/influxdb/v2/monitor-alert/checks/delete.md index cb2fd095a..43189e955 100644 --- a/content/influxdb/v2/monitor-alert/checks/delete.md +++ b/content/influxdb/v2/monitor-alert/checks/delete.md @@ -10,24 +10,8 @@ weight: 204 related: - /influxdb/v2/monitor-alert/notification-rules/ - /influxdb/v2/monitor-alert/notification-endpoints/ +source: /shared/influxdb-v2/monitor-alert/checks/delete.md --- -If you no longer need a check, use the InfluxDB user interface (UI) to delete it. - -{{% warn %}} -Deleting a check cannot be undone. -{{% /warn %}} - -1. In the navigation menu on the left, select **Alerts > Alerts**. - - {{< nav-icon "alerts" >}} - -2. Click the **{{< icon "delete" >}}** icon, and then click **{{< caps >}}Confirm{{< /caps >}}**. - -After a check is deleted, all statuses generated by the check remain in the `_monitoring` -bucket until the retention period for the bucket expires. - -{{% note %}} -You can also [disable a check](/influxdb/v2/monitor-alert/checks/update/#enable-or-disable-a-check) -without having to delete it. -{{% /note %}} + diff --git a/content/influxdb/v2/monitor-alert/checks/update.md b/content/influxdb/v2/monitor-alert/checks/update.md index 0c4c3e196..5fb2401da 100644 --- a/content/influxdb/v2/monitor-alert/checks/update.md +++ b/content/influxdb/v2/monitor-alert/checks/update.md @@ -10,51 +10,8 @@ weight: 203 related: - /influxdb/v2/monitor-alert/notification-rules/ - /influxdb/v2/monitor-alert/notification-endpoints/ +source: /shared/influxdb-v2/monitor-alert/checks/update.md --- -Update checks in the InfluxDB user interface (UI). -Common updates include: - -- [Update check queries and logic](#update-check-queries-and-logic) -- [Enable or disable a check](#enable-or-disable-a-check) -- [Rename a check](#rename-a-check) -- [Add or update a check description](#add-or-update-a-check-description) -- [Add a label to a check](#add-a-label-to-a-check) - -To update checks, select **Alerts > Alerts** in the navigation menu on the left. - -{{< nav-icon "alerts" >}} - - -## Update check queries and logic -1. Click the name of the check you want to update. The check builder appears. -2. To edit the check query, click **{{< caps >}}1. Define Query{{< /caps >}}** at the top of the check builder window. -3. To edit the check logic, click **{{< caps >}}2. Configure Check{{< /caps >}}** at the top of the check builder window. - -_For details about using the check builder, see [Create checks](/influxdb/v2/monitor-alert/checks/create/)._ - -## Enable or disable a check -Click the {{< icon "toggle" >}} toggle next to a check to enable or disable it. - -## Rename a check -1. Hover over the name of the check you want to update. -2. Click the **{{< icon "edit" >}}** icon that appears next to the check name. -2. Enter a new name and click out of the name field or press enter to save. - -_You can also rename a check in the [check builder](#update-check-queries-and-logic)._ - -## Add or update a check description -1. Hover over the check description you want to update. -2. Click the **{{< icon "edit" >}}** icon that appears next to the description. -2. Enter a new description and click out of the name field or press enter to save. - -## Add a label to a check -1. Click **{{< icon "add-label" >}} Add a label** next to the check you want to add a label to. - The **Add Labels** box appears. -2. To add an existing label, select the label from the list. -3. To create and add a new label: - - In the search field, enter the name of the new label. The **Create Label** box opens. - - In the **Description** field, enter an optional description for the label. - - Select a color for the label. - - Click **{{< caps >}}Create Label{{< /caps >}}**. -4. To remove a label, click **{{< icon "x" >}}** on the label. + diff --git a/content/influxdb/v2/monitor-alert/checks/view.md b/content/influxdb/v2/monitor-alert/checks/view.md index f16a90921..2ced63161 100644 --- a/content/influxdb/v2/monitor-alert/checks/view.md +++ b/content/influxdb/v2/monitor-alert/checks/view.md @@ -10,28 +10,8 @@ weight: 202 related: - /influxdb/v2/monitor-alert/notification-rules/ - /influxdb/v2/monitor-alert/notification-endpoints/ +source: /shared/influxdb-v2/monitor-alert/checks/view.md --- -View check details and statuses and notifications generated by checks in the InfluxDB user interface (UI). - -- [View a list of all checks](#view-a-list-of-all-checks) -- [View check details](#view-check-details) -- [View statuses generated by a check](#view-statuses-generated-by-a-check) -- [View notifications triggered by a check](#view-notifications-triggered-by-a-check) - -To view checks, click **Alerts > Alerts** in navigation menu on the left. - -{{< nav-icon "alerts" >}} - -## View a list of all checks -The **{{< caps >}}Checks{{< /caps >}}** section of the Alerts landing page displays all existing checks. - -## View check details -Click the name of the check you want to view. -The check builder appears. -Here you can view the check query and logic. - -## View statuses generated by a check -1. Click the **{{< icon "view" >}}** icon on the check. -2. Click **View History**. - The Statuses History page displays statuses generated by the selected check. + diff --git a/content/influxdb/v2/monitor-alert/custom-checks.md b/content/influxdb/v2/monitor-alert/custom-checks.md index 86f4ae2e4..a57e0267f 100644 --- a/content/influxdb/v2/monitor-alert/custom-checks.md +++ b/content/influxdb/v2/monitor-alert/custom-checks.md @@ -8,89 +8,8 @@ menu: parent: Monitor & alert weight: 201 influxdb/v2/tags: [alerts, checks, tasks, Flux] +source: /shared/influxdb-v2/monitor-alert/custom-checks.md --- -In the UI, you can create two kinds of [checks](/influxdb/v2/reference/glossary/#check): -[`threshold`](/influxdb/v2/monitor-alert/checks/create/#threshold-check) and -[`deadman`](/influxdb/v2/monitor-alert/checks/create/#deadman-check). - -Using a Flux task, you can create a custom check that provides a couple advantages: - -- Customize and transform the data you would like to use for the check. -- Set up custom criteria for your alert (other than `threshold` and `deadman`). - -## Create a task - -1. In the InfluxDB UI, select **Tasks** in the navigation menu on the left. - - {{< nav-icon "tasks" >}} - -2. Click **{{< caps >}}{{< icon "plus" >}} Create Task{{< /caps >}}**. -3. In the **Name** field, enter a descriptive name, - and then enter how often to run the task in the **Every** field (for example, `10m`). - For more detail, such as using cron syntax or including an offset, see [Task configuration options](/influxdb/v2/process-data/task-options/). -4. Enter the Flux script for your custom check, including the [`monitor.check`](/flux/v0/stdlib/influxdata/influxdb/monitor/check/) function. - -{{% note %}} -Use the [`/api/v2/checks/{checkID}/query` API endpoint](/influxdb/v2/api/#operation/DeleteDashboardsIDOwnersID) -to see the Flux code for a check built in the UI. -This can be useful for constructing custom checks. -{{% /note %}} - -### Example: Monitor failed tasks - -The script below is fairly complex, and can be used as a framework for similar tasks. -It does the following: - -- Import the necessary `influxdata/influxdb/monitor` package, and other packages for data processing. -- Query the `_tasks` bucket to retrieve all statuses generated by your check. -- Set the `_level` to alert on, for example, `crit`, `warn`, `info`, or `ok`. -- Create a `check` object that specifies an ID, name, and type for the check. -- Define the `ok` and `crit` statuses. -- Execute the `monitor` function on the `check` using the `task_data`. - -#### Example alert task script - -```js -import "strings" -import "regexp" -import "influxdata/influxdb/monitor" -import "influxdata/influxdb/schema" - -option task = {name: "Failed Tasks Check", every: 1h, offset: 4m} - -task_data = from(bucket: "_tasks") - |> range(start: -task.every) - |> filter(fn: (r) => r["_measurement"] == "runs") - |> filter(fn: (r) => r["_field"] == "logs") - |> map(fn: (r) => ({r with name: strings.split(v: regexp.findString(r: /option task = \{([^\}]+)/, v: r._value), t: "\\\\\\\"")[1]})) - |> drop(columns: ["_value", "_start", "_stop"]) - |> group(columns: ["name", "taskID", "status", "_measurement"]) - |> map(fn: (r) => ({r with _value: if r.status == "failed" then 1 else 0})) - |> last() - -check = { - // 16 characters, alphanumeric - _check_id: "0000000000000001", - // Name string - _check_name: "Failed Tasks Check", - // Check type (threshold, deadman, or custom) - _type: "custom", - tags: {}, -} -ok = (r) => r["logs"] == 0 -crit = (r) => r["logs"] == 1 -messageFn = (r) => "The task: ${r.taskID} - ${r.name} has a status of ${r.status}" - -task_data - |> schema["fieldsAsCols"]() - |> monitor["check"](data: check, messageFn: messageFn, ok: ok, crit: crit) -``` - -{{% note %}} -Creating a custom check does not send a notification email. -For information on how to create notification emails, see -[Create notification endpoints](/influxdb/v2/monitor-alert/notification-endpoints/create), -[Create notification rules](/influxdb/v2/monitor-alert/notification-rules/create), -and [Send alert email](/influxdb/v2/monitor-alert/send-email/) -{{% /note %}} + diff --git a/content/influxdb/v2/monitor-alert/notification-endpoints/create.md b/content/influxdb/v2/monitor-alert/notification-endpoints/create.md index 808c88cde..d4ba9ffce 100644 --- a/content/influxdb/v2/monitor-alert/notification-endpoints/create.md +++ b/content/influxdb/v2/monitor-alert/notification-endpoints/create.md @@ -10,58 +10,8 @@ weight: 201 related: - /influxdb/v2/monitor-alert/checks/ - /influxdb/v2/monitor-alert/notification-rules/ +source: /shared/influxdb-v2/monitor-alert/notification-endpoints/create.md --- -To send notifications about changes in your data, start by creating a notification endpoint to a third-party service. After creating notification endpoints, [create notification rules](/influxdb/v2/monitor-alert/notification-rules/create) to send alerts to third-party services on [check statuses](/influxdb/v2/monitor-alert/checks/create). - -{{% cloud-only %}} - -#### Endpoints available in InfluxDB Cloud -The following endpoints are available for the InfluxDB Cloud Free Plan and Usage-based Plan: - -| Endpoint | Free Plan | Usage-based Plan | -|:-------- |:-------------------: |:----------------------------:| -| **Slack** | **{{< icon "check" >}}** | **{{< icon "check" >}}** | -| **PagerDuty** | | **{{< icon "check" >}}** | -| **HTTP** | | **{{< icon "check" >}}** | - -{{% /cloud-only %}} - -## Create a notification endpoint - -1. In the navigation menu on the left, select **Alerts > Alerts**. - - {{< nav-icon "alerts" >}} - -2. Select **{{< caps >}}Notification Endpoints{{< /caps >}}**. -3. Click **{{< caps >}}{{< icon "plus" >}} Create{{< /caps >}}**. -4. From the **Destination** drop-down list, select a destination endpoint to send notifications to. - {{% cloud-only %}}_See [available endpoints](#endpoints-available-in-influxdb-cloud)._{{% /cloud-only %}} -5. In the **Name** and **Description** fields, enter a name and description for the endpoint. -6. Enter information to connect to the endpoint: - - - **For HTTP**, enter the **URL** to send the notification. - Select the **auth method** to use: **None** for no authentication. - To authenticate with a username and password, select **Basic** and then - enter credentials in the **Username** and **Password** fields. - To authenticate with an API token, select **Bearer**, and then enter the - API token in the **Token** field. - - - **For Slack**, create an [Incoming WebHook](https://api.slack.com/incoming-webhooks#posting_with_webhooks) - in Slack, and then enter your webHook URL in the **Slack Incoming WebHook URL** field. - - - **For PagerDuty**: - - [Create a new service](https://support.pagerduty.com/docs/services-and-integrations#section-create-a-new-service), - [add an integration for your service](https://support.pagerduty.com/docs/services-and-integrations#section-add-integrations-to-an-existing-service), - and then enter the PagerDuty integration key for your new service in the **Routing Key** field. - - The **Client URL** provides a useful link in your PagerDuty notification. - Enter any URL that you'd like to use to investigate issues. - This URL is sent as the `client_url` property in the PagerDuty trigger event. - By default, the **Client URL** is set to your Monitoring & Alerting History - page, and the following included in the PagerDuty trigger event: - - ```json - "client_url": "http://localhost:8086/orgs//alert-history" - ``` - -6. Click **{{< caps >}}Create Notification Endpoint{{< /caps >}}**. + diff --git a/content/influxdb/v2/monitor-alert/notification-endpoints/delete.md b/content/influxdb/v2/monitor-alert/notification-endpoints/delete.md index 234720a4c..9795aeedb 100644 --- a/content/influxdb/v2/monitor-alert/notification-endpoints/delete.md +++ b/content/influxdb/v2/monitor-alert/notification-endpoints/delete.md @@ -10,19 +10,8 @@ weight: 204 related: - /influxdb/v2/monitor-alert/checks/ - /influxdb/v2/monitor-alert/notification-rules/ +source: /shared/influxdb-v2/monitor-alert/notification-endpoints/delete.md --- -If notifications are no longer sent to an endpoint, complete the steps below to -delete the endpoint, and then [update notification rules](/influxdb/v2/monitor-alert/notification-rules/update) -with a new notification endpoint as needed. - -## Delete a notification endpoint - -1. In the navigation menu on the left, select **Alerts > Alerts**. - - {{< nav-icon "alerts" >}} - -2. Select **{{< caps >}}Notification Endpoints{{< /caps >}}** and find the rule - you want to delete. -3. Click the **{{< icon "trash" >}}** icon on the notification you want to delete - and then click **{{< caps >}}Confirm{{< /caps >}}**. + diff --git a/content/influxdb/v2/monitor-alert/notification-endpoints/update.md b/content/influxdb/v2/monitor-alert/notification-endpoints/update.md index fec021021..7b60e6c38 100644 --- a/content/influxdb/v2/monitor-alert/notification-endpoints/update.md +++ b/content/influxdb/v2/monitor-alert/notification-endpoints/update.md @@ -10,46 +10,8 @@ weight: 203 related: - /influxdb/v2/monitor-alert/checks/ - /influxdb/v2/monitor-alert/notification-rules/ +source: /shared/influxdb-v2/monitor-alert/notification-endpoints/update.md --- -Complete the following steps to update notification endpoint details. -To update the notification endpoint selected for a notification rule, see [update notification rules](/influxdb/v2/monitor-alert/notification-rules/update/). - -**To update a notification endpoint** - -1. In the navigation menu on the left, select **Alerts > Alerts**. - - {{< nav-icon "alerts" >}} - -2. Select **{{< caps >}}Notification Endpoints{{< /caps >}}** and then do the following as needed: - - - [Update the name or description for notification endpoint](#update-the-name-or-description-for-notification-endpoint) - - [Change endpoint details](#change-endpoint-details) - - [Disable notification endpoint](#disable-notification-endpoint) - - [Add a label to notification endpoint](#add-a-label-to-notification-endpoint) - -## Update the name or description for notification endpoint -1. Hover over the name or description of the endpoint and click the pencil icon - (**{{< icon "edit" >}}**) to edit the field. -2. Click outside of the field to save your changes. - -## Change endpoint details -1. Click the name of the endpoint to update. -2. Update details as needed, and then click **Edit Notification Endpoint**. - For details about each field, see [Create notification endpoints](/influxdb/v2/monitor-alert/notification-endpoints/create/). - -## Disable notification endpoint -Click the {{< icon "toggle" >}} toggle to disable the notification endpoint. - -## Add a label to notification endpoint -1. Click **{{< icon "add-label" >}} Add a label** next to the endpoint you want to add a label to. - The **Add Labels** box opens. -2. To add an existing label, select the label from the list. -3. To create and add a new label: - - - In the search field, enter the name of the new label. The **Create Label** box opens. - - In the **Description** field, enter an optional description for the label. - - Select a color for the label. - - Click **{{< caps >}}Create Label{{< /caps >}}**. - -4. To remove a label, click **{{< icon "x" >}}** on the label. + diff --git a/content/influxdb/v2/monitor-alert/notification-endpoints/view.md b/content/influxdb/v2/monitor-alert/notification-endpoints/view.md index f8a46f638..2c49ca86e 100644 --- a/content/influxdb/v2/monitor-alert/notification-endpoints/view.md +++ b/content/influxdb/v2/monitor-alert/notification-endpoints/view.md @@ -11,30 +11,8 @@ weight: 202 related: - /influxdb/v2/monitor-alert/checks/ - /influxdb/v2/monitor-alert/notification-rules/ +source: /shared/influxdb-v2/monitor-alert/notification-endpoints/view.md --- -View notification endpoint details and history in the InfluxDB user interface (UI). - - -1. In the navigation menu on the left, select **Alerts**. - - {{< nav-icon "alerts" >}} - -2. Select **{{< caps >}}Notification Endpoints{{< /caps >}}**. - - - [View notification endpoint details](#view-notification-endpoint-details) - - [View history notification endpoint history](#view-notification-endpoint-history), including statues and notifications sent to the endpoint - -## View notification endpoint details -On the notification endpoints page: - -1. Click the name of the notification endpoint you want to view. -2. View the notification endpoint destination, name, and information to connect to the endpoint. - -## View notification endpoint history -On the notification endpoints page, click the **{{< icon "gear" >}}** icon, -and then click **View History**. -The Check Statuses History page displays: - -- Statuses generated for the selected notification endpoint -- Notifications sent to the selected notification endpoint + diff --git a/content/influxdb/v2/monitor-alert/notification-rules/create.md b/content/influxdb/v2/monitor-alert/notification-rules/create.md index 2e8b6a8f3..af444d31e 100644 --- a/content/influxdb/v2/monitor-alert/notification-rules/create.md +++ b/content/influxdb/v2/monitor-alert/notification-rules/create.md @@ -9,36 +9,8 @@ menu: related: - /influxdb/v2/monitor-alert/checks/ - /influxdb/v2/monitor-alert/notification-endpoints/ +source: /shared/influxdb-v2/monitor-alert/notification-rules/create.md --- -Once you've set up checks and notification endpoints, create notification rules to alert you. -_For details, see [Manage checks](/influxdb/v2/monitor-alert/checks/) and -[Manage notification endpoints](/influxdb/v2/monitor-alert/notification-endpoints/)._ - - -1. In the navigation menu on the left, select **Alerts > Alerts**. - - {{< nav-icon "alerts" >}} - -2. Select **{{< caps >}}Notification Rules{{< /caps >}}** near to top of the page. - - - [Create a new notification rule in the UI](#create-a-new-notification-rule-in-the-ui) - - [Clone an existing notification rule in the UI](#clone-an-existing-notification-rule-in-the-ui) - -## Create a new notification rule - -1. On the notification rules page, click **{{< caps >}}{{< icon "plus" >}} Create{{< /caps >}}**. -2. Complete the **About** section: - 1. In the **Name** field, enter a name for the notification rule. - 2. In the **Schedule Every** field, enter how frequently the rule should run. - 3. In the **Offset** field, enter an offset time. For example,if a task runs on the hour, a 10m offset delays the task to 10 minutes after the hour. Time ranges defined in the task are relative to the specified execution time. -3. In the **Conditions** section, build a condition using a combination of status and tag keys. - - Next to **When status is equal to**, select a status from the drop-down field. - - Next to **AND When**, enter one or more tag key-value pairs to filter by. -4. In the **Message** section, select an endpoint to notify. -5. Click **{{< caps >}}Create Notification Rule{{< /caps >}}**. - -## Clone an existing notification rule - -On the notification rules page, click the **{{< icon "gear" >}}** icon and select **Clone**. -The cloned rule appears. + diff --git a/content/influxdb/v2/monitor-alert/notification-rules/delete.md b/content/influxdb/v2/monitor-alert/notification-rules/delete.md index 36b7b4638..7d55e2958 100644 --- a/content/influxdb/v2/monitor-alert/notification-rules/delete.md +++ b/content/influxdb/v2/monitor-alert/notification-rules/delete.md @@ -9,16 +9,8 @@ menu: related: - /influxdb/v2/monitor-alert/checks/ - /influxdb/v2/monitor-alert/notification-endpoints/ +source: /shared/influxdb-v2/monitor-alert/notification-rules/delete.md --- -If you no longer need to receive an alert, delete the associated notification rule. - -## Delete a notification rule - -1. In the navigation menu on the left, select **Alerts > Alerts**. - - {{< nav-icon "alerts" >}} - -2. Select **{{< caps >}}Notification Rules{{< /caps >}}** near to top of the page. -3. Click the **{{< icon "trash" >}}** icon on the notification rule you want to delete. -4. Click **{{< caps >}}Confirm{{< /caps >}}**. + diff --git a/content/influxdb/v2/monitor-alert/notification-rules/update.md b/content/influxdb/v2/monitor-alert/notification-rules/update.md index af08483bf..5df12f283 100644 --- a/content/influxdb/v2/monitor-alert/notification-rules/update.md +++ b/content/influxdb/v2/monitor-alert/notification-rules/update.md @@ -9,42 +9,8 @@ menu: related: - /influxdb/v2/monitor-alert/checks/ - /influxdb/v2/monitor-alert/notification-endpoints/ +source: /shared/influxdb-v2/monitor-alert/notification-rules/update.md --- -Update notification rules to update the notification message or change the schedule or conditions. - - -1. In the navigation menu on the left, select **Alerts > Alerts**. - - {{< nav-icon "alerts" >}} - -2. Select **{{< caps >}}Notification Rules{{< /caps >}}** near to top of the page. - -- [Update the name or description for notification rules](#update-the-name-or-description-for-notification-rules) -- [Enable or disable notification rules](#enable-or-disable-notification-rules) -- [Add a label to notification rules](#add-a-label-to-notification-rules) - -## Update the name or description for notification rules -On the Notification Rules page: - -1. Hover over the name or description of a rule and click the pencil icon - (**{{< icon "edit" >}}**) to edit the field. -2. Click outside of the field to save your changes. - -## Enable or disable notification rules -On the notification rules page, click the {{< icon "toggle" >}} toggle to -enable or disable the notification rule. - -## Add a label to notification rules -On the notification rules page: - -1. Click **{{< icon "add-label" >}} Add a label** - next to the rule you want to add a label to. - The **Add Labels** box opens. -2. To add an existing label, select the label from the list. -3. To create and add a new label: - - In the search field, enter the name of the new label. The **Create Label** box opens. - - In the **Description** field, enter an optional description for the label. - - Select a color for the label. - - Click **{{< caps >}}Create Label{{< /caps >}}**. -4. To remove a label, click **{{< icon "x" >}}** on the label. + diff --git a/content/influxdb/v2/monitor-alert/notification-rules/view.md b/content/influxdb/v2/monitor-alert/notification-rules/view.md index 0e7332a7b..a69067ed2 100644 --- a/content/influxdb/v2/monitor-alert/notification-rules/view.md +++ b/content/influxdb/v2/monitor-alert/notification-rules/view.md @@ -9,36 +9,8 @@ menu: related: - /influxdb/v2/monitor-alert/checks/ - /influxdb/v2/monitor-alert/notification-endpoints/ +source: /shared/influxdb-v2/monitor-alert/notification-rules/view.md --- -View notification rule details and statuses and notifications generated by notification rules in the InfluxDB user interface (UI). - -- [View a list of all notification rules](#view-a-list-of-all-notification-rules) -- [View notification rule details](#view-notification-rule-details) -- [View statuses generated by a check](#view-statuses-generated-by-a-notification-rule) -- [View notifications triggered by a notification rule](#view-notifications-triggered-by-a-notification-rule) - -**To view notification rules:** - -1. In the navigation menu on the left, select **Alerts**. - - {{< nav-icon "alerts" >}} - -2. Select **{{< caps >}}Notification Rules{{< /caps >}}** near to top of the page. - -## View a list of all notification rules -The **{{< caps >}}Notification Rules{{< /caps >}}** section of the Alerts landing page displays all existing checks. - -## View notification rule details -Click the name of the check you want to view. -The check builder appears. -Here you can view the check query and logic. - -## View statuses generated by a notification rule -Click the **{{< icon "gear" >}}** icon on the notification rule, and then **View History**. -The Statuses History page displays statuses generated by the selected check. - -## View notifications triggered by a notification rule -1. Click the **{{< icon "gear" >}}** icon on the notification rule, and then **View History**. -2. In the top left corner, click **{{< caps >}}Notifications{{< /caps >}}**. - The Notifications History page displays notifications initiated by the selected notification rule. + diff --git a/content/influxdb/v2/monitor-alert/send-email.md b/content/influxdb/v2/monitor-alert/send-email.md index 66dbc89f2..2fc73ce6c 100644 --- a/content/influxdb/v2/monitor-alert/send-email.md +++ b/content/influxdb/v2/monitor-alert/send-email.md @@ -9,287 +9,8 @@ weight: 104 influxdb/v2/tags: [alert, email, notifications, check] related: - /influxdb/v2/monitor-alert/checks/ +source: /shared/influxdb-v2/monitor-alert/send-email.md --- -Send an alert email using a third-party service, such as [SendGrid](https://sendgrid.com/), [Amazon Simple Email Service (SES)](https://aws.amazon.com/ses/), [Mailjet](https://www.mailjet.com/), or [Mailgun](https://www.mailgun.com/). To send an alert email, complete the following steps: - -1. [Create a check](/influxdb/v2/monitor-alert/checks/create/#create-a-check-in-the-influxdb-ui) to identify the data to monitor and the status to alert on. -2. Set up your preferred email service (sign up, retrieve API credentials, and send test email): - - **SendGrid**: See [Getting Started With the SendGrid API](https://sendgrid.com/docs/API_Reference/api_getting_started.html) - - **AWS Simple Email Service (SES)**: See [Using the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email.html). Your AWS SES request, including the `url` (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html) and [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html). - - **Mailjet**: See [Getting Started with Mailjet](https://dev.mailjet.com/email/guides/getting-started/) - - **Mailgun**: See [Mailgun Signup](https://signup.mailgun.com/new/signup) -3. [Create an alert email task](#create-an-alert-email-task) to call your email service and send an alert email. - - {{% note %}} - In the procedure below, we use the **Task** page in the InfluxDB UI (user interface) to create a task. Explore other ways to [create a task](/influxdb/v2/process-data/manage-tasks/create-task/). - {{% /note %}} - -### Create an alert email task - -1. In the InfluxDB UI, select **Tasks** in the navigation menu on the left. - - {{< nav-icon "tasks" >}} - -2. Click **{{< caps >}}{{< icon "plus" >}} Create Task{{< /caps >}}**. -3. In the **Name** field, enter a descriptive name, for example, **Send alert email**, - and then enter how often to run the task in the **Every** field, for example, `10m`. - For more detail, such as using cron syntax or including an offset, see [Task configuration options](/influxdb/v2/process-data/task-options/). - -4. In the right panel, enter the following detail in your **task script** (see [examples below](#examples)): - - Import the [Flux HTTP package](/flux/v0/stdlib/http/). - - (Optional) Store your API key as a secret for reuse. - First, [add your API key as a secret](/influxdb/v2/admin/secrets/add/), - and then import the [Flux InfluxDB Secrets package](/flux/v0/stdlib/influxdata/influxdb/secrets/). - - Query the `statuses` measurement in the `_monitoring` bucket to retrieve all statuses generated by your check. - - Set the time range to monitor; use the same interval that the task is scheduled to run. For example, `range (start: -task.every)`. - - Set the `_level` to alert on, for example, `crit`, `warn`, `info`, or `ok`. - - Use the `map()` function to evaluate the criteria to send an alert using `http.post()`. - - Specify your email service `url` (endpoint), include applicable request `headers`, and verify your request `data` format follows the format specified for your email service. - -#### Examples - -{{< tabs-wrapper >}} -{{% tabs %}} -[SendGrid](#) -[AWS SES](#) -[Mailjet](#) -[Mailgun](#) -{{% /tabs %}} - - -{{% tab-content %}} - -The example below uses the SendGrid API to send an alert email when more than 3 critical statuses occur since the previous task run. - -```js -import "http" -import "json" -// Import the Secrets package if you store your API key as a secret. -// For detail on how to do this, see Step 4 above. -import "influxdata/influxdb/secrets" - -// Retrieve the secret if applicable. Otherwise, skip this line -// and add the API key as the Bearer token in the Authorization header. -SENDGRID_APIKEY = secrets.get(key: "SENDGRID_APIKEY") - -numberOfCrits = from(bucket: "_monitoring") - |> range(start: -task.every) - |> filter(fn: (r) => r._measurement == "statuses" and r._level == "crit") - |> count() - -numberOfCrits - |> map( - fn: (r) => if r._value > 3 then - {r with _value: http.post( - url: "https://api.sendgrid.com/v3/mail/send", - headers: {"Content-Type": "application/json", "Authorization": "Bearer ${SENDGRID_APIKEY}"}, - data: json.encode( - v: { - "personalizations": [ - { - "to": [ - { - "email": "jane.doe@example.com" - } - ] - } - ], - "from": { - "email": "john.doe@example.com" - }, - "subject": "InfluxDB critical alert", - "content": [ - { - "type": "text/plain", - "value": "There have been ${r._value} critical statuses." - } - ] - } - ) - )} - else - {r with _value: 0}, - ) -``` - -{{% /tab-content %}} - - -{{% tab-content %}} - -The example below uses the AWS SES API v2 to send an alert email when more than 3 critical statuses occur since the last task run. - -{{% note %}} -Your AWS SES request, including the `url` (endpoint), authentication, and the structure of the request may vary. For more information, see [Amazon SES API requests](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-requests.html) and [Authenticating requests to the Amazon SES API](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/using-ses-api-authentication.html). We recommend signing your AWS API requests using the [Signature Version 4 signing process](https://docs.aws.amazon.com/general/latest/gr/signing_aws_api_requests.html). -{{% /note %}} - -```js -import "http" -import "json" -// Import the Secrets package if you store your API credentials as secrets. -// For detail on how to do this, see Step 4 above. -import "influxdata/influxdb/secrets" - -// Retrieve the secrets if applicable. Otherwise, skip this line -// and add the API key as the Bearer token in the Authorization header. -AWS_AUTH_ALGORITHM = secrets.get(key: "AWS_AUTH_ALGORITHM") -AWS_CREDENTIAL = secrets.get(key: "AWS_CREDENTIAL") -AWS_SIGNED_HEADERS = secrets.get(key: "AWS_SIGNED_HEADERS") -AWS_CALCULATED_SIGNATURE = secrets.get(key: "AWS_CALCULATED_SIGNATURE") - -numberOfCrits = from(bucket: "_monitoring") - |> range(start: -task.every) - |> filter(fn: (r) => r.measurement == "statuses" and r._level == "crit") - |> count() - -numberOfCrits - |> map( - fn: (r) => if r._value > 3 then - {r with _value: http.post( - url: "https://email.your-aws-region.amazonaws.com/sendemail/v2/email/outbound-emails", - headers: { - "Content-Type": "application/json", - "Authorization": "Bearer ${AWS_AUTH_ALGORITHM}${AWS_CREDENTIAL}${AWS_SIGNED_HEADERS}${AWS_CALCULATED_SIGNATURE}"}, - data: json.encode(v: { - "Content": { - "Simple": { - "Body": { - "Text": { - "Charset": "UTF-8", - "Data": "There have been ${r._value} critical statuses." - } - }, - "Subject": { - "Charset": "UTF-8", - "Data": "InfluxDB critical alert" - } - } - }, - "Destination": { - "ToAddresses": [ - "john.doe@example.com" - ] - } - } - ) - )} - else - {r with _value: 0}, - ) -``` - -For details on the request syntax, see [SendEmail API v2 reference](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_SendEmail.html). - -{{% /tab-content %}} - - -{{% tab-content %}} - -The example below uses the Mailjet Send API to send an alert email when more than 3 critical statuses occur since the last task run. - -{{% note %}} -To view your Mailjet API credentials, sign in to Mailjet and open the [API Key Management page](https://app.mailjet.com/account/api_keys). -{{% /note %}} - -```js -import "http" -import "json" -// Import the Secrets package if you store your API keys as secrets. -// For detail on how to do this, see Step 4 above. -import "influxdata/influxdb/secrets" - -// Retrieve the secrets if applicable. Otherwise, skip this line -// and add the API keys as Basic credentials in the Authorization header. -MAILJET_APIKEY = secrets.get(key: "MAILJET_APIKEY") -MAILJET_SECRET_APIKEY = secrets.get(key: "MAILJET_SECRET_APIKEY") - -numberOfCrits = from(bucket: "_monitoring") - |> range(start: -task.every) - |> filter(fn: (r) => r.measurement == "statuses" and "r.level" == "crit") - |> count() - -numberOfCrits - |> map( - fn: (r) => if r._value > 3 then - {r with - _value: http.post( - url: "https://api.mailjet.com/v3.1/send", - headers: { - "Content-type": "application/json", - "Authorization": "Basic ${MAILJET_APIKEY}:${MAILJET_SECRET_APIKEY}" - }, - data: json.encode( - v: { - "Messages": [ - { - "From": {"Email": "jane.doe@example.com"}, - "To": [{"Email": "john.doe@example.com"}], - "Subject": "InfluxDB critical alert", - "TextPart": "There have been ${r._value} critical statuses.", - "HTMLPart": "

${r._value} critical statuses

There have been ${r._value} critical statuses.", - }, - ], - }, - ), - ), - } - else - {r with _value: 0}, - ) -``` - -{{% /tab-content %}} - - - -{{% tab-content %}} - -The example below uses the Mailgun API to send an alert email when more than 3 critical statuses occur since the last task run. - -{{% note %}} -To view your Mailgun API keys, sign in to Mailjet and open [Account Security - API security](https://app.mailgun.com/app/account/security/api_keys). Mailgun requires that a domain be specified via Mailgun. A domain is automatically created for you when you first set up your account. You must include this domain in your `url` endpoint (for example, `https://api.mailgun.net/v3/YOUR_DOMAIN` or `https://api.eu.mailgun.net/v3/YOUR_DOMAIN`. If you're using a free version of Mailgun, you can set up a maximum of five authorized recipients (to receive email alerts) for your domain. To view your Mailgun domains, sign in to Mailgun and view the [Domains page](https://app.mailgun.com/app/sending/domains). -{{% /note %}} - -```js -import "http" -import "json" -// Import the Secrets package if you store your API key as a secret. -// For detail on how to do this, see Step 4 above. -import "influxdata/influxdb/secrets" - -// Retrieve the secret if applicable. Otherwise, skip this line -// and add the API key as the Bearer token in the Authorization header. -MAILGUN_APIKEY = secrets.get(key: "MAILGUN_APIKEY") - -numberOfCrits = from(bucket: "_monitoring") - |> range(start: -task.every) - |> filter(fn: (r) => r["_measurement"] == "statuses") - |> filter(fn: (r) => r["_level"] == "crit") - |> count() - -numberOfCrits - |> map( - fn: (r) => if r._value > 1 then - {r with _value: http.post( - url: "https://api.mailgun.net/v3/YOUR_DOMAIN/messages", - headers: { - "Content-type": "application/json", - "Authorization": "Basic api:${MAILGUN_APIKEY}" - }, - data: json.encode(v: { - "from": "Username ", - "to": "email@example.com", - "subject": "InfluxDB critical alert", - "text": "There have been ${r._value} critical statuses." - } - ) - )} - else - {r with _value: 0}, - ) -``` - -{{% /tab-content %}} - -{{< /tabs-wrapper >}} + diff --git a/content/influxdb/v2/monitor-alert/templates/infrastructure/aws.md b/content/influxdb/v2/monitor-alert/templates/infrastructure/aws.md index a3cf72a6b..e071d821d 100644 --- a/content/influxdb/v2/monitor-alert/templates/infrastructure/aws.md +++ b/content/influxdb/v2/monitor-alert/templates/infrastructure/aws.md @@ -7,53 +7,8 @@ menu: parent: Monitor infrastructure name: AWS CloudWatch weight: 201 +source: /shared/influxdb-v2/monitor-alert/templates/infrastructure/aws.md --- -Use the [AWS CloudWatch Monitoring template](https://github.com/influxdata/community-templates/tree/master/aws_cloudwatch) to monitor data from [Amazon Web Services (AWS)](https://aws.amazon.com/), [Amazon Elastic Compute Cloud (EC2)](https://aws.amazon.com/ec2/), and [Amazon Elastic Load Balancing (ELB)](https://aws.amazon.com/elasticloadbalancing/) with the [AWS CloudWatch Service](https://aws.amazon.com/cloudwatch/). - -The AWS CloudWatch Monitoring template includes the following: - -- two [dashboards](/influxdb/v2/reference/glossary/#dashboard): - - **AWS CloudWatch NLB (Network Load Balancers) Monitoring**: Displays data from the `cloudwatch_aws_network_elb measurement` - - **AWS CloudWatch Instance Monitoring**: Displays data from the `cloudwatch_aws_ec2` measurement -- two [buckets](/influxdb/v2/reference/glossary/#bucket): `kubernetes` and `cloudwatch` -- two labels: `inputs.cloudwatch`, `AWS` -- one variable: `v.bucket` -- one [Telegraf configuration](/influxdb/v2/tools/telegraf-configs/): [AWS CloudWatch input plugin](/telegraf/v1/plugins//#cloudwatch) - -## Apply the template - -1. Use the [`influx` CLI](/influxdb/v2/reference/cli/influx/) to run the following command: - - ```sh - influx apply -f https://raw.githubusercontent.com/influxdata/community-templates/master/aws_cloudwatch/aws_cloudwatch.yml - ``` - For more information, see [influx apply](/influxdb/v2/reference/cli/influx/apply/). -2. [Install Telegraf](/telegraf/v1/introduction/installation/) on a server with network access to both the CloudWatch API and [InfluxDB v2 API](/influxdb/v2/reference/api/). -3. In your Telegraf configuration file (`telegraf.conf`), find the following example `influxdb_v2` output plugins, and then **replace** the `urls` to specify the servers to monitor: - - ```sh - ## k8s - [[outputs.influxdb_v2]] - urls = ["http://influxdb.monitoring:8086"] - organization = "InfluxData" - bucket = "kubernetes" - token = "secret-token" - - ## cloudv2 sample - [[outputs.influxdb_v2]] - urls = ["$INFLUX_HOST"] - token = "$INFLUX_TOKEN" - organization = "$INFLUX_ORG" - bucket = “cloudwatch" - ``` -4. [Start Telegraf](/influxdb/v2/write-data/no-code/use-telegraf/auto-config/#start-telegraf). - -## View the incoming data - -1. In the InfluxDB user interface (UI), select **Dashboards** in the left navigation. - - {{< nav-icon "dashboards" >}} - -2. Open your AWS dashboards, and then set the `v.bucket` variable to specify the - bucket to query data from (`kubernetes` or `cloudwatch`). + diff --git a/content/influxdb/v2/monitor-alert/templates/infrastructure/docker.md b/content/influxdb/v2/monitor-alert/templates/infrastructure/docker.md index 8ff6b869f..b33f75fab 100644 --- a/content/influxdb/v2/monitor-alert/templates/infrastructure/docker.md +++ b/content/influxdb/v2/monitor-alert/templates/infrastructure/docker.md @@ -7,51 +7,8 @@ menu: parent: Monitor infrastructure name: Docker weight: 202 +source: /shared/influxdb-v2/monitor-alert/templates/infrastructure/docker.md --- -Use the [Docker Monitoring template](https://github.com/influxdata/community-templates/tree/master/docker) to monitor your Docker containers. First, [apply the template](#apply-the-template), and then [view incoming data](#view-incoming-data). -This template uses the [Docker input plugin](/telegraf/v1/plugins//#docker) to collect metrics stored in InfluxDB and display these metrics in a dashboard. - -The Docker Monitoring template includes the following: - -- one [dashboard](/influxdb/v2/reference/glossary/#dashboard): **Docker** -- one [bucket](/influxdb/v2/reference/glossary/#bucket): `docker, 7d retention` -- labels: Docker input plugin labels -- one [Telegraf configuration](/influxdb/v2/tools/telegraf-configs/): Docker input plugin -- one variable: `bucket` -- four [checks](/influxdb/v2/reference/glossary/#check): `Container cpu`, `mem`, `disk`, `non-zero exit` -- one [notification endpoint](/influxdb/v2/reference/glossary/#notification-endpoint): `Http Post` -- one [notification rule](/influxdb/v2/reference/glossary/#notification-rule): `Crit Alert` - -For more information about how checks, notification endpoints, and notifications rules work together, see [monitor data and send alerts](/influxdb/v2/monitor-alert/). - -## Apply the template - -1. Use the [`influx` CLI](/influxdb/v2/reference/cli/influx/) to run the following command: - - ```sh - influx apply -f https://raw.githubusercontent.com/influxdata/community-templates/master/docker/docker.yml - ``` - For more information, see [influx apply](/influxdb/v2/reference/cli/influx/apply/). - - {{% note %}} -Ensure your `influx` CLI is configured with your account credentials and that configuration is active. For more information, see [influx config](/influxdb/v2/reference/cli/influx/config/). - {{% /note %}} - -2. [Install Telegraf](/telegraf/v1/introduction/installation/) on a server with network access to both the Docker containers and [InfluxDB v2 API](/influxdb/v2/reference/api/). -3. In your [Telegraf configuration file (`telegraf.conf`)](/influxdb/v2/tools/telegraf-configs/), do the following: - - Depending on how you run Docker, you may need to customize the [Docker input plugin](/telegraf/v1/plugins//#docker) configuration, for example, you may need to specify the `endpoint` value. - - Set the following environment variables: - - INFLUX_TOKEN: Token must have permissions to read Telegraf configurations and write data to the `telegraf` bucket. See how to [view tokens](/influxdb/v2/admin/tokens/view-tokens/). - - INFLUX_ORG: Name of your organization. See how to [view your organization](/influxdb/v2/admin/organizations/view-orgs/). - - INFLUX_HOST: Your InfluxDB host URL, for example, localhost, a remote instance, or InfluxDB Cloud. - -4. [Start Telegraf](/influxdb/v2/write-data/no-code/use-telegraf/auto-config/#start-telegraf). - -## View incoming data - -1. In the InfluxDB user interface (UI), select **Dashboards** in the left navigation. - - {{< nav-icon "dashboards" >}} - -2. Open the **Docker** dashboard to start monitoring. + diff --git a/content/influxdb/v2/monitor-alert/templates/infrastructure/raspberry-pi.md b/content/influxdb/v2/monitor-alert/templates/infrastructure/raspberry-pi.md index 855769bfb..297565373 100644 --- a/content/influxdb/v2/monitor-alert/templates/infrastructure/raspberry-pi.md +++ b/content/influxdb/v2/monitor-alert/templates/infrastructure/raspberry-pi.md @@ -7,56 +7,8 @@ menu: parent: Monitor infrastructure name: Raspberry Pi weight: 201 +source: /shared/influxdb-v2/monitor-alert/templates/infrastructure/raspberry-pi.md --- -Use the [Raspberry Pi Monitoring template](https://github.com/influxdata/community-templates/tree/master/raspberry-pi) -to monitor your Raspberry Pi 4 or 400 Linux system. - -The Raspberry Pi template includes the following: - -- one [bucket](/influxdb/v2/reference/glossary/#bucket): `rasp-pi` (7d retention) -- labels: `raspberry-pi` + Telegraf plugin labels - - [Diskio input plugin](/telegraf/v1/plugins//#diskio) - - [Mem input plugin](/telegraf/v1/plugins//#mem) - - [Net input plugin](/telegraf/v1/plugins//#net) - - [Processes input plugin](/telegraf/v1/plugins//#processes) - - [Swap input plugin](/telegraf/v1/plugins//#swap) - - [System input plugin](/telegraf/v1/plugins//#system) -- one [Telegraf configuration](/influxdb/v2/tools/telegraf-configs/) -- one [dashboard](/influxdb/v2/reference/glossary/#dashboard): Raspberry Pi System -- two variables: `bucket` and `linux_host` - -## Apply the template - -1. Use the [`influx` CLI](/influxdb/v2/reference/cli/influx/) to run the following command: - - ```sh - influx apply -f https://raw.githubusercontent.com/influxdata/community-templates/master/raspberry-pi/raspberry-pi-system.yml - ``` - For more information, see [influx apply](/influxdb/v2/reference/cli/influx/apply/). -2. [Install Telegraf](/telegraf/v1/introduction/installation/) on - your Raspberry Pi and ensure your Raspberry Pi has network access to the - [InfluxDB {{% cloud-only %}}Cloud{{% /cloud-only %}} API](/influxdb/v2/reference/api/). -3. Add the following environment variables to your Telegraf environment: - - - `INFLUX_HOST`: {{% oss-only %}}Your [InfluxDB URL](/influxdb/v2/reference/urls/){{% /oss-only %}} - {{% cloud-only %}}Your [InfluxDB Cloud region URL](/influxdb/cloud/reference/regions/){{% /cloud-only %}} - - `INFLUX_TOKEN`: Your [InfluxDB {{% cloud-only %}}Cloud{{% /cloud-only %}} API token](/influxdb/v2/admin/tokens/) - - `INFLUX_ORG`: Your InfluxDB {{% cloud-only %}}Cloud{{% /cloud-only %}} organization name. - - ```sh - export INFLUX_HOST=http://localhost:8086 - export INFLUX_TOKEN=mY5uP3rS3cr3T70keN - export INFLUX_ORG=example-org - ``` - -4. [Start Telegraf](/influxdb/v2/write-data/no-code/use-telegraf/auto-config/#start-telegraf). - -## View the incoming data - -1. In the InfluxDB user interface (UI), select **Boards** (**Dashboards**). - - {{< nav-icon "dashboards" >}} - -2. Click the Raspberry Pi System link to open your dashboard, then select `rasp-pi` -as your bucket and select your linux_host. + diff --git a/content/influxdb/v2/monitor-alert/templates/infrastructure/vshpere.md b/content/influxdb/v2/monitor-alert/templates/infrastructure/vshpere.md index e02f2e8ba..18268a538 100644 --- a/content/influxdb/v2/monitor-alert/templates/infrastructure/vshpere.md +++ b/content/influxdb/v2/monitor-alert/templates/infrastructure/vshpere.md @@ -7,52 +7,8 @@ menu: parent: Monitor infrastructure name: vSphere weight: 206 +source: /shared/influxdb-v2/monitor-alert/templates/infrastructure/vshpere.md --- -Use the [vSphere Dashboard for InfluxDB v2 template](https://github.com/influxdata/community-templates/tree/master/vsphere) to monitor your vSphere host. First, [apply the template](#apply-the-template), and then [view incoming data](#view-incoming-data). -This template uses the [Docker input plugin](/telegraf/v1/plugins//#docker) to collect metrics stored in InfluxDB and display these metrics in a dashboard. - -The Docker Monitoring template includes the following: - -- one [dashboard](/influxdb/v2/reference/glossary/#dashboard): **vsphere** -- one [bucket](/influxdb/v2/reference/glossary/#bucket): `vsphere` -- label: vsphere -- one [Telegraf configuration](/influxdb/v2/tools/telegraf-configs/): InfluxDB v2 output plugin, vSphere input plugin -- one variable: `bucket` - -## Apply the template - -1. Use the [`influx` CLI](/influxdb/v2/reference/cli/influx/) to run the following command: - - ```sh - influx apply -f https://raw.githubusercontent.com/influxdata/community-templates/master/vsphere/vsphere.yml - ``` - For more information, see [influx apply](/influxdb/v2/reference/cli/influx/apply/). - - {{% note %}} -Ensure your `influx` CLI is configured with your account credentials and that configuration is active. For more information, see [influx config](/influxdb/v2/reference/cli/influx/config/). - {{% /note %}} - -2. [Install Telegraf](/telegraf/v1/introduction/installation/) on a server with network access to both the vSphere host and [InfluxDB v2 API](/influxdb/v2/reference/api/). -3. In your [Telegraf configuration file (`telegraf.conf`)](/influxdb/v2/tools/telegraf-configs/), do the following: - - Set the following environment variables: - - INFLUX_TOKEN: Token must have permissions to read Telegraf configurations and write data to the `telegraf` bucket. See how to [view tokens](/influxdb/v2/admin/tokens/view-tokens/). - - INFLUX_ORG: Name of your organization. See how to [view your organization](/influxdb/v2/admin/organizations/view-orgs/). - - INFLUX_HOST: Your InfluxDB host URL, for example, localhost, a remote instance, or InfluxDB Cloud. - - INFLUX_BUCKET: Bucket to store data in. To use the bucket included, you must export the variable: `export INFLUX_BUCKET=vsphere` -4. - Set the host address to the vSphere and provide the `username` and `password` as variables: - ```sh - vcenters = [ "https://$VSPHERE_HOST/sdk" ] - username = "$vsphere-user" - password = "$vsphere-password" - ``` - -4. [Start Telegraf](/influxdb/v2/write-data/no-code/use-telegraf/auto-config/#start-telegraf). - -## View incoming data - -1. In the InfluxDB user interface (UI), select **Dashboards** in the left navigation. - - {{< nav-icon "dashboards" >}} - -2. Open the **vsphere** dashboard to start monitoring. + diff --git a/content/influxdb/v2/monitor-alert/templates/infrastructure/windows.md b/content/influxdb/v2/monitor-alert/templates/infrastructure/windows.md index d9de3b3c7..a1f6c88ff 100644 --- a/content/influxdb/v2/monitor-alert/templates/infrastructure/windows.md +++ b/content/influxdb/v2/monitor-alert/templates/infrastructure/windows.md @@ -7,49 +7,8 @@ menu: parent: Monitor infrastructure name: Windows weight: 207 +source: /shared/influxdb-v2/monitor-alert/templates/infrastructure/windows.md --- -Use the [Windows System Monitoring template](https://github.com/influxdata/community-templates/tree/master/windows_system) to monitor your Windows system. First, [apply the template](#apply-the-template), and then [view incoming data](#view-incoming-data). - -The Windows System Monitoring template includes the following: - -- one [dashboard](/influxdb/v2/reference/glossary/#dashboard): **Windows System** -- one [bucket](/influxdb/v2/reference/glossary/#bucket): `telegraf`, 7d retention -- label: `Windows System Template`, Telegraf plugin labels: `outputs.influxdb_v2` -- one [Telegraf configuration](/influxdb/v2/tools/telegraf-configs/): InfluxDB v2 output plugin, Windows Performance Counters input plugin -- two variables: `bucket`, `windows_host` - -## Apply the template - -1. Use the [`influx` CLI](/influxdb/v2/reference/cli/influx/) to run the following command: - - ```sh - influx apply -f https://raw.githubusercontent.com/influxdata/community-templates/master/windows_system/windows_system.yml - ``` - For more information, see [influx apply](/influxdb/v2/reference/cli/influx/apply/). - - {{% note %}} -Ensure your `influx` CLI is configured with your account credentials and that configuration is active. For more information, see [influx config](/influxdb/v2/reference/cli/influx/config/). - {{% /note %}} - -2. [Install Telegraf](/telegraf/v1/introduction/installation/) on a server with network access to both the Windows system and [InfluxDB v2 API](/influxdb/v2/reference/api/). -3. In your [Telegraf configuration file (`telegraf.conf`)](/influxdb/v2/tools/telegraf-configs/), do the following: - - Set the following environment variables: - - INFLUX_TOKEN: Token must have permissions to read Telegraf configurations and write data to the `telegraf` bucket. See how to [view tokens](/influxdb/v2/admin/tokens/view-tokens/). - - INFLUX_ORG: Name of your organization. See how to [view your organization](/influxdb/v2/admin/organizations/view-orgs/). - - INFLUX_URL: Your InfluxDB host URL, for example, localhost, a remote instance, or InfluxDB Cloud. - -4. [Start Telegraf](/influxdb/v2/write-data/no-code/use-telegraf/auto-config/#start-telegraf). -5. To monitor multiple Windows systems, repeat steps 1-4 for each system. - -## View incoming data - -1. In the InfluxDB user interface (UI), select **Dashboards** in the left navigation. - - {{< nav-icon "dashboards" >}} - -2. Open the **Windows System** dashboard to start monitoring. - - {{% note %}} - If you're monitoring multiple Windows machines, switch between them using the `windows_host` filter at the top of the dashboard. - {{% /note %}} + diff --git a/content/influxdb/v2/monitor-alert/templates/monitor.md b/content/influxdb/v2/monitor-alert/templates/monitor.md index 3ef0c4785..dea98f455 100644 --- a/content/influxdb/v2/monitor-alert/templates/monitor.md +++ b/content/influxdb/v2/monitor-alert/templates/monitor.md @@ -14,162 +14,8 @@ aliases: related: - /influxdb/v2/reference/cli/influx/apply/ - /influxdb/v2/reference/cli/influx/template/ +source: /shared/influxdb-v2/monitor-alert/templates/monitor.md --- -Use [InfluxDB Cloud](/influxdb/cloud/), the [InfluxDB Open Source (OSS) Metrics template](https://github.com/influxdata/community-templates/tree/master/influxdb2_oss_metrics), -and [Telegraf](/telegraf/v1/) to monitor one or more InfluxDB OSS instances. - -Do the following: - -1. [Review requirements](#review-requirements) -2. [Install the InfluxDB OSS Monitoring template](#install-the-influxdb-oss-monitoring-template) -3. [Set up InfluxDB OSS for monitoring](#set-up-influxdb-oss-for-monitoring) -4. [Set up Telegraf](#set-up-telegraf) -5. [View the Monitoring dashboard](#view-the-monitoring-dashboard) -6. (Optional) [Alert when metrics stop reporting](#alert-when-metrics-stop-reporting) -7. (Optional) [Create a notification endpoint and rule](#create-a-notification-endpoint-and-rule) - -## Review requirements - -Before you begin, make sure you have access to the following: - -- InfluxDB Cloud account ([sign up for free here](https://cloud2.influxdata.com/signup)) -- Command line access to a machine [running InfluxDB OSS 2.x](/influxdb/v2/install/) and permissions to install Telegraf on this machine -- Internet connectivity from the machine running InfluxDB OSS 2.x and Telegraf to InfluxDB Cloud -- Sufficient resource availability to install the template (InfluxDB Cloud Free - Plan accounts include [resource limits](/influxdb/cloud/account-management/pricing-plans/#resource-limits/influxdb/cloud/account-management/pricing-plans/#resource-limits)) - -## Install the InfluxDB OSS Monitoring template - -The InfluxDB OSS Monitoring template includes a Telegraf configuration that sends -InfluxDB OSS metrics to an InfluxDB endpoint and a dashboard that visualizes the metrics. - -1. [Log into your InfluxDB Cloud account](https://cloud2.influxdata.com/). -2. Go to **Settings > Templates** in the navigation bar on the left - - {{< nav-icon "Settings" >}} - -3. Under **Paste the URL of the Template's resource manifest file**, enter the - following template URL: - - ``` - https://raw.githubusercontent.com/influxdata/community-templates/master/influxdb2_oss_metrics/influxdb2_oss_metrics.yml - ``` - -4. Click **{{< caps >}}Lookup Template{{< /caps >}}**, and then click **{{< caps >}}Install Template{{< /caps >}}**. - InfluxDB Cloud imports the template, which includes the following resources: - - - Dashboard `InfluxDB OSS Metrics` - - Telegraf configuration `scrape-influxdb-oss-telegraf` - - Bucket `oss_metrics` - - Check `InfluxDB OSS Deadman` - - Labels `influxdb2` and `prometheus` - -## Set up InfluxDB OSS for monitoring - -By default, InfluxDB OSS 2.x has a `/metrics` endpoint available, which exports -internal InfluxDB metrics in [Prometheus format](https://prometheus.io/docs/concepts/data_model/). - -1. Ensure the `/metrics` endpoint is [enabled](/influxdb/v2/reference/config-options/#metrics-disabled). - If you've changed the default settings to disable the `/metrics` endpoint, - [re-enable these settings](/influxdb/v2/reference/config-options/#metrics-disabled). -2. Navigate to the `/metrics` endpoint of your InfluxDB OSS instance to view the InfluxDB OSS system metrics in your browser: - -## Set up Telegraf - -Set up Telegraf to scrape metrics from InfluxDB OSS to send to your InfluxDB Cloud account. - -On each InfluxDB OSS instance you want to monitor, do the following: - -1. [Install Telegraf](/telegraf/v1/introduction/installation/). -2. Set the following environment variables in your Telegraf environment: - - - `INFLUX_URL`: Your [InfluxDB Cloud region URL](/influxdb/cloud/reference/regions/) - - `INFLUX_ORG`: Your InfluxDB Cloud organization name - -1. [In the InfluxDB Cloud UI](https://cloud2.influxdata.com/), go to **Load Data > Telegraf** in the left navigation. - - {{< nav-icon "load-data" >}} - -2. Click **Setup Instructions** under **Scrape InfluxDB OSS Metrics**. -3. Complete the Telegraf Setup instructions to start Telegraf using the Scrape InfluxDB OSS Metrics - Telegraf configuration stored in InfluxDB Cloud. - - {{% note %}} -For your API token, generate a new token or use an existing All Access token. If you run Telegraf as a service, edit your init script to set the environment variable and ensure its available to the service. - {{% /note %}} - -Telegraf runs quietly in the background (no immediate output appears), and begins -pushing metrics to the `oss_metrics` bucket in your InfluxDB Cloud account. - -## View the Monitoring dashboard - -To see your data in real time, view the Monitoring dashboard. - -1. Select **Dashboards** in your **InfluxDB Cloud** account. - - {{< nav-icon "dashboards" >}} - -2. Click **InfluxDB OSS Metrics**. Metrics appear in your dashboard. -3. Customize your monitoring dashboard as needed. For example, send an alert in the following cases: - - Users create a new task or bucket - - You're testing machine limits - - [Metrics stop reporting](#alert-when-metrics-stop-reporting) - -## Alert when metrics stop reporting - -The Monitoring template includes a [deadman check](/influxdb/cloud/monitor-alert/checks/create/#deadman-check) to verify metrics are reported at regular intervals. - -To alert when data stops flowing from InfluxDB OSS instances to your InfluxDB Cloud account, do the following: - -1. [Customize the deadman check](#customize-the-deadman-check) to identify the fields you want to monitor. -2. [Create a notification endpoint and rule](#create-a-notification-endpoint-and-rule) to receive notifications when your deadman check is triggered. - -### Customize the deadman check - -1. To view the deadman check, click **Alerts** in the navigation bar of your **InfluxDB Cloud** account. - - {{< nav-icon "alerts" >}} - -2. Choose a InfluxDB OSS field or create a new OSS field for your deadman alert: - 1. Click **{{< caps >}}{{< icon "plus" >}} Create{{< /caps >}}** and select **Deadman Check** in the dropdown menu. - 2. Define your query with at least one field. - 3. Click **{{< caps >}}Submit{{< /caps >}}** and **{{< caps >}}Configure Check{{< /caps >}}**. - When metrics stop reporting, you'll receive an alert. -3. Start under **Schedule Every**, set the amount of time to check for data. -4. Set the amount of time to wait before switching to a critical alert. -5. Click **{{< icon "check" >}}** to save the check. - -## Create a notification endpoint and rule - -To receive a notification message when your deadman check is triggered, create a [notification endpoint](#create-a-notification-endpoint) and [rule](#create-a-notification-rule). - -### Create a notification endpoint - -InfluxData supports different endpoints: Slack, PagerDuty, and HTTP. Slack is free for all users, while PagerDuty and HTTP are exclusive to the Usage-Based Plan. - -#### Send a notification to Slack - -1. Create a [Slack Webhooks](https://api.slack.com/messaging/webhooks). -2. Go to **Alerts > Alerts** in the left navigation menu and then click **{{< caps >}}Notification Endpoints{{< /caps >}}**. - - {{< nav-icon "alerts" >}} - -4. Click **{{< caps >}}{{< icon "plus" >}} Create{{< /caps >}}**, and enter a name and description for your Slack endpoint. -3. Enter your Slack Webhook under **Incoming Webhook URL** and click **{{< caps >}}Create Notification Endpoint{{< /caps >}}**. - -#### Send a notification to PagerDuty or HTTP - -Send a notification to PagerDuty or HTTP endpoints (other webhooks) by [upgrading your InfluxDB Cloud account](/influxdb/cloud/account-management/billing/#upgrade-to-usage-based-plan). - -### Create a notification rule - -[Create a notification rule](/influxdb/cloud/monitor-alert/notification-rules/create/) to set rules for when to send a deadman alert message to your notification endpoint. - -1. Go to **Alerts > Alerts** in the left navigation menu and then click **{{< caps >}}Notification Rules{{< /caps >}}**. - - {{< nav-icon "alerts" >}} - -4. Click **{{< caps >}}{{< icon "plus" >}} Create{{< /caps >}}**, and then provide - the required information. -3. Click **{{< caps >}}Create Notification Rule{{< /caps >}}**. + diff --git a/content/influxdb/v2/monitor-alert/templates/networks/haproxy.md b/content/influxdb/v2/monitor-alert/templates/networks/haproxy.md index d63adf541..0f11ada1f 100644 --- a/content/influxdb/v2/monitor-alert/templates/networks/haproxy.md +++ b/content/influxdb/v2/monitor-alert/templates/networks/haproxy.md @@ -7,43 +7,8 @@ menu: parent: Monitor networks name: HAproxy weight: 201 +source: /shared/influxdb-v2/monitor-alert/templates/networks/haproxy.md --- -Use the [HAProxy for InfluxDB v2 template](https://github.com/influxdata/community-templates/tree/master/haproxy) to monitor your HAProxy instances. First, [apply the template](#apply-the-template), and then [view incoming data](#view-incoming-data). -This template uses the [HAProxy input plugin](/telegraf/v1/plugins//#haproxy) to collect metrics stored in an HAProxy instance and display these metrics in a dashboard. - -The HAProxy for InfluxDB v2 template includes the following: - -- one [dashboard](/influxdb/v2/reference/glossary/#dashboard): **HAProxy** -- one [bucket](/influxdb/v2/reference/glossary/#bucket): `haproxy` -- label: `haproxy` -- one [Telegraf configuration](/influxdb/v2/tools/telegraf-configs/): HAProxy input plugin, InfluxDB v2 output plugin -- one variable: `bucket` - -## Apply the template - -1. Use the [`influx` CLI](/influxdb/v2/reference/cli/influx/) to run the following command: - - ```sh - influx apply -f https://raw.githubusercontent.com/influxdata/community-templates/master/haproxy/haproxy.yml - ``` - For more information, see [influx apply](/influxdb/v2/reference/cli/influx/apply/). - - > **Note:** Ensure your `influx` CLI is configured with your account credentials and that configuration is active. For more information, see [influx config](/influxdb/v2/reference/cli/influx/config/). - -2. [Install Telegraf](/telegraf/v1/introduction/installation/) on a server with network access to both the HAProxy instances and [InfluxDB v2 API](/influxdb/v2/reference/api/). -3. In your [Telegraf configuration file (`telegraf.conf`)](/influxdb/v2/tools/telegraf-configs/), do the following: - - Set the following environment variables: - - INFLUX_TOKEN: Token must have permissions to read Telegraf configurations and write data to the `haproxy` bucket. See how to [view tokens](/influxdb/v2/admin/tokens/view-tokens/). - - INFLUX_ORG: Name of your organization. See how to [view your organization](/influxdb/v2/admin/organizations/view-orgs/). - - INFLUX_HOST: Your InfluxDB host URL, for example, localhost, a remote instance, or InfluxDB Cloud. - -4. [Start Telegraf](/influxdb/v2/write-data/no-code/use-telegraf/auto-config/#start-telegraf). - -## View incoming data - -1. In the InfluxDB user interface (UI), select **Dashboards** in the left navigation. - - {{< nav-icon "dashboards" >}} - -2. Open the **HAProxy** dashboard to start monitoring. + diff --git a/content/influxdb/v2/process-data/get-started.md b/content/influxdb/v2/process-data/get-started.md index ceeb34690..d4097ee2f 100644 --- a/content/influxdb/v2/process-data/get-started.md +++ b/content/influxdb/v2/process-data/get-started.md @@ -16,262 +16,8 @@ related: - /influxdb/v2/process-data/manage-tasks/ - /influxdb/v2/process-data/manage-tasks/create-task/ - /resources/videos/influxdb-tasks/ +source: /shared/influxdb-v2/process-data/get-started.md --- -An **InfluxDB task** is a scheduled Flux script that takes a stream of input data, -modifies or analyzes it in some way, then writes the modified data back to InfluxDB -or performs other actions. - -This article walks through writing a basic InfluxDB task that downsamples -data and stores it in a new bucket. - -## Components of a task - -Every InfluxDB task needs the following components. -Their form and order can vary, but they are all essential parts of a task. - -- [Task options](#define-task-options) -- [A data source](#define-a-data-source) -- [Data processing or transformation](#process-or-transform-your-data) -- [A destination](#define-a-destination) - -_[Skip to the full example task script](#full-example-flux-task-script)_ - -## Define task options - -Task options define the schedule, name, and other information about the task. -The following example shows how to set task options in a Flux script: - -```js -option task = {name: "downsample_5m_precision", every: 1h, offset: 0m} -``` - -_See [Task configuration options](/influxdb/v2/process-data/task-options) for detailed information -about each option._ - -_Note that InfluxDB doesn't guarantee that a task will run at the scheduled time. -See [View task run logs for a task](/influxdb/v2/process-data/manage-tasks/task-run-history) -for detailed information on task service-level agreements (SLAs)._ - -{{% note %}} -The InfluxDB UI provides a form for defining task options. -{{% /note %}} - - -{{% cloud-only %}} - -### Task options for invokable scripts - -Use the InfluxDB Cloud API to create tasks that reference and run [invokable scripts](/influxdb/cloud/api-guide/api-invokable-scripts/). -When you create or update the task, pass task options as properties in the request body--for example: - -```json - { - "name": "30-day-avg-temp", - "description": "IoT Center 30d environment average.", - "every": "1d", - "offset": "0m" - ... - } -``` - -To learn more about creating tasks that run invokable scripts, see how to [create a task that references a script](/influxdb/cloud/process-data/manage-tasks/create-task/#create-a-task-that-references-a-script). - -{{% /cloud-only %}} - -## Retrieve and filter data - -A minimal Flux script uses the following functions to retrieve a specified amount -of data from a data source -and then filter the data based on time or column values: - -1. [`from()`](/flux/v0/stdlib/influxdata/influxdb/from/): - queries data from InfluxDB {{% cloud-only %}}Cloud{{% /cloud-only %}}. -2. [`range()`](/flux/v0/stdlib/universe/range/): defines the time - range to return data from. -3. [`filter()`](/flux/v0/stdlib/universe/filter/): filters - data based on column values. - -The following sample Flux retrieves data from an InfluxDB bucket and then filters by -the `_measurement` and `host` columns: - -```js -from(bucket: "example-bucket") - |> range(start: -task.every) - |> filter(fn: (r) => r._measurement == "mem" and r.host == "myHost") -``` - -_To retrieve data from other sources, see [Flux input functions](/flux/v0/function-types/#inputs)._ - -{{% note %}} - -#### Use task options in your Flux script - -InfluxDB stores options in a `task` option record that you can reference in your Flux script. -The following sample Flux uses the time range `-task.every`: - -```js -from(bucket: "example-bucket") - |> range(start: -task.every) - |> filter(fn: (r) => r._measurement == "mem" and r.host == "myHost") -``` - -`task.every` is dot notation that references the `every` property of the `task` option record. -`every` is defined as `1h`, therefore `-task.every` equates to `-1h`. - -Using task options to define values in your Flux script can make reusing your task easier. -{{% /note %}} - -## Process or transform your data - -Tasks run scripts automatically at regular intervals. -Scripts process or transform data in some way--for example: downsampling, detecting -anomalies, or sending notifications. - -Consider a task that runs hourly and downsamples data by calculating the average of set intervals. -It uses [`aggregateWindow()`](/flux/v0/stdlib/universe/aggregatewindow/) -to group points into 5-minute (`5m`) windows and calculate the average of each -window with [`mean()`](/flux/v0/stdlib/universe/mean/). - -The following sample code shows the Flux script with task options: - -```js -option task = {name: "downsample_5m_precision", every: 1h, offset: 0m} - -from(bucket: "example-bucket") - |> range(start: -task.every) - |> filter(fn: (r) => r._measurement == "mem" and r.host == "myHost") - |> aggregateWindow(every: 5m, fn: mean) -``` - -{{% note %}} -#### Use offset to account for latent data - -Use the `offset` task option to account for potentially latent data (like data from edge devices). -A task that runs at one hour intervals (`every: 1h`) with an offset of five minutes (`offset: 5m`) -executes 5 minutes after the hour, but queries data from the original one-hour interval. -{{% /note %}} - -_See [Common tasks](/influxdb/v2/process-data/common-tasks) for examples of tasks commonly used with InfluxDB._ - -{{% cloud-only %}} - -### Process data with invokable scripts - -In InfluxDB Cloud, you can create tasks that run invokable scripts. -You can use invokable scripts to manage and reuse scripts for your organization. -You can use tasks to schedule script runs with options and parameters. - -The following sample `POST /api/v2/scripts` request body defines a new invokable script with the Flux from the previous example: - -```json -{ - "name": "aggregate-intervals", - "description": "Group points into 5 minute windows and calculate the average of each - window.", - "script": "from(bucket: "example-bucket")\ - |> range(start: -task.every)\ - |> filter(fn: (r) => r._measurement == "mem" and r.host == "myHost")\ - |> aggregateWindow(every: 5m, fn: mean)", - "language": "flux" -} -``` - -Note that the script doesn't contain task options. -Once you create the invokable script, you can use `POST /api/v2/tasks` to create a task that runs the script. -The following sample request body defines a task with the script ID and options: - -```json -{ - "every": "1h", - "description": "Downsample host with 5 min precision.", - "name": "downsample_5m_precision", - "scriptID": "09b2136232083000" -} -``` - -To create a script and a task that use parameters, see how to [create a task to run an invokable script](/influxdb/cloud/process-data/manage-tasks/create-task/). - -{{% /cloud-only %}} - -## Define a destination - -In most cases, you'll want to send and store data after the task has transformed it. -The destination could be a separate InfluxDB measurement or bucket. - -The example below uses [`to()`](/flux/v0/stdlib/universe/to) -to write the transformed data back to another InfluxDB bucket: - -```js -// ... - |> to(bucket: "example-downsampled", org: "my-org") -``` - -To write data into InfluxDB, `to()` requires the following columns: - -- `_time` -- `_measurement` -- `_field` -- `_value` - -_To write data to other destinations, see -[Flux output functions](/flux/v0/function-types/#outputs)._ - -## Full example Flux task script - -The following sample Flux combines all the components described in this guide: - -```js -// Task options -option task = {name: "downsample_5m_precision", every: 1h, offset: 0m} - -// Data source -from(bucket: "example-bucket") - |> range(start: -task.every) - |> filter(fn: (r) => r._measurement == "mem" and r.host == "myHost") - // Data processing - |> aggregateWindow(every: 5m, fn: mean) - // Data destination - |> to(bucket: "example-downsampled") -``` - -{{% cloud-only %}} - -## Full example task with invokable script - -The following sample code shows a `POST /api/v2/scripts` request body that -combines the components described in this guide: - -```json -{ - "name": "aggregate-intervals-and-export", - "description": "Group points into 5 minute windows and calculate the average of each - window.", - "script": "from(bucket: "example-bucket")\ - |> range(start: -task.every)\ - |> filter(fn: (r) => r._measurement == "mem" and r.host == "myHost")\ - // Data processing\ - |> aggregateWindow(every: 5m, fn: mean)\ - // Data destination\ - |> to(bucket: "example-downsampled")", - "language": "flux" -} -``` - -The following sample code shows a `POST /api/v2/tasks` request body to -schedule the script: - -```json -{ - "every": "1h", - "description": "Downsample host with 5 min precision.", - "name": "downsample_5m_precision", - "scriptID": "SCRIPT_ID" -} -``` - -{{% /cloud-only %}} - -To learn more about InfluxDB tasks and how they work, watch the following video: - -{{< youtube zgCmdtZaH9M >}} + diff --git a/content/influxdb/v2/process-data/manage-tasks/create-task.md b/content/influxdb/v2/process-data/manage-tasks/create-task.md index 3b1d5c401..339ef7fdf 100644 --- a/content/influxdb/v2/process-data/manage-tasks/create-task.md +++ b/content/influxdb/v2/process-data/manage-tasks/create-task.md @@ -10,296 +10,8 @@ menu: weight: 201 related: - /influxdb/v2/reference/cli/influx/task/create +source: /shared/influxdb-v2/process-data/manage-tasks/create-task.md --- -Create tasks with the InfluxDB user interface (UI), `influx` command line interface (CLI), or `/api/v2` API. - -_Before creating a task, review the [basics for writing a task](/influxdb/v2/process-data/get-started)._ - -- [InfluxDB UI](#create-a-task-in-the-influxdb-ui) -- [`influx` CLI](#create-a-task-using-the-influx-cli) -- [InfluxDB API](#create-a-task-using-the-influxdb-api) - -## Create a task in the InfluxDB UI - -The InfluxDB UI provides multiple ways to create a task: - -- [Create a task from the Data Explorer](#create-a-task-from-the-data-explorer) -- [Create a task in the Task UI](#create-a-task-in-the-task-ui) -- [Import a task](#import-a-task) -- [Create a task from a template](#create-a-task-from-a-template) -- [Clone a task](#clone-a-task) - -### Create a task from the Data Explorer - -1. In the navigation menu on the left, select **Data Explorer**. - - {{< nav-icon "data-explorer" >}} - -2. Build a query and click **Save As** in the upper right. -3. Select the **{{< caps >}}Task{{< /caps >}}** heading. -4. Specify the task options. See [Task options](/influxdb/v2/process-data/task-options) - for detailed information about each option. -5. Click **{{< caps >}}Save as Task{{< /caps >}}**. - -### Create a task in the Task UI - -1. In the navigation menu on the left, select **Tasks**. - - {{< nav-icon "tasks" >}} - -2. Click **{{< caps >}}{{< icon "plus" >}} Create Task{{< /caps >}}** in the upper right. -3. In the left panel, specify the task options. - See [Task options](/influxdb/v2/process-data/task-options) for detailed information about each option. -4. In the right panel, enter your task script. - - {{% note %}} - -##### Leave out the option tasks assignment - -When creating a _new_ task in the InfluxDB Task UI, leave the code editor empty. -When you save the task, the Task UI uses the [task options](/influxdb/v2/process-data/task-options/) you specify in the **Task options** form to populate `option task = {task_options}` for you. - -When you edit the saved task, you'll see the injected `option task = {task_options}`. - {{% /note %}} - -7. Click **Save** in the upper right. - -### Import a task - -1. In the navigation menu on the left, select **Tasks**. - - {{< nav-icon "tasks" >}} - -2. Click **{{< caps >}}{{< icon "plus" >}} Create Task{{< /caps >}}** in the upper right. -3. In the left panel, specify the task options. - See [Task options](/influxdb/v2/process-data/task-options) for detailed information about each option. -4. Paste a raw Flux task in the code editor to the right of the task options fields. -5. Click **{{< caps >}}Save{{< /caps >}}** in the upper right. - -### Create a task from a template - -1. In the navigation menu on the left, select **Settings** > **Templates**. - - {{< nav-icon "Settings" >}} - -2. Find the template you want to use and click its **Resources** list to expand the list of resources. -3. In the **Resources** list, click the task you want to use. - -### Clone a task - -1. In the navigation menu on the left, select **Tasks**. - - {{< nav-icon "tasks" >}} - -2. Find the task you would like to clone and click the **{{< icon "settings" >}}** icon located far right of the task name. -3. Click **Clone**. - -## Create a task using the influx CLI - -Use the `influx task create` command to create a new task. -It accepts either a file path or raw Flux. - -### Create a task using a file - -```sh -# Syntax -influx task create --org -f - -# Example -influx task create --org my-org -f /tasks/cq-mean-1h.flux -``` - -### Create a task using raw Flux - -```sh -influx task create --org my-org - # to open stdin pipe - -option task = { - name: "task-name", - every: 6h -} - -# ... Task script ... - -# Linux & macOS: to close the pipe and submit the command -# Windows: , then , then to close the pipe and submit the command -``` - -## Create a task using the InfluxDB API - -{{% oss-only %}} - -Use the [`/api/v2/tasks` InfluxDB API endpoint](/influxdb/v2/api/#operation/PostTasks) to create a task. - -{{< api-endpoint method="POST" endpoint="http://localhost:8086/api/v2/tasks/" api-ref="/influxdb/v2/api/#operation/PostTasks" >}} - -Provide the following in your API request: -##### Request headers - -- **Content-Type**: application/json -- **Authorization**: Token *`INFLUX_API_TOKEN`* - -##### Request body - -JSON object with the following fields: - -- **flux**: raw Flux task string that contains a [`task` option](/flux/v0/spec/options/) and a query. -- **orgID**: your [InfluxDB organization ID](/influxdb/v2/admin/organizations/view-orgs/#view-your-organization-id) -- **status**: task status ("active" or "inactive") -- **description**: task description - -```sh -curl --request POST 'http://localhost:8086/api/v2/tasks' \ - --header 'Content-Type: application/json' \ - --header 'Authorization: Token INFLUX_API_TOKEN' \ - --data-raw '{ - "flux": "option task = {name: \"CPU Total 1 Hour New\", every: 1h}\n\nfrom(bucket: \"telegraf\")\n\t|> range(start: -1h)\n\t|> filter(fn: (r) =>\n\t\t(r._measurement == \"cpu\"))\n\t|> filter(fn: (r) =>\n\t\t(r._field == \"usage_system\"))\n\t|> filter(fn: (r) =>\n\t\t(r.cpu == \"cpu-total\"))\n\t|> aggregateWindow(every: 1h, fn: max)\n\t|> to(bucket: \"cpu_usage_user_total_1h\", org: \"INFLUX_ORG\")", - "orgID": "INFLUX_ORG_ID", - "status": "active", - "description": "This task downsamples CPU data every hour" -}' -``` - -{{% /oss-only %}} - -{{% cloud-only %}} - -An InfluxDB Cloud task can run either an [invokable script](/influxdb/cloud/api-guide/api-invokable-scripts/) or raw Flux stored in the task. - -- [Create a task that references a script](#create-a-task-that-references-a-script) -- [Create a task that contains a Flux script](#create-a-task-that-contains-a-flux-script) - -### Create a task that references a script - -With InfluxDB Cloud invokable scripts, you can manage, reuse, and invoke scripts as API endpoints. -You can use tasks to pass script parameters and schedule runs. - -Use the [`/api/v2/tasks` InfluxDB API endpoint](/influxdb/cloud/api/#operation/PostTasks) to create a task -that references a script ID. - -{{< api-endpoint method="POST" endpoint="http://localhost:8086/api/v2/tasks/" api-ref="/influxdb/cloud/api/#operation/PostTasks" >}} - -Provide the following in your API request: - -#### Request headers - -- **Content-Type**: application/json -- **Authorization**: Token *`INFLUX_API_TOKEN`* - -#### Request body - -JSON object with the following fields: - -- **cron** or **every**: task schedule -- **name**: task name -- **scriptID**: [invokable script](/influxdb/cloud/api-guide/api-invokable-scripts/) ID - -```sh -curl --request POST 'https://cloud2.influxdata.com/api/v2/tasks' \ - --header 'Content-Type: application/json' \ - --header 'Authorization: Token INFLUX_API_TOKEN' \ - "cron": "0 * * * *", - "name": "downsample cpu", - "scriptID": "085a2960eaa20000", - "description": "This task downsamples CPU data every hour" -}' -``` - -To create a task that passes parameters when invoking the script, pass the _`scriptParameters`_ -property in the request body. -The following sample code creates a script with parameters, and then creates a -task to run the new script daily: - -```sh -SCRIPT_ID=$( -curl https://cloud2.influxdata.com/api/v2/scripts \ - --header "Authorization: Token INFLUX_API_TOKEN" \ - --header 'Accept: application/json' \ - --header 'Content-Type: application/json' \ - --data-binary @- << EOF | jq -r '.id' - { - "name": "filter-and-group19", - "description": "Returns filtered and grouped points from a bucket.", - "script": "from(bucket: params.bucket)\ - |> range(start: duration(v: params.rangeStart))\ - |> filter(fn: (r) => r._field == params.filterField)\ - |> group(columns: [params.groupColumn])", - "language": "flux" - } -EOF -) - -echo $SCRIPT_ID - -curl https://cloud2.influxdata.com/api/v2/tasks \ ---header "Content-type: application/json" \ ---header "Authorization: Token INFLUX_API_TOKEN" \ ---data @- << EOF - { - "name": "30-day-avg-temp", - "description": "IoT Center 30d temperature average.", - "every": "1d", - "scriptID": "${SCRIPT_ID}", - "scriptParameters": - { - "rangeStart": "-30d", - "bucket": "air_sensor", - "filterField": "temperature", - "groupColumn": "_time" - } - } -EOF -``` - -Replace **`INFLUX_API_TOKEN`** with your InfluxDB API token. - -### Create a task that contains a Flux script - -Use the [`/api/v2/tasks` InfluxDB API endpoint](/influxdb/cloud/api/#operation/PostTasks) to create a task that contains a Flux script with task options. - -{{< api-endpoint method="POST" endpoint="https://cloud2.influxdata.com/api/v2/tasks/" api-ref="/influxdb/cloud/api/#operation/PostTasks" >}} - -Provide the following in your API request: - -#### Request headers - -- **Content-Type**: application/json -- **Authorization**: Token **`INFLUX_API_TOKEN`** - -#### Request body - -JSON object with the following fields: - -- **flux**: raw Flux task string that contains [`options`](/flux/v0/spec/options/) and the query. -- **status**: task status ("active" or "inactive") -- **description**: task description - -```sh -curl --request POST 'https://cloud2.influxdata.com/api/v2/tasks' \ - --header 'Content-Type: application/json' \ - --header 'Authorization: Token INFLUX_API_TOKEN' \ - --data-binary @- << EOF - { - "flux": "option task = {name: \"CPU Total 1 Hour New\", every: 1h}\ - from(bucket: \"telegraf\") - |> range(start: -1h) - |> filter(fn: (r) => (r._measurement == \"cpu\")) - |> filter(fn: (r) =>\n\t\t(r._field == \"usage_system\")) - |> filter(fn: (r) => (r.cpu == \"cpu-total\")) - |> aggregateWindow(every: 1h, fn: max) - |> to(bucket: \"cpu_usage_user_total_1h\", org: \"INFLUX_ORG\")", - "orgID": "INFLUX_ORG_ID", - "status": "active", - "description": "This task downsamples CPU data every hour" - } -EOF -``` - -Replace the following: - -- **`INFLUX_API_TOKEN`**: your InfluxDB [API token](/influxdb/cloud/admin/tokens/view-tokens/) -- **`INFLUX_ORG`**: your InfluxDB organization name -- **`INFLUX_ORG_ID`**: your InfluxDB organization ID - -{{% /cloud-only %}} + diff --git a/content/influxdb/v2/process-data/manage-tasks/delete-task.md b/content/influxdb/v2/process-data/manage-tasks/delete-task.md index 446699689..079ceb35e 100644 --- a/content/influxdb/v2/process-data/manage-tasks/delete-task.md +++ b/content/influxdb/v2/process-data/manage-tasks/delete-task.md @@ -10,39 +10,8 @@ menu: weight: 206 related: - /influxdb/v2/reference/cli/influx/task/delete +source: /shared/influxdb-v2/process-data/manage-tasks/delete-task.md --- -## Delete a task in the InfluxDB UI -1. In the navigation menu on the left, select **Tasks**. - - {{< nav-icon "tasks" >}} - -2. In the list of tasks, hover over the task you want to delete. -3. Click **Delete** on the far right. -4. Click **Confirm**. - -## Delete a task with the influx CLI -Use the `influx task delete` command to delete a task. - -```sh -# Syntax -influx task delete -i - -# Example -influx task delete -i 0343698431c35000 -``` - -_To find the task ID, see [how to view tasks](/influxdb/v2/process-data/manage-tasks/view-tasks/)_ - -## Delete a task using the InfluxDB API - -Use the [`/tasks/TASK_ID` InfluxDB API endpoint](/influxdb/v2/api/#operation/DeleteTasksID) to delete a task and all associated records (task runs, logs, and labels). - -{{< api-endpoint method="DELETE" endpoint="http://localhost:8086/api/v2/tasks/TASK_ID" api-ref="/influxdb/v2/api/#operation/DeleteTasksID" >}} - -_To find the task ID, see [how to view tasks](/influxdb/v2/process-data/manage-tasks/view-tasks/)_ - -Once the task is deleted, InfluxDB cancels all scheduled runs of the task. - -If you want to disable a task instead of delete it, see how to -[update the task status](/influxdb/v2/process-data/manage-tasks/update-task/) to `inactive`. + diff --git a/content/influxdb/v2/process-data/manage-tasks/run-task.md b/content/influxdb/v2/process-data/manage-tasks/run-task.md index 710877e81..37793f22c 100644 --- a/content/influxdb/v2/process-data/manage-tasks/run-task.md +++ b/content/influxdb/v2/process-data/manage-tasks/run-task.md @@ -14,68 +14,8 @@ related: - /influxdb/v2/reference/cli/influx/task/retry-failed - /influxdb/v2/api/#operation/PostTasksIDRuns - /influxdb/v2/api/#operation/PostTasksIDRunsIDRetry +source: /shared/influxdb-v2/process-data/manage-tasks/run-task.md --- -InfluxDB data processing tasks generally run in defined intervals or at a specific time, -however, you can manually run a task from the InfluxDB user interface (UI), -the `influx` command line interface (CLI), -or the InfluxDB `/api/v2` API. - -## Run a task from the InfluxDB UI -1. In the navigation menu on the left, select **Tasks**. - - {{< nav-icon "tasks" >}} - -2. Hover over the task you want to run and click the **{{< icon "gear" >}}** icon. -3. Select **Run Task**. - -## Run a task with the influx CLI -Use the `influx task run retry` command to run a task. - -{{% note %}} -To run a task from the `influx` CLI, the task must have already run at least once. -{{% /note %}} - -{{< cli/influx-creds-note >}} - -```sh -# List all tasks to find the ID of the task to run -influx task list - -# Use the task ID to list previous runs of the task -influx task run list --task-id=0000000000000000 - -# Use the task ID and run ID to retry a run -influx task run retry --task-id=0000000000000000 --run-id=0000000000000000 -``` - -### Retry failed task runs -Use the [`influx task retry-failed` command](/influxdb/v2/reference/cli/influx/task/retry-failed/) -to retry failed task runs. - -```sh -# Retry failed tasks for a specific task -influx task retry-failed \ - --id 0000000000000000 - -# Print information about runs that will be retried -influx task retry-failed \ - --dry-run - -# Retry failed task runs that occurred in a specific time range -influx task retry-failed \ - --after 2021-01-01T00:00:00Z \ - --before 2021-01-01T23:59:59Z -``` - -## Run a task with the InfluxDB API -Use the [`/tasks/TASK_ID/runs` InfluxDB API endpoint](/influxdb/v2/api/#operation/PostTasksIDRuns) -to manually start a task run. - -{{< api-endpoint method="POST" endpoint="http://localhost:8086/api/v2/tasks/TASK_ID/runs" api-ref="/influxdb/v2/api/#operation/PostTasksIDRuns" >}} - -### Retry failed task runs -Use the [`/tasks/TASK_ID/runs/RUN_ID/retry` InfluxDB API endpoint](/influxdb/v2/api/#operation/PostTasksIDRunsIDRetry) -to retry a task run. - -{{< api-endpoint method="POST" endpoint="http://localhost:8086/api/v2/tasks/TASK_ID/runs/RUN_ID/retry" api-ref="/influxdb/v2/api/#operation/PostTasksIDRunsIDRetry" >}} + diff --git a/content/influxdb/v2/process-data/manage-tasks/task-run-history.md b/content/influxdb/v2/process-data/manage-tasks/task-run-history.md index 75ba2b841..eced96b92 100644 --- a/content/influxdb/v2/process-data/manage-tasks/task-run-history.md +++ b/content/influxdb/v2/process-data/manage-tasks/task-run-history.md @@ -11,75 +11,8 @@ related: - /influxdb/v2/reference/cli/influx/task/list - /influxdb/v2/reference/cli/influx/task/run/list - /influxdb/v2/reference/cli/influx/task/retry-failed +source: /shared/influxdb-v2/process-data/manage-tasks/task-run-history.md --- -When an InfluxDB task runs, a _run_ record is created in the task's history. -Logs associated with each run provide relevant log messages, timestamps, -and the exit status of the run attempt. - -Use the InfluxDB user interface (UI), the `influx` command line interface (CLI), -or the InfluxDB `/api/v2` API to view task run histories and associated logs. - -{{% warn %}} -InfluxDB doesn’t guarantee that a task will run at the scheduled time. During busy -periods, tasks are added to the run queue and processed in order of submission. -The scheduled start time and actual start time can be viewed in the logs under -`scheduledFor` and `startedAt`. - -Task execution time doesn't affect the time range queried. Tasks will query -over the set time range as if executed on schedule regardless of delay. -{{% /warn %}} - -## View a task's run history in the InfluxDB UI - -1. In the navigation menu on the left, select **Tasks**. - - {{< nav-icon "tasks" >}} - -2. Hover over the task you want to run and click the **{{< icon "gear" >}}** icon. -3. Select **View Task Runs**. - -### View task run logs - -To view logs associated with a run, click **View Logs** next to the run in the task's run history. - -## View a task's run history with the influx CLI - -Use the `influx task run list` command to view a task's run history. - -```sh -# List all tasks to find the ID of the task to run -influx task list - -# Use the task ID to view the run history of a task -influx task run list --task-id=0000000000000000 -``` - -{{% note %}} -Detailed run logs are not currently available in the `influx` CLI. -{{% /note %}} - -To retry failed task runs, see how to [run tasks](/influxdb/v2/process-data/manage-tasks/run-task/). - -## View logs for a task with the InfluxDB API - -Use the [`/api/v2/tasks/TASK_ID/logs` InfluxDB API endpoint](/influxdb/v2/api/#operation/GetTasksIDLogs) -to view the log events for a task and exclude additional task metadata. - -{{< api-endpoint method="GET" endpoint="http://localhost:8086/api/v2/tasks/TASK_ID/logs" api-ref="/influxdb/v2/api/#operation/GetTasksIDLogs" >}} - -## View a task's run history with the InfluxDB API - -Use the [`/tasks/TASK_ID/runs` InfluxDB API endpoint](/influxdb/v2/api/#operation/GetTasksIDRuns) -to view a task's run history. - -{{< api-endpoint method="GET" endpoint="http://localhost:8086/api/v2/tasks/{taskID}/runs" api-ref="/influxdb/v2/api/#operation/GetTasksIDRuns" >}} - -### View task run logs with the InfluxDB API - -To view logs associated with a run, use the -[`/api/v2/tasks/TASK_ID/runs/RUN_ID/logs` InfluxDB API endpoint](/influxdb/v2/api/#operation/GetTasksIDRunsIDLogs). - -{{< api-endpoint method="GET" endpoint="http://localhost:8086/api/v2/tasks/TASK_ID/runs/RUN_ID/logs" api-ref="/influxdb/v2/api/#operation/GetTasksIDRunsIDLogs" >}} - -To retry failed task runs, see how to [run tasks](/influxdb/v2/process-data/manage-tasks/run-task/). + diff --git a/content/influxdb/v2/process-data/manage-tasks/update-task.md b/content/influxdb/v2/process-data/manage-tasks/update-task.md index d79c4b72c..caa8a0d96 100644 --- a/content/influxdb/v2/process-data/manage-tasks/update-task.md +++ b/content/influxdb/v2/process-data/manage-tasks/update-task.md @@ -10,77 +10,8 @@ menu: weight: 204 related: - /influxdb/v2/reference/cli/influx/task/update +source: /shared/influxdb-v2/process-data/manage-tasks/update-task.md --- -## Update a task in the InfluxDB UI -1. In the navigation menu on the left, select **Tasks**. - - {{< nav-icon "tasks" "v2" >}} - -2. Find the task you would like to edit and click the **{{< icon "settings" >}}** icon located far right of the task name. -3. Click **Edit**. -4. Click **{{< caps >}}Save{{< /caps >}}** in the upper right. - -#### Update a task Flux script -1. In the list of tasks, click the **Name** of the task you want to update. -2. In the left panel, modify the task options. -3. In the right panel, modify the task script. -4. Click **{{< caps >}}Save{{< /caps >}}** in the upper right. - -#### Update the status of a task -In the list of tasks, click the {{< icon "toggle" >}} toggle to the left of the -task you want to activate or inactivate. - -#### Update a task description -1. In the list of tasks, hover over the name of the task you want to update. -2. Click the pencil icon {{< icon "pencil" >}}. -3. Click outside of the field or press `RETURN` to update. - -## Update a task with the influx CLI -Use the `influx task update` command to update or change the status of an existing task. - -_This command requires a task ID, which is available in the output of `influx task list`._ - -#### Update a task Flux script -Pass the file path of your updated Flux script to the `influx task update` command -with the ID of the task you want to update. -Modified [task options](/influxdb/v2/process-data/task-options) defined in the Flux -script are also updated. - -```sh -# Syntax -influx task update -i -f -``` - -```sh -# Example -influx task update -i 0343698431c35000 -f /tasks/cq-mean-1h.flux -``` - -#### Update the status of a task -Pass the ID of the task you want to update to the `influx task update` -command with the `--status` flag. - -_Possible arguments of the `--status` flag are `active` or `inactive`._ - -```sh -# Syntax -influx task update -i --status < active | inactive > -``` - -```sh -# Example -influx task update -i 0343698431c35000 --status inactive -``` - -## Update a task with the InfluxDB API -Use the [`/tasks/TASK_ID` InfluxDB API endpoint](/influxdb/v2/api/#operation/PatchTasksID) to update properties of a task. - -{{< api-endpoint method="PATCH" endpoint="http://localhost:8086/api/v2/tasks/TASK_ID" api-ref="/influxdb/v2/api/#operation/PatchTasksID" >}} - -In your request, pass the task ID and an object that contains the updated key-value pairs. -To activate or inactivate a task, set the `status` property. -`"status": "inactive"` cancels scheduled runs and prevents manual runs of the task. -_To find the task ID, see [how to view tasks](/influxdb/v2/process-data/manage-tasks/view-tasks/)._ - -Once InfluxDB applies the update, it cancels all previously scheduled runs of the task. + diff --git a/content/influxdb/v2/process-data/task-options.md b/content/influxdb/v2/process-data/task-options.md index 11e166767..7dc848197 100644 --- a/content/influxdb/v2/process-data/task-options.md +++ b/content/influxdb/v2/process-data/task-options.md @@ -10,147 +10,8 @@ menu: parent: Process data weight: 105 influxdb/v2/tags: [tasks, flux] +source: /shared/influxdb-v2/process-data/task-options.md --- -Task options define specific information about a task. -They are set in a Flux script {{% cloud-only %}}, in the InfluxDB API, {{% /cloud-only %}} or in the InfluxDB user interface (UI). -The following task options are available: - -- [name](#name) -- [every](#every) -- [cron](#cron) -- [offset](#offset) - -{{% note %}} -`every` and `cron` are mutually exclusive, but at least one is required. -{{% /note %}} - -## name - -The name of the task. _**Required**_. - -_**Data type:** String_ - -In Flux: - -```js -option task = { - name: "taskName", - // ... -} -``` - -{{% cloud-only %}} -In a `/api/v2/tasks` request body with `scriptID`: - -```json -{ - "scriptID": "SCRIPT_ID", - "name": "TASK_NAME" - ... -} -``` - -Replace `SCRIPT_ID` with the ID of your InfluxDB invokable script. -{{% /cloud-only %}} - -## every - -The interval at which the task runs. This option also determines when the task first starts to run, depending on the specified time (in [duration literal](/flux/v0/spec/lexical-elements/#duration-literals)). - -_**Data type:** Duration_ - -For example, if you save or schedule a task at 2:30 and run the task every hour (`1h`): - -`option task = {name: "aggregation", every: 1h}` - -The task first executes at 3:00pm, and subsequently every hour after that. - -In Flux: - -```js -option task = { - // ... - every: 1h, -} -``` - -{{% cloud-only %}} -In a `/api/v2/tasks` request body with `scriptID`: - -```json -{ - "scriptID": "SCRIPT_ID", - "every": "1h" - ... -} -``` - -{{% /cloud-only %}} - -{{% note %}} -In the InfluxDB UI, use the **Interval** field to set this option. -{{% /note %}} - -## cron - -The [cron expression](https://en.wikipedia.org/wiki/Cron#Overview) that -defines the schedule on which the task runs. -Cron scheduling is based on system time. - -_**Data type:** String_ - -In Flux: - -```js -option task = { - // ... - cron: "0 * * * *", -} -``` - -{{% cloud-only %}} -In a `/api/v2/tasks` request body with `scriptID`: - -```json -{ - "scriptID": "SCRIPT_ID", - "cron": "0 * * * *", - ... -} -``` - -{{% /cloud-only %}} - -## offset - -Delays the execution of the task but preserves the original time range. -For example, if a task is to run on the hour, a `10m` offset will delay it to 10 -minutes after the hour, but all time ranges defined in the task are relative to -the specified execution time. -A common use case is offsetting execution to account for data that may arrive late. - -_**Data type:** Duration_ - -In Flux: - -```js -option task = { - // ... - offset: 10m, -} -``` - -{{% cloud-only %}} - -In a `/api/v2/tasks` request body with `scriptID`: - -```json -{ - "scriptID": "SCRIPT_ID", - "offset": "10m", - ... -} -``` - -{{% /cloud-only %}} \ No newline at end of file + diff --git a/content/influxdb/v2/query-data/common-queries/_index.md b/content/influxdb/v2/query-data/common-queries/_index.md index 89ada2e00..147590ecb 100644 --- a/content/influxdb/v2/query-data/common-queries/_index.md +++ b/content/influxdb/v2/query-data/common-queries/_index.md @@ -9,14 +9,8 @@ menu: name: Common queries parent: Query data weight: 104 +source: /shared/influxdb-v2/query-data/common-queries/_index.md --- -The following articles walk through common queries using the -[NOAA water database data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data). - -{{< children >}} - -{{% note %}} -This list will continue to grow. -If you have suggestions, please [submit them to the InfluxData Community](https://community.influxdata.com/c/influxdb2). -{{% /note %}} + diff --git a/content/influxdb/v2/query-data/common-queries/compare-values.md b/content/influxdb/v2/query-data/common-queries/compare-values.md index d68601cdf..bcb80c7f0 100644 --- a/content/influxdb/v2/query-data/common-queries/compare-values.md +++ b/content/influxdb/v2/query-data/common-queries/compare-values.md @@ -9,40 +9,8 @@ menu: name: Compare values from different buckets parent: Common queries weight: 104 +source: /shared/influxdb-v2/query-data/common-queries/compare-values.md --- -{{% note %}} -This example uses [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data). -{{% /note %}} - -This example compares the value from the latest point to an average value stored in another bucket. This is useful when using the average value to calculate a [threshold check](/influxdb/v2/monitor-alert/checks/create/#threshold-check). - -The following query: - -- Uses [`range()`](/flux/v0/stdlib/universe/range/) to define a time range. -- Gets the last value in the `means` bucket and compares it to the last value in the `noaa` bucket using [`last()`](/flux/v0/stdlib/universe/last/). -- Uses [`join()`](/flux/v0/stdlib/universe/join/) to combine the results -- Uses [`map()`](/flux/v0/stdlib/universe/map/) to calculate the differences - -```js -means = from(bucket: "weekly_means") - |> range(start: 2019-09-01T00:00:00Z) - |> last() - |> keep(columns: ["_value", "location"]) - -latest = from(bucket: "noaa") - |> range(start: 2019-09-01T00:00:00Z) - |> filter(fn: (r) => r._measurement == "average_temperature") - |> last() - |> keep(columns: ["_value", "location"]) - -join(tables: {mean: means, reading: latest}, on: ["location"]) - |> map(fn: (r) => ({r with deviation: r._value_reading - r._value_mean})) -``` - -### Example results - -| location | _value_mean | _value_reading | deviation | -|:-------- | -----------: | --------------:| ---------: | -| coyote_creek | 79.82710622710623 | 89 | 9.172893772893772 | -| santa_monica | 80.20451339915374 | 85 | 4.79548660084626 | + diff --git a/content/influxdb/v2/query-data/common-queries/iot-common-queries.md b/content/influxdb/v2/query-data/common-queries/iot-common-queries.md index b535b9343..4da31fd32 100644 --- a/content/influxdb/v2/query-data/common-queries/iot-common-queries.md +++ b/content/influxdb/v2/query-data/common-queries/iot-common-queries.md @@ -8,206 +8,8 @@ menu: name: IoT common queries parent: Common queries weight: 205 +source: /shared/influxdb-v2/query-data/common-queries/iot-common-queries.md --- -The following scenarios illustrate common queries used to extract information from IoT sensor data: - -- [Calculate time in state](#calculate-time-in-state) -- [Calculate time weighted average](#calculate-time-weighted-average) -- [Calculate value between events](#calculate-value-between-events) -- [Determine a state within existing values](#determine-a-state-within-existing-values) - -All scenarios below use the `machineProduction` sample dataset provided by the [InfluxDB `sample` package](/flux/v0/stdlib/influxdata/influxdb/sample/). -For more information, see [Sample data](/influxdb/cloud/reference/sample-data/). - -## Calculate time in state - -In this scenario, we look at whether a production line is running smoothly (`state`=`OK`) and what percentage of time the production line is running smoothly or not (`state`=`NOK`). If no points are recorded during the interval (`state`=`NaN`), you may opt to retrieve the last state prior to the interval. - -To visualize the time in state, see the [Mosaic visualization](#mosaic-visualization). - -**To calculate the percentage of time a machine spends in each state** - -1. Import the [`contrib/tomhollingworth/events` package](/flux/v0/stdlib/contrib/tomhollingworth/events/). -1. Query the `state` field. -2. Use `events.duration()` to return the amount of time (in a specified unit) between each data point, and store the interval in the `duration` column. -3. Group columns by the status value column (in this case `_value`), `_start`, `_stop`, and other relevant dimensions. -4. Sum the `duration` column to calculate the total amount of time spent in each state. -5. Pivot the summed durations into the `_value` column. -6. Use `map()` to calculate the percentage of time spent in each state. - -```js -import "contrib/tomhollingworth/events" - -from(bucket: "machine") - |> range(start: 2021-08-01T00:00:00Z, stop: 2021-08-02T00:30:00Z) - |> filter(fn: (r) => r["_measurement"] == "machinery") - |> filter(fn: (r) => r["_field"] == "state") - |> events.duration(unit: 1h, columnName: "duration") - |> group(columns: ["_value", "_start", "_stop", "station_id"]) - |> sum(column: "duration") - |> pivot(rowKey: ["_stop"], columnKey: ["_value"], valueColumn: "duration") - |> map( - fn: (r) => { - totalTime = float(v: r.NOK + r.OK) - - return {r with NOK: float(v: r.NOK) / totalTime * 100.0, OK: float(v: r.OK) / totalTime * 100.0} - }, - ) -``` - -The query above focuses on a specific time range of state changes reported in the production line. - -- `range()` defines the time range to query. -- `filter()` defines the field (`state`) and measurement (`machinery`) to filter by. -- `events.duration()` calculates the time between points. -- `group()` regroups the data by the field value, so points with `OK` and `NOK` field values are grouped into separate tables. -- `sum()` returns the sum of durations spent in each state. - -The output of the query at this point is: - -| _value | duration | -| ------ | -------: | -| NOK | 22 | - -| _value | duration | -| ------ | -------: | -| OK | 172 | - -`pivot()` creates columns for each unique value in the `_value` column, and then assigns the associated duration as the column value. -The output of the pivot operation is: - -| NOK | OK | -| :-- | :-- | -| 22 | 172 | - -Given the output above, `map()` does the following: - -1. Adds the `NOK` and `OK` values to calculate `totalTime`. -2. Divides `NOK` by `totalTime`, and then multiplies the quotient by 100. -3. Divides `OK` by `totalTime`, and then multiplies the quotient by 100. - -This returns: - -| NOK | OK | -| :---------------- | :----------------- | -| 11.34020618556701 | 88.65979381443299 | - -The result shows that 88.66% of time production is in the `OK` state, and that 11.34% of time, production is in the `NOK` state. - -#### Mosaic visualization - -The [mosaic visualization](/influxdb/v2/visualize-data/visualization-types/mosaic/) displays state changes over time. In this example, the mosaic visualization displays different colored tiles based on the `state` field. - -```js -from(bucket: "machine") - |> range(start: 2021-08-01T00:00:00Z, stop: 2021-08-02T00:30:00Z) - |> filter(fn: (r) => r._measurement == "machinery") - |> filter(fn: (r) => r._field == "state") - |> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false) -``` - -When visualizing data, it is possible to have more data points than available pixels. To divide data into time windows that span a single pixel, use `aggregateWindow` with the `every` parameter set to `v.windowPeriod`. -Use `last` as the aggregate `fn` to return the last value in each time window. -Set `createEmpty` to `false` so results won't include empty time windows. - - -## Calculate time weighted average - -To calculate the time-weighted average of data points, use the [`timeWeightedAvg()` function](/flux/v0/stdlib/universe/timeweightedavg/). - -The example below queries the `oil_temp` field in the `machinery` measurement. The `timeWeightedAvg()` function returns the time-weighted average of oil temperatures based on 5 second intervals. - -```js -from(bucket: "machine") - |> range(start: 2021-08-01T00:00:00Z, stop: 2021-08-01T00:00:30Z) - |> filter(fn: (r) => r._measurement == "machinery" and r._field == "oil_temp") - |> timeWeightedAvg(unit: 5s) -``` - -##### Output data - -| stationID | _start | _stop | _value | -|:----- | ----- | ----- | ------:| -| g1 | 2021-08-01T01:00:00.000Z | 2021-08-01T00:00:30.000Z | 40.25396118491921 | -| g2 | 2021-08-01T01:00:00.000Z | 2021-08-01T00:00:30.000Z | 40.6 | -| g3 | 2021-08-01T01:00:00.000Z | 2021-08-01T00:00:30.000Z | 41.384505595567866 | -| g4 | 2021-08-01T01:00:00.000Z | 2021-08-01T00:00:30.000Z | 41.26735518634935 | - - -## Calculate value between events - -Calculate the value between events by getting the average value during a specific time range. - -The following scenario queries data starting when four production lines start and end. -The following query calculates the average oil temperature for each grinding station during that period. - -```js -batchStart = 2021-08-01T00:00:00Z -batchStop = 2021-08-01T00:00:20Z - -from(bucket: "machine") - |> range(start: batchStart, stop: batchStop) - |> filter(fn: (r) => r._measurement == "machinery" and r._field == "oil_temp") - |> mean() -``` - -##### Output - -| stationID | _start | _stop | _value | -|:----- | ----- | ----- | ------:| -| g1 | 2021-08-01T01:00:00.000Z | 2021-08-02T00:00:00.000Z | 40 | -| g2 | 2021-08-01T01:00:00.000Z | 2021-08-02T00:00:00.000Z | 40.6 | -| g3 | 2021-08-01T01:00:00.000Z | 2021-08-02T00:00:00.000Z | 41.379999999999995 | -| g4 | 2021-08-01T01:00:00.000Z | 2021-08-02T00:00:00.000Z | 41.2 | - - -## Determine a state with existing values - -Use multiple existing values to determine a state. -The following example calculates a state based on the difference between the `pressure` and `pressure-target` fields in the machine-production sample data. -To determine a state by comparing existing fields: - -1. Query the fields to compare (in this case, `pressure` and `pressure_target`). -2. (Optional) Use `aggregateWindow()` to window data into time-based windows and - apply an aggregate function (like `mean()`) to return values that represent larger windows of time. -3. Use `pivot()` to shift field values into columns. -4. Use `map()` to compare or operate on the different field column values. -5. Use `map()` to assign a status (in this case, `needsMaintenance` based on the relationship of the field column values. - -```js -import "math" - -from(bucket: "machine") - |> range(start: 2021-08-01T00:00:00Z, stop: 2021-08-02T00:00:00Z) - |> filter(fn: (r) => r["_measurement"] == "machinery") - |> filter(fn: (r) => r["_field"] == "pressure" or r["_field"] == "pressure_target") - |> aggregateWindow(every: 12h, fn: mean) - |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value") - |> map(fn: (r) => ({ r with pressureDiff: r.pressure - r.pressure_target })) - |> map(fn: (r) => ({ r with needsMaintenance: if math.abs(x: r.pressureDiff) >= 15.0 then true else false })) -``` - -##### Output - -| _time | needsMaintenance | pressure | pressure_target | pressureDiff | stationID | -| :----------------------- | :--------------- | -----------------: | -----------------: | ------------------: | --------: | -| 2021-08-01T12:00:00.000Z | false | 101.83929080014092 | 104.37786394078252 | -2.5385731406416028 | g1 | -| 2021-08-02T00:00:00.000Z | false | 96.04368008245874 | 102.27698650674662 | -6.233306424287889 | g1 | - -| _time | needsMaintenance | pressure | pressure_target | pressureDiff | stationID | -| :----------------------- | :--------------- | -----------------: | -----------------: | ------------------: | --------: | -| 2021-08-01T12:00:00.000Z | false | 101.62490431541765 | 104.83915260886623 | -3.214248293448577 | g2 | -| 2021-08-02T00:00:00.000Z | false | 94.52039415465273 | 105.90869375273046 | -11.388299598077722 | g2 | - -| _time | needsMaintenance | pressure | pressure_target | pressureDiff | stationID | -| :----------------------- | :--------------- | -----------------: | -----------------: | ------------------: | --------: | -| 2021-08-01T12:00:00.000Z | false | 92.23774168403503 | 104.81867444768653 | -12.580932763651504 | g3 | -| 2021-08-02T00:00:00.000Z | true | 89.20867846153847 | 108.2579185520362 | -19.049240090497733 | g3 | - -| _time | needsMaintenance | pressure | pressure_target | pressureDiff | stationID | -| :----------------------- | :--------------- | -----------------: | -----------------: | ------------------: | --------: | -| 2021-08-01T12:00:00.000Z | false | 94.40834093349847 | 107.6827757125155 | -13.274434779017028 | g4 | -| 2021-08-02T00:00:00.000Z | true | 88.61785638936534 | 108.25471698113208 | -19.636860591766734 | g4 | - -The table reveals that the `pressureDiff` value `-19.636860591766734` from station g4 and `-19.049240090497733` from station g3 are higher than 15, therefore there is a change in state that marks the `needMaintenance` value as "true" and would require that station to need work to turn that value back to `false`. \ No newline at end of file + diff --git a/content/influxdb/v2/query-data/common-queries/multiple-fields-in-calculations.md b/content/influxdb/v2/query-data/common-queries/multiple-fields-in-calculations.md index 7cd108e76..6c7e19562 100644 --- a/content/influxdb/v2/query-data/common-queries/multiple-fields-in-calculations.md +++ b/content/influxdb/v2/query-data/common-queries/multiple-fields-in-calculations.md @@ -8,99 +8,8 @@ menu: influxdb_v2: parent: Common queries weight: 103 +source: /shared/influxdb-v2/query-data/common-queries/multiple-fields-in-calculations.md --- -To use values from multiple fields in a mathematic calculation, complete the following steps: - -1. [Filter by fields required in your calculation](#filter-by-fields) -2. [Pivot fields into columns](#pivot-fields-into-columns) -3. [Perform the mathematic calculation](#perform-the-calculation) - -## Filter by fields -Use [`filter()`](/flux/v0/stdlib/universe/filter/) -to return only the fields necessary for your calculation. -Use the [`or` logical operator](/flux/v0/spec/operators/#logical-operators) -to filter by multiple fields. - -The following example queries two fields, `A` and `B`: - -```js -from(bucket: "example-bucket") - |> range(start: -1m) - |> filter(fn: (r) => r._field == "A" or r._field == "B") -``` - -This query returns one or more tables for each field. For example: - -{{< flex >}} -{{% flex-content %}} -| _time | _field | _value | -|:----- |:------:| ------:| -| 2021-01-01T00:00:00Z | A | 12.4 | -| 2021-01-01T00:00:15Z | A | 12.2 | -| 2021-01-01T00:00:30Z | A | 11.6 | -| 2021-01-01T00:00:45Z | A | 11.9 | -{{% /flex-content %}} -{{% flex-content %}} -| _time | _field | _value | -|:----- |:------:| ------:| -| 2021-01-01T00:00:00Z | B | 3.1 | -| 2021-01-01T00:00:15Z | B | 4.8 | -| 2021-01-01T00:00:30Z | B | 2.2 | -| 2021-01-01T00:00:45Z | B | 3.3 | -{{% /flex-content %}} -{{< /flex >}} - -## Pivot fields into columns -Use [`pivot()`](/flux/v0/stdlib/universe/pivot/) -to align multiple fields by time. - -{{% note %}} -To correctly pivot on `_time`, points for each field must have identical timestamps. -If timestamps are irregular or do not align perfectly, see -[Normalize irregular timestamps](/influxdb/v2/query-data/flux/manipulate-timestamps/#normalize-irregular-timestamps). -{{% /note %}} - -```js -// ... - |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value") -``` - -Using the queried data [above](#filter-by-fields), this `pivot()` function returns: - -| _time | A | B | -|:----- | ------:| ------:| -| 2021-01-01T00:00:00Z | 12.4 | 3.1 | -| 2021-01-01T00:00:15Z | 12.2 | 4.8 | -| 2021-01-01T00:00:30Z | 11.6 | 2.2 | -| 2021-01-01T00:00:45Z | 11.9 | 3.3 | - -## Perform the calculation -Use [`map()`](/flux/v0/stdlib/universe/map/) -to perform the mathematic operation using column values as operands. - -The following example uses values in the `A` and `B` columns to calculate a new `_value` column: - -```js -// ... - |> map(fn: (r) => ({ r with _value: r.A * r.B })) -``` - -Using the pivoted data above, this `map()` function returns: - -| _time | A | B | _value | -|:----- | ------:| ------:| ------:| -| 2021-01-01T00:00:00Z | 12.4 | 3.1 | 38.44 | -| 2021-01-01T00:00:15Z | 12.2 | 4.8 | 58.56 | -| 2021-01-01T00:00:30Z | 11.6 | 2.2 | 25.52 | -| 2021-01-01T00:00:45Z | 11.9 | 3.3 | 39.27 | - -## Full example query - -```js -from(bucket: "example-bucket") - |> range(start: -1m) - |> filter(fn: (r) => r._field == "A" or r._field == "B") - |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value") - |> map(fn: (r) => ({r with _value: r.A * r.B})) -``` + diff --git a/content/influxdb/v2/query-data/common-queries/operate-on-columns.md b/content/influxdb/v2/query-data/common-queries/operate-on-columns.md index 87a4ec7f5..41a7194f4 100644 --- a/content/influxdb/v2/query-data/common-queries/operate-on-columns.md +++ b/content/influxdb/v2/query-data/common-queries/operate-on-columns.md @@ -11,127 +11,9 @@ menu: influxdb_v2: name: Operate on columns parent: Common queries -weight: 100 +weight: 100 +source: /shared/influxdb-v2/query-data/common-queries/operate-on-columns.md --- -Use the following common queries to operate on columns: - -- [Find and count unique values in a column](#find-and-count-unique-values-in-a-column) -- [Recalculate the _values column](#recalculate-the-_values-column) -- [Calculate a new column](#calculate-a-new-column) - -{{% note %}} -These examples use [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data). -{{% /note %}} - -## Find and count unique values in a column - -Find and count the number of unique values in a specified column. -The following examples find and count unique locations where data was collected. - -### Find unique values - -This query: - - - Uses [`group()`](/flux/v0/stdlib/universe/group/) to ungroup data and return results in a single table. - - Uses [`keep()`](/flux/v0/stdlib/universe/keep/) and [`unique()`](/flux/v0/stdlib/universe/unique/) to return unique values in the specified column. - -```js -from(bucket: "noaa") - |> range(start: -30d) - |> group() - |> keep(columns: ["location"]) - |> unique(column: "location") -``` - -#### Example results -| location | -|:-------- | -| coyote_creek | -| santa_monica | - -### Count unique values - -This query: - -- Uses [`group()`](/flux/v0/stdlib/universe/group/) to ungroup data and return results in a single table. -- Uses [`keep()`](/flux/v0/stdlib/universe/keep/), [`unique()`](/flux/v0/stdlib/universe/unique/), and then [`count()`](/flux/v0/stdlib/universe/count/) to count the number of unique values. - -```js -from(bucket: "noaa") - |> group() - |> unique(column: "location") - |> count(column: "location") -``` - -#### Example results - -| location | -| ---------:| -| 2 | - - -## Recalculate the _values column - -To recalculate the `_value` column, use the `with` operator in [`map()`](/flux/v0/stdlib/universe/map/) to overwrite the existing `_value` column. - -The following query: - - - Uses [`filter()`](/flux/v0/stdlib/universe/filter/) to filter the `average_temperature` measurement. - - Uses [`map()`](/flux/v0/stdlib/universe/map/) to convert Fahrenheit temperature values into Celsius. - -```js - -from(bucket: "noaa") - |> filter(fn: (r) => r._measurement == "average_temperature") - |> range(start: -30d) - |> map(fn: (r) => ({r with _value: (float(v: r._value) - 32.0) * 5.0 / 9.0} )) -``` - -| _field | _measurement | _start | _stop | _time | location | _value | -|:------ |:------------ |:------ |:----- |:----- |:-------- | ------: | -| degrees | average_temperature | 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | 2019-08-17T00:00:00Z | coyote_creek | 27.77777777777778 | -| degrees | average_temperature | 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | 2019-08-17T00:06:00Z | coyote_creek | 22.77777777777778 | -| degrees | average_temperature | 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | 2019-08-17T00:12:00Z | coyote_creek | 30 | -| degrees | average_temperature | 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | 2019-08-17T00:18:00Z | coyote_creek | 31.666666666666668 | -| degrees | average_temperature | 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | 2019-08-17T00:24:00Z | coyote_creek | 25 | -| degrees | average_temperature | 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | 2019-08-17T00:30:00Z | coyote_creek | 21.11111111111111 | -| degrees | average_temperature | 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | 2019-08-17T00:36:00Z | coyote_creek | 28.88888888888889 | -| degrees | average_temperature | 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | 2019-08-17T00:42:00Z | coyote_creek | 24.444444444444443 | -| degrees | average_temperature | 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | 2019-08-17T00:48:00Z | coyote_creek | 29.444444444444443 | -| degrees | average_temperature | 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | 2019-08-17T00:54:00Z | coyote_creek | 26.666666666666668 | -| degrees | average_temperature | 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | 2019-08-17T01:00:00Z | coyote_creek | 21.11111111111111 | -| ••• | ••• | ••• | ••• | ••• | ••• | ••• | - -## Calculate a new column - -To use values in a row to calculate and add a new column, use `map()`. -This example below converts temperature from Fahrenheit to Celsius and maps the Celsius value to a new `celsius` column. - -The following query: - - - Uses [`filter()`](/flux/v0/stdlib/universe/filter/) to filter the `average_temperature` measurement. - - Uses [`map()`](/flux/v0/stdlib/universe/map/) to create a new column calculated from existing values in each row. - -```js -from(bucket: "noaa") - |> filter(fn: (r) => r._measurement == "average_temperature") - |> range(start: -30d) - |> map(fn: (r) => ({r with celsius: (r._value - 32.0) * 5.0 / 9.0})) -``` - -#### Example results - -| _start | _stop | _field | _measurement | location | _time | _value | celsius | -|:------ |:----- |:------: |:------------: |:--------: |:----- | ------:| -------:| -| 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | degrees | average_temperature | coyote_creek | 2019-08-17T00:00:00Z | 82 | 27.78 | -| 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | degrees | average_temperature | coyote_creek | 2019-08-17T00:06:00Z | 73 | 22.78 | -| 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | degrees | average_temperature | coyote_creek | 2019-08-17T00:12:00Z | 86 | 30.00 | -| 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | degrees | average_temperature | coyote_creek | 2019-08-17T00:18:00Z | 89 | 31.67 | -| 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | degrees | average_temperature | coyote_creek | 2019-08-17T00:24:00Z | 77 | 25.00 | -| 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | degrees | average_temperature | coyote_creek | 2019-08-17T00:30:00Z | 70 | 21.11 | -| 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | degrees | average_temperature | coyote_creek | 2019-08-17T00:36:00Z | 84 | 28.89 | -| 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | degrees | average_temperature | coyote_creek | 2019-08-17T00:42:00Z | 76 | 24.44 | -| 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | degrees | average_temperature | coyote_creek | 2019-08-17T00:48:00Z | 85 | 29.44 | -| 1920-03-05T22:10:01Z | 2020-03-05T22:10:01Z | degrees | average_temperature | coyote_creek | 2019-08-17T00:54:00Z | 80 | 26.67 | -| ••• | ••• | ••• | ••• | ••• | ••• | ••• | ••• | + diff --git a/content/influxdb/v2/query-data/execute-queries/data-explorer.md b/content/influxdb/v2/query-data/execute-queries/data-explorer.md index ec8a0f69f..cf7416bc0 100644 --- a/content/influxdb/v2/query-data/execute-queries/data-explorer.md +++ b/content/influxdb/v2/query-data/execute-queries/data-explorer.md @@ -10,92 +10,8 @@ menu: name: Query with Data Explorer parent: Execute queries influxdb/v2/tags: [query] +source: /shared/influxdb-v2/query-data/execute-queries/data-explorer.md --- -Build, execute, and visualize your queries in InfluxDB UI's **Data Explorer**. - -![Data Explorer with Flux](/img/influxdb/2-0-data-explorer.png) - -Move seamlessly between using the Flux builder or templates and manually editing the query. -Choose between [visualization types](/influxdb/v2/visualize-data/visualization-types/) for your query. - -## Query data with Flux and the Data Explorer - -Flux is a functional data scripting language designed for querying, -analyzing, and acting on time series data. -See [Get started with Flux](/influxdb/v2/query-data/get-started) to learn more about Flux. - -1. In the navigation menu on the left, click **Data Explorer**. - - {{< nav-icon "data-explorer" >}} - -2. Use the Flux builder in the bottom panel to create a Flux query: - - Select a bucket to define your data source or select `+ Create Bucket` to add a new bucket. - - Edit your time range with the [time range option](#select-time-range) in the dropdown menu. - - Add filters to narrow your data by selecting attributes or columns in the dropdown menu. - - Select **Group** from the **Filter** dropdown menu to group data into tables. For more about how grouping data in Flux works, see [Group data](/influxdb/v2/query-data/flux/group-data/). -3. Alternatively, click **Script Editor** to manually edit the query. - To switch back to the query builder, click **Query Builder**. Note that your updates from the Script Editor will not be saved. -4. Use the **Functions** list to review the available Flux functions. - Click a function from the list to add it to your query. -5. Click **Submit** (or press `Control+Enter`) to run your query. You can then preview your graph in the above pane. - To cancel your query while it's running, click **Cancel**. -6. To work on multiple queries at once, click the {{< icon "plus" >}} to add another tab. - - Click the eye icon on a tab to hide or show a query's visualization. - - Click the name of the query in the tab to rename it. - -## Visualize your query - -- Select an available [visualization types](/influxdb/v2/visualize-data/visualization-types/) from the dropdown menu in the upper-left: - - {{< img-hd src="/img/influxdb/2-0-visualizations-dropdown.png" title="Visualization dropdown" />}} - -## Control your dashboard cell - -To open the cell editor overlay, click the gear icon in the upper right of a cell and select **Configure**. - The cell editor overlay opens. - -### View raw data - -Toggle the **View Raw Data** {{< icon "toggle" >}} option to see your data in table format instead of a graph. Scroll through raw data using arrows, or click page numbers to find specific tables. [Group keys](/influxdb/cloud/reference/glossary/#group-key) and [data types](/influxdb/cloud/reference/glossary/#data-type) are easily identifiable at the top of each column underneath the headings. Use this option when data can't be visualized using a visualization type. - - {{< img-hd src="/img/influxdb/cloud-controls-view-raw-data.png" alt="View raw data" />}} - -### Save as CSV - -Click the CSV icon to save the cells contents as a CSV file. - -### Manually refresh dashboard - -Click the refresh button ({{< icon "refresh" >}}) to manually refresh the dashboard's data. - -### Select time range - -1. Select from the time range options in the dropdown menu. - - {{< img-hd src="/img/influxdb/2-0-controls-time-range.png" alt="Select time range" />}} - -2. Select **Custom Time Range** to enter a custom time range with precision up to nanoseconds. -The default time range is 5m. - -> The custom time range uses the selected timezone (local time or UTC). - -### Query Builder or Script Editor - -Click **Query Builder** to use the builder to create a Flux query. Click **Script Editor** to manually edit the query. - -#### Keyboard shortcuts - -In **Script Editor** mode, the following keyboard shortcuts are available: - -| Key | Description | -|--------------------------------|---------------------------------------------| -| `Control + /` (`⌘ + /` on Mac) | Comment/uncomment current or selected lines | -| `Control + Enter` | Submit query | - -## Save your query as a dashboard cell or task - -- Click **Save as** in the upper right, and then: - - To add your query to a dashboard, click **Dashboard Cell**. - - To save your query as a task, click **Task**. - - To save your query as a variable, click **Variable**. + diff --git a/content/influxdb/v2/query-data/execute-queries/flux-repl.md b/content/influxdb/v2/query-data/execute-queries/flux-repl.md index a79848354..dcb6ec006 100644 --- a/content/influxdb/v2/query-data/execute-queries/flux-repl.md +++ b/content/influxdb/v2/query-data/execute-queries/flux-repl.md @@ -7,13 +7,8 @@ menu: name: Query in the Flux REPL parent: Execute queries influxdb/v2/tags: [query] +source: /shared/influxdb-v2/query-data/execute-queries/flux-repl.md --- -The [Flux REPL](/influxdb/v2/tools/flux-repl/) starts an interactive -Read-Eval-Print Loop (REPL) where you can write and execute Flux queries. - -```sh -./flux repl -``` - -For more information, see [Use the Flux REPL](/influxdb/v2/tools/flux-repl/). + diff --git a/content/influxdb/v2/query-data/execute-queries/influx-api.md b/content/influxdb/v2/query-data/execute-queries/influx-api.md index 82a0ac4d9..d088dc2b6 100644 --- a/content/influxdb/v2/query-data/execute-queries/influx-api.md +++ b/content/influxdb/v2/query-data/execute-queries/influx-api.md @@ -7,105 +7,8 @@ menu: name: Query with the InfluxDB API parent: Execute queries influxdb/v2/tags: [query] +source: /shared/influxdb-v2/query-data/execute-queries/influx-api.md --- -The [InfluxDB v2 API](/influxdb/v2/reference/api) provides a programmatic interface for all interactions with InfluxDB. -To query InfluxDB {{< current-version >}}, do one of the following: - -- Send a Flux query request to the [`/api/v2/query`](/influxdb/v2/api/#operation/PostQueryAnalyze) endpoint. -- Send an InfluxQL query request to the [/query 1.x compatibility API](/influxdb/v2/reference/api/influxdb-1x/query/). - -In your request, set the following: - -- Your organization via the `org` or `orgID` URL parameters. -- `Authorization` header to `Token ` + your API token. -- `Accept` header to `application/csv`. -- `Content-type` header to `application/vnd.flux` (Flux only) or `application/json` (Flux or InfluxQL). -- Query in Flux or InfluxQL with the request's raw data. - -{{% note %}} -#### Use gzip to compress the query response - -To compress the query response, set the `Accept-Encoding` header to `gzip`. -This saves network bandwidth, but increases server-side load. - -We recommend only using gzip compression on responses that are larger than 1.4 KB. -If the response is smaller than 1.4 KB, gzip encoding will always return a 1.4 KB -response, despite the uncompressed response size. -1500 bytes (~1.4 KB) is the maximum transmission unit (MTU) size for the public -network and is the largest packet size allowed at the network layer. -{{% /note %}} - -#### Flux - Example query request - -Below is an example `curl` request that sends a Flux query to InfluxDB {{< current-version >}}: - -{{< code-tabs-wrapper >}} -{{% code-tabs %}} -[Without compression](#) -[With compression](#) -{{% /code-tabs %}} - -{{% code-tab-content %}} -```bash -curl --request POST \ - http://localhost:8086/api/v2/query?orgID=INFLUX_ORG_ID \ - --header 'Authorization: Token INFLUX_TOKEN' \ - --header 'Accept: application/csv' \ - --header 'Content-type: application/vnd.flux' \ - --data 'from(bucket:"example-bucket") - |> range(start: -12h) - |> filter(fn: (r) => r._measurement == "example-measurement") - |> aggregateWindow(every: 1h, fn: mean)' -``` -{{% /code-tab-content %}} - -{{% code-tab-content %}} -```bash -curl --request POST \ - http://localhost:8086/api/v2/query?orgID=INFLUX_ORG_ID \ - --header 'Authorization: Token INFLUX_TOKEN' \ - --header 'Accept: application/csv' \ - --header 'Content-type: application/vnd.flux' \ - --header 'Accept-Encoding: gzip' \ - --data 'from(bucket:"example-bucket") - |> range(start: -12h) - |> filter(fn: (r) => r._measurement == "example-measurement") - |> aggregateWindow(every: 1h, fn: mean)' -``` -{{% /code-tab-content %}} -{{< /code-tabs-wrapper >}} - -#### InfluxQL - Example query request - -Below is an example `curl` request that sends an InfluxQL query to InfluxDB {{< current-version >}}: - -{{< code-tabs-wrapper >}} -{{% code-tabs %}} -[Without compression](#) -[With compression](#) -{{% /code-tabs %}} - -{{% code-tab-content %}} -```bash -curl --request -G http://localhost:8086/query?orgID=INFLUX_ORG_ID&database=MyDB&retention_policy=MyRP \ - --header 'Authorization: Token INFLUX_TOKEN' \ - --header 'Accept: application/csv' \ - --header 'Content-type: application/json' \ - --data-urlencode "q=SELECT used_percent FROM example-db.example-rp.example-measurement WHERE host=host1" -``` -{{% /code-tab-content %}} - -{{% code-tab-content %}} -```bash -curl --request -G http://localhost:8086/query?orgID=INFLUX_ORG_ID&database=MyDB&retention_policy=MyRP \ - --header 'Authorization: Token INFLUX_TOKEN' \ - --header 'Accept: application/csv' \ - --header 'Content-type: application/json' \ - --header 'Accept-Encoding: gzip' \ - --data-urlencode "q=SELECT used_percent FROM example-db.example-rp.example-measurement WHERE host=host1" -``` -{{% /code-tab-content %}} -{{< /code-tabs-wrapper >}} - -InfluxDB returns the query results in [annotated CSV](/influxdb/v2/reference/syntax/annotated-csv/). + diff --git a/content/influxdb/v2/query-data/execute-queries/influx-query.md b/content/influxdb/v2/query-data/execute-queries/influx-query.md index c3baf4a31..2eea28ae7 100644 --- a/content/influxdb/v2/query-data/execute-queries/influx-query.md +++ b/content/influxdb/v2/query-data/execute-queries/influx-query.md @@ -9,34 +9,8 @@ menu: influxdb/v2/tags: [query] related: - /influxdb/v2/reference/cli/influx/query/ +source: /shared/influxdb-v2/query-data/execute-queries/influx-query.md --- -Use the [`influx query` command](/influxdb/v2/reference/cli/influx/query) to query data in InfluxDB using Flux. -Pass Flux queries to the command as either a file or via stdin. - -###### Run a query from a file - -```bash -influx query --file /path/to/query.flux -``` - -###### Pass raw Flux via stdin pipe - -```bash -influx query - # Return to open the pipe - -data = from(bucket: "example-bucket") |> range(start: -10m) # ... -# Linux & macOS: to close the pipe and submit the command -# Windows: , then , then to close the pipe and submit the command -``` - -{{% note %}} -#### Remove unnecessary columns in large datasets -When using the `influx query` command to query and download large datasets, -drop columns such as `_start` and `_stop` to optimize the download file size. - -```js -// ... - |> drop(columns: ["_start", "_stop"]) -``` -{{% /note %}} + diff --git a/content/influxdb/v2/query-data/flux/_index.md b/content/influxdb/v2/query-data/flux/_index.md index 8fd735b15..aee9bd338 100644 --- a/content/influxdb/v2/query-data/flux/_index.md +++ b/content/influxdb/v2/query-data/flux/_index.md @@ -9,27 +9,8 @@ menu: parent: Query data aliases: - /influxdb/v2/query-data/guides/ +source: /shared/influxdb-v2/query-data/flux/_index.md --- -The following guides walk through both common and complex queries and use cases for Flux. - -{{% note %}} -#### Example data variable -Many of the examples provided in the following guides use a `data` variable, -which represents a basic query that filters data by measurement and field. -`data` is defined as: - -```js -data = from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "example-measurement" and r._field == "example-field") -``` -{{% /note %}} - -## Flux query guides - -{{< children type="anchored-list" pages="all" >}} - ---- - -{{< children pages="all" readmore=true hr=true >}} + diff --git a/content/influxdb/v2/query-data/flux/calculate-percentages.md b/content/influxdb/v2/query-data/flux/calculate-percentages.md index 88215050e..dfab3e572 100644 --- a/content/influxdb/v2/query-data/flux/calculate-percentages.md +++ b/content/influxdb/v2/query-data/flux/calculate-percentages.md @@ -17,195 +17,8 @@ related: - /flux/v0/stdlib/universe/pivot - /flux/v0/stdlib/universe/join list_query_example: percentages +source: /shared/influxdb-v2/query-data/flux/calculate-percentages.md --- -Calculating percentages from queried data is a common use case for time series data. -To calculate a percentage in Flux, operands must be in each row. -Use `map()` to re-map values in the row and calculate a percentage. - -**To calculate percentages** - -1. Use [`from()`](/flux/v0/stdlib/influxdata/influxdb/from/), - [`range()`](/flux/v0/stdlib/universe/range/) and - [`filter()`](/flux/v0/stdlib/universe/filter/) to query operands. -2. Use [`pivot()` or `join()`](/influxdb/v2/query-data/flux/mathematic-operations/#pivot-vs-join) - to align operand values into rows. -3. Use [`map()`](/flux/v0/stdlib/universe/map/) - to divide the numerator operand value by the denominator operand value and multiply by 100. - -{{% note %}} -The following examples use `pivot()` to align operands into rows because -`pivot()` works in most cases and is more performant than `join()`. -_See [Pivot vs join](/influxdb/v2/query-data/flux/mathematic-operations/#pivot-vs-join)._ -{{% /note %}} - -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "m1" and r._field =~ /field[1-2]/ ) - |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value") - |> map(fn: (r) => ({ r with _value: r.field1 / r.field2 * 100.0 })) -``` - -## GPU monitoring example -The following example queries data from the gpu-monitor bucket and calculates the -percentage of GPU memory used over time. -Data includes the following: - -- **`gpu` measurement** -- **`mem_used` field**: used GPU memory in bytes -- **`mem_total` field**: total GPU memory in bytes - -### Query mem_used and mem_total fields -```js -from(bucket: "gpu-monitor") - |> range(start: 2020-01-01T00:00:00Z) - |> filter(fn: (r) => r._measurement == "gpu" and r._field =~ /mem_/) -``` - -###### Returns the following stream of tables: - -| _time | _measurement | _field | _value | -|:----- |:------------:|:------: | ------: | -| 2020-01-01T00:00:00Z | gpu | mem_used | 2517924577 | -| 2020-01-01T00:00:10Z | gpu | mem_used | 2695091978 | -| 2020-01-01T00:00:20Z | gpu | mem_used | 2576980377 | -| 2020-01-01T00:00:30Z | gpu | mem_used | 3006477107 | -| 2020-01-01T00:00:40Z | gpu | mem_used | 3543348019 | -| 2020-01-01T00:00:50Z | gpu | mem_used | 4402341478 | - -

- -| _time | _measurement | _field | _value | -|:----- |:------------:|:------: | ------: | -| 2020-01-01T00:00:00Z | gpu | mem_total | 8589934592 | -| 2020-01-01T00:00:10Z | gpu | mem_total | 8589934592 | -| 2020-01-01T00:00:20Z | gpu | mem_total | 8589934592 | -| 2020-01-01T00:00:30Z | gpu | mem_total | 8589934592 | -| 2020-01-01T00:00:40Z | gpu | mem_total | 8589934592 | -| 2020-01-01T00:00:50Z | gpu | mem_total | 8589934592 | - -### Pivot fields into columns -Use `pivot()` to pivot the `mem_used` and `mem_total` fields into columns. -Output includes `mem_used` and `mem_total` columns with values for each corresponding `_time`. - -```js -// ... - |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value") -``` - -###### Returns the following: - -| _time | _measurement | mem_used | mem_total | -|:----- |:------------:| --------: | ---------: | -| 2020-01-01T00:00:00Z | gpu | 2517924577 | 8589934592 | -| 2020-01-01T00:00:10Z | gpu | 2695091978 | 8589934592 | -| 2020-01-01T00:00:20Z | gpu | 2576980377 | 8589934592 | -| 2020-01-01T00:00:30Z | gpu | 3006477107 | 8589934592 | -| 2020-01-01T00:00:40Z | gpu | 3543348019 | 8589934592 | -| 2020-01-01T00:00:50Z | gpu | 4402341478 | 8589934592 | - -### Map new values -Each row now contains the values necessary to calculate a percentage. -Use `map()` to re-map values in each row. -Divide `mem_used` by `mem_total` and multiply by 100 to return the percentage. - -{{% note %}} -To return a precise float percentage value that includes decimal points, the example -below casts integer field values to floats and multiplies by a float value (`100.0`). -{{% /note %}} - -```js -// ... - |> map( - fn: (r) => ({ - _time: r._time, - _measurement: r._measurement, - _field: "mem_used_percent", - _value: float(v: r.mem_used) / float(v: r.mem_total) * 100.0 - }), - ) -``` -##### Query results: - -| _time | _measurement | _field | _value | -|:----- |:------------:|:------: | ------: | -| 2020-01-01T00:00:00Z | gpu | mem_used_percent | 29.31 | -| 2020-01-01T00:00:10Z | gpu | mem_used_percent | 31.37 | -| 2020-01-01T00:00:20Z | gpu | mem_used_percent | 30.00 | -| 2020-01-01T00:00:30Z | gpu | mem_used_percent | 35.00 | -| 2020-01-01T00:00:40Z | gpu | mem_used_percent | 41.25 | -| 2020-01-01T00:00:50Z | gpu | mem_used_percent | 51.25 | - -### Full query -```js -from(bucket: "gpu-monitor") - |> range(start: 2020-01-01T00:00:00Z) - |> filter(fn: (r) => r._measurement == "gpu" and r._field =~ /mem_/ ) - |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value") - |> map( - fn: (r) => ({ - _time: r._time, - _measurement: r._measurement, - _field: "mem_used_percent", - _value: float(v: r.mem_used) / float(v: r.mem_total) * 100.0 - }), - ) -``` - -## Examples - -#### Calculate percentages using multiple fields -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "example-measurement") - |> filter(fn: (r) => r._field == "used_system" or r._field == "used_user" or r._field == "total") - |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value") - |> map( - fn: (r) => ({ - r with _value: float(v: r.used_system + r.used_user) / float(v: r.total) * 100.0 - }), - ) -``` - -#### Calculate percentages using multiple measurements - -1. Ensure measurements are in the same [bucket](/influxdb/v2/reference/glossary/#bucket). -2. Use `filter()` to include data from both measurements. -3. Use `group()` to ungroup data and return a single table. -4. Use `pivot()` to pivot fields into columns. -5. Use `map()` to re-map rows and perform the percentage calculation. - - -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => (r._measurement == "m1" or r._measurement == "m2") and (r._field == "field1" or r._field == "field2")) - |> group() - |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value") - |> map(fn: (r) => ({r with _value: r.field1 / r.field2 * 100.0})) -``` - -#### Calculate percentages using multiple data sources -```js -import "sql" -import "influxdata/influxdb/secrets" - -pgUser = secrets.get(key: "POSTGRES_USER") -pgPass = secrets.get(key: "POSTGRES_PASSWORD") -pgHost = secrets.get(key: "POSTGRES_HOST") - -t1 = sql.from( - driverName: "postgres", - dataSourceName: "postgresql://${pgUser}:${pgPass}@${pgHost}", - query: "SELECT id, name, available FROM example_table", -) - -t2 = from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "example-measurement" and r._field == "example-field") - -join(tables: {t1: t1, t2: t2}, on: ["id"]) - |> map(fn: (r) => ({r with _value: r._value_t2 / r.available_t1 * 100.0})) -``` + diff --git a/content/influxdb/v2/query-data/flux/conditional-logic.md b/content/influxdb/v2/query-data/flux/conditional-logic.md index 4435bb4b6..6fb9dfdb7 100644 --- a/content/influxdb/v2/query-data/flux/conditional-logic.md +++ b/content/influxdb/v2/query-data/flux/conditional-logic.md @@ -22,203 +22,8 @@ list_code_example: | ```js if color == "green" then "008000" else "ffffff" ``` +source: /shared/influxdb-v2/query-data/flux/conditional-logic.md --- -Flux provides `if`, `then`, and `else` conditional expressions that allow for powerful and flexible Flux queries. - -If you're just getting started with Flux queries, check out the following: - -- [Get started with Flux](/flux/v0/get-started/) for a conceptual overview of Flux and parts of a Flux query. -- [Execute queries](/influxdb/v2/query-data/execute-queries/) to discover a variety of ways to run your queries. - -##### Conditional expression syntax -```js -// Pattern -if then else - -// Example -if color == "green" then "008000" else "ffffff" -``` - -Conditional expressions are most useful in the following contexts: - -- When defining variables. -- When using functions that operate on a single row at a time ( - [`filter()`](/flux/v0/stdlib/universe/filter/), - [`map()`](/flux/v0/stdlib/universe/map/), - [`reduce()`](/flux/v0/stdlib/universe/reduce) ). - -## Evaluating conditional expressions - -Flux evaluates statements in order and stops evaluating once a condition matches. - -For example, given the following statement: - -```js -if r._value > 95.0000001 and r._value <= 100.0 then - "critical" -else if r._value > 85.0000001 and r._value <= 95.0 then - "warning" -else if r._value > 70.0000001 and r._value <= 85.0 then - "high" -else - "normal" -``` - -When `r._value` is 96, the output is "critical" and the remaining conditions are not evaluated. - -## Examples - -- [Conditionally set the value of a variable](#conditionally-set-the-value-of-a-variable) -- [Create conditional filters](#create-conditional-filters) -- [Conditionally transform column values with map()](#conditionally-transform-column-values-with-map) -- [Conditionally increment a count with reduce()](#conditionally-increment-a-count-with-reduce) - -### Conditionally set the value of a variable -The following example sets the `overdue` variable based on the -`dueDate` variable's relation to `now()`. - -```js -dueDate = 2019-05-01 -overdue = if dueDate < now() then true else false -``` - -### Create conditional filters -The following example uses an example `metric` [dashboard variable](/influxdb/v2/visualize-data/variables/) -to change how the query filters data. -`metric` has three possible values: - -- Memory -- CPU -- Disk - -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter( - fn: (r) => if v.metric == "Memory" then - r._measurement == "mem" and r._field == "used_percent" - else if v.metric == "CPU" then - r._measurement == "cpu" and r._field == "usage_user" - else if v.metric == "Disk" then - r._measurement == "disk" and r._field == "used_percent" - else - r._measurement != "", - ) -``` - - -### Conditionally transform column values with map() -The following example uses the [`map()` function](/flux/v0/stdlib/universe/map/) -to conditionally transform column values. -It sets the `level` column to a specific string based on `_value` column. - -{{< code-tabs-wrapper >}} -{{% code-tabs %}} -[No Comments](#) -[Comments](#) -{{% /code-tabs %}} -{{% code-tab-content %}} -```js -from(bucket: "example-bucket") - |> range(start: -5m) - |> filter(fn: (r) => r._measurement == "mem" and r._field == "used_percent") - |> map( - fn: (r) => ({r with - level: if r._value >= 95.0000001 and r._value <= 100.0 then - "critical" - else if r._value >= 85.0000001 and r._value <= 95.0 then - "warning" - else if r._value >= 70.0000001 and r._value <= 85.0 then - "high" - else - "normal", - }), - ) -``` -{{% /code-tab-content %}} -{{% code-tab-content %}} -```js -from(bucket: "example-bucket") - |> range(start: -5m) - |> filter(fn: (r) => r._measurement == "mem" and r._field == "used_percent") - |> map( - fn: (r) => ({ - // Retain all existing columns in the mapped row - r with - // Set the level column value based on the _value column - level: if r._value >= 95.0000001 and r._value <= 100.0 then - "critical" - else if r._value >= 85.0000001 and r._value <= 95.0 then - "warning" - else if r._value >= 70.0000001 and r._value <= 85.0 then - "high" - else - "normal", - }), - ) -``` - -{{% /code-tab-content %}} -{{< /code-tabs-wrapper >}} - -### Conditionally increment a count with reduce() -The following example uses the [`aggregateWindow()`](/flux/v0/stdlib/universe/aggregatewindow/) -and [`reduce()`](/flux/v0/stdlib/universe/reduce/) -functions to count the number of records in every five minute window that exceed a defined threshold. - -{{< code-tabs-wrapper >}} -{{% code-tabs %}} -[No Comments](#) -[Comments](#) -{{% /code-tabs %}} -{{% code-tab-content %}} -```js -threshold = 65.0 - -data = from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "mem" and r._field == "used_percent") - |> aggregateWindow( - every: 5m, - fn: (column, tables=<-) => tables - |> reduce( - identity: {above_threshold_count: 0.0}, - fn: (r, accumulator) => ({ - above_threshold_count: if r._value >= threshold then - accumulator.above_threshold_count + 1.0 - else - accumulator.above_threshold_count + 0.0, - }), - ), - ) -``` -{{% /code-tab-content %}} -{{% code-tab-content %}} -```js -threshold = 65.0 - -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "mem" and r._field == "used_percent") - // Aggregate data into 5 minute windows using a custom reduce() function - |> aggregateWindow( - every: 5m, - // Use a custom function in the fn parameter. - // The aggregateWindow fn parameter requires 'column' and 'tables' parameters. - fn: (column, tables=<-) => tables - |> reduce( - identity: {above_threshold_count: 0.0}, - fn: (r, accumulator) => ({ - // Conditionally increment above_threshold_count if - // r.value exceeds the threshold - above_threshold_count: if r._value >= threshold then - accumulator.above_threshold_count + 1.0 - else - accumulator.above_threshold_count + 0.0, - }), - ), - ) -``` -{{% /code-tab-content %}} -{{< /code-tabs-wrapper >}} + diff --git a/content/influxdb/v2/query-data/flux/cumulativesum.md b/content/influxdb/v2/query-data/flux/cumulativesum.md index d28048629..2676b1394 100644 --- a/content/influxdb/v2/query-data/flux/cumulativesum.md +++ b/content/influxdb/v2/query-data/flux/cumulativesum.md @@ -13,58 +13,8 @@ influxdb/v2/tags: [query, cumulative sum] related: - /flux/v0/stdlib/universe/cumulativesum/ list_query_example: cumulative_sum +source: /shared/influxdb-v2/query-data/flux/cumulativesum.md --- -Use the [`cumulativeSum()` function](/flux/v0/stdlib/universe/cumulativesum/) -to calculate a running total of values. -`cumulativeSum` sums the values of subsequent records and returns each row updated with the summed total. - -{{< flex >}} -{{% flex-content "half" %}} -**Given the following input table:** - -| _time | _value | -| ----- |:------:| -| 0001 | 1 | -| 0002 | 2 | -| 0003 | 1 | -| 0004 | 3 | -{{% /flex-content %}} -{{% flex-content "half" %}} -**`cumulativeSum()` returns:** - -| _time | _value | -| ----- |:------:| -| 0001 | 1 | -| 0002 | 3 | -| 0003 | 4 | -| 0004 | 7 | -{{% /flex-content %}} -{{< /flex >}} - -{{% note %}} -The examples below use the [example data variable](/influxdb/v2/query-data/flux/#example-data-variable). -{{% /note %}} - -##### Calculate the running total of values -```js -data - |> cumulativeSum() -``` - -## Use cumulativeSum() with aggregateWindow() -[`aggregateWindow()`](/flux/v0/stdlib/universe/aggregatewindow/) -segments data into windows of time, aggregates data in each window into a single -point, then removes the time-based segmentation. -It is primarily used to [downsample data](/influxdb/v2/process-data/common-tasks/downsample-data/). - -`aggregateWindow()` expects an aggregate function that returns a single row for each time window. -To use `cumulativeSum()` with `aggregateWindow`, use `sum` in `aggregateWindow()`, -then calculate the running total of the aggregate values with `cumulativeSum()`. - - -```js -data - |> aggregateWindow(every: 5m, fn: sum) - |> cumulativeSum() -``` + diff --git a/content/influxdb/v2/query-data/flux/custom-functions/_index.md b/content/influxdb/v2/query-data/flux/custom-functions/_index.md index 16a88e5ab..753e486ae 100644 --- a/content/influxdb/v2/query-data/flux/custom-functions/_index.md +++ b/content/influxdb/v2/query-data/flux/custom-functions/_index.md @@ -18,206 +18,8 @@ list_code_example: | data |> multByX(x: 2.0) ``` +source: /shared/influxdb-v2/query-data/flux/custom-functions/_index.md --- -Flux's functional syntax lets you create custom functions. -This guide walks through the basics of creating your own function. - -- [Function definition syntax](#function-definition-syntax) -- [Use piped-forward data in a custom function](#use-piped-forward-data-in-a-custom-function) -- [Define parameter defaults](#define-parameter-defaults) -- [Define functions with scoped variables](#define-functions-with-scoped-variables) - -## Function definition syntax -The basic syntax for defining functions in Flux is as follows: - -```js -// Basic function definition syntax -functionName = (functionParameters) => functionOperations -``` - -##### functionName -The name used to call the function in your Flux script. - -##### functionParameters -A comma-separated list of parameters passed into the function and used in its operations. -[Parameter defaults](#define-parameter-defaults) can be defined for each. - -##### functionOperations -Operations and functions that manipulate the input into the desired output. - -#### Basic function examples - -###### Example square function -```js -// Function definition -square = (n) => n * n - -// Function usage -> square(n:3) -9 -``` - -###### Example multiply function -```js -// Function definition -multiply = (x, y) => x * y - -// Function usage -> multiply(x: 2, y: 15) -30 -``` - -## Use piped-forward data in a custom function -Most Flux functions process piped-forward data. -To process piped-forward data, one of the function -parameters must capture the input tables using the `<-` pipe-receive expression. - -In the example below, the `tables` parameter is assigned to the `<-` expression, -which represents all data piped-forward into the function. -`tables` is then piped-forward into other operations in the function definition. - -```js -functionName = (tables=<-) => tables |> functionOperations -``` - -#### Pipe-forwardable function example - -###### Multiply row values by x -The example below defines a `multByX` function that multiplies the `_value` column -of each row in the input table by the `x` parameter. -It uses the [`map()` function](/flux/v0/stdlib/universe/map) -to modify each `_value`. - -```js -// Function definition -multByX = (tables=<-, x) => tables - |> map(fn: (r) => ({r with _value: r._value * x})) - -// Function usage -from(bucket: "example-bucket") - |> range(start: -1m) - |> filter(fn: (r) => r._measurement == "mem" and r._field == "used_percent") - |> multByX(x: 2.0) -``` - -## Define parameter defaults -Use the `=` assignment operator to assign a default value to function parameters -in your function definition: - -```js -functionName = (param1=defaultValue1, param2=defaultValue2) => functionOperation -``` - -Defaults are overridden by explicitly defining the parameter in the function call. - -### Example functions with defaults - -#### Get a list of leaders -The example below defines a `leaderBoard` function that returns a limited number -of records sorted by values in specified columns. -It uses the [`sort()` function](/flux/v0/stdlib/universe/sort) -to sort records in either descending or ascending order. -It then uses the [`limit()` function](/flux/v0/stdlib/universe/limit) -to return a specified number of records from the sorted table. - -```js -// Function definition -leaderBoard = (tables=<-, limit=4, columns=["_value"], desc=true) => tables - |> sort(columns: columns, desc: desc) - |> limit(n: limit) - -// Function usage -// Get the 4 highest scoring players -from(bucket: "example-bucket") - |> range(start: -1m) - |> filter(fn: (r) => r._measurement == "player-stats" and r._field == "total-points") - |> leaderBoard() - -// Get the 10 shortest race times -from(bucket: "example-bucket") - |> range(start: -1m) - |> filter(fn: (r) => r._measurement == "race-times" and r._field == "elapsed-time") - |> leaderBoard(limit: 10, desc: false) -``` - -## Define functions with scoped variables -To create custom functions with variables scoped to the function, place your -function operations and variables inside of a [block (`{}`)](/influxdb/v2/reference/flux/language/blocks/) -and use a `return` statement to return a specific variable. - -```js -functionName = (functionParameters) => { - exampleVar = "foo" - - return exampleVar -} -``` - -### Example functions with scoped variables - -- [Return an alert level based on a value](#return-an-alert-level-based-on-a-value) -- [Convert a HEX color code to a name](#convert-a-hex-color-code-to-a-name) - -#### Return an alert level based on a value -The following function uses conditional logic to return an alert level based on -a numeric input value: - -```js -alertLevel = (v) => { - level = if float(v: v) >= 90.0 then - "crit" - else if float(v: v) >= 80.0 then - "warn" - else if float(v: v) >= 65.0 then - "info" - else - "ok" - - return level -} - -alertLevel(v: 87.3) -// Returns "warn" -``` - -#### Convert a HEX color code to a name -The following function converts a hexadecimal (HEX) color code to the equivalent HTML color name. -The functions uses the [Flux dictionary package](/flux/v0/stdlib/dict/) -to create a dictionary of HEX codes and their corresponding names. - -```js -import "dict" - -hexName = (hex) => { - hexNames = dict.fromList( - pairs: [ - {key: "#00ffff", value: "Aqua"}, - {key: "#000000", value: "Black"}, - {key: "#0000ff", value: "Blue"}, - {key: "#ff00ff", value: "Fuchsia"}, - {key: "#808080", value: "Gray"}, - {key: "#008000", value: "Green"}, - {key: "#00ff00", value: "Lime"}, - {key: "#800000", value: "Maroon"}, - {key: "#000080", value: "Navy"}, - {key: "#808000", value: "Olive"}, - {key: "#800080", value: "Purple"}, - {key: "#ff0000", value: "Red"}, - {key: "#c0c0c0", value: "Silver"}, - {key: "#008080", value: "Teal"}, - {key: "#ffffff", value: "White"}, - {key: "#ffff00", value: "Yellow"}, - ], - ) - name = dict.get(dict: hexNames, key: hex, default: "No known name") - - return name -} - -hexName(hex: "#000000") -// Returns "Black" - -hexName(hex: "#8b8b8b") -// Returns "No known name" -``` + diff --git a/content/influxdb/v2/query-data/flux/custom-functions/custom-aggregate.md b/content/influxdb/v2/query-data/flux/custom-functions/custom-aggregate.md index 95edf1eda..3dd9c3e9d 100644 --- a/content/influxdb/v2/query-data/flux/custom-functions/custom-aggregate.md +++ b/content/influxdb/v2/query-data/flux/custom-functions/custom-aggregate.md @@ -11,235 +11,8 @@ aliases: - /influxdb/v2/query-data/guides/custom-functions/custom-aggregate/ related: - /iflux/v0/stdlib/universe/reduce/ +source: /shared/influxdb-v2/query-data/flux/custom-functions/custom-aggregate.md --- -To aggregate your data, use the Flux -[aggregate functions](/flux/v0/function-types#aggregates) -or create custom aggregate functions using the -[`reduce()`function](/flux/v0/stdlib/universe/reduce/). - -## Aggregate function characteristics -Aggregate functions all have the same basic characteristics: - -- They operate on individual input tables and transform all records into a single record. -- The output table has the same [group key](/flux/v0/get-started/data-model/#group-key) as the input table. - -## How reduce() works -The `reduce()` function operates on one row at a time using the function defined in -the [`fn` parameter](/flux/v0/stdlib/universe/reduce/#fn). -The `fn` function maps keys to specific values using two [records](/flux/v0/data-types/composite/record/) -specified by the following parameters: - -| Parameter | Description | -|:---------: |:----------- | -| `r` | A record that represents the row or record. | -| `accumulator` | A record that contains values used in each row's aggregate calculation. | - -{{% note %}} -The `reduce()` function's [`identity` parameter](/flux/v0/stdlib/universe/reduce/#identity) -defines the initial `accumulator` record. -{{% /note %}} - -### Example reduce() function -The following example `reduce()` function produces a sum and product of all values -in an input table. - -```js -|> reduce( - fn: (r, accumulator) => ({ - sum: r._value + accumulator.sum, - product: r._value * accumulator.product - }), - identity: {sum: 0.0, product: 1.0}, -) -``` - -To illustrate how this function works, take this simplified table for example: - -| _time | _value | -|:----- | ------:| -| 2019-04-23T16:10:49Z | 1.6 | -| 2019-04-23T16:10:59Z | 2.3 | -| 2019-04-23T16:11:09Z | 0.7 | -| 2019-04-23T16:11:19Z | 1.2 | -| 2019-04-23T16:11:29Z | 3.8 | - -###### Input records -The `fn` function uses the data in the first row to define the `r` record. -It defines the `accumulator` record using the `identity` parameter. - -```js -r = { _time: 2019-04-23T16:10:49.00Z, _value: 1.6 } -accumulator = { sum : 0.0, product : 1.0 } -``` - -###### Key mappings -It then uses the `r` and `accumulator` records to populate values in the key mappings: -```js -// sum: r._value + accumulator.sum -sum: 1.6 + 0.0 - -// product: r._value * accumulator.product -product: 1.6 * 1.0 -``` - -###### Output record -This produces an output record with the following key value pairs: - -```js -{ sum: 1.6, product: 1.6 } -``` - -The function then processes the next row using this **output record** as the `accumulator`. - -{{% note %}} -Because `reduce()` uses the output record as the `accumulator` when processing the next row, -keys mapped in the `fn` function must match keys in the `identity` and `accumulator` records. -{{% /note %}} - -###### Processing the next row -```js -// Input records for the second row -r = { _time: 2019-04-23T16:10:59.00Z, _value: 2.3 } -accumulator = { sum : 1.6, product : 1.6 } - -// Key mappings for the second row -sum: 2.3 + 1.6 -product: 2.3 * 1.6 - -// Output record of the second row -{ sum: 3.9, product: 3.68 } -``` - -It then uses the new output record as the `accumulator` for the next row. -This cycle continues until all rows in the table are processed. - -##### Final output record and table -After all records in the table are processed, `reduce()` uses the final output record -to create a transformed table with one row and columns for each mapped key. - -###### Final output record -```js -{ sum: 9.6, product: 11.74656 } -``` - -###### Output table -| sum | product | -| --- | -------- | -| 9.6 | 11.74656 | - -{{% note %}} -#### What happened to the \_time column? -The `reduce()` function only keeps columns that are: - -1. Are part of the input table's [group key](/flux/v0/get-started/data-model/#group-key). -2. Explicitly mapped in the `fn` function. - -It drops all other columns. -Because `_time` is not part of the group key and is not mapped in the `fn` function, -it isn't included in the output table. -{{% /note %}} - -## Custom aggregate function examples -To create custom aggregate functions, use principles outlined in -[Creating custom functions](/influxdb/v2/query-data/flux/custom-functions) -and the `reduce()` function to aggregate rows in each input table. - -### Create a custom average function -This example illustrates how to create a function that averages values in a table. -_This is meant for demonstration purposes only. -The built-in [`mean()` function](/flux/v0/stdlib/universe/mean/) -does the same thing and is much more performant._ - -{{< code-tabs-wrapper >}} -{{% code-tabs %}} -[Comments](#) -[No Comments](#) -{{% /code-tabs %}} - -{{% code-tab-content %}} - -```js -average = (tables=<-, outputField="average") => tables - |> reduce( - // Define the initial accumulator record - identity: {count: 0.0, sum: 0.0, avg: 0.0}, - fn: (r, accumulator) => ({ - // Increment the counter on each reduce loop - count: accumulator.count + 1.0, - // Add the _value to the existing sum - sum: accumulator.sum + r._value, - // Divide the existing sum by the existing count for a new average - avg: (accumulator.sum + r._value) / (accumulator.count + 1.0), - }), - ) - // Drop the sum and the count columns since they are no longer needed - |> drop(columns: ["sum", "count"]) - // Set the _field column of the output table to to the value - // provided in the outputField parameter - |> set(key: "_field", value: outputField) - // Rename avg column to _value - |> rename(columns: {avg: "_value"}) -``` -{{% /code-tab-content %}} - -{{% code-tab-content %}} -```js -average = (tables=<-, outputField="average") => tables - |> reduce( - identity: {count: 0.0, sum: 0.0, avg: 0.0}, - fn: (r, accumulator) => ({ - count: accumulator.count + 1.0, - sum: accumulator.sum + r._value, - avg: (accumulator.sum + r._value) / (accumulator.count + 1.0), - }), - ) - |> drop(columns: ["sum", "count"]) - |> set(key: "_field", value: outputField) - |> rename(columns: {avg: "_value"}) -``` -{{% /code-tab-content %}} -{{< /code-tabs-wrapper >}} - -### Aggregate multiple columns -Built-in aggregate functions only operate on one column. -Use `reduce()` to create a custom aggregate function that aggregates multiple columns. - -The following function expects input tables to have `c1_value` and `c2_value` -columns and generates an average for each. - -```js -multiAvg = (tables=<-) => tables - |> reduce( - identity: { - count: 1.0, - c1_sum: 0.0, - c1_avg: 0.0, - c2_sum: 0.0, - c2_avg: 0.0, - }, - fn: (r, accumulator) => ({ - count: accumulator.count + 1.0, - c1_sum: accumulator.c1_sum + r.c1_value, - c1_avg: accumulator.c1_sum / accumulator.count, - c2_sum: accumulator.c2_sum + r.c2_value, - c2_avg: accumulator.c2_sum / accumulator.count, - }), - ) -``` - -### Aggregate gross and net profit -Use `reduce()` to create a function that aggregates gross and net profit. -This example expects `profit` and `expenses` columns in the input tables. - -```js -profitSummary = (tables=<-) => tables - |> reduce( - identity: {gross: 0.0, net: 0.0}, - fn: (r, accumulator) => ({ - gross: accumulator.gross + r.profit, - net: accumulator.net + r.profit - r.expenses - } - ) - ) -``` + diff --git a/content/influxdb/v2/query-data/flux/exists.md b/content/influxdb/v2/query-data/flux/exists.md index 9664000da..e0b07ca3e 100644 --- a/content/influxdb/v2/query-data/flux/exists.md +++ b/content/influxdb/v2/query-data/flux/exists.md @@ -22,94 +22,8 @@ list_code_example: | data |> filter(fn: (r) => exists r._value) ``` +source: /shared/influxdb-v2/query-data/flux/exists.md --- -Use the `exists` operator to check if a row record contains a column or if a -column's value is _null_. - -```js -(r) => exists r.column -``` - -If you're just getting started with Flux queries, check out the following: - -- [Get started with Flux](/flux/v0/get-started/) for a conceptual overview of Flux and parts of a Flux query. -- [Execute queries](/influxdb/v2/query-data/execute-queries/) to discover a variety of ways to run your queries. - -Use `exists` with row functions ( -[`filter()`](/flux/v0/stdlib/universe/filter/), -[`map()`](/flux/v0/stdlib/universe/map/), -[`reduce()`](/flux/v0/stdlib/universe/reduce/)) -to check if a row includes a column or if the value for that column is _null_. - -#### Filter null values - -```js -from(bucket: "example-bucket") - |> range(start: -5m) - |> filter(fn: (r) => exists r._value) -``` - -#### Map values based on existence - -```js -from(bucket: "default") - |> range(start: -30s) - |> map( - fn: (r) => ({r with - human_readable: if exists r._value then - "${r._field} is ${string(v: r._value)}." - else - "${r._field} has no value.", - }), - ) -``` - -#### Ignore null values in a custom aggregate function - -```js -customSumProduct = (tables=<-) => tables - |> reduce( - identity: {sum: 0.0, product: 1.0}, - fn: (r, accumulator) => ({r with - sum: if exists r._value then - r._value + accumulator.sum - else - accumulator.sum, - product: if exists r._value then - r.value * accumulator.product - else - accumulator.product, - }), - ) -``` - -#### Check if a statically defined record contains a key - -When you use the [record literal syntax](/flux/v0/data-types/composite/record/#record-syntax) -to statically define a record, Flux knows the record type and what keys to expect. - -- If the key exists in the static record, `exists` returns `true`. -- If the key exists in the static record, but has a _null_ value, `exists` returns `false`. -- If the key does not exist in the static record, because the record type is - statically known, `exists` returns an error. - -```js -import "internal/debug" - -p = { - firstName: "John", - lastName: "Doe", - age: 42, - height: debug.null(type: "int"), -} - -exists p.firstName -// Returns true - -exists p.height -// Returns false - -exists p.hairColor -// Returns "error: record is missing label hairColor" -``` + diff --git a/content/influxdb/v2/query-data/flux/explore-schema.md b/content/influxdb/v2/query-data/flux/explore-schema.md index 6551ceb1b..1578c5c36 100644 --- a/content/influxdb/v2/query-data/flux/explore-schema.md +++ b/content/influxdb/v2/query-data/flux/explore-schema.md @@ -38,254 +38,8 @@ list_code_example: | // List tag values schema.tagValues(bucket: "example-bucket", tag: "example-tag") ``` +source: /shared/influxdb-v2/query-data/flux/explore-schema.md --- -Flux provides functions that let you explore the structure and schema of your -data stored in InfluxDB. - -- [List buckets](#list-buckets) -- [List measurements](#list-measurements) -- [List field keys](#list-field-keys) -- [List tag keys](#list-tag-keys) -- [List tag values](#list-tag-values) - -{{% warn %}} -Functions in the `schema` package are not supported in the [Flux REPL](/influxdb/v2/tools/repl/). -{{% /warn %}} - -## List buckets -Use [`buckets()`](/flux/v0/stdlib/universe/buckets/) -to list **buckets in your organization**. - -```js -buckets() -``` - -{{< expand-wrapper >}} -{{% expand "View example `buckets()` output" %}} - -`buckets()` returns a single table with the following columns: - -- **organizationID**: Organization ID -- **name**: Bucket name -- **id**: Bucket ID -- **retentionPolicy**: Retention policy associated with the bucket -- **retentionPeriod**: Retention period in nanoseconds - -| organizationID | name | id | retentionPolicy | retentionPeriod | -| :------------- | :--------------- | :------ | :-------------- | --------------: | -| XooX0x0 | _monitoring | XooX0x1 | | 604800000000000 | -| XooX0x0 | _tasks | XooX0x2 | | 259200000000000 | -| XooX0x0 | example-bucket-1 | XooX0x3 | | 0 | -| XooX0x0 | example-bucket-2 | XooX0x4 | | 0 | -| XooX0x0 | example-bucket-3 | XooX0x5 | | 172800000000000 | - -{{% /expand %}} -{{< /expand-wrapper >}} - -## List measurements -Use [`schema.measurements()`](/flux/v0/stdlib/influxdata/influxdb/schema/measurements) -to list **measurements in a bucket**. -_By default, this function returns results from the last 30 days._ - -```js -import "influxdata/influxdb/schema" - -schema.measurements(bucket: "example-bucket") -``` - -{{< expand-wrapper >}} -{{% expand "View example `schema.measurements()` output" %}} - -`schema.measurements()` returns a single table with a `_value` column. -Each row contains the name of a measurement. - -| _value | -| :----- | -| m1 | -| m2 | -| m3 | -| m4 | -| m5 | - -{{% /expand %}} -{{< /expand-wrapper >}} - -## List field keys -Use [`schema.fieldKeys`](/flux/v0/stdlib/influxdata/influxdb/schema/fieldkeys) -to list **field keys in a bucket**. -_By default, this function returns results from the last 30 days._ - -```js -import "influxdata/influxdb/schema" - -schema.fieldKeys(bucket: "example-bucket") -``` - -{{< expand-wrapper >}} -{{% expand "View example `schema.fieldKeys()` output" %}} - -`schema.fieldKeys()` returns a single table with a `_value` column. -Each row contains a unique field key from the specified bucket. - -| _value | -| :----- | -| field1 | -| field2 | -| field3 | -| field4 | -| field5 | - -{{% /expand %}} -{{< /expand-wrapper >}} - -### List fields in a measurement -Use [`schema.measurementFieldKeys`](/flux/v0/stdlib/influxdata/influxdb/schema/measurementfieldkeys) -to list **field keys in a measurement**. -_By default, this function returns results from the last 30 days._ - -```js -import "influxdata/influxdb/schema" - -schema.measurementFieldKeys( - bucket: "example-bucket", - measurement: "example-measurement", -) -``` - -{{< expand-wrapper >}} -{{% expand "View example `schema.measurementFieldKeys()` output" %}} - -`schema.measurementFieldKeys()` returns a single table with a `_value` column. -Each row contains the name of a unique field key in the specified bucket and measurement. - -| _value | -| :----- | -| field1 | -| field2 | -| field3 | -| field4 | -| field5 | - -{{% /expand %}} -{{< /expand-wrapper >}} - -## List tag keys -Use [`schema.tagKeys()`](/flux/v0/stdlib/influxdata/influxdb/schema/tagkeys) -to list **tag keys in a bucket**. -_By default, this function returns results from the last 30 days._ - -```js -import "influxdata/influxdb/schema" - -schema.tagKeys(bucket: "example-bucket") -``` - -{{< expand-wrapper >}} -{{% expand "View example `schema.tagKeys()` output" %}} - -`schema.tagKeys()` returns a single table with a `_value` column. -Each row contains the a unique tag key from the specified bucket. - -| _value | -| :----- | -| tag1 | -| tag2 | -| tag3 | -| tag4 | -| tag5 | - -{{% /expand %}} -{{< /expand-wrapper >}} - -### List tag keys in a measurement -Use [`schema.measurementTagKeys`](/flux/v0/stdlib/influxdata/influxdb/schema/measurementtagkeys) -to list **tag keys in a measurement**. -_By default, this function returns results from the last 30 days._ - -```js -import "influxdata/influxdb/schema" - -schema.measurementTagKeys( - bucket: "example-bucket", - measurement: "example-measurement", -) -``` - -{{< expand-wrapper >}} -{{% expand "View example `schema.measurementTagKeys()` output" %}} - -`schema.measurementTagKeys()` returns a single table with a `_value` column. -Each row contains a unique tag key from the specified bucket and measurement. - -| _value | -| :----- | -| tag1 | -| tag2 | -| tag3 | -| tag4 | -| tag5 | - -{{% /expand %}} -{{< /expand-wrapper >}} - -## List tag values -Use [`schema.tagValues()`](/flux/v0/stdlib/influxdata/influxdb/schema/tagvalues) -to list **tag values for a given tag in a bucket**. -_By default, this function returns results from the last 30 days._ - -```js -import "influxdata/influxdb/schema" - -schema.tagValues(bucket: "example-bucket", tag: "example-tag") -``` - -{{< expand-wrapper >}} -{{% expand "View example `schema.tagValues()` output" %}} - -`schema.tagValues()` returns a single table with a `_value` column. -Each row contains a unique tag value from the specified bucket and tag key. - -| _value | -| :-------- | -| tagValue1 | -| tagValue2 | -| tagValue3 | -| tagValue4 | -| tagValue5 | - -{{% /expand %}} -{{< /expand-wrapper >}} - -### List tag values in a measurement -Use [`schema.measurementTagValues`](/flux/v0/stdlib/influxdata/influxdb/schema/measurementtagvalues) -to list **tag values for a given tag in a measurement**. -_By default, this function returns results from the last 30 days._ - -```js -import "influxdata/influxdb/schema" - -schema.measurementTagValues( - bucket: "example-bucket", - tag: "example-tag", - measurement: "example-measurement", -) -``` - -{{< expand-wrapper >}} -{{% expand "View example `schema.measurementTagValues()` output" %}} - -`schema.measurementTagValues()` returns a single table with a `_value` column. -Each row contains a unique tag value from the specified bucket, measurement, -and tag key. - -| _value | -| :-------- | -| tagValue1 | -| tagValue2 | -| tagValue3 | -| tagValue4 | -| tagValue5 | - -{{% /expand %}} -{{< /expand-wrapper >}} + diff --git a/content/influxdb/v2/query-data/flux/fill.md b/content/influxdb/v2/query-data/flux/fill.md index 59ee35a2e..d0b2ee63b 100644 --- a/content/influxdb/v2/query-data/flux/fill.md +++ b/content/influxdb/v2/query-data/flux/fill.md @@ -13,101 +13,8 @@ influxdb/v2/tags: [query, fill] related: - /flux/v0/stdlib/universe/fill/ list_query_example: fill_null +source: /shared/influxdb-v2/query-data/flux/fill.md --- -Use [`fill()`](/flux/v0/stdlib/universe/fill/) -to replace _null_ values with: - -- [the previous non-null value](#fill-with-the-previous-value) -- [a specified value](#fill-with-a-specified-value) - - -```js -data - |> fill(usePrevious: true) - -// OR - -data - |> fill(value: 0.0) -``` - -{{% note %}} -#### Fill empty windows of time -The `fill()` function **does not** fill empty windows of time. -It only replaces _null_ values in existing data. -Filling empty windows of time requires time interpolation -_(see [influxdata/flux#2428](https://github.com/influxdata/flux/issues/2428))_. -{{% /note %}} - -## Fill with the previous value -To fill _null_ values with the previous **non-null** value, set the `usePrevious` parameter to `true`. - -{{% note %}} -Values remain _null_ if there is no previous non-null value in the table. -{{% /note %}} - -```js -data - |> fill(usePrevious: true) -``` - -{{< flex >}} -{{% flex-content %}} -**Given the following input:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:01:00Z | null | -| 2020-01-01T00:02:00Z | 0.8 | -| 2020-01-01T00:03:00Z | null | -| 2020-01-01T00:04:00Z | null | -| 2020-01-01T00:05:00Z | 1.4 | -{{% /flex-content %}} -{{% flex-content %}} -**`fill(usePrevious: true)` returns:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:01:00Z | null | -| 2020-01-01T00:02:00Z | 0.8 | -| 2020-01-01T00:03:00Z | 0.8 | -| 2020-01-01T00:04:00Z | 0.8 | -| 2020-01-01T00:05:00Z | 1.4 | -{{% /flex-content %}} -{{< /flex >}} - -## Fill with a specified value -To fill _null_ values with a specified value, use the `value` parameter to specify the fill value. -_The fill value must match the [data type](/flux/v0/spec/types/#basic-types) -of the [column](/flux/v0/stdlib/universe/fill/#column)._ - -```js -data - |> fill(value: 0.0) -``` - -{{< flex >}} -{{% flex-content %}} -**Given the following input:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:01:00Z | null | -| 2020-01-01T00:02:00Z | 0.8 | -| 2020-01-01T00:03:00Z | null | -| 2020-01-01T00:04:00Z | null | -| 2020-01-01T00:05:00Z | 1.4 | -{{% /flex-content %}} -{{% flex-content %}} -**`fill(value: 0.0)` returns:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:01:00Z | 0.0 | -| 2020-01-01T00:02:00Z | 0.8 | -| 2020-01-01T00:03:00Z | 0.0 | -| 2020-01-01T00:04:00Z | 0.0 | -| 2020-01-01T00:05:00Z | 1.4 | -{{% /flex-content %}} -{{< /flex >}} + diff --git a/content/influxdb/v2/query-data/flux/first-last.md b/content/influxdb/v2/query-data/flux/first-last.md index 5b8541fa4..8a0c5fc48 100644 --- a/content/influxdb/v2/query-data/flux/first-last.md +++ b/content/influxdb/v2/query-data/flux/first-last.md @@ -14,132 +14,8 @@ related: - /flux/v0/stdlib/universe/first/ - /flux/v0/stdlib/universe/last/ list_query_example: first_last +source: /shared/influxdb-v2/query-data/flux/first-last.md --- -Use [`first()`](/flux/v0/stdlib/universe/first/) or -[`last()`](/flux/v0/stdlib/universe/last/) to return the first or -last record in an input table. - -```js -data - |> first() - -// OR - -data - |> last() -``` - -{{% note %}} -By default, InfluxDB returns results sorted by time, however you can use the -[`sort()` function](/flux/v0/stdlib/universe/sort/) -to change how results are sorted. -`first()` and `last()` respect the sort order of input data and return records -based on the order they are received in. -{{% /note %}} - -### first -`first()` returns the first non-null record in an input table. - -{{< flex >}} -{{% flex-content %}} -**Given the following input:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:01:00Z | 1.0 | -| 2020-01-01T00:02:00Z | 1.0 | -| 2020-01-01T00:03:00Z | 2.0 | -| 2020-01-01T00:04:00Z | 3.0 | -{{% /flex-content %}} -{{% flex-content %}} -**The following function returns:** -```js -|> first() -``` - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:01:00Z | 1.0 | -{{% /flex-content %}} -{{< /flex >}} - -### last -`last()` returns the last non-null record in an input table. - -{{< flex >}} -{{% flex-content %}} -**Given the following input:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:01:00Z | 1.0 | -| 2020-01-01T00:02:00Z | 1.0 | -| 2020-01-01T00:03:00Z | 2.0 | -| 2020-01-01T00:04:00Z | 3.0 | -{{% /flex-content %}} -{{% flex-content %}} -**The following function returns:** - -```js -|> last() -``` - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:04:00Z | 3.0 | -{{% /flex-content %}} -{{< /flex >}} - -## Use first() or last() with aggregateWindow() -Use `first()` and `last()` with [`aggregateWindow()`](/flux/v0/stdlib/universe/aggregatewindow/) -to select the first or last records in time-based groups. -`aggregateWindow()` segments data into windows of time, aggregates data in each window into a single -point using aggregate or selector functions, and then removes the time-based segmentation. - - -{{< flex >}} -{{% flex-content %}} -**Given the following input:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:00:00Z | 10 | -| 2020-01-01T00:00:15Z | 12 | -| 2020-01-01T00:00:45Z | 9 | -| 2020-01-01T00:01:05Z | 9 | -| 2020-01-01T00:01:10Z | 15 | -| 2020-01-01T00:02:30Z | 11 | -{{% /flex-content %}} - -{{% flex-content %}} -**The following function returns:** -{{< code-tabs-wrapper >}} -{{% code-tabs %}} -[first](#) -[last](#) -{{% /code-tabs %}} -{{% code-tab-content %}} -```js -|> aggregateWindow(every: 1h, fn: first) -``` -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:00:59Z | 10 | -| 2020-01-01T00:01:59Z | 9 | -| 2020-01-01T00:02:59Z | 11 | -{{% /code-tab-content %}} -{{% code-tab-content %}} -```js -|> aggregateWindow(every: 1h, fn: last) -``` - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:00:59Z | 9 | -| 2020-01-01T00:01:59Z | 15 | -| 2020-01-01T00:02:59Z | 11 | -{{% /code-tab-content %}} -{{< /code-tabs-wrapper >}} -{{%/flex-content %}} -{{< /flex >}} + diff --git a/content/influxdb/v2/query-data/flux/flux-version.md b/content/influxdb/v2/query-data/flux/flux-version.md index 8c182c69c..5e8d15f94 100644 --- a/content/influxdb/v2/query-data/flux/flux-version.md +++ b/content/influxdb/v2/query-data/flux/flux-version.md @@ -19,128 +19,8 @@ list_code_example: | array.from(rows: [{version: runtime.version()}]) ``` +source: /shared/influxdb-v2/query-data/flux/flux-version.md --- -InfluxDB {{< current-version >}} includes specific version of Flux that may or -may not support documented Flux functionality. -It's important to know what version of Flux you're currently using and what -functions are supported in that specific version. - -To query the version of Flux installed with InfluxDB, use `array.from()` to -create an ad hoc stream of tables and `runtime.version()` to populate a column -with the Flux version. - -{{% note %}} -Because the InfluxDB `/api/v2/query` endpoint can only return a stream of tables -and not single scalar values, you must use `array.from()` to create a stream of tables. -{{% /note %}} - -Run the following query in the **InfluxDB user interface**, with the **`influx` CLI**, -or **InfluxDB API**: - -```js -import "array" -import "runtime" - -array.from(rows: [{version: runtime.version()}]) -``` - -{{< tabs-wrapper >}} -{{% tabs %}} -[InfluxDB UI](#) -[influx CLI](#) -[InfluxDB API](#) -{{% /tabs %}} -{{% tab-content %}} - -To return the version of Flux installed with InfluxDB using the InfluxDB UI: - -1. Click **Data Explorer** in the left navigation bar. - -{{< nav-icon "data-explorer" >}} - -2. Click **{{% caps %}}Script Editor{{% /caps %}}** to manually create and - edit a Flux query. -3. Enable the **View Raw Data {{< icon "toggle" >}}** toggle or select one of the - following visualization types: - - - [Single Stat](/influxdb/v2/visualize-data/visualization-types/single-stat/) - - [Table](/influxdb/v2/visualize-data/visualization-types/table/) - -4. Enter and run the following query: - - ```js - import "array" - import "runtime" - - array.from(rows: [{version: runtime.version()}]) - ``` - -{{% /tab-content %}} -{{% tab-content %}} - -To return the version of Flux installed with InfluxDB using the `influx` CLI, -use the `influx query` command. Provide the following: - -- InfluxDB **host**, **organization**, and **API token** - _(the example below assumes that a - [CLI configuration](/influxdb/v2/reference/cli/influx/#provide-required-authentication-credentials) - is set up and active)_ -- Query to execute - -```sh -$ influx query \ - 'import "array" - import "runtime" - - array.from(rows: [{version: runtime.version()}])' - -# Output -Result: _result -Table: keys: [] - version:string ----------------------- - v0.161.0 -``` -{{% /tab-content %}} - -{{% tab-content %}} - -To return the version of Flux installed with InfluxDB using the InfluxDB API, -use the [`/api/v2/query` endpoint](/influxdb/v2/api/#tag/Query). - -{{< api-endpoint method="POST" endpoint="http://localhost:8086/api/v2/query" api-ref="/influxdb/v2/api/#operation/PostQuery" >}} -Provide the following: - -- InfluxDB {{% cloud-only %}}Cloud{{% /cloud-only %}} host -- InfluxDB organization name or ID as a query parameter -- `Authorization` header with the `Token` scheme and your API token -- `Accept: application/csv` header -- `Content-type: application/vnd.flux` header -- Query to execute as the request body - -```sh -curl --request POST \ - http://localhost:8086/api/v2/query?orgID=INFLUX_ORG_ID \ - --header 'Authorization: Token INFLUX_TOKEN' \ - --header 'Accept: application/csv' \ - --header 'Content-type: application/vnd.flux' \ - --data 'import "array" - import "runtime" - - array.from(rows: [{version: runtime.version()}])' - -# Output -,result,table,version -,_result,0,v0.161.0 -``` - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -{{% warn %}} -#### Flux version in the Flux REPL -When you run `runtime.version()` in the [Flux REPL](/influxdb/v2/tools/flux-repl/), -the function returns the version of Flux the REPL was built with, not the version -of Flux installed in the instance of InfluxDB you're querying. -{{% /warn %}} \ No newline at end of file + diff --git a/content/influxdb/v2/query-data/flux/geo/_index.md b/content/influxdb/v2/query-data/flux/geo/_index.md index 3286047cb..d9ff63a70 100644 --- a/content/influxdb/v2/query-data/flux/geo/_index.md +++ b/content/influxdb/v2/query-data/flux/geo/_index.md @@ -16,54 +16,8 @@ list_code_example: | |> geo.filterRows(region: {lat: 30.04, lon: 31.23, radius: 200.0}) |> geo.groupByArea(newColumn: "geoArea", level: 5) ``` +source: /shared/influxdb-v2/query-data/flux/geo/_index.md --- -Use the [Flux Geo package](/flux/v0/stdlib/experimental/geo) to -filter geo-temporal data and group by geographic location or track. - -{{% warn %}} -The Geo package is experimental and subject to change at any time. -By using it, you agree to the [risks of experimental functions](/flux/v0/stdlib/experimental/to/#experimental-functions-are-subject-to-change). -{{% /warn %}} - -**To work with geo-temporal data:** - -1. Import the `experimental/geo` package. - - ```js - import "experimental/geo" - ``` - -2. Load geo-temporal data. _See below for [sample geo-temporal data](#sample-data)._ -3. Do one or more of the following: - - - [Shape data to work with the Geo package](#shape-data-to-work-with-the-geo-package) - - [Filter data by region](#filter-geo-temporal-data-by-region) (using strict or non-strict filters) - - [Group data by area or by track](#group-geo-temporal-data) - -{{< children >}} - ---- - -## Sample data -Many of the examples in this section use a `sampleGeoData` variable that represents -a sample set of geo-temporal data. -The [Bird Migration Sample Data](/influxdb/v2/reference/sample-data/#bird-migration-sample-data) -provides sample geo-temporal data that meets the -[requirements of the Flux Geo package](/flux/v0/stdlib/experimental/geo/#geo-schema-requirements). - -### Load bird migration sample data -Use the [`sample.data()` function](/flux/v0/stdlib/influxdata/influxdb/sample/data/) -to load the sample bird migration data: - -```js -import "influxdata/influxdb/sample" - -sampleGeoData = sample.data(set: "birdMigration") -``` - -{{% note %}} -`sample.data()` downloads sample data each time you execute the query **(~1.3 MB)**. -If bandwidth is a concern, use the [`to()` function](/flux/v0/stdlib/influxdata/influxdb/to/) -to write the data to a bucket, and then query the bucket with [`from()`](/flux/v0/stdlib/influxdata/influxdb/from/). -{{% /note %}} + diff --git a/content/influxdb/v2/query-data/flux/geo/filter-by-region.md b/content/influxdb/v2/query-data/flux/geo/filter-by-region.md index 8fbb61831..842c2e41a 100644 --- a/content/influxdb/v2/query-data/flux/geo/filter-by-region.md +++ b/content/influxdb/v2/query-data/flux/geo/filter-by-region.md @@ -17,108 +17,8 @@ list_code_example: | sampleGeoData |> geo.filterRows(region: {lat: 30.04, lon: 31.23, radius: 200.0}, strict: true) ``` +source: /shared/influxdb-v2/query-data/flux/geo/filter-by-region.md --- -Use the [`geo.filterRows` function](/flux/v0/stdlib/experimental/geo/filterrows/) -to filter geo-temporal data by geographic region: - -1. [Define a geographic region](#define-a-geographic-region) -2. [Use strict or non-strict filtering](#strict-and-non-strict-filtering) - -The following example uses the [sample bird migration data](/influxdb/v2/query-data/flux/geo/#sample-data) -and queries data points **within 200km of Cairo, Egypt**: - -```js -import "experimental/geo" - -sampleGeoData - |> geo.filterRows(region: {lat: 30.04, lon: 31.23, radius: 200.0}, strict: true) -``` - -## Define a geographic region -Many functions in the Geo package filter data based on geographic region. -Define a geographic region using one of the the following shapes: - -- [box](#box) -- [circle](#circle) -- [polygon](#polygon) - -### box -Define a box-shaped region by specifying a record containing the following properties: - -- **minLat:** minimum latitude in decimal degrees (WGS 84) _(Float)_ -- **maxLat:** maximum latitude in decimal degrees (WGS 84) _(Float)_ -- **minLon:** minimum longitude in decimal degrees (WGS 84) _(Float)_ -- **maxLon:** maximum longitude in decimal degrees (WGS 84) _(Float)_ - -##### Example box-shaped region -```js -{ - minLat: 40.51757813, - maxLat: 40.86914063, - minLon: -73.65234375, - maxLon: -72.94921875, -} -``` - -### circle -Define a circular region by specifying a record containing the following properties: - -- **lat**: latitude of the circle center in decimal degrees (WGS 84) _(Float)_ -- **lon**: longitude of the circle center in decimal degrees (WGS 84) _(Float)_ -- **radius**: radius of the circle in kilometers (km) _(Float)_ - -##### Example circular region -```js -{ - lat: 40.69335938, - lon: -73.30078125, - radius: 20.0, -} -``` - -### polygon -Define a polygonal region with a record containing the latitude and longitude for -each point in the polygon: - -- **points**: points that define the custom polygon _(Array of records)_ - - Define each point with a record containing the following properties: - - - **lat**: latitude in decimal degrees (WGS 84) _(Float)_ - - **lon**: longitude in decimal degrees (WGS 84) _(Float)_ - -##### Example polygonal region -```js -{ - points: [ - {lat: 40.671659, lon: -73.936631}, - {lat: 40.706543, lon: -73.749177}, - {lat: 40.791333, lon: -73.880327}, - ] -} -``` - -## Strict and non-strict filtering -In most cases, the specified geographic region does not perfectly align with S2 grid cells. - -- **Non-strict filtering** returns points that may be outside of the specified region but - inside S2 grid cells partially covered by the region. -- **Strict filtering** returns only points inside the specified region. - -_Strict filtering is less performant, but more accurate than non-strict filtering._ - - S2 grid cell - Filter region - Returned point - -{{< flex >}} -{{% flex-content %}} -**Strict filtering** -{{< svg "/static/svgs/geo-strict.svg" >}} -{{% /flex-content %}} -{{% flex-content %}} -**Non-strict filtering** -{{< svg "/static/svgs/geo-non-strict.svg" >}} -{{% /flex-content %}} -{{< /flex >}} + diff --git a/content/influxdb/v2/query-data/flux/geo/group-geo-data.md b/content/influxdb/v2/query-data/flux/geo/group-geo-data.md index 5e47aabdf..538815948 100644 --- a/content/influxdb/v2/query-data/flux/geo/group-geo-data.md +++ b/content/influxdb/v2/query-data/flux/geo/group-geo-data.md @@ -19,55 +19,8 @@ list_code_example: | |> geo.groupByArea(newColumn: "geoArea", level: 5) |> geo.asTracks(groupBy: ["id"],sortBy: ["_time"]) ``` +source: /shared/influxdb-v2/query-data/flux/geo/group-geo-data.md --- -Use the `geo.groupByArea()` to group geo-temporal data by area and `geo.asTracks()` -to group data into tracks or routes. - -- [Group data by area](#group-data-by-area) -- [Group data into tracks or routes](#group-data-by-track-or-route) - -{{% note %}} -For example results, use the [bird migration sample data](/influxdb/v2/reference/sample-data/#bird-migration-sample-data) -to populate the `sampleGeoData` variable in the queries below. -{{% /note %}} - -### Group data by area -Use the [`geo.groupByArea()` function](/flux/v0/stdlib/experimental/geo/groupbyarea/) -to group geo-temporal data points by geographic area. -Areas are determined by [S2 grid cells](https://s2geometry.io/devguide/s2cell_hierarchy.html#s2cellid-numbering) - -- Specify a new column to store the unique area identifier for each point with the `newColumn` parameter. -- Specify the [S2 cell level](https://s2geometry.io/resources/s2cell_statistics) - to use when calculating geographic areas with the `level` parameter. - -The following example uses the [sample bird migration data](/influxdb/v2/query-data/flux/geo/#sample-data) -to query data points within 200km of Cairo, Egypt and group them by geographic area: - -```js -import "experimental/geo" - -sampleGeoData - |> geo.filterRows(region: {lat: 30.04, lon: 31.23, radius: 200.0}) - |> geo.groupByArea(newColumn: "geoArea", level: 5) -``` - -### Group data by track or route -Use [`geo.asTracks()` function](/flux/v0/stdlib/experimental/geo/astracks/) -to group data points into tracks or routes and order them by time or other columns. -Data must contain a unique identifier for each track. For example: `id` or `tid`. - -- Specify columns that uniquely identify each track or route with the `groupBy` parameter. -- Specify which columns to sort by with the `sortBy` parameter. Default is `["_time"]`. - -The following example uses the [sample bird migration data](/influxdb/v2/query-data/flux/geo/#sample-data) -to query data points within 200km of Cairo, Egypt and group them into routes unique -to each bird: - -```js -import "experimental/geo" - -sampleGeoData - |> geo.filterRows(region: {lat: 30.04, lon: 31.23, radius: 200.0}) - |> geo.asTracks(groupBy: ["id"], orderBy: ["_time"]) -``` + diff --git a/content/influxdb/v2/query-data/flux/geo/shape-geo-data.md b/content/influxdb/v2/query-data/flux/geo/shape-geo-data.md index b73ff2f03..1c10aee01 100644 --- a/content/influxdb/v2/query-data/flux/geo/shape-geo-data.md +++ b/content/influxdb/v2/query-data/flux/geo/shape-geo-data.md @@ -18,103 +18,8 @@ list_code_example: | sampleGeoData |> geo.shapeData(latField: "latitude", lonField: "longitude", level: 10) ``` +source: /shared/influxdb-v2/query-data/flux/geo/shape-geo-data.md --- -Functions in the Geo package require the following data schema: - -- an **s2_cell_id** tag containing the [S2 Cell ID](https://s2geometry.io/devguide/s2cell_hierarchy.html#s2cellid-numbering) - **as a token** -- a **`lat` field** field containing the **latitude in decimal degrees** (WGS 84) -- a **`lon` field** field containing the **longitude in decimal degrees** (WGS 84) - -## Shape geo-temporal data -If your data already contains latitude and longitude fields, use the -[`geo.shapeData()`function](/flux/v0/stdlib/experimental/geo/shapedata/) -to rename the fields to match the requirements of the Geo package, pivot the data -into row-wise sets, and generate S2 cell ID tokens for each point. - -```js -import "experimental/geo" - -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "example-measurement") - |> geo.shapeData(latField: "latitude", lonField: "longitude", level: 10) -``` - -## Generate S2 cell ID tokens -The Geo package uses the [S2 Geometry Library](https://s2geometry.io/) to represent -geographic coordinates on a three-dimensional sphere. -The sphere is divided into [cells](https://s2geometry.io/devguide/s2cell_hierarchy), -each with a unique 64-bit identifier (S2 cell ID). -Grid and S2 cell ID accuracy are defined by a [level](https://s2geometry.io/resources/s2cell_statistics). - -{{% note %}} -To filter more quickly, use higher S2 Cell ID levels, -but know that that higher levels increase [series cardinality](/influxdb/v2/reference/glossary/#series-cardinality). -{{% /note %}} - -The Geo package requires S2 cell IDs as tokens. -To generate add S2 cell IDs tokens to your data, use one of the following options: - -- [Generate S2 cell ID tokens with Telegraf](#generate-s2-cell-id-tokens-with-telegraf) -- [Generate S2 cell ID tokens language-specific libraries](#generate-s2-cell-id-tokens-language-specific-libraries) -- [Generate S2 cell ID tokens with Flux](#generate-s2-cell-id-tokens-with-flux) - -### Generate S2 cell ID tokens with Telegraf -Enable the [Telegraf S2 Geo (`s2geo`) processor](https://github.com/influxdata/telegraf/tree/master/plugins/processors/s2geo) -to generate S2 cell ID tokens at a specified `cell_level` using `lat` and `lon` field values. - -Add the `processors.s2geo` configuration to your Telegraf configuration file (`telegraf.conf`): - -```toml -[[processors.s2geo]] - ## The name of the lat and lon fields containing WGS-84 latitude and - ## longitude in decimal degrees. - lat_field = "lat" - lon_field = "lon" - - ## New tag to create - tag_key = "s2_cell_id" - - ## Cell level (see https://s2geometry.io/resources/s2cell_statistics.html) - cell_level = 9 -``` - -Telegraf stores the S2 cell ID token in the `s2_cell_id` tag. - -### Generate S2 cell ID tokens language-specific libraries -Many programming languages offer S2 Libraries with methods for generating S2 cell ID tokens. -Use latitude and longitude with the `s2.CellID.ToToken` endpoint of the S2 Geometry -Library to generate `s2_cell_id` tags. For example: - -- **Go:** [s2.CellID.ToToken()](https://godoc.org/github.com/golang/geo/s2#CellID.ToToken) -- **Python:** [s2sphere.CellId.to_token()](https://s2sphere.readthedocs.io/en/latest/api.html#s2sphere.CellId) -- **Crystal:** [cell.to_token(level)](https://github.com/spider-gazelle/s2_cells#usage) -- **JavaScript:** [s2.cellid.toToken()](https://github.com/mapbox/node-s2/blob/master/API.md#cellidtotoken---string) - -### Generate S2 cell ID tokens with Flux -Use the [`geo.s2CellIDToken()` function](/flux/v0/stdlib/experimental/geo/s2cellidtoken/) -with existing longitude (`lon`) and latitude (`lat`) field values to generate and add the S2 cell ID token. -First, use the [`geo.toRows()` function](/flux/v0/stdlib/experimental/geo/torows/) -to pivot **lat** and **lon** fields into row-wise sets: - -```js -import "experimental/geo" - -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "example-measurement") - |> geo.toRows() - |> map( - fn: (r) => ({ - r with - s2_cell_id: geo.s2CellIDToken(point: {lon: r.lon, lat: r.lat}, level: 10) - }) - ) -``` - -{{% note %}} -The [`geo.shapeData()`function](/flux/v0/stdlib/experimental/geo/shapedata/) -generates S2 cell ID tokens as well. -{{% /note %}} + diff --git a/content/influxdb/v2/query-data/flux/group-data.md b/content/influxdb/v2/query-data/flux/group-data.md index d3f33f9bc..77255a71d 100644 --- a/content/influxdb/v2/query-data/flux/group-data.md +++ b/content/influxdb/v2/query-data/flux/group-data.md @@ -16,661 +16,8 @@ related: - /flux/v0/stdlib/universe/group - /flux/v0/stdlib/experimental/group list_query_example: group +source: /shared/influxdb-v2/query-data/flux/group-data.md --- -With Flux, you can group data by any column in your queried data set. -"Grouping" partitions data into tables in which each row shares a common value for specified columns. -This guide walks through grouping data in Flux and provides examples of how data is shaped in the process. - -If you're just getting started with Flux queries, check out the following: - -- [Get started with Flux](/flux/v0/get-started/) for a conceptual overview of Flux and parts of a Flux query. -- [Execute queries](/influxdb/v2/query-data/execute-queries/) to discover a variety of ways to run your queries. - -## Group keys -Every table has a **group key** – a list of columns for which every row in the table has the same value. - -###### Example group key -```js -[_start, _stop, _field, _measurement, host] -``` - -Grouping data in Flux is essentially defining the group key of output tables. -Understanding how modifying group keys shapes output data is key to successfully -grouping and transforming data into your desired output. - -## group() Function -Flux's [`group()` function](/flux/v0/stdlib/universe/group) defines the -group key for output tables, i.e. grouping records based on values for specific columns. - -###### group() example -```js -dataStream - |> group(columns: ["cpu", "host"]) -``` - -###### Resulting group key -```js -[cpu, host] -``` - -The `group()` function has the following parameters: - -### columns -The list of columns to include or exclude (depending on the [mode](#mode)) in the grouping operation. - -### mode -The method used to define the group and resulting group key. -Possible values include `by` and `except`. - - -## Example grouping operations -To illustrate how grouping works, define a `dataSet` variable that queries System -CPU usage from the `example-bucket` bucket. -Filter the `cpu` tag so it only returns results for each numbered CPU core. - -### Data set -CPU used by system operations for all numbered CPU cores. -It uses a regular expression to filter only numbered cores. - -```js -dataSet = from(bucket: "example-bucket") - |> range(start: -2m) - |> filter(fn: (r) => r._field == "usage_system" and r.cpu =~ /cpu[0-9*]/) - |> drop(columns: ["host"]) -``` - -{{% note %}} -This example drops the `host` column from the returned data since the CPU data -is only tracked for a single host and it simplifies the output tables. -Don't drop the `host` column if monitoring multiple hosts. -{{% /note %}} - -{{% truncate %}} -``` -Table: keys: [_start, _stop, _field, _measurement, cpu] - _start:time _stop:time _field:string _measurement:string cpu:string _time:time _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ---------------------- ------------------------------ ---------------------------- -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu0 2018-11-05T21:34:00.000000000Z 7.892107892107892 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu0 2018-11-05T21:34:10.000000000Z 7.2 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu0 2018-11-05T21:34:20.000000000Z 7.4 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu0 2018-11-05T21:34:30.000000000Z 5.5 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu0 2018-11-05T21:34:40.000000000Z 7.4 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu0 2018-11-05T21:34:50.000000000Z 7.5 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu0 2018-11-05T21:35:00.000000000Z 10.3 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu0 2018-11-05T21:35:10.000000000Z 9.2 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu0 2018-11-05T21:35:20.000000000Z 8.4 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu0 2018-11-05T21:35:30.000000000Z 8.5 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu0 2018-11-05T21:35:40.000000000Z 8.6 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu0 2018-11-05T21:35:50.000000000Z 10.2 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu0 2018-11-05T21:36:00.000000000Z 10.6 - -Table: keys: [_start, _stop, _field, _measurement, cpu] - _start:time _stop:time _field:string _measurement:string cpu:string _time:time _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ---------------------- ------------------------------ ---------------------------- -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu1 2018-11-05T21:34:00.000000000Z 0.7992007992007992 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu1 2018-11-05T21:34:10.000000000Z 0.7 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu1 2018-11-05T21:34:20.000000000Z 0.7 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu1 2018-11-05T21:34:30.000000000Z 0.4 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu1 2018-11-05T21:34:40.000000000Z 0.7 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu1 2018-11-05T21:34:50.000000000Z 0.7 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu1 2018-11-05T21:35:00.000000000Z 1.4 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu1 2018-11-05T21:35:10.000000000Z 1.2 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu1 2018-11-05T21:35:20.000000000Z 0.8 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu1 2018-11-05T21:35:30.000000000Z 0.8991008991008991 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu1 2018-11-05T21:35:40.000000000Z 0.8008008008008008 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu1 2018-11-05T21:35:50.000000000Z 0.999000999000999 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu1 2018-11-05T21:36:00.000000000Z 1.1022044088176353 - -Table: keys: [_start, _stop, _field, _measurement, cpu] - _start:time _stop:time _field:string _measurement:string cpu:string _time:time _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ---------------------- ------------------------------ ---------------------------- -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu2 2018-11-05T21:34:00.000000000Z 4.1 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu2 2018-11-05T21:34:10.000000000Z 3.6 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu2 2018-11-05T21:34:20.000000000Z 3.5 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu2 2018-11-05T21:34:30.000000000Z 2.6 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu2 2018-11-05T21:34:40.000000000Z 4.5 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu2 2018-11-05T21:34:50.000000000Z 4.895104895104895 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu2 2018-11-05T21:35:00.000000000Z 6.906906906906907 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu2 2018-11-05T21:35:10.000000000Z 5.7 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu2 2018-11-05T21:35:20.000000000Z 5.1 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu2 2018-11-05T21:35:30.000000000Z 4.7 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu2 2018-11-05T21:35:40.000000000Z 5.1 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu2 2018-11-05T21:35:50.000000000Z 5.9 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu2 2018-11-05T21:36:00.000000000Z 6.4935064935064934 - -Table: keys: [_start, _stop, _field, _measurement, cpu] - _start:time _stop:time _field:string _measurement:string cpu:string _time:time _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ---------------------- ------------------------------ ---------------------------- -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu3 2018-11-05T21:34:00.000000000Z 0.5005005005005005 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu3 2018-11-05T21:34:10.000000000Z 0.5 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu3 2018-11-05T21:34:20.000000000Z 0.5 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu3 2018-11-05T21:34:30.000000000Z 0.3 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu3 2018-11-05T21:34:40.000000000Z 0.6 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu3 2018-11-05T21:34:50.000000000Z 0.6 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu3 2018-11-05T21:35:00.000000000Z 1.3986013986013985 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu3 2018-11-05T21:35:10.000000000Z 0.9 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu3 2018-11-05T21:35:20.000000000Z 0.5005005005005005 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu3 2018-11-05T21:35:30.000000000Z 0.7 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu3 2018-11-05T21:35:40.000000000Z 0.6 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu3 2018-11-05T21:35:50.000000000Z 0.8 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z usage_system cpu cpu3 2018-11-05T21:36:00.000000000Z 0.9 -``` -{{% /truncate %}} - -**Note that the group key is output with each table: `Table: keys: `.** - -![Group example data set](/img/flux/grouping-data-set.png) - -### Group by CPU -Group the `dataSet` stream by the `cpu` column. - -```js -dataSet - |> group(columns: ["cpu"]) -``` - -This won't actually change the structure of the data since it already has `cpu` -in the group key and is therefore grouped by `cpu`. -However, notice that it does change the group key: - -{{% truncate %}} -###### Group by CPU output tables -``` -Table: keys: [cpu] - cpu:string _stop:time _time:time _value:float _field:string _measurement:string _start:time ----------------------- ------------------------------ ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ - cpu0 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:00.000000000Z 7.892107892107892 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu0 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:10.000000000Z 7.2 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu0 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:20.000000000Z 7.4 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu0 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:30.000000000Z 5.5 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu0 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:40.000000000Z 7.4 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu0 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:50.000000000Z 7.5 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu0 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:00.000000000Z 10.3 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu0 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:10.000000000Z 9.2 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu0 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:20.000000000Z 8.4 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu0 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:30.000000000Z 8.5 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu0 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:40.000000000Z 8.6 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu0 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:50.000000000Z 10.2 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu0 2018-11-05T21:36:00.000000000Z 2018-11-05T21:36:00.000000000Z 10.6 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [cpu] - cpu:string _stop:time _time:time _value:float _field:string _measurement:string _start:time ----------------------- ------------------------------ ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ - cpu1 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:00.000000000Z 0.7992007992007992 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu1 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:10.000000000Z 0.7 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu1 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:20.000000000Z 0.7 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu1 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:30.000000000Z 0.4 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu1 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:40.000000000Z 0.7 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu1 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:50.000000000Z 0.7 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu1 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:00.000000000Z 1.4 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu1 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:10.000000000Z 1.2 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu1 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:20.000000000Z 0.8 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu1 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:30.000000000Z 0.8991008991008991 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu1 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:40.000000000Z 0.8008008008008008 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu1 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:50.000000000Z 0.999000999000999 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu1 2018-11-05T21:36:00.000000000Z 2018-11-05T21:36:00.000000000Z 1.1022044088176353 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [cpu] - cpu:string _stop:time _time:time _value:float _field:string _measurement:string _start:time ----------------------- ------------------------------ ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ - cpu2 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:00.000000000Z 4.1 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu2 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:10.000000000Z 3.6 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu2 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:20.000000000Z 3.5 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu2 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:30.000000000Z 2.6 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu2 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:40.000000000Z 4.5 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu2 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:50.000000000Z 4.895104895104895 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu2 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:00.000000000Z 6.906906906906907 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu2 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:10.000000000Z 5.7 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu2 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:20.000000000Z 5.1 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu2 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:30.000000000Z 4.7 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu2 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:40.000000000Z 5.1 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu2 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:50.000000000Z 5.9 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu2 2018-11-05T21:36:00.000000000Z 2018-11-05T21:36:00.000000000Z 6.4935064935064934 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [cpu] - cpu:string _stop:time _time:time _value:float _field:string _measurement:string _start:time ----------------------- ------------------------------ ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ - cpu3 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:00.000000000Z 0.5005005005005005 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu3 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:10.000000000Z 0.5 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu3 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:20.000000000Z 0.5 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu3 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:30.000000000Z 0.3 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu3 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:40.000000000Z 0.6 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu3 2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:50.000000000Z 0.6 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu3 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:00.000000000Z 1.3986013986013985 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu3 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:10.000000000Z 0.9 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu3 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:20.000000000Z 0.5005005005005005 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu3 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:30.000000000Z 0.7 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu3 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:40.000000000Z 0.6 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu3 2018-11-05T21:36:00.000000000Z 2018-11-05T21:35:50.000000000Z 0.8 usage_system cpu 2018-11-05T21:34:00.000000000Z - cpu3 2018-11-05T21:36:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.9 usage_system cpu 2018-11-05T21:34:00.000000000Z -``` -{{% /truncate %}} - -The visualization remains the same. - -![Group by CPU](/img/flux/grouping-data-set.png) - -### Group by time -Grouping data by the `_time` column is a good illustration of how grouping changes the structure of your data. - -```js -dataSet - |> group(columns: ["_time"]) -``` - -When grouping by `_time`, all records that share a common `_time` value are grouped into individual tables. -So each output table represents a single point in time. - -{{% truncate %}} -###### Group by time output tables -``` -Table: keys: [_time] - _time:time _start:time _stop:time _value:float _field:string _measurement:string cpu:string ------------------------------- ------------------------------ ------------------------------ ---------------------------- ---------------------- ---------------------- ---------------------- -2018-11-05T21:34:00.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 7.892107892107892 usage_system cpu cpu0 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.7992007992007992 usage_system cpu cpu1 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 4.1 usage_system cpu cpu2 -2018-11-05T21:34:00.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.5005005005005005 usage_system cpu cpu3 - -Table: keys: [_time] - _time:time _start:time _stop:time _value:float _field:string _measurement:string cpu:string ------------------------------- ------------------------------ ------------------------------ ---------------------------- ---------------------- ---------------------- ---------------------- -2018-11-05T21:34:10.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 7.2 usage_system cpu cpu0 -2018-11-05T21:34:10.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.7 usage_system cpu cpu1 -2018-11-05T21:34:10.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 3.6 usage_system cpu cpu2 -2018-11-05T21:34:10.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.5 usage_system cpu cpu3 - -Table: keys: [_time] - _time:time _start:time _stop:time _value:float _field:string _measurement:string cpu:string ------------------------------- ------------------------------ ------------------------------ ---------------------------- ---------------------- ---------------------- ---------------------- -2018-11-05T21:34:20.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 7.4 usage_system cpu cpu0 -2018-11-05T21:34:20.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.7 usage_system cpu cpu1 -2018-11-05T21:34:20.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 3.5 usage_system cpu cpu2 -2018-11-05T21:34:20.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.5 usage_system cpu cpu3 - -Table: keys: [_time] - _time:time _start:time _stop:time _value:float _field:string _measurement:string cpu:string ------------------------------- ------------------------------ ------------------------------ ---------------------------- ---------------------- ---------------------- ---------------------- -2018-11-05T21:34:30.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 5.5 usage_system cpu cpu0 -2018-11-05T21:34:30.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.4 usage_system cpu cpu1 -2018-11-05T21:34:30.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 2.6 usage_system cpu cpu2 -2018-11-05T21:34:30.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.3 usage_system cpu cpu3 - -Table: keys: [_time] - _time:time _start:time _stop:time _value:float _field:string _measurement:string cpu:string ------------------------------- ------------------------------ ------------------------------ ---------------------------- ---------------------- ---------------------- ---------------------- -2018-11-05T21:34:40.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 7.4 usage_system cpu cpu0 -2018-11-05T21:34:40.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.7 usage_system cpu cpu1 -2018-11-05T21:34:40.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 4.5 usage_system cpu cpu2 -2018-11-05T21:34:40.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.6 usage_system cpu cpu3 - -Table: keys: [_time] - _time:time _start:time _stop:time _value:float _field:string _measurement:string cpu:string ------------------------------- ------------------------------ ------------------------------ ---------------------------- ---------------------- ---------------------- ---------------------- -2018-11-05T21:34:50.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 7.5 usage_system cpu cpu0 -2018-11-05T21:34:50.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.7 usage_system cpu cpu1 -2018-11-05T21:34:50.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 4.895104895104895 usage_system cpu cpu2 -2018-11-05T21:34:50.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.6 usage_system cpu cpu3 - -Table: keys: [_time] - _time:time _start:time _stop:time _value:float _field:string _measurement:string cpu:string ------------------------------- ------------------------------ ------------------------------ ---------------------------- ---------------------- ---------------------- ---------------------- -2018-11-05T21:35:00.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 10.3 usage_system cpu cpu0 -2018-11-05T21:35:00.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 1.4 usage_system cpu cpu1 -2018-11-05T21:35:00.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 6.906906906906907 usage_system cpu cpu2 -2018-11-05T21:35:00.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 1.3986013986013985 usage_system cpu cpu3 - -Table: keys: [_time] - _time:time _start:time _stop:time _value:float _field:string _measurement:string cpu:string ------------------------------- ------------------------------ ------------------------------ ---------------------------- ---------------------- ---------------------- ---------------------- -2018-11-05T21:35:10.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 9.2 usage_system cpu cpu0 -2018-11-05T21:35:10.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 1.2 usage_system cpu cpu1 -2018-11-05T21:35:10.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 5.7 usage_system cpu cpu2 -2018-11-05T21:35:10.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.9 usage_system cpu cpu3 - -Table: keys: [_time] - _time:time _start:time _stop:time _value:float _field:string _measurement:string cpu:string ------------------------------- ------------------------------ ------------------------------ ---------------------------- ---------------------- ---------------------- ---------------------- -2018-11-05T21:35:20.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 8.4 usage_system cpu cpu0 -2018-11-05T21:35:20.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.8 usage_system cpu cpu1 -2018-11-05T21:35:20.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 5.1 usage_system cpu cpu2 -2018-11-05T21:35:20.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.5005005005005005 usage_system cpu cpu3 - -Table: keys: [_time] - _time:time _start:time _stop:time _value:float _field:string _measurement:string cpu:string ------------------------------- ------------------------------ ------------------------------ ---------------------------- ---------------------- ---------------------- ---------------------- -2018-11-05T21:35:30.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 8.5 usage_system cpu cpu0 -2018-11-05T21:35:30.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.8991008991008991 usage_system cpu cpu1 -2018-11-05T21:35:30.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 4.7 usage_system cpu cpu2 -2018-11-05T21:35:30.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.7 usage_system cpu cpu3 - -Table: keys: [_time] - _time:time _start:time _stop:time _value:float _field:string _measurement:string cpu:string ------------------------------- ------------------------------ ------------------------------ ---------------------------- ---------------------- ---------------------- ---------------------- -2018-11-05T21:35:40.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 8.6 usage_system cpu cpu0 -2018-11-05T21:35:40.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.8008008008008008 usage_system cpu cpu1 -2018-11-05T21:35:40.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 5.1 usage_system cpu cpu2 -2018-11-05T21:35:40.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.6 usage_system cpu cpu3 - -Table: keys: [_time] - _time:time _start:time _stop:time _value:float _field:string _measurement:string cpu:string ------------------------------- ------------------------------ ------------------------------ ---------------------------- ---------------------- ---------------------- ---------------------- -2018-11-05T21:35:50.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 10.2 usage_system cpu cpu0 -2018-11-05T21:35:50.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.999000999000999 usage_system cpu cpu1 -2018-11-05T21:35:50.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 5.9 usage_system cpu cpu2 -2018-11-05T21:35:50.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.8 usage_system cpu cpu3 - -Table: keys: [_time] - _time:time _start:time _stop:time _value:float _field:string _measurement:string cpu:string ------------------------------- ------------------------------ ------------------------------ ---------------------------- ---------------------- ---------------------- ---------------------- -2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 10.6 usage_system cpu cpu0 -2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 1.1022044088176353 usage_system cpu cpu1 -2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 6.4935064935064934 usage_system cpu cpu2 -2018-11-05T21:36:00.000000000Z 2018-11-05T21:34:00.000000000Z 2018-11-05T21:36:00.000000000Z 0.9 usage_system cpu cpu3 -``` -{{% /truncate %}} - -Because each timestamp is structured as a separate table, when visualized, all -points that share the same timestamp appear connected. - -![Group by time](/img/flux/grouping-by-time.png) - -{{% note %}} -With some further processing, you could calculate the average CPU usage across all CPUs per point -of time and group them into a single table, but we won't cover that in this example. -If you're interested in running and visualizing this yourself, here's what the query would look like: - -```js -dataSet - |> group(columns: ["_time"]) - |> mean() - |> group(columns: ["_value", "_time"], mode: "except") -``` -{{% /note %}} - -## Group by CPU and time -Group by the `cpu` and `_time` columns. - -```js -dataSet - |> group(columns: ["cpu", "_time"]) -``` - -This outputs a table for every unique `cpu` and `_time` combination: - -{{% truncate %}} -###### Group by CPU and time output tables -``` -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:00.000000000Z cpu0 2018-11-05T21:36:00.000000000Z 7.892107892107892 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:00.000000000Z cpu1 2018-11-05T21:36:00.000000000Z 0.7992007992007992 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:00.000000000Z cpu2 2018-11-05T21:36:00.000000000Z 4.1 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:00.000000000Z cpu3 2018-11-05T21:36:00.000000000Z 0.5005005005005005 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:10.000000000Z cpu0 2018-11-05T21:36:00.000000000Z 7.2 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:10.000000000Z cpu1 2018-11-05T21:36:00.000000000Z 0.7 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:10.000000000Z cpu2 2018-11-05T21:36:00.000000000Z 3.6 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:10.000000000Z cpu3 2018-11-05T21:36:00.000000000Z 0.5 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:20.000000000Z cpu0 2018-11-05T21:36:00.000000000Z 7.4 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:20.000000000Z cpu1 2018-11-05T21:36:00.000000000Z 0.7 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:20.000000000Z cpu2 2018-11-05T21:36:00.000000000Z 3.5 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:20.000000000Z cpu3 2018-11-05T21:36:00.000000000Z 0.5 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:30.000000000Z cpu0 2018-11-05T21:36:00.000000000Z 5.5 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:30.000000000Z cpu1 2018-11-05T21:36:00.000000000Z 0.4 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:30.000000000Z cpu2 2018-11-05T21:36:00.000000000Z 2.6 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:30.000000000Z cpu3 2018-11-05T21:36:00.000000000Z 0.3 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:40.000000000Z cpu0 2018-11-05T21:36:00.000000000Z 7.4 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:40.000000000Z cpu1 2018-11-05T21:36:00.000000000Z 0.7 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:40.000000000Z cpu2 2018-11-05T21:36:00.000000000Z 4.5 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:40.000000000Z cpu3 2018-11-05T21:36:00.000000000Z 0.6 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:50.000000000Z cpu0 2018-11-05T21:36:00.000000000Z 7.5 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:50.000000000Z cpu1 2018-11-05T21:36:00.000000000Z 0.7 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:50.000000000Z cpu2 2018-11-05T21:36:00.000000000Z 4.895104895104895 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:34:50.000000000Z cpu3 2018-11-05T21:36:00.000000000Z 0.6 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:00.000000000Z cpu0 2018-11-05T21:36:00.000000000Z 10.3 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:00.000000000Z cpu1 2018-11-05T21:36:00.000000000Z 1.4 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:00.000000000Z cpu2 2018-11-05T21:36:00.000000000Z 6.906906906906907 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:00.000000000Z cpu3 2018-11-05T21:36:00.000000000Z 1.3986013986013985 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:10.000000000Z cpu0 2018-11-05T21:36:00.000000000Z 9.2 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:10.000000000Z cpu1 2018-11-05T21:36:00.000000000Z 1.2 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:10.000000000Z cpu2 2018-11-05T21:36:00.000000000Z 5.7 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:10.000000000Z cpu3 2018-11-05T21:36:00.000000000Z 0.9 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:20.000000000Z cpu0 2018-11-05T21:36:00.000000000Z 8.4 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:20.000000000Z cpu1 2018-11-05T21:36:00.000000000Z 0.8 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:20.000000000Z cpu2 2018-11-05T21:36:00.000000000Z 5.1 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:20.000000000Z cpu3 2018-11-05T21:36:00.000000000Z 0.5005005005005005 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:30.000000000Z cpu0 2018-11-05T21:36:00.000000000Z 8.5 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:30.000000000Z cpu1 2018-11-05T21:36:00.000000000Z 0.8991008991008991 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:30.000000000Z cpu2 2018-11-05T21:36:00.000000000Z 4.7 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:30.000000000Z cpu3 2018-11-05T21:36:00.000000000Z 0.7 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:40.000000000Z cpu0 2018-11-05T21:36:00.000000000Z 8.6 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:40.000000000Z cpu1 2018-11-05T21:36:00.000000000Z 0.8008008008008008 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:40.000000000Z cpu2 2018-11-05T21:36:00.000000000Z 5.1 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:40.000000000Z cpu3 2018-11-05T21:36:00.000000000Z 0.6 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:50.000000000Z cpu0 2018-11-05T21:36:00.000000000Z 10.2 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:50.000000000Z cpu1 2018-11-05T21:36:00.000000000Z 0.999000999000999 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:50.000000000Z cpu2 2018-11-05T21:36:00.000000000Z 5.9 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:35:50.000000000Z cpu3 2018-11-05T21:36:00.000000000Z 0.8 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:36:00.000000000Z cpu0 2018-11-05T21:36:00.000000000Z 10.6 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:36:00.000000000Z cpu1 2018-11-05T21:36:00.000000000Z 1.1022044088176353 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:36:00.000000000Z cpu2 2018-11-05T21:36:00.000000000Z 6.4935064935064934 usage_system cpu 2018-11-05T21:34:00.000000000Z - -Table: keys: [_time, cpu] - _time:time cpu:string _stop:time _value:float _field:string _measurement:string _start:time ------------------------------- ---------------------- ------------------------------ ---------------------------- ---------------------- ---------------------- ------------------------------ -2018-11-05T21:36:00.000000000Z cpu3 2018-11-05T21:36:00.000000000Z 0.9 usage_system cpu 2018-11-05T21:34:00.000000000Z -``` -{{% /truncate %}} - -When visualized, tables appear as individual, unconnected points. - -![Group by CPU and time](/img/flux/grouping-by-cpu-time.png) - -Grouping by `cpu` and `_time` is a good illustration of how grouping works. - -## In conclusion -Grouping is a powerful way to shape your data into your desired output format. -It modifies the group keys of output tables, grouping records into tables that -all share common values within specified columns. + diff --git a/content/influxdb/v2/query-data/flux/histograms.md b/content/influxdb/v2/query-data/flux/histograms.md index 89e5c8de4..33c660214 100644 --- a/content/influxdb/v2/query-data/flux/histograms.md +++ b/content/influxdb/v2/query-data/flux/histograms.md @@ -15,157 +15,8 @@ related: - /flux/v0/stdlib/universe/histogram - /flux/v0/prometheus/metric-types/histogram/, Work with Prometheus histograms in Flux list_query_example: histogram +source: /shared/influxdb-v2/query-data/flux/histograms.md --- -Histograms provide valuable insight into the distribution of your data. -This guide walks through using Flux's `histogram()` function to transform your data into a **cumulative histogram**. - -If you're just getting started with Flux queries, check out the following: - -- [Get started with Flux](/flux/v0/get-started/) for a conceptual overview of Flux and parts of a Flux query. -- [Execute queries](/influxdb/v2/query-data/execute-queries/) to discover a variety of ways to run your queries. - -## histogram() function - -The [`histogram()` function](/flux/v0/stdlib/universe/histogram) approximates the -cumulative distribution of a dataset by counting data frequencies for a list of "bins." -A **bin** is simply a range in which a data point falls. -All data points that are less than or equal to the bound are counted in the bin. -In the histogram output, a column is added (`le`) that represents the upper bounds of of each bin. -Bin counts are cumulative. - -```js -from(bucket: "example-bucket") - |> range(start: -5m) - |> filter(fn: (r) => r._measurement == "mem" and r._field == "used_percent") - |> histogram(bins: [0.0, 10.0, 20.0, 30.0]) -``` - -{{% note %}} -Values output by the `histogram` function represent points of data aggregated over time. -Since values do not represent single points in time, there is no `_time` column in the output table. -{{% /note %}} - -## Bin helper functions -Flux provides two helper functions for generating histogram bins. -Each generates an array of floats designed to be used in the `histogram()` function's `bins` parameter. - -### linearBins() -The [`linearBins()` function](/flux/v0/stdlib/universe/linearbins) generates a list of linearly separated floats. - -```js -linearBins(start: 0.0, width: 10.0, count: 10) - -// Generated list: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, +Inf] -``` - -### logarithmicBins() -The [`logarithmicBins()` function](/flux/v0/stdlib/universe/logarithmicbins) generates a list of exponentially separated floats. - -```js -logarithmicBins(start: 1.0, factor: 2.0, count: 10, infinity: true) - -// Generated list: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, +Inf] -``` - -## Histogram visualization -The [Histogram visualization type](/influxdb/v2/visualize-data/visualization-types/histogram/) -automatically converts query results into a binned and segmented histogram. - -{{< img-hd src="/img/influxdb/2-0-visualizations-histogram-example.png" alt="Histogram visualization" />}} - -Use the [Histogram visualization controls](/influxdb/v2/visualize-data/visualization-types/histogram/#histogram-controls) -to specify the number of bins and define groups in bins. - -### Histogram visualization data structure -Because the Histogram visualization uses visualization controls to creates bins and groups, -**do not** structure query results as histogram data. - -{{% note %}} -Output of the [`histogram()` function](#histogram-function) is **not** compatible -with the Histogram visualization type. -View the example [below](#visualize-errors-by-severity). -{{% /note %}} - -## Examples - -### Generate a histogram with linear bins -```js -from(bucket: "example-bucket") - |> range(start: -5m) - |> filter(fn: (r) => r._measurement == "mem" and r._field == "used_percent") - |> histogram(bins: linearBins(start: 65.5, width: 0.5, count: 20, infinity: false)) -``` - -###### Output table -``` -Table: keys: [_start, _stop, _field, _measurement, host] - _start:time _stop:time _field:string _measurement:string host:string le:float _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ------------------------ ---------------------------- ---------------------------- -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 65.5 5 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 66 6 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 66.5 8 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 67 9 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 67.5 9 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 68 10 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 68.5 12 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 69 12 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 69.5 15 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 70 23 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 70.5 30 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 71 30 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 71.5 30 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 72 30 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 72.5 30 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 73 30 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 73.5 30 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 74 30 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 74.5 30 -2018-11-07T22:19:58.423358000Z 2018-11-07T22:24:58.423358000Z used_percent mem Scotts-MacBook-Pro.local 75 30 -``` - -### Generate a histogram with logarithmic bins -```js -from(bucket: "example-bucket") - |> range(start: -5m) - |> filter(fn: (r) => r._measurement == "mem" and r._field == "used_percent") - |> histogram(bins: logarithmicBins(start: 0.5, factor: 2.0, count: 10, infinity: false)) -``` - -###### Output table -``` -Table: keys: [_start, _stop, _field, _measurement, host] - _start:time _stop:time _field:string _measurement:string host:string le:float _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ------------------------ ---------------------------- ---------------------------- -2018-11-07T22:23:36.860664000Z 2018-11-07T22:28:36.860664000Z used_percent mem Scotts-MacBook-Pro.local 0.5 0 -2018-11-07T22:23:36.860664000Z 2018-11-07T22:28:36.860664000Z used_percent mem Scotts-MacBook-Pro.local 1 0 -2018-11-07T22:23:36.860664000Z 2018-11-07T22:28:36.860664000Z used_percent mem Scotts-MacBook-Pro.local 2 0 -2018-11-07T22:23:36.860664000Z 2018-11-07T22:28:36.860664000Z used_percent mem Scotts-MacBook-Pro.local 4 0 -2018-11-07T22:23:36.860664000Z 2018-11-07T22:28:36.860664000Z used_percent mem Scotts-MacBook-Pro.local 8 0 -2018-11-07T22:23:36.860664000Z 2018-11-07T22:28:36.860664000Z used_percent mem Scotts-MacBook-Pro.local 16 0 -2018-11-07T22:23:36.860664000Z 2018-11-07T22:28:36.860664000Z used_percent mem Scotts-MacBook-Pro.local 32 0 -2018-11-07T22:23:36.860664000Z 2018-11-07T22:28:36.860664000Z used_percent mem Scotts-MacBook-Pro.local 64 2 -2018-11-07T22:23:36.860664000Z 2018-11-07T22:28:36.860664000Z used_percent mem Scotts-MacBook-Pro.local 128 30 -2018-11-07T22:23:36.860664000Z 2018-11-07T22:28:36.860664000Z used_percent mem Scotts-MacBook-Pro.local 256 30 -``` - -### Visualize errors by severity -Use the [Telegraf Syslog plugin](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/syslog) -to collect error information from your system. -Query the `severity_code` field in the `syslog` measurement: - -```js -from(bucket: "example-bucket") - |> range(start: v.timeRangeStart, stop: v.timeRangeStop) - |> filter(fn: (r) => r._measurement == "syslog" and r._field == "severity_code") -``` - -In the Histogram visualization options, select `_time` as the **X Column** -and `severity` as the **Group By** option: - -{{< img-hd src="/img/influxdb/2-0-visualizations-histogram-errors.png" alt="Logs by severity histogram" />}} - -### Use Prometheus histograms in Flux - -_For information about working with Prometheus histograms in Flux, see -[Work with Prometheus histograms](/flux/v0/prometheus/metric-types/histogram/)._ \ No newline at end of file + diff --git a/content/influxdb/v2/query-data/flux/increase.md b/content/influxdb/v2/query-data/flux/increase.md index 2d11048e9..6ac6250a4 100644 --- a/content/influxdb/v2/query-data/flux/increase.md +++ b/content/influxdb/v2/query-data/flux/increase.md @@ -15,43 +15,8 @@ influxdb/v2/tags: [query, increase, counters] related: - /flux/v0/stdlib/universe/increase/ list_query_example: increase +source: /shared/influxdb-v2/query-data/flux/increase.md --- -Use [`increase()`](/flux/v0/stdlib/universe/increase/) -to track increases across multiple columns in a table. -This function is especially useful when tracking changes in counter values that -wrap over time or periodically reset. - -```js -data - |> increase() -``` - -`increase()` returns a cumulative sum of **non-negative** differences between rows in a table. -For example: - -{{< flex >}} -{{% flex-content %}} -**Given the following input:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:01:00Z | 1 | -| 2020-01-01T00:02:00Z | 2 | -| 2020-01-01T00:03:00Z | 8 | -| 2020-01-01T00:04:00Z | 10 | -| 2020-01-01T00:05:00Z | 0 | -| 2020-01-01T00:06:00Z | 4 | -{{% /flex-content %}} -{{% flex-content %}} -**`increase()` returns:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:02:00Z | 1 | -| 2020-01-01T00:03:00Z | 7 | -| 2020-01-01T00:04:00Z | 9 | -| 2020-01-01T00:05:00Z | 9 | -| 2020-01-01T00:06:00Z | 13 | -{{% /flex-content %}} -{{< /flex >}} + diff --git a/content/influxdb/v2/query-data/flux/join.md b/content/influxdb/v2/query-data/flux/join.md index 498de6976..e64997f2d 100644 --- a/content/influxdb/v2/query-data/flux/join.md +++ b/content/influxdb/v2/query-data/flux/join.md @@ -20,382 +20,8 @@ related: - /flux/v0/join-data/time/ - /flux/v0/stdlib/join/ list_query_example: join-new +source: /shared/influxdb-v2/query-data/flux/join.md --- -Use the Flux [`join` package](/flux/v0/stdlib/join/) to join two data sets -based on common values using the following join methods: - -{{< flex >}} -{{< flex-content "quarter" >}} -

Inner join

- {{< svg svg="static/svgs/join-diagram.svg" class="inner small center" >}} -{{< /flex-content >}} -{{< flex-content "quarter" >}} -

Left outer join

- {{< svg svg="static/svgs/join-diagram.svg" class="left small center" >}} -{{< /flex-content >}} -{{< flex-content "quarter" >}} -

Right outer join

- {{< svg svg="static/svgs/join-diagram.svg" class="right small center" >}} -{{< /flex-content >}} -{{< flex-content "quarter" >}} -

Full outer join

- {{< svg svg="static/svgs/join-diagram.svg" class="full small center" >}} -{{< /flex-content >}} -{{< /flex >}} - -The join package lets you join data from different data sources such as -[InfluxDB](/flux/v0/query-data/influxdb/), [SQL database](/flux/v0/query-data/sql/), -[CSV](/flux/v0/query-data/csv/), and [others](/flux/v0/query-data/). - -## Use join functions to join your data - -{{< tabs-wrapper >}} -{{% tabs %}} -[Inner join](#) -[Left join](#) -[Right join](#) -[Full outer join](#) -[Join on time](#) -{{% /tabs %}} - - -{{% tab-content %}} - -1. Import the `join` package. -2. Define the **left** and **right** data streams to join: - - - Each stream must have one or more columns with common values. - Column labels do not need to match, but column values do. - - Each stream should have identical [group keys](/flux/v0/get-started/data-model/#group-key). - - _For more information, see [join data requirements](/flux/v0/join-data/#data-requirements)._ - -3. Use [`join.inner()`](/flux/v0/stdlib/join/inner/) to join the two streams together. - Provide the following required parameters: - - - `left`: Stream of data representing the left side of the join. - - `right`: Stream of data representing the right side of the join. - - `on`: [Join predicate](/flux/v0/join-data/#join-predicate-function-on). - For example: `(l, r) => l.column == r.column`. - - `as`: [Join output function](/flux/v0/join-data/#join-output-function-as) - that returns a record with values from each input stream. - For example: `(l, r) => ({l with column1: r.column1, column2: r.column2})`. - -```js -import "join" -import "sql" - -left = - from(bucket: "example-bucket-1") - |> range(start: "-1h") - |> filter(fn: (r) => r._measurement == "example-measurement") - |> filter(fn: (r) => r._field == "example-field") - -right = - sql.from( - driverName: "postgres", - dataSourceName: "postgresql://username:password@localhost:5432", - query: "SELECT * FROM example_table", - ) - -join.inner( - left: left, - right: right, - on: (l, r) => l.column == r.column, - as: (l, r) => ({l with name: r.name, location: r.location}), -) -``` - -For more information and detailed examples, see [Perform an inner join](/flux/v0/join-data/inner/) -in the Flux documentation. - -{{% /tab-content %}} - - - -{{% tab-content %}} - -1. Import the `join` package. -2. Define the **left** and **right** data streams to join: - - - Each stream must have one or more columns with common values. - Column labels do not need to match, but column values do. - - Each stream should have identical [group keys](/flux/v0/get-started/data-model/#group-key). - - _For more information, see [join data requirements](/flux/v0/join-data/#data-requirements)._ - -3. Use [`join.left()`](/flux/v0/stdlib/join/left/) to join the two streams together. - Provide the following required parameters: - - - `left`: Stream of data representing the left side of the join. - - `right`: Stream of data representing the right side of the join. - - `on`: [Join predicate](/flux/v0/join-data/#join-predicate-function-on). - For example: `(l, r) => l.column == r.column`. - - `as`: [Join output function](/flux/v0/join-data/#join-output-function-as) - that returns a record with values from each input stream. - For example: `(l, r) => ({l with column1: r.column1, column2: r.column2})`. - -```js -import "join" -import "sql" - -left = - from(bucket: "example-bucket-1") - |> range(start: "-1h") - |> filter(fn: (r) => r._measurement == "example-measurement") - |> filter(fn: (r) => r._field == "example-field") - -right = - sql.from( - driverName: "postgres", - dataSourceName: "postgresql://username:password@localhost:5432", - query: "SELECT * FROM example_table", - ) - -join.left( - left: left, - right: right, - on: (l, r) => l.column == r.column, - as: (l, r) => ({l with name: r.name, location: r.location}), -) -``` - -For more information and detailed examples, see [Perform a left outer join](/flux/v0/join-data/left-outer/) -in the Flux documentation. - -{{% /tab-content %}} - - - -{{% tab-content %}} - -1. Import the `join` package. -2. Define the **left** and **right** data streams to join: - - - Each stream must have one or more columns with common values. - Column labels do not need to match, but column values do. - - Each stream should have identical [group keys](/flux/v0/get-started/data-model/#group-key). - - _For more information, see [join data requirements](/flux/v0/join-data/#data-requirements)._ - -3. Use [`join.right()`](/flux/v0/stdlib/join/right/) to join the two streams together. - Provide the following required parameters: - - - `left`: Stream of data representing the left side of the join. - - `right`: Stream of data representing the right side of the join. - - `on`: [Join predicate](/flux/v0/join-data/#join-predicate-function-on). - For example: `(l, r) => l.column == r.column`. - - `as`: [Join output function](/flux/v0/join-data/#join-output-function-as) - that returns a record with values from each input stream. - For example: `(l, r) => ({l with column1: r.column1, column2: r.column2})`. - -```js -import "join" -import "sql" - -left = - from(bucket: "example-bucket-1") - |> range(start: "-1h") - |> filter(fn: (r) => r._measurement == "example-measurement") - |> filter(fn: (r) => r._field == "example-field") - -right = - sql.from( - driverName: "postgres", - dataSourceName: "postgresql://username:password@localhost:5432", - query: "SELECT * FROM example_table", - ) - -join.right( - left: left, - right: right, - on: (l, r) => l.column == r.column, - as: (l, r) => ({l with name: r.name, location: r.location}), -) -``` - -For more information and detailed examples, see [Perform a right outer join](/flux/v0/join-data/right-outer/) -in the Flux documentation. - -{{% /tab-content %}} - - - -{{% tab-content %}} -1. Import the `join` package. -2. Define the **left** and **right** data streams to join: - - - Each stream must have one or more columns with common values. - Column labels do not need to match, but column values do. - - Each stream should have identical [group keys](/flux/v0/get-started/data-model/#group-key). - - _For more information, see [join data requirements](/flux/v0/join-data/#data-requirements)._ - -3. Use [`join.full()`](/flux/v0/stdlib/join/full/) to join the two streams together. - Provide the following required parameters: - - - `left`: Stream of data representing the left side of the join. - - `right`: Stream of data representing the right side of the join. - - `on`: [Join predicate](/flux/v0/join-data/#join-predicate-function-on). - For example: `(l, r) => l.column == r.column`. - - `as`: [Join output function](/flux/v0/join-data/#join-output-function-as) - that returns a record with values from each input stream. - For example: `(l, r) => ({l with column1: r.column1, column2: r.column2})`. - -{{% note %}} -Full outer joins must account for non-group-key columns in both `l` and `r` -records being null. Use conditional logic to check which record contains non-null -values for columns not in the group key. -For more information, see [Account for missing, non-group-key values](/flux/v0/join-data/full-outer/#account-for-missing-non-group-key-values). -{{% /note %}} - -```js -import "join" -import "sql" - -left = - from(bucket: "example-bucket-1") - |> range(start: "-1h") - |> filter(fn: (r) => r._measurement == "example-measurement") - |> filter(fn: (r) => r._field == "example-field") - -right = - sql.from( - driverName: "postgres", - dataSourceName: "postgresql://username:password@localhost:5432", - query: "SELECT * FROM example_table", - ) - -join.full( - left: left, - right: right, - on: (l, r) => l.id== r.id, - as: (l, r) => { - id = if exists l.id then l.id else r.id - - return {name: l.name, location: r.location, id: id} - }, -) -``` - -For more information and detailed examples, see [Perform a full outer join](/flux/v0/join-data/full-outer/) -in the Flux documentation. - -{{% /tab-content %}} - - - -{{% tab-content %}} - -1. Import the `join` package. -2. Define the **left** and **right** data streams to join: - - - Each stream must also have a `_time` column. - - Each stream must have one or more columns with common values. - Column labels do not need to match, but column values do. - - Each stream should have identical [group keys](/flux/v0/get-started/data-model/#group-key). - - _For more information, see [join data requirements](/flux/v0/join-data/#data-requirements)._ - -3. Use [`join.time()`](/flux/v0/stdlib/join/time/) to join the two streams - together based on time values. - Provide the following parameters: - - - `left`: ({{< req >}}) Stream of data representing the left side of the join. - - `right`: ({{< req >}}) Stream of data representing the right side of the join. - - `as`: ({{< req >}}) [Join output function](/flux/v0/join-data/#join-output-function-as) - that returns a record with values from each input stream. - For example: `(l, r) => ({r with column1: l.column1, column2: l.column2})`. - - `method`: Join method to use. Default is `inner`. - -```js -import "join" -import "sql" - -left = - from(bucket: "example-bucket-1") - |> range(start: "-1h") - |> filter(fn: (r) => r._measurement == "example-m1") - |> filter(fn: (r) => r._field == "example-f1") - -right = - from(bucket: "example-bucket-2") - |> range(start: "-1h") - |> filter(fn: (r) => r._measurement == "example-m2") - |> filter(fn: (r) => r._field == "example-f2") - -join.time(method: "left", left: left, right: right, as: (l, r) => ({l with f2: r._value})) -``` - -For more information and detailed examples, see [Join on time](/flux/v0/join-data/time/) -in the Flux documentation. - -{{% /tab-content %}} - -{{< /tabs-wrapper >}} - ---- - -## When to use union and pivot instead of join functions - -We recommend using the `join` package to join streams that have mostly different -schemas or that come from two separate data sources. -If you're joining two datasets queried from InfluxDB, using -[`union()`](/flux/v0/stdlib/universe/union/) and [`pivot()`](/flux/v0/stdlib/universe/pivot/) -to combine the data will likely be more performant. - -For example, if you need to query fields from different InfluxDB buckets and align -field values in each row based on time: - -```js -f1 = - from(bucket: "example-bucket-1") - |> range(start: "-1h") - |> filter(fn: (r) => r._field == "f1") - |> drop(columns: "_measurement") - -f2 = - from(bucket: "example-bucket-2") - |> range(start: "-1h") - |> filter(fn: (r) => r._field == "f2") - |> drop(columns: "_measurement") - -union(tables: [f1, f2]) - |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value") -``` -{{< expand-wrapper >}} -{{% expand "View example input and output data" %}} - -#### Input -{{< flex >}} -{{% flex-content %}} -##### f1 -| _time | _field | _value | -| :------------------- | :----- | -----: | -| 2020-01-01T00:01:00Z | f1 | 1 | -| 2020-01-01T00:02:00Z | f1 | 2 | -| 2020-01-01T00:03:00Z | f1 | 1 | -| 2020-01-01T00:04:00Z | f1 | 3 | -{{% /flex-content %}} -{{% flex-content %}} -##### f2 -| _time | _field | _value | -| :------------------- | :----- | -----: | -| 2020-01-01T00:01:00Z | f2 | 5 | -| 2020-01-01T00:02:00Z | f2 | 12 | -| 2020-01-01T00:03:00Z | f2 | 8 | -| 2020-01-01T00:04:00Z | f2 | 6 | -{{% /flex-content %}} -{{< /flex >}} - -#### Output -| _time | f1 | f2 | -| :------------------- | --: | --: | -| 2020-01-01T00:01:00Z | 1 | 5 | -| 2020-01-01T00:02:00Z | 2 | 12 | -| 2020-01-01T00:03:00Z | 1 | 8 | -| 2020-01-01T00:04:00Z | 3 | 6 | - -{{% /expand %}} -{{< /expand-wrapper >}} + diff --git a/content/influxdb/v2/query-data/flux/mathematic-operations.md b/content/influxdb/v2/query-data/flux/mathematic-operations.md index c53874803..215f6bce1 100644 --- a/content/influxdb/v2/query-data/flux/mathematic-operations.md +++ b/content/influxdb/v2/query-data/flux/mathematic-operations.md @@ -19,190 +19,8 @@ related: - /flux/v0/function-types/#type-conversions, Flux type-conversion functions - /influxdb/v2/query-data/flux/calculate-percentages/ list_query_example: map_math +source: /shared/influxdb-v2/query-data/flux/mathematic-operations.md --- -[Flux](/flux/v0/), InfluxData's data scripting and query language, -supports mathematic expressions in data transformations. -This article describes how to use [Flux arithmetic operators](/flux/v0/spec/operators/#arithmetic-operators) -to "map" over data and transform values using mathematic operations. - -If you're just getting started with Flux queries, check out the following: - -- [Get started with Flux](/flux/v0/get-started/) for a conceptual overview of Flux and parts of a Flux query. -- [Execute queries](/influxdb/v2/query-data/execute-queries/) to discover a variety of ways to run your queries. - -##### Basic mathematic operations -```js -// Examples executed using the Flux REPL -> 9 + 9 -18 -> 22 - 14 -8 -> 6 * 5 -30 -> 21 / 7 -3 -``` - -

See Flux Read-Eval-Print Loop (REPL).

- -{{% note %}} -#### Operands must be the same type -Operands in Flux mathematic operations must be the same data type. -For example, integers cannot be used in operations with floats. -Otherwise, you will get an error similar to: - -``` -Error: type error: float != int -``` - -To convert operands to the same type, use [type-conversion functions](/flux/v0/stdlib/universe/) -or manually format operands. -The operand data type determines the output data type. -For example: - -```js -100 // Parsed as an integer -100.0 // Parsed as a float - -// Example evaluations -> 20 / 8 -2 - -> 20.0 / 8.0 -2.5 -``` -{{% /note %}} - -## Custom mathematic functions -Flux lets you [create custom functions](/influxdb/v2/query-data/flux/custom-functions) that use mathematic operations. -View the examples below. - -###### Custom multiplication function -```js -multiply = (x, y) => x * y - -multiply(x: 10, y: 12) -// Returns 120 -``` - -###### Custom percentage function -```js -percent = (sample, total) => (sample / total) * 100.0 - -percent(sample: 20.0, total: 80.0) -// Returns 25.0 -``` - -### Transform values in a data stream -To transform multiple values in an input stream, your function needs to: - -- [Handle piped-forward data](/influxdb/v2/query-data/flux/custom-functions/#use-piped-forward-data-in-a-custom-function). -- Each operand necessary for the calculation exists in each row _(see [Pivot vs join](#pivot-vs-join) below)_. -- Use the [`map()` function](/flux/v0/stdlib/universe/map) to iterate over each row. - -The example `multiplyByX()` function below includes: - -- A `tables` parameter that represents the input data stream (`<-`). -- An `x` parameter which is the number by which values in the `_value` column are multiplied. -- A `map()` function that iterates over each row in the input stream. - It uses the `with` operator to preserve existing columns in each row. - It also multiples the `_value` column by `x`. - -```js -multiplyByX = (x, tables=<-) => tables - |> map(fn: (r) => ({r with _value: r._value * x})) - -data - |> multiplyByX(x: 10) -``` - -## Examples - -### Convert bytes to gigabytes -To convert active memory from bytes to gigabytes (GB), divide the `active` field -in the `mem` measurement by 1,073,741,824. - -The `map()` function iterates over each row in the piped-forward data and defines -a new `_value` by dividing the original `_value` by 1073741824. - -```js -from(bucket: "example-bucket") - |> range(start: -10m) - |> filter(fn: (r) => r._measurement == "mem" and r._field == "active") - |> map(fn: (r) => ({r with _value: r._value / 1073741824})) -``` - -You could turn that same calculation into a function: - -```js -bytesToGB = (tables=<-) => tables - |> map(fn: (r) => ({r with _value: r._value / 1073741824})) - -data - |> bytesToGB() -``` - -#### Include partial gigabytes -Because the original metric (bytes) is an integer, the output of the operation is an integer and does not include partial GBs. -To calculate partial GBs, convert the `_value` column and its values to floats using the -[`float()` function](/flux/v0/stdlib/universe/float) -and format the denominator in the division operation as a float. - -```js -bytesToGB = (tables=<-) => tables - |> map(fn: (r) => ({r with _value: float(v: r._value) / 1073741824.0})) -``` - -### Calculate a percentage -To calculate a percentage, use simple division, then multiply the result by 100. - -```js -> 1.0 / 4.0 * 100.0 -25.0 -``` - -_For an in-depth look at calculating percentages, see [Calculate percentages](/influxdb/v2/query-data/flux/calculate-percentages)._ - -## Pivot vs join -To query and use values in mathematical operations in Flux, operand values must -exists in a single row. -Both `pivot()` and `join()` will do this, but there are important differences between the two: - -#### Pivot is more performant -`pivot()` reads and operates on a single stream of data. -`join()` requires two streams of data and the overhead of reading and combining -both streams can be significant, especially for larger data sets. - -#### Use join for multiple data sources -Use `join()` when querying data from different buckets or data sources. - -##### Pivot fields into columns for mathematic calculations -```js -data - |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value") - |> map(fn: (r) => ({r with _value: (r.field1 + r.field2) / r.field3 * 100.0})) -``` - -##### Join multiple data sources for mathematic calculations -```js -import "sql" -import "influxdata/influxdb/secrets" - -pgUser = secrets.get(key: "POSTGRES_USER") -pgPass = secrets.get(key: "POSTGRES_PASSWORD") -pgHost = secrets.get(key: "POSTGRES_HOST") - -t1 = sql.from( - driverName: "postgres", - dataSourceName: "postgresql://${pgUser}:${pgPass}@${pgHost}", - query: "SELECT id, name, available FROM example_table", -) - -t2 = from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "example-measurement" and r._field == "example-field") - -join(tables: {t1: t1, t2: t2}, on: ["id"]) - |> map(fn: (r) => ({r with _value: r._value_t2 / r.available_t1 * 100.0})) -``` + diff --git a/content/influxdb/v2/query-data/flux/median.md b/content/influxdb/v2/query-data/flux/median.md index ddc0d3921..6d5fc8419 100644 --- a/content/influxdb/v2/query-data/flux/median.md +++ b/content/influxdb/v2/query-data/flux/median.md @@ -15,135 +15,8 @@ related: - /flux/v0/stdlib/universe/median/ - /flux/v0/stdlib/universe/quantile/ list_query_example: median +source: /shared/influxdb-v2/query-data/flux/median.md --- -Use the [`median()` function](/flux/v0/stdlib/universe/median/) -to return a value representing the `0.5` quantile (50th percentile) or median of input data. - -## Select a method for calculating the median -Select one of the following methods to calculate the median: - -- [estimate_tdigest](#estimate_tdigest) -- [exact_mean](#exact_mean) -- [exact_selector](#exact_selector) - -### estimate_tdigest -**(Default)** An aggregate method that uses a [t-digest data structure](https://github.com/tdunning/t-digest) -to compute an accurate `0.5` quantile estimate on large data sources. -Output tables consist of a single row containing the calculated median. - -{{< flex >}} -{{% flex-content %}} -**Given the following input table:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:01:00Z | 1.0 | -| 2020-01-01T00:02:00Z | 1.0 | -| 2020-01-01T00:03:00Z | 2.0 | -| 2020-01-01T00:04:00Z | 3.0 | -{{% /flex-content %}} -{{% flex-content %}} -**`estimate_tdigest` returns:** - -| _value | -|:------:| -| 1.5 | -{{% /flex-content %}} -{{< /flex >}} - -### exact_mean -An aggregate method that takes the average of the two points closest to the `0.5` quantile value. -Output tables consist of a single row containing the calculated median. - -{{< flex >}} -{{% flex-content %}} -**Given the following input table:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:01:00Z | 1.0 | -| 2020-01-01T00:02:00Z | 1.0 | -| 2020-01-01T00:03:00Z | 2.0 | -| 2020-01-01T00:04:00Z | 3.0 | -{{% /flex-content %}} -{{% flex-content %}} -**`exact_mean` returns:** - -| _value | -|:------:| -| 1.5 | -{{% /flex-content %}} -{{< /flex >}} - -### exact_selector -A selector method that returns the data point for which at least 50% of points are less than. -Output tables consist of a single row containing the calculated median. - -{{< flex >}} -{{% flex-content %}} -**Given the following input table:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:01:00Z | 1.0 | -| 2020-01-01T00:02:00Z | 1.0 | -| 2020-01-01T00:03:00Z | 2.0 | -| 2020-01-01T00:04:00Z | 3.0 | -{{% /flex-content %}} -{{% flex-content %}} -**`exact_selector` returns:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:02:00Z | 1.0 | -{{% /flex-content %}} -{{< /flex >}} - -{{% note %}} -The examples below use the [example data variable](/influxdb/v2/query-data/flux/#example-data-variable). -{{% /note %}} - -## Find the value that represents the median -Use the default method, `"estimate_tdigest"`, to return all rows in a table that -contain values in the 50th percentile of data in the table. - -```js -data - |> median() -``` - -## Find the average of values closest to the median -Use the `exact_mean` method to return a single row per input table containing the -average of the two values closest to the mathematical median of data in the table. - -```js -data - |> median(method: "exact_mean") -``` - -## Find the point with the median value -Use the `exact_selector` method to return a single row per input table containing the -value that 50% of values in the table are less than. - -```js -data - |> median(method: "exact_selector") -``` - -## Use median() with aggregateWindow() -[`aggregateWindow()`](/flux/v0/stdlib/universe/aggregatewindow/) -segments data into windows of time, aggregates data in each window into a single -point, and then removes the time-based segmentation. -It is primarily used to [downsample data](/influxdb/v2/process-data/common-tasks/downsample-data/). - -To specify the [median calculation method](#select-a-method-for-calculating-the-median) in `aggregateWindow()`, use the -[full function syntax](/flux/v0/stdlib/universe/aggregatewindow/#specify-parameters-of-the-aggregate-function): - -```js -data - |> aggregateWindow( - every: 5m, - fn: (tables=<-, column) => tables |> median(method: "exact_selector"), - ) -``` + diff --git a/content/influxdb/v2/query-data/flux/monitor-states.md b/content/influxdb/v2/query-data/flux/monitor-states.md index b5a4c5c41..1064c1bde 100644 --- a/content/influxdb/v2/query-data/flux/monitor-states.md +++ b/content/influxdb/v2/query-data/flux/monitor-states.md @@ -13,177 +13,8 @@ aliases: related: - /flux/v0/stdlib/universe/stateduration/ - /flux/v0/stdlib/universe/statecount/ +source: /shared/influxdb-v2/query-data/flux/monitor-states.md --- -Flux helps you monitor states in your metrics and events: - -- [Find how long a state persists](#find-how-long-a-state-persists) -- [Count the number of consecutive states](#count-the-number-of-consecutive-states) - - -If you're just getting started with Flux queries, check out the following: - -- [Get started with Flux](/flux/v0/get-started/) for a conceptual overview of Flux. -- [Execute queries](/influxdb/v2/query-data/execute-queries/) to discover a variety of ways to run your queries. - -## Find how long a state persists - -Use [`stateDuration()`](/flux/v0/stdlib/universe/stateduration/) -to calculate the duration of consecutive rows with a specified state. -For each consecutive point that matches the specified state, `stateDuration()` -increments and stores the duration (in the specified unit) in a user-defined column. - -Include the following information: - -- **Column to search:** any tag key, tag value, field key, field value, or measurement. -- **Value:** the value (or state) to search for in the specified column. -- **State duration column:** a new column to store the state duration─the length of time that the specified value persists. -- **Unit:** the unit of time (`1s` (by default), `1m`, `1h`) used to increment the state duration. - -```js -data - |> stateDuration(fn: (r) => r.column_to_search == "value_to_search_for", column: "state_duration", unit: 1s) -``` - -- For the first point that evaluates `true`, the state duration is set to `0`. - For each consecutive point that evaluates `true`, the state duration - increases by the time interval between each consecutive point (in specified units). -- If the state is `false`, the state duration is reset to `-1`. - -### Example query with stateDuration() - -The following query searches the `doors` bucket over the past 5 minutes to find how many seconds a door has been `closed`. - -```js -from(bucket: "doors") - |> range(start: -5m) - |> stateDuration(fn: (r) => r._value == "closed", column: "door_closed", unit: 1s) -``` - -In this example, `door_closed` is the **State duration** column. -If you write data to the `doors` bucket every minute, the state duration -increases by `60s` for each consecutive point where `_value` is `closed`. -If `_value` is not `closed`, the state duration is reset to `0`. - -#### Query results - -Results for the example query above may look like this (for simplicity, we've omitted the measurement, tag, and field columns): - -| _time | _value | door_closed | -| :------------------- | :----: | ----------: | -| 2019-10-26T17:39:16Z | closed | 0 | -| 2019-10-26T17:40:16Z | closed | 60 | -| 2019-10-26T17:41:16Z | closed | 120 | -| 2019-10-26T17:42:16Z | open | -1 | -| 2019-10-26T17:43:16Z | closed | 0 | -| 2019-10-26T17:44:27Z | closed | 60 | - -## Count the number of consecutive states - -Use the [`stateCount()` function](/flux/v0/stdlib/universe/statecount/) -and include the following information: - -- **Column to search:** any tag key, tag value, field key, field value, or measurement. -- **Value:** to search for in the specified column. -- **State count column:** a new column to store the state count─the number of - consecutive records in which the specified value exists. - -```js -|> stateCount( - fn: (r) => r.column_to_search == "value_to_search_for", - column: "state_count", -) -``` - -- For the first point that evaluates `true`, the state count is set to `1`. For each consecutive point that evaluates `true`, the state count increases by 1. -- If the state is `false`, the state count is reset to `-1`. - -### Example query with stateCount() - -The following query searches the `doors` bucket over the past 5 minutes and calculates how many points have `closed` as their `_value`. - -```js -from(bucket: "doors") - |> range(start: -5m) - |> stateCount(fn: (r) => r._value == "closed", column: "door_closed") -``` - -This example stores the **state count** in the `door_closed` column. If you write data to the `doors` bucket every minute, the state count increases by `1` for each consecutive point where `_value` is `closed`. If `_value` is not `closed`, the state count is reset to `-1`. - -#### Query results - -Results for the example query above may look like this (for simplicity, we've omitted the measurement, tag, and field columns): - -| _time | _value | door_closed | -| :------------------- | :----: | ----------: | -| 2019-10-26T17:39:16Z | closed | 1 | -| 2019-10-26T17:40:16Z | closed | 2 | -| 2019-10-26T17:41:16Z | closed | 3 | -| 2019-10-26T17:42:16Z | open | -1 | -| 2019-10-26T17:43:16Z | closed | 1 | -| 2019-10-26T17:44:27Z | closed | 2 | - -#### Example query to count machine state - -The following query checks the machine state every minute (idle, assigned, or busy). InfluxDB searches the `servers` bucket over the past hour and counts records with a machine state of `idle`, `assigned` or `busy`. - -```js -from(bucket: "servers") - |> range(start: -1h) - |> filter(fn: (r) => r.machine_state == "idle" or r.machine_state == "assigned" or r.machine_state == "busy") - |> stateCount(fn: (r) => r.machine_state == "busy", column: "_count") - |> stateCount(fn: (r) => r.machine_state == "assigned", column: "_count") - |> stateCount(fn: (r) => r.machine_state == "idle", column: "_count") -``` - - - - + diff --git a/content/influxdb/v2/query-data/flux/moving-average.md b/content/influxdb/v2/query-data/flux/moving-average.md index 61b0bbdc5..a98927d70 100644 --- a/content/influxdb/v2/query-data/flux/moving-average.md +++ b/content/influxdb/v2/query-data/flux/moving-average.md @@ -14,105 +14,8 @@ related: - /flux/v0/stdlib/universe/movingaverage/ - /flux/v0/stdlib/universe/timedmovingaverage/ list_query_example: moving_average +source: /shared/influxdb-v2/query-data/flux/moving-average.md --- -Use [`movingAverage()`](/flux/v0/stdlib/universe/movingaverage/) -or [`timedMovingAverage()`](/flux/v0/stdlib/universe/timedmovingaverage/) -to return the moving average of data. - -```js -data - |> movingAverage(n: 5) - -// OR - -data - |> timedMovingAverage(every: 5m, period: 10m) -``` - -### movingAverage() -For each row in a table, `movingAverage()` returns the average of the current value and -**previous** values where `n` is the total number of values used to calculate the average. - -If `n = 3`: - -| Row # | Calculation | -|:-----:|:----------- | -| 1 | _Insufficient number of rows_ | -| 2 | _Insufficient number of rows_ | -| 3 | (Row1 + Row2 + Row3) / 3 | -| 4 | (Row2 + Row3 + Row4) / 3 | -| 5 | (Row3 + Row4 + Row5) / 3 | - -{{< flex >}} -{{% flex-content %}} -**Given the following input:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:01:00Z | 1.0 | -| 2020-01-01T00:02:00Z | 1.2 | -| 2020-01-01T00:03:00Z | 1.8 | -| 2020-01-01T00:04:00Z | 0.9 | -| 2020-01-01T00:05:00Z | 1.4 | -| 2020-01-01T00:06:00Z | 2.0 | -{{% /flex-content %}} -{{% flex-content %}} -**The following would return:** - -```js -|> movingAverage(n: 3) -``` - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:03:00Z | 1.33 | -| 2020-01-01T00:04:00Z | 1.30 | -| 2020-01-01T00:05:00Z | 1.36 | -| 2020-01-01T00:06:00Z | 1.43 | -{{% /flex-content %}} -{{< /flex >}} - -### timedMovingAverage() -For each row in a table, `timedMovingAverage()` returns the average of the -current value and all row values in the **previous** `period` (duration). -It returns moving averages at a frequency defined by the `every` parameter. - -Each color in the diagram below represents a period of time used to calculate an -average and the time a point representing the average is returned. -If `every = 30m` and `period = 1h`: - -{{< svg "/static/svgs/timed-moving-avg.svg" >}} - -{{< flex >}} -{{% flex-content %}} -**Given the following input:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:00:00Z | 1.0 | -| 2020-01-01T00:30:00Z | 1.2 | -| 2020-01-01T01:00:00Z | 1.8 | -| 2020-01-01T01:30:00Z | 0.9 | -| 2020-01-01T02:00:00Z | 1.4 | -| 2020-01-01T02:30:00Z | 2.0 | -| 2020-01-01T03:00:00Z | 1.9 | -{{% /flex-content %}} -{{% flex-content %}} -**The following would return:** - -```js -|> timedMovingAverage(every: 30m, period: 1h) -``` - -| _time | _value | -| :------------------- | -----: | -| 2020-01-01T00:30:00Z | 1.0 | -| 2020-01-01T01:00:00Z | 1.1 | -| 2020-01-01T01:30:00Z | 1.5 | -| 2020-01-01T02:00:00Z | 1.35 | -| 2020-01-01T02:30:00Z | 1.15 | -| 2020-01-01T03:00:00Z | 1.7 | -| 2020-01-01T03:00:00Z | 2 | -{{% /flex-content %}} -{{< /flex >}} + diff --git a/content/influxdb/v2/query-data/flux/operate-on-timestamps.md b/content/influxdb/v2/query-data/flux/operate-on-timestamps.md index 8fec808aa..8c0b6e75b 100644 --- a/content/influxdb/v2/query-data/flux/operate-on-timestamps.md +++ b/content/influxdb/v2/query-data/flux/operate-on-timestamps.md @@ -21,183 +21,8 @@ related: - /flux/v0/stdlib/date/truncate/ - /flux/v0/stdlib/date/add/ - /flux/v0/stdlib/date/sub/ +source: /shared/influxdb-v2/query-data/flux/operate-on-timestamps.md --- -Every point stored in InfluxDB has an associated timestamp. -Use Flux to process and operate on timestamps to suit your needs. - -- [Convert timestamp format](#convert-timestamp-format) -- [Calculate the duration between two timestamps](#calculate-the-duration-between-two-timestamps) -- [Retrieve the current time](#retrieve-the-current-time) -- [Normalize irregular timestamps](#normalize-irregular-timestamps) -- [Use timestamps and durations together](#use-timestamps-and-durations-together) - -{{% note %}} -If you're just getting started with Flux queries, check out the following: - -- [Get started with Flux](/flux/v0/get-started/) for a conceptual overview of Flux and parts of a Flux query. -- [Execute queries](/influxdb/v2/query-data/execute-queries/) to discover a variety of ways to run your queries. -{{% /note %}} - - -## Convert timestamp format - -- [Unix nanosecond to RFC3339](#unix-nanosecond-to-rfc3339) -- [RFC3339 to Unix nanosecond](#rfc3339-to-unix-nanosecond) - -### Unix nanosecond to RFC3339 -Use the [`time()` function](/flux/v0/stdlib/universe/time/) -to convert a [Unix **nanosecond** timestamp](/influxdb/v2/reference/glossary/#unix-timestamp) -to an [RFC3339 timestamp](/influxdb/v2/reference/glossary/#rfc3339-timestamp). - -```js -time(v: 1568808000000000000) -// Returns 2019-09-18T12:00:00.000000000Z -``` - -### RFC3339 to Unix nanosecond -Use the [`uint()` function](/flux/v0/stdlib/universe/uint/) -to convert an RFC3339 timestamp to a Unix nanosecond timestamp. - -```js -uint(v: 2019-09-18T12:00:00.000000000Z) -// Returns 1568808000000000000 -``` - -## Calculate the duration between two timestamps -Flux doesn't support mathematical operations using [time type](/flux/v0/spec/types/#time-types) values. -To calculate the duration between two timestamps: - -1. Use the `uint()` function to convert each timestamp to a Unix nanosecond timestamp. -2. Subtract one Unix nanosecond timestamp from the other. -3. Use the `duration()` function to convert the result into a duration. - -```js -time1 = uint(v: 2019-09-17T21:12:05Z) -time2 = uint(v: 2019-09-18T22:16:35Z) - -duration(v: time2 - time1) -// Returns 25h4m30s -``` - -{{% note %}} -Flux doesn't support duration column types. -To store a duration in a column, use the [`string()` function](/flux/v0/stdlib/universe/string/) -to convert the duration to a string. -{{% /note %}} - -## Retrieve the current time -- [Current UTC time](#current-utc-time) -- [Current system time](#current-system-time) - -### Current UTC time -Use the [`now()` function](/flux/v0/stdlib/universe/now/) to -return the current UTC time in RFC3339 format. - -```js -now() -``` - -{{% note %}} -`now()` is cached at runtime, so all instances of `now()` in a Flux script -return the same value. -{{% /note %}} - -### Current system time -Import the `system` package and use the [`system.time()` function](/flux/v0/stdlib/system/time/) -to return the current system time of the host machine in RFC3339 format. - -```js -import "system" - -system.time() -``` - -{{% note %}} -`system.time()` returns the time it is executed, so each instance of `system.time()` -in a Flux script returns a unique value. -{{% /note %}} - -## Normalize irregular timestamps -To normalize irregular timestamps, truncate all `_time` values to a specified unit -with the [`truncateTimeColumn()` function](/flux/v0/stdlib/universe/truncatetimecolumn/). -This is useful in [`join()`](/flux/v0/stdlib/universe/join/) -and [`pivot()`](/flux/v0/stdlib/universe/pivot/) -operations where points should align by time, but timestamps vary slightly. - -```js -data - |> truncateTimeColumn(unit: 1m) -``` - -{{< flex >}} -{{% flex-content %}} -**Input:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:00:49Z | 2.0 | -| 2020-01-01T00:01:01Z | 1.9 | -| 2020-01-01T00:03:22Z | 1.8 | -| 2020-01-01T00:04:04Z | 1.9 | -| 2020-01-01T00:05:38Z | 2.1 | -{{% /flex-content %}} -{{% flex-content %}} -**Output:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:00:00Z | 2.0 | -| 2020-01-01T00:01:00Z | 1.9 | -| 2020-01-01T00:03:00Z | 1.8 | -| 2020-01-01T00:04:00Z | 1.9 | -| 2020-01-01T00:05:00Z | 2.1 | -{{% /flex-content %}} -{{< /flex >}} - -## Use timestamps and durations together -- [Add a duration to a timestamp](#add-a-duration-to-a-timestamp) -- [Subtract a duration from a timestamp](#subtract-a-duration-from-a-timestamp) - -### Add a duration to a timestamp -[`date.add()`](/flux/v0/stdlib/date/add/) -adds a duration to a specified time and returns the resulting time. - -```js -import "date" - -date.add(d: 6h, to: 2019-09-16T12:00:00Z) - -// Returns 2019-09-16T18:00:00.000000000Z -``` - -### Subtract a duration from a timestamp -[`date.sub()`](/flux/v0/stdlib/date/sub/) -subtracts a duration from a specified time and returns the resulting time. - -```js -import "date" - -date.sub(d: 6h, from: 2019-09-16T12:00:00Z) - -// Returns 2019-09-16T06:00:00.000000000Z -``` - -### Shift a timestamp forward or backward - -The [timeShift()](/flux/v0/stdlib/universe/timeshift/) function adds the specified duration of time to each value in time columns (`_start`, `_stop`, `_time`). - -Shift forward in time: - -```js -from(bucket: "example-bucket") - |> range(start: -5m) - |> timeShift(duration: 12h) -``` -Shift backward in time: - -```js -from(bucket: "example-bucket") - |> range(start: -5m) - |> timeShift(duration: -12h) -``` + diff --git a/content/influxdb/v2/query-data/flux/percentile-quantile.md b/content/influxdb/v2/query-data/flux/percentile-quantile.md index 8826cd3a2..bd5bcf72b 100644 --- a/content/influxdb/v2/query-data/flux/percentile-quantile.md +++ b/content/influxdb/v2/query-data/flux/percentile-quantile.md @@ -15,150 +15,8 @@ related: - /influxdb/v2/query-data/flux/query-median/ - /flux/v0/stdlib/universe/quantile/ list_query_example: quantile +source: /shared/influxdb-v2/query-data/flux/percentile-quantile.md --- -Use the [`quantile()` function](/flux/v0/stdlib/universe/quantile/) -to return a value representing the `q` quantile or percentile of input data. - -## Percentile versus quantile -Percentiles and quantiles are very similar, differing only in the number used to calculate return values. -A percentile is calculated using numbers between `0` and `100`. -A quantile is calculated using numbers between `0.0` and `1.0`. -For example, the **`0.5` quantile** is the same as the **50th percentile**. - -## Select a method for calculating the quantile -Select one of the following methods to calculate the quantile: - -- [estimate_tdigest](#estimate_tdigest) -- [exact_mean](#exact_mean) -- [exact_selector](#exact_selector) - -### estimate_tdigest -**(Default)** An aggregate method that uses a [t-digest data structure](https://github.com/tdunning/t-digest) -to compute a quantile estimate on large data sources. -Output tables consist of a single row containing the calculated quantile. - -If calculating the `0.5` quantile or 50th percentile: - -{{< flex >}} -{{% flex-content %}} -**Given the following input table:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:01:00Z | 1.0 | -| 2020-01-01T00:02:00Z | 1.0 | -| 2020-01-01T00:03:00Z | 2.0 | -| 2020-01-01T00:04:00Z | 3.0 | -{{% /flex-content %}} -{{% flex-content %}} -**`estimate_tdigest` returns:** - -| _value | -|:------:| -| 1.5 | -{{% /flex-content %}} -{{< /flex >}} - -### exact_mean -An aggregate method that takes the average of the two points closest to the quantile value. -Output tables consist of a single row containing the calculated quantile. - -If calculating the `0.5` quantile or 50th percentile: - -{{< flex >}} -{{% flex-content %}} -**Given the following input table:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:01:00Z | 1.0 | -| 2020-01-01T00:02:00Z | 1.0 | -| 2020-01-01T00:03:00Z | 2.0 | -| 2020-01-01T00:04:00Z | 3.0 | -{{% /flex-content %}} -{{% flex-content %}} -**`exact_mean` returns:** - -| _value | -|:------:| -| 1.5 | -{{% /flex-content %}} -{{< /flex >}} - -### exact_selector -A selector method that returns the data point for which at least `q` points are less than. -Output tables consist of a single row containing the calculated quantile. - -If calculating the `0.5` quantile or 50th percentile: - -{{< flex >}} -{{% flex-content %}} -**Given the following input table:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:01:00Z | 1.0 | -| 2020-01-01T00:02:00Z | 1.0 | -| 2020-01-01T00:03:00Z | 2.0 | -| 2020-01-01T00:04:00Z | 3.0 | -{{% /flex-content %}} -{{% flex-content %}} -**`exact_selector` returns:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:02:00Z | 1.0 | -{{% /flex-content %}} -{{< /flex >}} - -{{% note %}} -The examples below use the [example data variable](/influxdb/v2/query-data/flux/#example-data-variable). -{{% /note %}} - -## Find the value representing the 99th percentile -Use the default method, `"estimate_tdigest"`, to return all rows in a table that -contain values in the 99th percentile of data in the table. - -```js -data - |> quantile(q: 0.99) -``` - -## Find the average of values closest to the quantile -Use the `exact_mean` method to return a single row per input table containing the -average of the two values closest to the mathematical quantile of data in the table. -For example, to calculate the `0.99` quantile: - -```js -data - |> quantile(q: 0.99, method: "exact_mean") -``` - -## Find the point with the quantile value -Use the `exact_selector` method to return a single row per input table containing the -value that `q * 100`% of values in the table are less than. -For example, to calculate the `0.99` quantile: - -```js -data - |> quantile(q: 0.99, method: "exact_selector") -``` - -## Use quantile() with aggregateWindow() -[`aggregateWindow()`](/flux/v0/stdlib/universe/aggregatewindow/) -segments data into windows of time, aggregates data in each window into a single -point, and then removes the time-based segmentation. -It is primarily used to [downsample data](/influxdb/v2/process-data/common-tasks/downsample-data/). - -To specify the [quantile calculation method](#select-a-method-for-calculating-the-quantile) in -`aggregateWindow()`, use the [full function syntax](/flux/v0/stdlib/universe/aggregatewindow/#specify-parameters-of-the-aggregate-function): - -```js -data - |> aggregateWindow( - every: 5m, - fn: (tables=<-, column) => tables - |> quantile(q: 0.99, method: "exact_selector"), - ) -``` + diff --git a/content/influxdb/v2/query-data/flux/query-fields.md b/content/influxdb/v2/query-data/flux/query-fields.md index 1575fb808..2ad149253 100644 --- a/content/influxdb/v2/query-data/flux/query-fields.md +++ b/content/influxdb/v2/query-data/flux/query-fields.md @@ -21,56 +21,8 @@ list_code_example: | |> filter(fn: (r) => r._measurement == "example-measurement" and r.tag == "example-tag") |> filter(fn: (r) => r._field == "example-field") ``` +source: /shared/influxdb-v2/query-data/flux/query-fields.md --- -Use [`filter()`](/flux/v0/stdlib/universe/filter/) -to query data based on fields, tags, or any other column value. -`filter()` performs operations similar to the `SELECT` statement and the `WHERE` -clause in InfluxQL and other SQL-like query languages. - -## The filter() function -`filter()` has an `fn` parameter that expects a [predicate function](/influxdb/v2/reference/glossary/#predicate-function), -an anonymous function comprised of one or more [predicate expressions](/influxdb/v2/reference/glossary/#predicate-expression). -The predicate function evaluates each input row. -Rows that evaluate to `true` are **included** in the output data. -Rows that evaluate to `false` are **excluded** from the output data. - -```js -// ... - |> filter(fn: (r) => r._measurement == "example-measurement-name" ) -``` - -The `fn` predicate function requires an `r` argument, which represents each row -as `filter()` iterates over input data. -Key-value pairs in the row record represent columns and their values. -Use [dot notation or bracket notation](/flux/v0/data-types/composite/record/#reference-values-in-a-record) -to reference specific column values in the predicate function. -Use [logical operators](/flux/v0/spec/operators/#logical-operators) -to chain multiple predicate expressions together. - -```js -// Row record -r = {foo: "bar", baz: "quz"} - -// Example predicate function -(r) => r.foo == "bar" and r["baz"] == "quz" - -// Evaluation results -(r) => true and true -``` - -## Filter by fields and tags -The combination of [`from()`](/flux/v0/stdlib/influxdata/influxdb/from), -[`range()`](/flux/v0/stdlib/universe/range), -and `filter()` represent the most basic Flux query: - -1. Use `from()` to define your [bucket](/influxdb/v2/reference/glossary/#bucket). -2. Use `range()` to limit query results by time. -3. Use `filter()` to identify what rows of data to output. - -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "example-measurement-name" and r.mytagname == "example-tag-value") - |> filter(fn: (r) => r._field == "example-field-name") -``` + diff --git a/content/influxdb/v2/query-data/flux/rate.md b/content/influxdb/v2/query-data/flux/rate.md index fe0f86f75..ec79e932e 100644 --- a/content/influxdb/v2/query-data/flux/rate.md +++ b/content/influxdb/v2/query-data/flux/rate.md @@ -17,157 +17,8 @@ related: - /flux/v0/stdlib/universe/derivative/ - /flux/v0/stdlib/experimental/aggregate/rate/ list_query_example: rate_of_change +source: /shared/influxdb-v2/query-data/flux/rate.md --- - -Use [`derivative()`](/flux/v0/stdlib/universe/derivative/) -to calculate the rate of change between subsequent values or -[`aggregate.rate()`](/flux/v0/stdlib/experimental/aggregate/rate/) -to calculate the average rate of change per window of time. -If time between points varies, these functions normalize points to a common time interval -making values easily comparable. - -- [Rate of change between subsequent values](#rate-of-change-between-subsequent-values) -- [Average rate of change per window of time](#average-rate-of-change-per-window-of-time) - -## Rate of change between subsequent values -Use the [`derivative()` function](/flux/v0/stdlib/universe/derivative/) -to calculate the rate of change per unit of time between subsequent _non-null_ values. - -```js -data - |> derivative(unit: 1s) -``` - -By default, `derivative()` returns only positive derivative values and replaces negative values with _null_. -Calculated values are returned as [floats](/flux/v0/spec/types/#numeric-types). - -{{< flex >}} -{{% flex-content %}} -**Given the following input:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:00:00Z | 250 | -| 2020-01-01T00:04:00Z | 160 | -| 2020-01-01T00:12:00Z | 150 | -| 2020-01-01T00:19:00Z | 220 | -| 2020-01-01T00:32:00Z | 200 | -| 2020-01-01T00:51:00Z | 290 | -| 2020-01-01T01:00:00Z | 340 | -{{% /flex-content %}} -{{% flex-content %}} -**`derivative(unit: 1m)` returns:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:04:00Z | | -| 2020-01-01T00:12:00Z | | -| 2020-01-01T00:19:00Z | 10.0 | -| 2020-01-01T00:32:00Z | | -| 2020-01-01T00:51:00Z | 4.74 | -| 2020-01-01T01:00:00Z | 5.56 | -{{% /flex-content %}} -{{< /flex >}} - -Results represent the rate of change **per minute** between subsequent values with -negative values set to _null_. - -### Return negative derivative values -To return negative derivative values, set the `nonNegative` parameter to `false`, - -{{< flex >}} -{{% flex-content %}} -**Given the following input:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:00:00Z | 250 | -| 2020-01-01T00:04:00Z | 160 | -| 2020-01-01T00:12:00Z | 150 | -| 2020-01-01T00:19:00Z | 220 | -| 2020-01-01T00:32:00Z | 200 | -| 2020-01-01T00:51:00Z | 290 | -| 2020-01-01T01:00:00Z | 340 | -{{% /flex-content %}} -{{% flex-content %}} -**The following returns:** - -```js -|> derivative(unit: 1m, nonNegative: false) -``` - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:04:00Z | -22.5 | -| 2020-01-01T00:12:00Z | -1.25 | -| 2020-01-01T00:19:00Z | 10.0 | -| 2020-01-01T00:32:00Z | -1.54 | -| 2020-01-01T00:51:00Z | 4.74 | -| 2020-01-01T01:00:00Z | 5.56 | -{{% /flex-content %}} -{{< /flex >}} - -Results represent the rate of change **per minute** between subsequent values and -include negative values. - -## Average rate of change per window of time - -Use the [`aggregate.rate()` function](/flux/v0/stdlib/experimental/aggregate/rate/) -to calculate the average rate of change per window of time. - -```js -import "experimental/aggregate" - -data - |> aggregate.rate( - every: 1m, - unit: 1s, - groupColumns: ["tag1", "tag2"], - ) -``` - -`aggregate.rate()` returns the average rate of change (as a [float](/flux/v0/spec/types/#numeric-types)) -per `unit` for time intervals defined by `every`. -Negative values are replaced with _null_. - -{{% note %}} -`aggregate.rate()` does not support `nonNegative: false`. -{{% /note %}} - -{{< flex >}} -{{% flex-content %}} -**Given the following input:** - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:00:00Z | 250 | -| 2020-01-01T00:04:00Z | 160 | -| 2020-01-01T00:12:00Z | 150 | -| 2020-01-01T00:19:00Z | 220 | -| 2020-01-01T00:32:00Z | 200 | -| 2020-01-01T00:51:00Z | 290 | -| 2020-01-01T01:00:00Z | 340 | -{{% /flex-content %}} -{{% flex-content %}} -**The following returns:** - -```js -|> aggregate.rate( - every: 20m, - unit: 1m, -) -``` - -| _time | _value | -|:----- | ------:| -| 2020-01-01T00:20:00Z | 10.00 | -| 2020-01-01T00:40:00Z | | -| 2020-01-01T01:00:00Z | 4.74 | -| 2020-01-01T01:20:00Z | 5.56 | -{{% /flex-content %}} -{{< /flex >}} - -Results represent the **average change rate per minute** of every **20 minute interval** -with negative values set to _null_. -Timestamps represent the right bound of the time window used to average values. + diff --git a/content/influxdb/v2/query-data/flux/regular-expressions.md b/content/influxdb/v2/query-data/flux/regular-expressions.md index 541b50640..e7a129ac8 100644 --- a/content/influxdb/v2/query-data/flux/regular-expressions.md +++ b/content/influxdb/v2/query-data/flux/regular-expressions.md @@ -14,77 +14,8 @@ related: - /influxdb/v2/query-data/flux/query-fields/ - /flux/v0/stdlib/regexp/ list_query_example: regular_expressions +source: /shared/influxdb-v2/query-data/flux/regular-expressions.md --- -Regular expressions (regexes) are incredibly powerful when matching patterns in large collections of data. -With Flux, regular expressions are primarily used for evaluation logic in predicate functions for things -such as filtering rows, dropping and keeping columns, state detection, etc. -This guide shows how to use regular expressions in your Flux scripts. - -If you're just getting started with Flux queries, check out the following: - -- [Get started with Flux](/flux/v0/get-started/) for a conceptual overview of Flux and parts of a Flux query. -- [Execute queries](/influxdb/v2/query-data/execute-queries/) to discover a variety of ways to run your queries. - -## Go regular expression syntax -Flux uses Go's [regexp package](https://golang.org/pkg/regexp/) for regular expression search. -The links [below](#helpful-links) provide information about Go's regular expression syntax. - -## Regular expression operators -Flux provides two comparison operators for use with regular expressions. - -#### `=~` -When the expression on the left **MATCHES** the regular expression on the right, this evaluates to `true`. - -#### `!~` -When the expression on the left **DOES NOT MATCH** the regular expression on the right, this evaluates to `true`. - -## Regular expressions in Flux -When using regex matching in your Flux scripts, enclose your regular expressions with `/`. -The following is the basic regex comparison syntax: - -###### Basic regex comparison syntax -```js -expression =~ /regex/ -expression !~ /regex/ -``` -## Examples - -### Use a regex to filter by tag value -The following example filters records by the `cpu` tag. -It only keeps records for which the `cpu` is either `cpu0`, `cpu1`, or `cpu2`. - -```js -from(bucket: "example-bucket") - |> range(start: -15m) - |> filter(fn: (r) => r._measurement == "cpu" and r.cpu =~ /cpu[0-2]$/) -``` - -### Use a regex to filter by field key -The following example excludes records that do not have `_percent` in a field key. - -```js -from(bucket: "example-bucket") - |> range(start: -15m) - |> filter(fn: (r) => r._measurement == "mem" and r._field =~ /_percent/) -``` - -### Drop columns matching a regex -The following example drops columns whose names do not begin with `_`. - -```js -from(bucket: "example-bucket") - |> range(start: -15m) - |> filter(fn: (r) => r._measurement == "mem") - |> drop(fn: (column) => column !~ /^_.*/) -``` - -## Helpful links - -##### Syntax documentation -[regexp Syntax GoDoc](https://godoc.org/regexp/syntax) -[RE2 Syntax Overview](https://github.com/google/re2/wiki/Syntax) - -##### Go regex testers -[Regex Tester - Golang](https://regex-golang.appspot.com/assets/html/index.html) -[Regex101](https://regex101.com/) + diff --git a/content/influxdb/v2/query-data/flux/scalar-values.md b/content/influxdb/v2/query-data/flux/scalar-values.md index ddcbced57..ed5c900b1 100644 --- a/content/influxdb/v2/query-data/flux/scalar-values.md +++ b/content/influxdb/v2/query-data/flux/scalar-values.md @@ -23,282 +23,8 @@ list_code_example: | return _record._value } ``` +source: /shared/influxdb-v2/query-data/flux/scalar-values.md --- -Use Flux [dynamic query functions](/flux/v0/function-types/#dynamic-queries) -to extract scalar values from Flux query output. -This lets you, for example, dynamically set variables using query results. - -**To extract scalar values from output:** - -1. [Extract a column from the input stream](#extract-a-column) - _**or**_ [extract a row from the input stream](#extract-a-row). -2. Use the returned array or record to reference scalar values. - -_The samples on this page use the [sample data provided below](#sample-data)._ - -{{% note %}} -#### Output scalar values - -The InfluxDB `/api/v2/query` HTTP API endpoint and all clients that use it -(InfluxDB UI, `influx` CLI, etc.) only support queries that return a stream of tables. -This endpoint does not support raw scalar output. - -To output a scalar value as part of a stream of tables: - -1. Import the [`array` package](/flux/v0/stdlib/array/from/). -2. Use [`array.from()`](/flux/v0/stdlib/array/from/) and - [`display()`](/flux/v0/stdlib/universe/display/) to wrap the - literal representation of a scalar value in a stream of tables and return it - as output. - -{{< expand-wrapper >}} -{{% expand "View example" %}} - -```js -import "array" - -SFOTemps = - sampleData - |> findColumn( - fn: (key) => key._field == "temp" and key.location == "sfo", - column: "_value", - ) - -array.from(rows: [{ output: display(v: SFOTemps) }]) -``` - -##### Returns - -| output | -| :------------------------- | -| [ 65.1, 66.2, 66.3, 66.8 ] | - -{{% /expand %}} -{{< /expand-wrapper >}} -{{% /note %}} - -## Table extraction - -Flux formats query results as a stream of tables. -Both [`findColumn()`](/flux/v0/stdlib/universe/findcolumn/) -and [`findRecord()`](/flux/v0/stdlib/universe/findrecord/) -extract the first table in a stream of tables whose [group key](/flux/v0/get-started/data-model/#group-key) -values match the `fn` [predicate function](/flux/v0/get-started/syntax-basics/#predicate-functions). - -{{% note %}} -#### Extract the correct table - -Flux functions do not guarantee table order. -`findColumn()` and `findRecord()` extract only the **first** table that matches the `fn` predicate. -To extract the correct table, use the `fn` predicate function to specifically identify the table to extract or -filter and transform your data to minimize the number of tables piped-forward into the functions. -{{% /note %}} - -## Extract a column - -Use the [`findColumn()` function](/flux/v0/stdlib/universe/findcolumn/) -to output an array of values from a specific column in the extracted table. - -_See [Sample data](#sample-data) below._ - -```js -sampleData - |> findColumn( - fn: (key) => key._field == "temp" and key.location == "sfo", - column: "_value", - ) - -// Returns [65.1, 66.2, 66.3, 66.8] -``` - -{{% caption %}} -To return this value from the InfluxDB query API, InfluxDB UI, or influx CLI see -[Output scalar values](#output-scalar-values). -{{% /caption %}} - - -### Use extracted column values - -Use a variable to store the array of values. -In the example below, `SFOTemps` represents the array of values. -Reference a specific index (integer starting from `0`) in the array to return the -value at that index. - -_See [Sample data](#sample-data) below._ - -```js -SFOTemps = sampleData - |> findColumn( - fn: (key) => key._field == "temp" and key.location == "sfo", - column: "_value", - ) - -SFOTemps -// Returns [65.1, 66.2, 66.3, 66.8] - -SFOTemps[0] -// Returns 65.1 - -SFOTemps[2] -// Returns 66.3 -``` - -{{% caption %}} -To return this value from the InfluxDB query API, InfluxDB UI, or influx CLI see -[Output scalar values](#output-scalar-values). -{{% /caption %}} - -## Extract a row - -Use the [`findRecord()` function](/flux/v0/stdlib/universe/findrecord/) -to output data from a single row in the extracted table. -Specify the index of the row to output using the `idx` parameter. -The function outputs a record with key-value pairs for each column. - -```js -sampleData - |> findRecord( - fn: (key) => key._field == "temp" and key.location == "sfo", - idx: 0, - ) - -// Returns { -// _time:2019-11-11T12:00:00Z, -// _field:"temp", -// location:"sfo", -// _value: 65.1 -// } -``` - -{{% caption %}} -To return this value from the InfluxDB query API, InfluxDB UI, or influx CLI see -[Output scalar values](#output-scalar-values). -{{% /caption %}} - -### Use an extracted row record - -Use a variable to store the extracted row record. -In the example below, `tempInfo` represents the extracted row. -Use [dot or bracket notation](/flux/v0/data-types/composite/record/#dot-notation) -to reference keys in the record. - -```js -tempInfo = sampleData - |> findRecord( - fn: (key) => key._field == "temp" and key.location == "sfo", - idx: 0, - ) - -tempInfo -// Returns { -// _time:2019-11-11T12:00:00Z, -// _field:"temp", -// location:"sfo", -// _value: 65.1 -// } - -tempInfo._time -// Returns 2019-11-11T12:00:00Z - -tempInfo.location -// Returns sfo -``` - -{{% caption %}} -To return this value from the InfluxDB query API, InfluxDB UI, or influx CLI see -[Output scalar values](#output-scalar-values). -{{% /caption %}} - -## Example helper functions - -Create custom helper functions to extract scalar values from query output. - -##### Extract a scalar field value - -```js -// Define a helper function to extract field values -getFieldValue = (tables=<-, field) => { - extract = tables - |> findColumn(fn: (key) => key._field == field, column: "_value") - - return extract[0] -} - -// Use the helper function to define a variable -lastJFKTemp = sampleData - |> filter(fn: (r) => r.location == "kjfk") - |> last() - |> getFieldValue(field: "temp") - -lastJFKTemp -// Returns 71.2 -``` - -{{% caption %}} -To return this value from the InfluxDB query API, InfluxDB UI, or influx CLI see -[Output scalar values](#output-scalar-values). -{{% /caption %}} - -##### Extract scalar row data - -```js -// Define a helper function to extract a row as a record -getRow = (tables=<-, field, idx=0) => { - extract = tables - |> findRecord(fn: (key) => true, idx: idx) - - return extract -} - -// Use the helper function to define a variable -lastReported = sampleData - |> last() - |> getRow(field: "temp") - -"The last location to report was ${lastReported.location}. -The temperature was ${string(v: lastReported._value)}°F." - -// Returns: -// The last location to report was kord. -// The temperature was 38.9°F. -``` - -{{% caption %}} -To return this value from the InfluxDB query API, InfluxDB UI, or influx CLI see -[Output scalar values](#output-scalar-values). -{{% /caption %}} - ---- - -## Sample data - -The following sample data set represents fictional temperature metrics collected -from three locations. -It's formatted as an array of Flux [records](/flux/v0/data-types/composite/record/) -and structured as a stream of stables using [`array.from()` function](/flux/v0/stdlib/array/from/). - -Place the following at the beginning of your query to use the sample data: - -```js -import "array" - -sampleData = - array.from( - rows: [ - {_time: 2019-11-01T12:00:00Z, location: "sfo", _field: "temp", _value: 65.1}, - {_time: 2019-11-01T13:00:00Z, location: "sfo", _field: "temp", _value: 66.2}, - {_time: 2019-11-01T14:00:00Z, location: "sfo", _field: "temp", _value: 66.3}, - {_time: 2019-11-01T15:00:00Z, location: "sfo", _field: "temp", _value: 66.8}, - {_time: 2019-11-01T12:00:00Z, location: "kjfk", _field: "temp", _value: 69.4}, - {_time: 2019-11-01T13:00:00Z, location: "kjfk", _field: "temp", _value: 69.9}, - {_time: 2019-11-01T14:00:00Z, location: "kjfk", _field: "temp", _value: 71.0}, - {_time: 2019-11-01T15:00:00Z, location: "kjfk", _field: "temp", _value: 71.2}, - {_time: 2019-11-01T12:00:00Z, location: "kord", _field: "temp", _value: 46.4}, - {_time: 2019-11-01T13:00:00Z, location: "kord", _field: "temp", _value: 46.3}, - {_time: 2019-11-01T14:00:00Z, location: "kord", _field: "temp", _value: 42.7}, - {_time: 2019-11-01T15:00:00Z, location: "kord", _field: "temp", _value: 38.9}, - ], - ) - |> group(columns: ["location", "_field"]) -``` + diff --git a/content/influxdb/v2/query-data/flux/sort-limit.md b/content/influxdb/v2/query-data/flux/sort-limit.md index acc27c97e..4e3d09db1 100644 --- a/content/influxdb/v2/query-data/flux/sort-limit.md +++ b/content/influxdb/v2/query-data/flux/sort-limit.md @@ -17,52 +17,8 @@ related: - /flux/v0/stdlib/universe/sort - /flux/v0/stdlib/universe/limit list_query_example: sort_limit +source: /shared/influxdb-v2/query-data/flux/sort-limit.md --- -Use [`sort()`](/flux/v0/stdlib/universe/sort) -to order records within each table by specific columns and -[`limit()`](/flux/v0/stdlib/universe/limit) -to limit the number of records in output tables to a fixed number, `n`. - -If you're just getting started with Flux queries, check out the following: - -- [Get started with Flux](/flux/v0/get-started/) for a conceptual overview of Flux and parts of a Flux query. -- [Execute queries](/influxdb/v2/query-data/execute-queries/) to discover a variety of ways to run your queries. - -##### Example sorting system uptime - -The following example orders system uptime first by region, then host, then value. - -```js -from(bucket: "example-bucket") - |> range(start: -12h) - |> filter(fn: (r) => r._measurement == "system" and r._field == "uptime") - |> sort(columns: ["region", "host", "_value"]) -``` - -The [`limit()` function](/flux/v0/stdlib/universe/limit) -limits the number of records in output tables to a fixed number, `n`. -The following example shows up to 10 records from the past hour. - -```js -from(bucket:"example-bucket") - |> range(start:-1h) - |> limit(n:10) -``` - -You can use `sort()` and `limit()` together to show the top N records. -The example below returns the 10 top system uptime values sorted first by -region, then host, then value. - -```js -from(bucket: "example-bucket") - |> range(start: -12h) - |> filter(fn: (r) => r._measurement == "system" and r._field == "uptime") - |> sort(columns: ["region", "host", "_value"]) - |> limit(n: 10) -``` - -You now have created a Flux query that sorts and limits data. -Flux also provides the [`top()`](/flux/v0/stdlib/universe/top) -and [`bottom()`](/flux/v0/stdlib/universe/bottom) -functions to perform both of these functions at the same time. + diff --git a/content/influxdb/v2/query-data/flux/sql.md b/content/influxdb/v2/query-data/flux/sql.md index 09dea9018..882fcd369 100644 --- a/content/influxdb/v2/query-data/flux/sql.md +++ b/content/influxdb/v2/query-data/flux/sql.md @@ -26,353 +26,8 @@ list_code_example: | query: "SELECT * FROM example_table", ) ``` +source: /shared/influxdb-v2/query-data/flux/sql.md --- -The [Flux](/influxdb/v2/reference/flux) `sql` package provides functions for working with SQL data sources. -[`sql.from()`](/flux/v0/stdlib/sql/from/) lets you query SQL data sources -like [PostgreSQL](https://www.postgresql.org/), [MySQL](https://www.mysql.com/), -[Snowflake](https://www.snowflake.com/), [SQLite](https://www.sqlite.org/index.html), -[Microsoft SQL Server](https://www.microsoft.com/en-us/sql-server/default.aspx), -[Amazon Athena](https://aws.amazon.com/athena/) and [Google BigQuery](https://cloud.google.com/bigquery) -and use the results with InfluxDB dashboards, tasks, and other operations. - -- [Query a SQL data source](#query-a-sql-data-source) -- [Join SQL data with data in InfluxDB](#join-sql-data-with-data-in-influxdb) -- [Use SQL results to populate dashboard variables](#use-sql-results-to-populate-dashboard-variables) -- [Use secrets to store SQL database credentials](#use-secrets-to-store-sql-database-credentials) -- [Sample sensor data](#sample-sensor-data) - -If you're just getting started with Flux queries, check out the following: - -- [Get started with Flux](/flux/v0/get-started/) for a conceptual overview of Flux and parts of a Flux query. -- [Execute queries](/influxdb/v2/query-data/execute-queries/) to discover a variety of ways to run your queries. - -## Query a SQL data source -To query a SQL data source: - -1. Import the `sql` package in your Flux query -2. Use the `sql.from()` function to specify the driver, data source name (DSN), - and query used to query data from your SQL data source: - -{{< code-tabs-wrapper >}} -{{% code-tabs %}} -[PostgreSQL](#) -[MySQL](#) -[Snowflake](#) -[SQLite](#) -[SQL Server](#) -[Athena](#) -[BigQuery](#) -{{% /code-tabs %}} - -{{% code-tab-content %}} -```js -import "sql" - -sql.from( - driverName: "postgres", - dataSourceName: "postgresql://user:password@localhost", - query: "SELECT * FROM example_table", -) -``` -{{% /code-tab-content %}} - -{{% code-tab-content %}} -```js -import "sql" - -sql.from( - driverName: "mysql", - dataSourceName: "user:password@tcp(localhost:3306)/db", - query: "SELECT * FROM example_table", -) -``` -{{% /code-tab-content %}} - -{{% code-tab-content %}} -```js -import "sql" - -sql.from( - driverName: "snowflake", - dataSourceName: "user:password@account/db/exampleschema?warehouse=wh", - query: "SELECT * FROM example_table", -) -``` -{{% /code-tab-content %}} - -{{% code-tab-content %}} -```js -// NOTE: InfluxDB OSS and InfluxDB Cloud do not have access to -// the local filesystem and cannot query SQLite data sources. -// Use the Flux REPL to query an SQLite data source. - -import "sql" - -sql.from( - driverName: "sqlite3", - dataSourceName: "file:/path/to/test.db?cache=shared&mode=ro", - query: "SELECT * FROM example_table", -) -``` -{{% /code-tab-content %}} - -{{% code-tab-content %}} -```js -import "sql" - -sql.from( - driverName: "sqlserver", - dataSourceName: "sqlserver://user:password@localhost:1234?database=examplebdb", - query: "GO SELECT * FROM Example.Table", -) -``` - -_For information about authenticating with SQL Server using ADO-style parameters, -see [SQL Server ADO authentication](/flux/v0/stdlib/sql/from/#sql-server-ado-authentication)._ -{{% /code-tab-content %}} - -{{% code-tab-content %}} -```js -import "sql" -sql.from( - driverName: "awsathena", - dataSourceName: "s3://myorgqueryresults/?accessID=12ab34cd56ef®ion=region-name&secretAccessKey=y0urSup3rs3crEtT0k3n", - query: "GO SELECT * FROM Example.Table", -) -``` - -_For information about parameters to include in the Athena DSN, -see [Athena connection string](/flux/v0/stdlib/sql/from/#athena-connection-string)._ -{{% /code-tab-content %}} -{{% code-tab-content %}} -```js -import "sql" -sql.from( - driverName: "bigquery", - dataSourceName: "bigquery://projectid/?apiKey=mySuP3r5ecR3tAP1K3y", - query: "SELECT * FROM exampleTable", -) -``` - -_For information about authenticating with BigQuery, see -[BigQuery authentication parameters](/flux/v0/stdlib/sql/from/#bigquery-authentication-parameters)._ -{{% /code-tab-content %}} -{{< /code-tabs-wrapper >}} - -_See the [`sql.from()` documentation](/flux/v0/stdlib/sql/from/) for -information about required function parameters._ - -## Join SQL data with data in InfluxDB -One of the primary benefits of querying SQL data sources from InfluxDB -is the ability to enrich query results with data stored outside of InfluxDB. - -Using the [air sensor sample data](#sample-sensor-data) below, the following query -joins air sensor metrics stored in InfluxDB with sensor information stored in PostgreSQL. -The joined data lets you query and filter results based on sensor information -that isn't stored in InfluxDB. - -```js -// Import the "sql" package -import "sql" - -// Query data from PostgreSQL -sensorInfo = sql.from( - driverName: "postgres", - dataSourceName: "postgresql://localhost?sslmode=disable", - query: "SELECT * FROM sensors", -) - -// Query data from InfluxDB -sensorMetrics = from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "airSensors") - -// Join InfluxDB query results with PostgreSQL query results -join(tables: {metric: sensorMetrics, info: sensorInfo}, on: ["sensor_id"]) -``` - -## Use SQL results to populate dashboard variables -Use `sql.from()` to [create dashboard variables](/influxdb/v2/visualize-data/variables/create-variable/) -from SQL query results. -The following example uses the [air sensor sample data](#sample-sensor-data) below to -create a variable that lets you select the location of a sensor. - -```js -import "sql" - -sql.from( - driverName: "postgres", - dataSourceName: "postgresql://localhost?sslmode=disable", - query: "SELECT * FROM sensors", -) - |> rename(columns: {location: "_value"}) - |> keep(columns: ["_value"]) -``` - -Use the variable to manipulate queries in your dashboards. - -{{< img-hd src="/img/influxdb/2-0-sql-dashboard-variable.png" alt="Dashboard variable from SQL query results" />}} - ---- - -## Use secrets to store SQL database credentials -If your SQL database requires authentication, use [InfluxDB secrets](/influxdb/v2/admin/secrets/) -to store and populate connection credentials. -By default, InfluxDB base64-encodes and stores secrets in its internal key-value store, BoltDB. -For added security, [store secrets in Vault](/influxdb/v2/admin/secrets/use-vault/). - -### Store your database credentials as secrets -Use the [InfluxDB API](/influxdb/v2/reference/api/) or the [`influx` CLI](/influxdb/v2/reference/cli/influx/secret/) -to store your database credentials as secrets. - -{{< tabs-wrapper >}} -{{% tabs %}} -[InfluxDB API](#) -[influx CLI](#) -{{% /tabs %}} -{{% tab-content %}} -```sh -curl --request PATCH http://localhost:8086/api/v2/orgs//secrets \ - --header 'Authorization: Token YOURAUTHTOKEN' \ - --header 'Content-type: application/json' \ - --data '{ - "POSTGRES_HOST": "http://example.com", - "POSTGRES_USER": "example-username", - "POSTGRES_PASS": "example-password" -}' -``` - -**To store secrets, you need:** - -- [your organization ID](/influxdb/v2/admin/organizations/view-orgs/#view-your-organization-id) -- [your API token](/influxdb/v2/admin/tokens/view-tokens/) -{{% /tab-content %}} -{{% tab-content %}} -```sh -# Syntax -influx secret update -k - -# Example -influx secret update -k POSTGRES_PASS -``` - -**When prompted, enter your secret value.** - -{{% warn %}} -You can provide the secret value with the `-v`, `--value` flag, but the **plain text -secret may appear in your shell history**. - -```sh -influx secret update -k -v -``` -{{% /warn %}} -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -### Use secrets in your query -Import the `influxdata/influxdb/secrets` package and use [string interpolation](/flux/v0/spec/string-interpolation/) -to populate connection credentials with stored secrets in your Flux query. - -```js -import "sql" -import "influxdata/influxdb/secrets" - -POSTGRES_HOST = secrets.get(key: "POSTGRES_HOST") -POSTGRES_USER = secrets.get(key: "POSTGRES_USER") -POSTGRES_PASS = secrets.get(key: "POSTGRES_PASS") - -sql.from( - driverName: "postgres", - dataSourceName: "postgresql://${POSTGRES_USER}:${POSTGRES_PASS}@${POSTGRES_HOST}", - query: "SELECT * FROM sensors", -) -``` - ---- - -## Sample sensor data -The [air sensor sample data](#download-sample-air-sensor-data) and -[sample sensor information](#import-the-sample-sensor-information) simulate a -group of sensors that measure temperature, humidity, and carbon monoxide -in rooms throughout a building. -Each collected data point is stored in InfluxDB with a `sensor_id` tag that identifies -the specific sensor it came from. -Sample sensor information is stored in PostgreSQL. - -**Sample data includes:** - -- Simulated data collected from each sensor and stored in the `airSensors` measurement in **InfluxDB**: - - temperature - - humidity - - co - -- Information about each sensor stored in the `sensors` table in **PostgreSQL**: - - sensor_id - - location - - model_number - - last_inspected - -#### Download sample air sensor data - -1. [Create a bucket](/influxdb/v2/admin/buckets/create-bucket/) to store the data. -2. [Create an InfluxDB task](/influxdb/v2/process-data/manage-tasks/create-task/) - and use the [`sample.data()` function](/flux/v0/stdlib/influxdata/influxdb/sample/data/) - to download sample air sensor data every 15 minutes. - Write the downloaded sample data to your new bucket: - - ```js - import "influxdata/influxdb/sample" - - option task = {name: "Collect sample air sensor data", every: 15m} - - sample.data(set: "airSensor") - |> to(org: "example-org", bucket: "example-bucket") - ``` - -3. [Query your target bucket](/influxdb/v2/query-data/execute-queries/) after - the first task run to ensure the sample data is writing successfully. - - ```js - from(bucket: "example-bucket") - |> range(start: -1m) - |> filter(fn: (r) => r._measurement == "airSensors") - ``` - -#### Import the sample sensor information -1. [Download and install PostgreSQL](https://www.postgresql.org/download/). -2. Download the sample sensor information CSV. - - Download sample sensor information - -3. Use a PostgreSQL client (`psql` or a GUI) to create the `sensors` table: - - ``` - CREATE TABLE sensors ( - sensor_id character varying(50), - location character varying(50), - model_number character varying(50), - last_inspected date - ); - ``` - -4. Import the downloaded CSV sample data. - _Update the `FROM` file path to the path of the downloaded CSV sample data._ - - ``` - COPY sensors(sensor_id,location,model_number,last_inspected) - FROM '/path/to/sample-sensor-info.csv' DELIMITER ',' CSV HEADER; - ``` - -5. Query the table to ensure the data was imported correctly: - - ``` - SELECT * FROM sensors; - ``` - -#### Import the sample data dashboard -Download and import the Air Sensors dashboard to visualize the generated data: - -View Air Sensors dashboard JSON - -_For information about importing a dashboard, see [Create a dashboard](/influxdb/v2/visualize-data/dashboards/create-dashboard)._ + diff --git a/content/influxdb/v2/query-data/flux/window-aggregate.md b/content/influxdb/v2/query-data/flux/window-aggregate.md index 4183400c8..ebad92aa5 100644 --- a/content/influxdb/v2/query-data/flux/window-aggregate.md +++ b/content/influxdb/v2/query-data/flux/window-aggregate.md @@ -20,339 +20,8 @@ related: - /flux/v0/function-types/#aggregates, Flux aggregate functions - /flux/v0/function-types/#selectors, Flux selector functions list_query_example: aggregate_window +source: /shared/influxdb-v2/query-data/flux/window-aggregate.md --- -A common operation performed with time series data is grouping data into windows of time, -or "windowing" data, then aggregating windowed values into a new value. -This guide walks through windowing and aggregating data with Flux and demonstrates -how data is shaped in the process. - -If you're just getting started with Flux queries, check out the following: - -- [Get started with Flux](/flux/v0/get-started/) for a conceptual overview of Flux and parts of a Flux query. -- [Execute queries](/influxdb/v2/query-data/execute-queries/) to discover a variety of ways to run your queries. - -{{% note %}} -The following example is an in-depth walk-through of the steps required to window and aggregate data. -The [`aggregateWindow()` function](#summing-up) performs these operations for you, but understanding -how data is shaped in the process helps to successfully create your desired output. -{{% /note %}} - -## Data set -For the purposes of this guide, define a variable that represents your base data set. -The following example queries the memory usage of the host machine. - -```js -dataSet = from(bucket: "example-bucket") - |> range(start: -5m) - |> filter(fn: (r) => r._measurement == "mem" and r._field == "used_percent") - |> drop(columns: ["host"]) -``` - -{{% note %}} -This example drops the `host` column from the returned data since the memory data -is only tracked for a single host and it simplifies the output tables. -Dropping the `host` column is optional and not recommended if monitoring memory -on multiple hosts. -{{% /note %}} - -`dataSet` can now be used to represent your base data, which will look similar to the following: - -{{% truncate %}} -``` -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _time:time _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ------------------------------ ---------------------------- -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:50:00.000000000Z 71.11611366271973 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:50:10.000000000Z 67.39630699157715 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:50:20.000000000Z 64.16666507720947 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:50:30.000000000Z 64.19951915740967 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:50:40.000000000Z 64.2122745513916 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:50:50.000000000Z 64.22209739685059 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:51:00.000000000Z 64.6336555480957 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:51:10.000000000Z 64.16516304016113 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:51:20.000000000Z 64.18349742889404 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:51:30.000000000Z 64.20474052429199 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:51:40.000000000Z 68.65062713623047 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:51:50.000000000Z 67.20139980316162 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:52:00.000000000Z 70.9143877029419 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:52:10.000000000Z 64.14549350738525 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:52:20.000000000Z 64.15379047393799 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:52:30.000000000Z 64.1592264175415 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:52:40.000000000Z 64.18190002441406 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:52:50.000000000Z 64.28837776184082 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:53:00.000000000Z 64.29731845855713 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:53:10.000000000Z 64.36963081359863 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:53:20.000000000Z 64.37397003173828 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:53:30.000000000Z 64.44413661956787 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:53:40.000000000Z 64.42906856536865 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:53:50.000000000Z 64.44573402404785 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:54:00.000000000Z 64.48912620544434 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:54:10.000000000Z 64.49522972106934 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:54:20.000000000Z 64.48652744293213 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:54:30.000000000Z 64.49949741363525 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:54:40.000000000Z 64.4949197769165 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:54:50.000000000Z 64.49787616729736 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:55:00.000000000Z 64.49816226959229 -``` -{{% /truncate %}} - -## Windowing data -Use the [`window()` function](/flux/v0/stdlib/universe/window) -to group your data based on time bounds. -The most common parameter passed with the `window()` is `every` which -defines the duration of time between windows. -Other parameters are available, but for this example, window the base data -set into one minute windows. - -```js -dataSet - |> window(every: 1m) -``` - -{{% note %}} -The `every` parameter supports all [valid duration units](/flux/v0/spec/types/#duration-types), -including **calendar months (`1mo`)** and **years (`1y`)**. -{{% /note %}} - -Each window of time is output in its own table containing all records that fall within the window. - -{{% truncate %}} -###### window() output tables -``` -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _time:time _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ------------------------------ ---------------------------- -2018-11-03T17:50:00.000000000Z 2018-11-03T17:51:00.000000000Z used_percent mem 2018-11-03T17:50:00.000000000Z 71.11611366271973 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:51:00.000000000Z used_percent mem 2018-11-03T17:50:10.000000000Z 67.39630699157715 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:51:00.000000000Z used_percent mem 2018-11-03T17:50:20.000000000Z 64.16666507720947 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:51:00.000000000Z used_percent mem 2018-11-03T17:50:30.000000000Z 64.19951915740967 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:51:00.000000000Z used_percent mem 2018-11-03T17:50:40.000000000Z 64.2122745513916 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:51:00.000000000Z used_percent mem 2018-11-03T17:50:50.000000000Z 64.22209739685059 - - -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _time:time _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ------------------------------ ---------------------------- -2018-11-03T17:51:00.000000000Z 2018-11-03T17:52:00.000000000Z used_percent mem 2018-11-03T17:51:00.000000000Z 64.6336555480957 -2018-11-03T17:51:00.000000000Z 2018-11-03T17:52:00.000000000Z used_percent mem 2018-11-03T17:51:10.000000000Z 64.16516304016113 -2018-11-03T17:51:00.000000000Z 2018-11-03T17:52:00.000000000Z used_percent mem 2018-11-03T17:51:20.000000000Z 64.18349742889404 -2018-11-03T17:51:00.000000000Z 2018-11-03T17:52:00.000000000Z used_percent mem 2018-11-03T17:51:30.000000000Z 64.20474052429199 -2018-11-03T17:51:00.000000000Z 2018-11-03T17:52:00.000000000Z used_percent mem 2018-11-03T17:51:40.000000000Z 68.65062713623047 -2018-11-03T17:51:00.000000000Z 2018-11-03T17:52:00.000000000Z used_percent mem 2018-11-03T17:51:50.000000000Z 67.20139980316162 - - -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _time:time _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ------------------------------ ---------------------------- -2018-11-03T17:52:00.000000000Z 2018-11-03T17:53:00.000000000Z used_percent mem 2018-11-03T17:52:00.000000000Z 70.9143877029419 -2018-11-03T17:52:00.000000000Z 2018-11-03T17:53:00.000000000Z used_percent mem 2018-11-03T17:52:10.000000000Z 64.14549350738525 -2018-11-03T17:52:00.000000000Z 2018-11-03T17:53:00.000000000Z used_percent mem 2018-11-03T17:52:20.000000000Z 64.15379047393799 -2018-11-03T17:52:00.000000000Z 2018-11-03T17:53:00.000000000Z used_percent mem 2018-11-03T17:52:30.000000000Z 64.1592264175415 -2018-11-03T17:52:00.000000000Z 2018-11-03T17:53:00.000000000Z used_percent mem 2018-11-03T17:52:40.000000000Z 64.18190002441406 -2018-11-03T17:52:00.000000000Z 2018-11-03T17:53:00.000000000Z used_percent mem 2018-11-03T17:52:50.000000000Z 64.28837776184082 - - -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _time:time _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ------------------------------ ---------------------------- -2018-11-03T17:53:00.000000000Z 2018-11-03T17:54:00.000000000Z used_percent mem 2018-11-03T17:53:00.000000000Z 64.29731845855713 -2018-11-03T17:53:00.000000000Z 2018-11-03T17:54:00.000000000Z used_percent mem 2018-11-03T17:53:10.000000000Z 64.36963081359863 -2018-11-03T17:53:00.000000000Z 2018-11-03T17:54:00.000000000Z used_percent mem 2018-11-03T17:53:20.000000000Z 64.37397003173828 -2018-11-03T17:53:00.000000000Z 2018-11-03T17:54:00.000000000Z used_percent mem 2018-11-03T17:53:30.000000000Z 64.44413661956787 -2018-11-03T17:53:00.000000000Z 2018-11-03T17:54:00.000000000Z used_percent mem 2018-11-03T17:53:40.000000000Z 64.42906856536865 -2018-11-03T17:53:00.000000000Z 2018-11-03T17:54:00.000000000Z used_percent mem 2018-11-03T17:53:50.000000000Z 64.44573402404785 - - -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _time:time _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ------------------------------ ---------------------------- -2018-11-03T17:54:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:54:00.000000000Z 64.48912620544434 -2018-11-03T17:54:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:54:10.000000000Z 64.49522972106934 -2018-11-03T17:54:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:54:20.000000000Z 64.48652744293213 -2018-11-03T17:54:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:54:30.000000000Z 64.49949741363525 -2018-11-03T17:54:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:54:40.000000000Z 64.4949197769165 -2018-11-03T17:54:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:54:50.000000000Z 64.49787616729736 - - -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _time:time _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ------------------------------ ---------------------------- -2018-11-03T17:55:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:55:00.000000000Z 64.49816226959229 -``` -{{% /truncate %}} - -When visualized in the InfluxDB UI, each window table is displayed in a different color. - -![Windowed data](/img/flux/simple-windowed-data.png) - -## Aggregate data -[Aggregate functions](/flux/v0/function-types#aggregates) take the values -of all rows in a table and use them to perform an aggregate operation. -The result is output as a new value in a single-row table. - -Since windowed data is split into separate tables, aggregate operations run against -each table separately and output new tables containing only the aggregated value. - -For this example, use the [`mean()` function](/flux/v0/stdlib/universe/mean) -to output the average of each window: - -```js -dataSet - |> window(every: 1m) - |> mean() -``` - -{{% truncate %}} -###### mean() output tables -``` -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ---------------------------- -2018-11-03T17:50:00.000000000Z 2018-11-03T17:51:00.000000000Z used_percent mem 65.88549613952637 - - -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ---------------------------- -2018-11-03T17:51:00.000000000Z 2018-11-03T17:52:00.000000000Z used_percent mem 65.50651391347249 - - -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ---------------------------- -2018-11-03T17:52:00.000000000Z 2018-11-03T17:53:00.000000000Z used_percent mem 65.30719598134358 - - -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ---------------------------- -2018-11-03T17:53:00.000000000Z 2018-11-03T17:54:00.000000000Z used_percent mem 64.39330975214641 - - -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ---------------------------- -2018-11-03T17:54:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 64.49386278788249 - - -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ---------------------------- -2018-11-03T17:55:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 64.49816226959229 -``` -{{% /truncate %}} - -Because each data point is contained in its own table, when visualized, -they appear as single, unconnected points. - -![Aggregated windowed data](/img/flux/simple-windowed-aggregate-data.png) - -### Recreate the time column -**Notice the `_time` column is not in the [aggregated output tables](#mean-output-tables).** -Because records in each table are aggregated together, their timestamps no longer -apply and the column is removed from the group key and table. - -Also notice the `_start` and `_stop` columns still exist. -These represent the lower and upper bounds of the time window. - -Many Flux functions rely on the `_time` column. -To further process your data after an aggregate function, you need to re-add `_time`. -Use the [`duplicate()` function](/flux/v0/stdlib/universe/duplicate) to -duplicate either the `_start` or `_stop` column as a new `_time` column. - -```js -dataSet - |> window(every: 1m) - |> mean() - |> duplicate(column: "_stop", as: "_time") -``` - -{{% truncate %}} -###### duplicate() output tables -``` -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _time:time _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ------------------------------ ---------------------------- -2018-11-03T17:50:00.000000000Z 2018-11-03T17:51:00.000000000Z used_percent mem 2018-11-03T17:51:00.000000000Z 65.88549613952637 - - -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _time:time _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ------------------------------ ---------------------------- -2018-11-03T17:51:00.000000000Z 2018-11-03T17:52:00.000000000Z used_percent mem 2018-11-03T17:52:00.000000000Z 65.50651391347249 - - -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _time:time _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ------------------------------ ---------------------------- -2018-11-03T17:52:00.000000000Z 2018-11-03T17:53:00.000000000Z used_percent mem 2018-11-03T17:53:00.000000000Z 65.30719598134358 - - -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _time:time _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ------------------------------ ---------------------------- -2018-11-03T17:53:00.000000000Z 2018-11-03T17:54:00.000000000Z used_percent mem 2018-11-03T17:54:00.000000000Z 64.39330975214641 - - -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _time:time _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ------------------------------ ---------------------------- -2018-11-03T17:54:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:55:00.000000000Z 64.49386278788249 - - -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _time:time _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ------------------------------ ---------------------------- -2018-11-03T17:55:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:55:00.000000000Z 64.49816226959229 -``` -{{% /truncate %}} - -## "Unwindow" aggregate tables -Keeping aggregate values in separate tables generally isn't the format in which you want your data. -Use the `window()` function to "unwindow" your data into a single infinite (`inf`) window. - -```js -dataSet - |> window(every: 1m) - |> mean() - |> duplicate(column: "_stop", as: "_time") - |> window(every: inf) -``` - -{{% note %}} -Windowing requires a `_time` column which is why it's necessary to -[recreate the `_time` column](#recreate-the-time-column) after an aggregation. -{{% /note %}} - -###### Unwindowed output table -``` -Table: keys: [_start, _stop, _field, _measurement] - _start:time _stop:time _field:string _measurement:string _time:time _value:float ------------------------------- ------------------------------ ---------------------- ---------------------- ------------------------------ ---------------------------- -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:51:00.000000000Z 65.88549613952637 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:52:00.000000000Z 65.50651391347249 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:53:00.000000000Z 65.30719598134358 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:54:00.000000000Z 64.39330975214641 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:55:00.000000000Z 64.49386278788249 -2018-11-03T17:50:00.000000000Z 2018-11-03T17:55:00.000000000Z used_percent mem 2018-11-03T17:55:00.000000000Z 64.49816226959229 -``` - -With the aggregate values in a single table, data points in the visualization are connected. - -![Unwindowed aggregate data](/img/flux/simple-unwindowed-data.png) - -## Summing up -You have now created a Flux query that windows and aggregates data. -The data transformation process outlined in this guide should be used for all aggregation operations. - -Flux also provides the [`aggregateWindow()` function](/flux/v0/stdlib/universe/aggregatewindow) -which performs all these separate functions for you. - -The following Flux query will return the same results: - -###### aggregateWindow function -```js -dataSet - |> aggregateWindow(every: 1m, fn: mean) -``` + diff --git a/content/influxdb/v2/query-data/get-started/_index.md b/content/influxdb/v2/query-data/get-started/_index.md index 0b1e4ad4e..ad9e056e4 100644 --- a/content/influxdb/v2/query-data/get-started/_index.md +++ b/content/influxdb/v2/query-data/get-started/_index.md @@ -15,21 +15,8 @@ related: - /flux/v0/get-started/ - /flux/v0/ - /flux/v0/stdlib/ +source: /shared/influxdb-v2/query-data/get-started/_index.md --- -Flux is InfluxData's functional data scripting language designed for querying, -analyzing, and acting on data. - -These guides walks through important concepts related to Flux and querying time -series data from InfluxDB using Flux. - -## Tools for working with Flux -The [Execute queries](/influxdb/v2/query-data/execute-queries) guide walks through -the different tools available for querying InfluxDB with Flux. - -## Before you start -To get a basic understanding of the Flux data model and syntax, see -[Get started with Flux](/flux/v0/get-started/) in the -[Flux documentation](/flux/v0/). - -{{< page-nav next="/influxdb/v2/query-data/get-started/query-influxdb/" >}} + diff --git a/content/influxdb/v2/query-data/get-started/query-influxdb.md b/content/influxdb/v2/query-data/get-started/query-influxdb.md index 5094d5b04..f58970435 100644 --- a/content/influxdb/v2/query-data/get-started/query-influxdb.md +++ b/content/influxdb/v2/query-data/get-started/query-influxdb.md @@ -13,121 +13,8 @@ related: - /flux/v0/stdlib/influxdata/influxdb/from - /flux/v0/stdlib/universe/range - /flux/v0/stdlib/universe/filter +source: /shared/influxdb-v2/query-data/get-started/query-influxdb.md --- -This guide walks through the basics of using Flux to query data from InfluxDB. -Every Flux query needs the following: - -1. [A data source](#1-define-your-data-source) -2. [A time range](#2-specify-a-time-range) -3. [Data filters](#3-filter-your-data) - - -## 1. Define your data source -Flux's [`from()`](/flux/v0/stdlib/influxdata/influxdb/from/) function defines an InfluxDB data source. -It requires a [`bucket`](/flux/v0/stdlib/influxdata/influxdb/from/#bucket) parameter. -The following examples use `example-bucket` as the bucket name. - -```js -from(bucket:"example-bucket") -``` - -## 2. Specify a time range -Flux requires a time range when querying time series data. -"Unbounded" queries are very resource-intensive and as a protective measure, -Flux will not query the database without a specified range. - -Use the [pipe-forward operator](/flux/v0/get-started/syntax-basics/#pipe-forward-operator) -(`|>`) to pipe data from your data source into -[`range()`](/flux/v0/stdlib/universe/range), which specifies a time range for your query. -It accepts two parameters: `start` and `stop`. -Start and stop values can be **relative** using negative [durations](/flux/v0/data-types/basic/duration/) -or **absolute** using [timestamps](/flux/v0/data-types/basic/time/). - -###### Example relative time ranges -```js -// Relative time range with start only. Stop defaults to now. -from(bucket:"example-bucket") - |> range(start: -1h) - -// Relative time range with start and stop -from(bucket:"example-bucket") - |> range(start: -1h, stop: -10m) -``` - -{{% note %}} -Relative ranges are relative to "now." -{{% /note %}} - -###### Example absolute time range -```js -from(bucket:"example-bucket") - |> range(start: 2021-01-01T00:00:00Z, stop: 2021-01-01T12:00:00Z) -``` - -#### Use the following: -For this guide, use the relative time range, `-15m`, to limit query results to data from the last 15 minutes: - -```js -from(bucket:"example-bucket") - |> range(start: -15m) -``` - -## 3. Filter your data -Pass your ranged data into `filter()` to narrow results based on data attributes or columns. -`filter()` has one parameter, `fn`, which expects a -[predicate function](/flux/v0/get-started/syntax-basics/#predicate-functions) -evaluates rows by column values. - -`filter()` iterates over every input row and structures row data as a Flux -[record](/flux/v0/data-types/composite/record/). -The record is passed into the predicate function as `r` where it is evaluated using -[predicate expressions](/flux/v0/get-started/syntax-basics/#predicate-expressions). - -Rows that evaluate to `false` are dropped from the output data. -Rows that evaluate to `true` persist in the output data. - -```js -// Pattern -(r) => (r.recordProperty comparisonOperator comparisonExpression) - -// Example with single filter -(r) => (r._measurement == "cpu") - -// Example with multiple filters -(r) => (r._measurement == "cpu" and r._field != "usage_system") -``` - -#### Use the following: -For this example, filter by the `cpu` measurement, `usage_system` field, and -`cpu-total` tag value: - -```js -from(bucket: "example-bucket") - |> range(start: -15m) - |> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system" and r.cpu == "cpu-total") -``` - -## 4. Yield your queried data -[`yield()`](/flux/v0/stdlib/universe/yield/) outputs the result of the query. - -```js -from(bucket: "example-bucket") - |> range(start: -15m) - |> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system" and r.cpu == "cpu-total") - |> yield() -``` - -Flux automatically assumes a `yield()` function at -the end of each script to output and visualize the data. -Explicitly calling `yield()` is only necessary when including multiple queries -in the same Flux query. -Each set of returned data needs to be named using the `yield()` function. - -## Congratulations! -You have now queried data from InfluxDB using Flux. - -The query shown here is a basic example. -Flux queries can be extended in many ways to form powerful scripts. - -{{< page-nav prev="/influxdb/v2/query-data/get-started/" next="/influxdb/v2/query-data/get-started/transform-data/" >}} + diff --git a/content/influxdb/v2/query-data/get-started/transform-data.md b/content/influxdb/v2/query-data/get-started/transform-data.md index db5ed21ee..cd7364a8f 100644 --- a/content/influxdb/v2/query-data/get-started/transform-data.md +++ b/content/influxdb/v2/query-data/get-started/transform-data.md @@ -10,153 +10,8 @@ weight: 202 related: - /flux/v0/stdlib/universe/aggregatewindow - /flux/v0/stdlib/universe/window +source: /shared/influxdb-v2/query-data/get-started/transform-data.md --- -When [querying data from InfluxDB](/influxdb/v2/query-data/get-started/query-influxdb), -you often need to transform that data in some way. -Common examples are aggregating data, downsampling data, etc. - -This guide demonstrates using [Flux functions](/flux/v0/stdlib/) to transform your data. -It walks through creating a Flux script that partitions data into windows of time, -averages the `_value`s in each window, and outputs the averages as a new table. - -{{% note %}} -If you're not familiar with how Flux structures and operates on data, see -[Flux data model](/flux/v0/get-started/data-model/). -{{% /note %}} - -## Query data -Use the query built in the previous [Query data from InfluxDB](/influxdb/v2/query-data/get-started/query-influxdb) -guide, but update the range to pull data from the last hour: - -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system" and r.cpu == "cpu-total") -``` - -## Flux functions -Flux provides a number of functions that perform specific operations, transformations, and tasks. -You can also [create custom functions](/influxdb/v2/query-data/flux/custom-functions) in your Flux queries. -_Functions are covered in detail in the [Flux standard library](/flux/v0/stdlib/) documentation._ - -A common type of function used when transforming data queried from InfluxDB is an aggregate function. -Aggregate functions take a set of `_value`s in a table, aggregate them, and transform -them into a new value. - -This example uses the [`mean()` function](/flux/v0/stdlib/universe/mean) -to average values within each time window. - -{{% note %}} -The following example walks through the steps required to window and aggregate data, -but there is a [`aggregateWindow()` helper function](#helper-functions) that does it for you. -It's just good to understand the steps in the process. -{{% /note %}} - -## Window your data -Flux's [`window()` function](/flux/v0/stdlib/universe/window) partitions records based on a time value. -Use the `every` parameter to define a duration of each window. - -{{% note %}} -#### Calendar months and years -`every` supports all [valid duration units](/flux/v0/spec/types/#duration-types), -including **calendar months (`1mo`)** and **years (`1y`)**. -{{% /note %}} - -For this example, window data in five minute intervals (`5m`). - -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system" and r.cpu == "cpu-total") - |> window(every: 5m) -``` - -As data is gathered into windows of time, each window is output as its own table. -When visualized, each table is assigned a unique color. - -![Windowed data tables](/img/flux/windowed-data.png) - -## Aggregate windowed data -Flux aggregate functions take the `_value`s in each table and aggregate them in some way. -Use the [`mean()` function](/flux/v0/stdlib/universe/mean) to average the `_value`s of each table. - -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system" and r.cpu == "cpu-total") - |> window(every: 5m) - |> mean() -``` - -As rows in each window are aggregated, their output table contains only a single row with the aggregate value. -Windowed tables are all still separate and, when visualized, will appear as single, unconnected points. - -![Windowed aggregate data](/img/flux/windowed-aggregates.png) - -## Add times to your aggregates -As values are aggregated, the resulting tables do not have a `_time` column because -the records used for the aggregation all have different timestamps. -Aggregate functions don't infer what time should be used for the aggregate value. -Therefore the `_time` column is dropped. - -A `_time` column is required in the [next operation](#unwindow-aggregate-tables). -To add one, use the [`duplicate()` function](/flux/v0/stdlib/universe/duplicate) -to duplicate the `_stop` column as the `_time` column for each windowed table. - -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system" and r.cpu == "cpu-total") - |> window(every: 5m) - |> mean() - |> duplicate(column: "_stop", as: "_time") -``` - -## Unwindow aggregate tables - -Use the `window()` function with the `every: inf` parameter to gather all points -into a single, infinite window. - -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system" and r.cpu == "cpu-total") - |> window(every: 5m) - |> mean() - |> duplicate(column: "_stop", as: "_time") - |> window(every: inf) -``` - -Once ungrouped and combined into a single table, the aggregate data points will appear connected in your visualization. - -![Unwindowed aggregate data](/img/flux/windowed-aggregates-ungrouped.png) - -## Helper functions -This may seem like a lot of coding just to build a query that aggregates data, however going through the -process helps to understand how data changes "shape" as it is passed through each function. - -Flux provides (and allows you to create) "helper" functions that abstract many of these steps. -The same operation performed in this guide can be accomplished using -[`aggregateWindow()`](/flux/v0/stdlib/universe/aggregatewindow). - -```js -from(bucket: "example-bucket") - |> range(start: -1h) - |> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_system" and r.cpu == "cpu-total") - |> aggregateWindow(every: 5m, fn: mean) -``` - -## Congratulations! -You have now constructed a Flux query that uses Flux functions to transform your data. -There are many more ways to manipulate your data using both Flux's primitive functions -and your own custom functions, but this is a good introduction into the basic syntax and query structure. - ---- - -_For a deeper dive into windowing and aggregating data with example data output for each transformation, -view the [Window and aggregate data](/influxdb/v2/query-data/flux/window-aggregate) guide._ - ---- - -{{< page-nav prev="/influxdb/v2/query-data/get-started/query-influxdb/" >}} + diff --git a/content/influxdb/v2/query-data/influxql/_index.md b/content/influxdb/v2/query-data/influxql/_index.md index 701f0c5b2..a4ca6434b 100644 --- a/content/influxdb/v2/query-data/influxql/_index.md +++ b/content/influxdb/v2/query-data/influxql/_index.md @@ -14,147 +14,8 @@ related: - /influxdb/v2/reference/api/influxdb-1x/query - /influxdb/v2/reference/api/influxdb-1x/dbrp - /influxdb/v2/tools/influxql-shell/ +source: /shared/influxdb-v2/query-data/influxql/_index.md --- -Use InfluxQL (an SQL-like query language) to interact with InfluxDB, and query and analyze your times series data. - -In InfluxDB 1.x, data is stored in [databases](/influxdb/v1/concepts/glossary/#database) -and [retention policies](/influxdb/v1/concepts/glossary/#retention-policy-rp). -In InfluxDB OSS {{< current-version >}}, data is stored in [buckets](/influxdb/v2/reference/glossary/#bucket). -Because InfluxQL uses the 1.x data model, a bucket must be mapped to a database and retention policy (DBRP) before it can be queried using InfluxQL. - -**To query data with InfluxQL, complete the following steps:** - -1. [Verify buckets have a mapping](#verify-buckets-have-a-mapping). -2. [Create DBRP mappings for unmapped buckets](#create-dbrp-mappings-for-unmapped-buckets). -3. [Query a mapped bucket with InfluxQL](#query-a-mapped-bucket-with-influxql). - -{{% note %}} - -#### InfluxQL reference documentation - -For complete InfluxQL reference documentation, see the -[InfluxQL specification for InfluxDB 2.x](/influxdb/v2/reference/syntax/influxql/spec/). -{{% /note %}} - -## Verify buckets have a mapping - -1. To verify the buckets you want to query are mapped to a database and retention policy, use the [`influx` CLI](/influxdb/v2/reference/cli/influx/) or the [InfluxDB API](/influxdb/v2/reference/api/). -_For examples, see [List DBRP mappings](/influxdb/v2/query-data/influxql/dbrp/#list-dbrp-mappings)._ - -2. If you **do not find a DBRP mapping for a bucket**, [create a new DBRP mapping](/influxdb/v2/query-data/influxql/dbrp/#create-dbrp-mappings) to -map the unmapped bucket. - -## Create DBRP mappings for unmapped buckets - -- Use the [`influx` CLI](/influxdb/v2/reference/cli/influx/) or the [InfluxDB API](/influxdb/v2/reference/api/) -to manually create DBRP mappings for unmapped buckets. -_For examples, see [Create DBRP mappings](/influxdb/v2/query-data/influxql/dbrp/#create-dbrp-mappings)._ - -## Query a mapped bucket with InfluxQL - -{{< tabs-wrapper >}} -{{% tabs %}} -[InfluxQL shell](#) -[InfluxDB API](#) -{{% /tabs %}} -{{% tab-content %}} - - -The [`influx` CLI](/influxdb/v2/reference/cli/influx/) provides an [InfluxQL shell](/influxdb/v2/tools/influxql-shell/) where you can execute InfluxQL queries in an interactive Read-Eval-Print-Loop (REPL). - -1. If you haven't already, do the following: - - - [Download and install the `influx` CLI](/influxdb/v2/tools/influx-cli/#install-the-influx-cli) - - [Configure your authentication credentials](/influxdb/v2/tools/influx-cli/#provide-required-authentication-credentials) - -2. Use the following command to start an InfluxQL shell: - - ```sh - influx v1 shell - ``` - -3. Execute an InfluxQL query inside the InfluxQL shell. - - ```sql - SELECT used_percent FROM "example-db"."example-rp"."example-measurement" WHERE host=host1 - ``` - - For more information, see how to [use the InfluxQL shell](/influxdb/v2/tools/influxql-shell/). For more information about DBRP mappings, see [Manage DBRP mappings](/influxdb/v2/query-data/influxql/dbrp/). - - -{{% /tab-content %}} -{{% tab-content %}} - - -The [InfluxDB 1.x compatibility API](/influxdb/v2/reference/api/influxdb-1x/) supports -all InfluxDB 1.x client libraries and integrations in InfluxDB {{< current-version >}}. - -1. To query a mapped bucket with InfluxQL, use the [`/query` 1.x compatibility endpoint](/influxdb/v2/reference/api/influxdb-1x/query/), and include the following in your request: - - - **Request method:** `GET` - - **Headers:** - - **Authorization:** _See [compatibility API authentication](/influxdb/v2/reference/api/influxdb-1x/#authentication)_ - - **Query parameters:** - - **db**: 1.x database to query - - **rp**: 1.x retention policy to query _(if no retention policy is specified, InfluxDB uses the default retention policy for the specified database)_ - - **q**: URL-encoded InfluxQL query - - {{% api/url-encode-note %}} - - ```sh - curl --get http://localhost:8086/query?db=example-db \ - --header "Authorization: Token YourAuthToken" \ - --data-urlencode "q=SELECT used_percent FROM \"example-db\".\"example-rp\".\"example-measurement\" WHERE host=host1" - ``` - - By default, the `/query` compatibility endpoint returns results in **JSON**. - -2. (Optional) To return results as **CSV**, include the `Accept: application/csv` header. - -For more information about DBRP mappings, see [Manage DBRP mappings](/influxdb/v2/query-data/influxql/dbrp/). - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -## InfluxQL support - -InfluxDB OSS 2.x supports the following InfluxQL statements and clauses. See supported and unsupported queries below. - -{{< flex >}} -{{< flex-content >}} -{{% note %}} -##### Supported InfluxQL queries - -- `DELETE`* -- `DROP MEASUREMENT`* -- `EXPLAIN ANALYZE` -- `SELECT` _(read-only)_ -- `SHOW DATABASES` -- `SHOW SERIES` -- `SHOW MEASUREMENTS` -- `SHOW TAG KEYS` -- `SHOW FIELD KEYS` -- `SHOW SERIES EXACT CARDINALITY` -- `SHOW TAG KEY CARDINALITY` -- `SHOW FIELD KEY CARDINALITY` - -\* These commands delete data. -{{% /note %}} -{{< /flex-content >}} -{{< flex-content >}} -{{% warn %}} - -##### Unsupported InfluxQL queries - -- `SELECT INTO` -- `ALTER` -- `CREATE` -- `DROP` _(limited support)_ -- `GRANT` -- `KILL` -- `REVOKE` -- `SHOW SERIES CARDINALITY` -{{% /warn %}} -{{< /flex-content >}} -{{< /flex >}} + diff --git a/content/influxdb/v2/query-data/influxql/dbrp.md b/content/influxdb/v2/query-data/influxql/dbrp.md index ec32a0559..bade00d56 100644 --- a/content/influxdb/v2/query-data/influxql/dbrp.md +++ b/content/influxdb/v2/query-data/influxql/dbrp.md @@ -9,335 +9,8 @@ menu: parent: Query with InfluxQL weight: 201 influxdb/v2/tags: [influxql, dbrp] +source: /shared/influxdb-v2/query-data/influxql/dbrp.md --- -InfluxQL requires a database and retention policy (DBRP) combination in order to query data. -In InfluxDB {{< current-version >}}, databases and retention policies have been -combined and replaced by InfluxDB [buckets](/influxdb/v2/reference/glossary/#bucket). -To query InfluxDB {{< current-version >}} with InfluxQL, the specified DBRP -combination must be mapped to a bucket. - -- [Automatic DBRP mapping](#automatic-dbrp-mapping) -- {{% oss-only %}}[Virtual DBRP mappings](#virtual-dbrp-mappings){{% /oss-only %}} -- [Create DBRP mappings](#create-dbrp-mappings) -- [List DBRP mappings](#list-dbrp-mappings) -- [Update a DBRP mapping](#update-a-dbrp-mapping) -- [Delete a DBRP mapping](#delete-a-dbrp-mapping) - -## Automatic DBRP mapping - -InfluxDB {{< current-version >}} will automatically create DBRP mappings for you -during the following operations: - -- Writing to the [`/write` v1 compatibility endpoint](/influxdb/v2/reference/api/influxdb-1x/write/) -- {{% cloud-only %}}[Upgrading from InfluxDB 1.x to InfluxDB Cloud](/influxdb/v2/upgrade/v1-to-cloud/){{% /cloud-only %}} -- {{% oss-only %}}[Upgrading from InfluxDB 1.x to {{< current-version noSpan=true >}}](/influxdb/v2/upgrade/v1-to-v2/){{% /oss-only %}} -- {{% oss-only %}}Creating a bucket ([virtual DBRPs](#virtual-dbrp-mappings)){{% /oss-only %}} - -For more information, see [Database and retention policy mapping](/influxdb/v2/reference/api/influxdb-1x/dbrp/). - -{{% oss-only %}} - -## Virtual DBRP mappings - -InfluxDB {{< current-version >}} provides "virtual" DBRP mappings for any bucket -that does not have an explicit DBRP mapping associated with it. -Virtual DBRP mappings use the bucket name to provide a DBRP mapping that can be -used without having to explicitly define a mapping. - -Virtual DBRP mappings are read-only. -To override a virtual DBRP mapping, [create an explicit mapping](#create-dbrp-mappings). - -For information about how virtual DBRP mappings are created, see -[Database and retention policy mapping – When creating a bucket](/influxdb/v2/reference/api/influxdb-1x/dbrp/#when-creating-a-bucket). - -{{% /oss-only %}} - -## Create DBRP mappings - -Use the [`influx` CLI](/influxdb/v2/reference/cli/influx/) or the -[InfluxDB API](/influxdb/v2/reference/api/) to create DBRP mappings. - -{{% note %}} -#### A DBRP combination can only be mapped to a single bucket -Each unique DBRP combination can only be mapped to a single bucket. -If you map a DBRP combination that is already mapped to another bucket, -it will overwrite the existing DBRP mapping. -{{% /note %}} - -{{< tabs-wrapper >}} -{{% tabs %}} -[influx CLI](#) -[InfluxDB API](#) -{{% /tabs %}} -{{% tab-content %}} - -Use the [`influx v1 dbrp create` command](/influxdb/v2/reference/cli/influx/v1/dbrp/create/) -to map an unmapped bucket to a database and retention policy. -Include the following: - -{{< req type="key" >}} - -- {{< req "\*" >}} **org** and **token** to authenticate. We recommend setting your organization and token to your active InfluxDB connection configuration in the influx CLI, so you don't have to add these parameters to each command. To set up your active InfluxDB configuration, see [`influx config set`](/influxdb/v2/reference/cli/influx/config/set/). -- {{< req "\*" >}} **database name** to map -- {{< req "\*" >}} **retention policy** name to map -- {{< req "\*" >}} [Bucket ID](/influxdb/v2/admin/buckets/view-buckets/#view-buckets-in-the-influxdb-ui) to map to -- **Default flag** to set the provided retention policy as the default retention policy for the database - -```sh -influx v1 dbrp create \ - --db example-db \ - --rp example-rp \ - --bucket-id 00oxo0oXx000x0Xo \ - --default -``` - -{{% /tab-content %}} -{{% tab-content %}} - -Use the [`/api/v2/dbrps` API endpoint](/influxdb/v2/api/#operation/PostDBRP) to create a new DBRP mapping. - -{{< api-endpoint endpoint="http://localhost:8086/api/v2/dbrps" method="POST" api-ref="/influxdb/v2/api/#operation/PostDBRP" >}} - -Include the following: - -- **Request method:** `POST` -- **Headers:** - - **Authorization:** `Token` schema with your InfluxDB [API token](/influxdb/v2/admin/tokens/) - - **Content-type:** `application/json` -- **Request body:** JSON object with the following fields: - {{< req type="key" >}} - - {{< req "\*" >}} **bucketID:** [bucket ID](/influxdb/v2/admin/buckets/view-buckets/) - - {{< req "\*" >}} **database:** database name - - **default:** set the provided retention policy as the default retention policy for the database - - {{< req "\*" >}} **org** or **orgID:** organization name or [organization ID](/influxdb/v2/admin/organizations/view-orgs/#view-your-organization-id) - - {{< req "\*" >}} **retention_policy:** retention policy name - - -```sh -curl --request POST http://localhost:8086/api/v2/dbrps \ - --header "Authorization: Token YourAuthToken" \ - --header 'Content-type: application/json' \ - --data '{ - "bucketID": "00oxo0oXx000x0Xo", - "database": "example-db", - "default": true, - "orgID": "00oxo0oXx000x0Xo", - "retention_policy": "example-rp" - }' -``` - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -## List DBRP mappings - -Use the [`influx` CLI](/influxdb/v2/reference/cli/influx/) or the [InfluxDB API](/influxdb/v2/reference/api/) -to list all DBRP mappings and verify the buckets you want to query are mapped -to a database and retention policy. - -{{< tabs-wrapper >}} -{{% tabs %}} -[influx CLI](#) -[InfluxDB API](#) -{{% /tabs %}} -{{% tab-content %}} - -Use the [`influx v1 dbrp list` command](/influxdb/v2/reference/cli/influx/v1/dbrp/list/) to list DBRP mappings. - -{{% note %}} -The examples below assume that your organization and API token are -provided by the active [InfluxDB connection configuration](/influxdb/v2/reference/cli/influx/config/) in the `influx` CLI. -If not, include your organization (`--org`) and API token (`--token`) with each command. -{{% /note %}} - -##### View all DBRP mappings -```sh -influx v1 dbrp list -``` - -##### Filter DBRP mappings by database -```sh -influx v1 dbrp list --db example-db -``` - -##### Filter DBRP mappings by bucket ID -```sh -influx v1 dbrp list --bucket-id 00oxo0oXx000x0Xo -``` -{{% /tab-content %}} -{{% tab-content %}} -Use the [`/api/v2/dbrps` API endpoint](/influxdb/v2/api/#operation/GetDBRPs) to list DBRP mappings. - -{{< api-endpoint endpoint="http://localhost:8086/api/v2/dbrps" method="GET" api-ref="/influxdb/v2/api/#operation/GetDBRPs" >}} - -Include the following: - -- **Request method:** `GET` -- **Headers:** - - **Authorization:** `Token` schema with your InfluxDB [API token](/influxdb/v2/admin/tokens/) -- **Query parameters:** - {{< req type="key" >}} - - {{< req "\*" >}} **orgID:** [organization ID](/influxdb/v2/admin/organizations/view-orgs/#view-your-organization-id) - - **bucketID:** [bucket ID](/influxdb/v2/admin/buckets/view-buckets/) _(to list DBRP mappings for a specific bucket)_ - - **database:** database name _(to list DBRP mappings with a specific database name)_ - - **rp:** retention policy name _(to list DBRP mappings with a specific retention policy name)_ - - **id:** DBRP mapping ID _(to list a specific DBRP mapping)_ - -##### View all DBRP mappings -```sh -curl --request GET \ - http://localhost:8086/api/v2/dbrps?orgID=00oxo0oXx000x0Xo \ - --header "Authorization: Token YourAuthToken" -``` - -##### Filter DBRP mappings by database -```sh -curl --request GET \ - http://localhost:8086/api/v2/dbrps?orgID=00oxo0oXx000x0Xo&db=example-db \ - --header "Authorization: Token YourAuthToken" -``` - -##### Filter DBRP mappings by bucket ID -```sh -curl --request GET \ - https://cloud2.influxdata.com/api/v2/dbrps?organization_id=00oxo0oXx000x0Xo&bucketID=00oxo0oXx000x0Xo \ - --header "Authorization: Token YourAuthToken" -``` -{{% /tab-content %}} -{{% /tabs-wrapper %}} - -## Update a DBRP mapping - -Use the [`influx` CLI](/influxdb/v2/reference/cli/influx/) or the -[InfluxDB API](/influxdb/v2/reference/api/) to update a DBRP mapping. - -{{% oss-only %}} - -{{% note %}} -Virtual DBRP mappings cannot be updated. -To override a virtual DBRP mapping, [create an explicit mapping](#create-dbrp-mappings). -{{% /note %}} - -{{% /oss-only %}} - -{{< tabs-wrapper >}} -{{% tabs %}} -[influx CLI](#) -[InfluxDB API](#) -{{% /tabs %}} -{{% tab-content %}} - -Use the [`influx v1 dbrp update` command](/influxdb/v2/reference/cli/influx/v1/dbrp/update/) -to update a DBRP mapping. -Include the following: - -{{< req type="key" >}} - -- {{< req "\*" >}} **org** and **token** to authenticate. We recommend setting your organization and token to your active InfluxDB connection configuration in the influx CLI, so you don't have to add these parameters to each command. To set up your active InfluxDB configuration, see [`influx config set`](/influxdb/v2/reference/cli/influx/config/set/). -- {{< req "\*" >}} **DBRP mapping ID** to update -- **Retention policy** name to update to -- **Default flag** to set the retention policy as the default retention policy for the database - -##### Update the default retention policy -```sh -influx v1 dbrp update \ - --id 00oxo0X0xx0XXoX0 - --rp example-rp \ - --default -``` - -{{% /tab-content %}} -{{% tab-content %}} - -Use the [`/api/v2/dbrps/{dbrpID}` API endpoint](/influxdb/v2/api/#operation/GetDBRPs) to update DBRP mappings. - -{{< api-endpoint endpoint="http://localhost:8086/api/v2/dbrps/{dbrpID}" method="PATCH" api-ref="/influxdb/v2/api/#operation/PatchDBRPID" >}} - -Include the following: - -{{< req type="key" >}} - -- **Request method:** `PATCH` -- **Headers:** - - {{< req "\*" >}} **Authorization:** `Token` schema with your InfluxDB [API token](/influxdb/v2/admin/tokens/) -- **Path parameters:** - - {{< req "\*" >}} **id:** DBRP mapping ID to update -- **Query parameters:** - - {{< req "\*" >}} **orgID:** [organization ID](/influxdb/v2/admin/organizations/view-orgs/#view-your-organization-id) -- **Request body (JSON):** - - **rp:** retention policy name to update to - - **default:** set the retention policy as the default retention policy for the database - -##### Update the default retention policy -```sh -curl --request PATCH \ - http://localhost:8086/api/v2/dbrps/00oxo0X0xx0XXoX0?orgID=00oxo0oXx000x0Xo \ - --header "Authorization: Token YourAuthToken" - --data '{ - "rp": "example-rp", - "default": true - }' -``` -{{% /tab-content %}} -{{% /tabs-wrapper %}} - -## Delete a DBRP mapping - -Use the [`influx` CLI](/influxdb/v2/reference/cli/influx/) or the -[InfluxDB API](/influxdb/v2/reference/api/) to delete a DBRP mapping. - -{{% oss-only %}} - -{{% note %}} -Virtual DBRP mappings cannot be deleted. -{{% /note %}} - -{{% /oss-only %}} - -{{< tabs-wrapper >}} -{{% tabs %}} -[influx CLI](#) -[InfluxDB API](#) -{{% /tabs %}} -{{% tab-content %}} - -Use the [`influx v1 dbrp delete` command](/influxdb/v2/reference/cli/influx/v1/dbrp/delete/) -to delete a DBRP mapping. -Include the following: - -{{< req type="key" >}} - -- {{< req "\*" >}} **org** and **token** to authenticate. We recommend setting your organization and token to your active InfluxDB connection configuration in the influx CLI, so you don't have to add these parameters to each command. To set up your active InfluxDB configuration, see [`influx config set`](/influxdb/v2/reference/cli/influx/config/set/). -- {{< req "\*" >}} **DBRP mapping ID** to delete - -```sh -influx v1 dbrp delete --id 00oxo0X0xx0XXoX0 -``` - -{{% /tab-content %}} -{{% tab-content %}} - -Use the [`/api/v2/dbrps/{dbrpID}` API endpoint](/influxdb/v2/api/#operation/DeleteDBRPID) to delete a DBRP mapping. - -{{< api-endpoint endpoint="http://localhost:8086/api/v2/dbrps/{dbrpID}" method="DELETE" api-ref="/influxdb/v2/api/#operation/DeleteDBRPID" >}} - -Include the following: - -{{< req type="key" >}} - -- **Request method:** `PATCH` -- **Headers:** - - {{< req "\*" >}} **Authorization:** `Token` schema with your InfluxDB [API token](/influxdb/v2/admin/tokens/) -- **Path parameters:** - - {{< req "\*" >}} **id:** DBRP mapping ID to update -- **Query parameters:** - - {{< req "\*" >}} **orgID:** [organization ID](/influxdb/v2/admin/organizations/view-orgs/#view-your-organization-id) - -```sh -curl --request DELETE \ - http://localhost:8086/api/v2/dbrps/00oxo0X0xx0XXoX0?orgID=00oxo0oXx000x0Xo \ - --header "Authorization: Token YourAuthToken" -``` -{{% /tab-content %}} -{{% /tabs-wrapper %}} + diff --git a/content/influxdb/v2/query-data/influxql/explore-data/_index.md b/content/influxdb/v2/query-data/influxql/explore-data/_index.md index c135c116e..463459e7f 100644 --- a/content/influxdb/v2/query-data/influxql/explore-data/_index.md +++ b/content/influxdb/v2/query-data/influxql/explore-data/_index.md @@ -8,66 +8,8 @@ menu: name: Explore data parent: Query with InfluxQL weight: 202 +source: /shared/influxdb-v2/query-data/influxql/explore-data/_index.md --- -To start exploring data with InfluxQL, do the following: - -1. Verify your bucket has a database and retention policy (DBRP) mapping by [listing DBRP mappings for your bucket](/influxdb/v2/query-data/influxql/dbrp/#list-dbrp-mappings). If not, [create a new DBRP mapping](/influxdb/v2/query-data/influxql/dbrp/#create-dbrp-mappings). - -2. [Configure timestamps in the InfluxQL shell](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/). - -3. _(Optional)_ If you would like to use the data used in the examples below, [download the NOAA sample data](#download-sample-data). - -4. Use the InfluxQL `SELECT` statement with other key clauses to explore your data. - -{{< children type="anchored-list" >}} - -{{< children readmore=true hr=true >}} - -## Download sample data - -The example InfluxQL queries in this documentation use publicly available [National Oceanic and Atmospheric Administration (NOAA)](https://www.noaa.gov/) data. - -To download a subset of NOAA data used in examples, run the script under [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data) (for example, copy and paste the script into your Data Explorer - Script Editor), and replace "example-org" in the script with the name of your InfluxDB organization. - -Let's get acquainted with this subsample of the data in the `h2o_feet` measurement: - -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -|time | level description | location | water_level | -| :------------------- | :------------------ | :----------------------- |----------------------:| -| 2019-08-18T00:00:00Z | between 6 and 9 feet |coyote_creek | 8.1200000000 | -| 2019-08-18T00:00:00Z | below 3 feet | santa_monica | 2.0640000000 | -| 2019-08-18T00:06:00Z | between 6 and 9 feet | coyote_creek | 8.0050000000 | -| 2019-08-18T00:06:00Z | below 3 feet| santa_monica | 2.1160000000 | -| 2019-08-18T00:12:00Z | between 6 and 9 feet| coyote_creek | 7.8870000000 | -| 2019-08-18T00:12:00Z | below 3 feet | santa_monica | 2.0280000000 | - -The data in the `h2o_feet` [measurement](/influxdb/v2/reference/glossary/#measurement) -occurs at six-minute time intervals. -This measurement has one [tag key](/influxdb/v2/reference/glossary/#tag-key) -(`location`) which has two [tag values](/influxdb/v2/reference/glossary/#tag-value): -`coyote_creek` and `santa_monica`. -The measurement also has two [fields](/influxdb/v2/reference/glossary/#field): -`level description` stores string [field values](/influxdb/v2/reference/glossary/#field-value) -and `water_level` stores float field values. - - -### Configure timestamps in the InfluxQL shell - -By default, the [InfluxQL shell](/influxdb/v2/tools/influxql-shell/) returns timestamps in -nanosecond UNIX epoch format by default. -To return human-readable RFC3339 timestamps instead of Unix nanosecond timestamps, -use the [precision helper command](/influxdb/v2/tools/influxql-shell/#precision) ` to configure -the timestamp format: - -```sql -precision rfc3339 -``` - -The [InfluxDB API](/influxdb/v2/reference/api/influxdb-1x/) returns timestamps -in [RFC3339](https://www.ietf.org/rfc/rfc3339.txt) format by default. -Specify alternative formats with the [`epoch` query string parameter](/influxdb/v2/reference/api/influxdb-1x/). + diff --git a/content/influxdb/v2/query-data/influxql/explore-data/group-by.md b/content/influxdb/v2/query-data/influxql/explore-data/group-by.md index 54b11eed1..35d729d78 100644 --- a/content/influxdb/v2/query-data/influxql/explore-data/group-by.md +++ b/content/influxdb/v2/query-data/influxql/explore-data/group-by.md @@ -11,1184 +11,8 @@ list_code_example: | ```sql SELECT_clause FROM_clause [WHERE_clause] GROUP BY [* | [,` groups query results by one or more specified [tags](/influxdb/v2/reference/glossary/#tag). - -### Syntax - -```sql -SELECT_clause FROM_clause [WHERE_clause] GROUP BY [* | [,]] -``` - - - `GROUP BY *` - Groups results by all [tags](/influxdb/v2/reference/glossary/#tag) - - `GROUP BY ` - Groups results by a specific tag - - `GROUP BY ,` - Groups results by more than one tag. The order of the [tag keys](/influxdb/v2/reference/glossary/#tag-key) is irrelevant. - - `GROUP BY \regex\` - Groups results by tags that match the regular expression. - -If the query includes a `WHERE` clause, the `GROUP BY` clause must appear after the `WHERE` clause. - -### Examples - -{{< expand-wrapper >}} - -{{% expand "Group query results by a single tag" %}} - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" GROUP BY "location" -``` - -Output: -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | -----------: | -| 1970-01-01T00:00:00Z | 5.3591424203 | - -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=santa_monica -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | -----------: | -| 1970-01-01T00:00:00Z | 3.5307120942 | - -The query uses the InfluxQL [MEAN() function](/influxdb/v2/query-data/influxql/functions/) -to calculate the average `water_level` for each -[tag value](/influxdb/v2/reference/glossary/#tag-value) of `location` in -the `h2o_feet` [measurement](/influxdb/v2/reference/glossary/#measurement). -InfluxDB returns results in two [series](/influxdb/v2/reference/glossary/#series): one for each tag value of `location`. - -{{% note %}} -**Note:** In InfluxDB, [epoch 0](https://en.wikipedia.org/wiki/Unix_time) (`1970-01-01T00:00:00Z`) is often used as a null timestamp equivalent. -If you request a query that has no timestamp to return, such as an [aggregation function](/influxdb/v2/query-data/influxql/functions/aggregates/) with an unbounded time range, InfluxDB returns epoch 0 as the timestamp. -{{% /note %}} - -{{% /expand %}} - -{{% expand "Group query results by more than one tag" %}} - -```sql -SELECT MEAN("index") FROM "h2o_quality" GROUP BY "location","randtag" -``` -Output: -{{% influxql/table-meta %}} -name: h2o_quality -tags: location=coyote_creek, randtag=1 -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 1970-01-01T00:00:00Z | 50.6903376019 | - -{{% influxql/table-meta %}} -name: h2o_quality -tags: location=coyote_creek, randtag=2 -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 1970-01-01T00:00:00Z | 49.6618675442 | - -{{% influxql/table-meta %}} -name: h2o_quality -tags: location=coyote_creek, randtag=3 -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 1970-01-01T00:00:00Z | 49.3609399076 | - -{{% influxql/table-meta %}} -name: h2o_quality -tags: location=santa_monica, randtag=1 -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 1970-01-01T00:00:00Z | 49.1327124563 | - -{{% influxql/table-meta %}} -name: h2o_quality -tags: location=santa_monica, randtag=2 -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 1970-01-01T00:00:00Z | 50.2937984496 | - -{{% influxql/table-meta %}} -name: h2o_quality -tags: location=santa_monica, randtag=3 -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 1970-01-01T00:00:00Z | 49.9991990388 | - -The query uses the InfluxQL [MEAN() function](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) to calculate the average `index` for -each combination of the `location` tag and the `randtag` tag in the -`h2o_quality` measurement. -Separate multiple tags with a comma in the `GROUP BY` clause. - -{{% /expand %}} - -{{% expand "Group query results by all tags" %}} - -```sql -SELECT MEAN("index") FROM "h2o_quality" GROUP BY * -``` -Output: -{{% influxql/table-meta %}} -name: h2o_quality -tags: location=coyote_creek, randtag=1 -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 1970-01-01T00:00:00Z | 50.6903376019 | - -{{% influxql/table-meta %}} -name: h2o_quality -tags: location=coyote_creek, randtag=2 -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 1970-01-01T00:00:00Z | 49.6618675442 | - -{{% influxql/table-meta %}} -name: h2o_quality -tags: location=coyote_creek, randtag=3 -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 1970-01-01T00:00:00Z | 49.3609399076 | - -{{% influxql/table-meta %}} -name: h2o_quality -tags: location=santa_monica, randtag=1 -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 1970-01-01T00:00:00Z | 49.1327124563 | - -{{% influxql/table-meta %}} -name: h2o_quality -tags: location=santa_monica, randtag=2 -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 1970-01-01T00:00:00Z | 50.2937984496 | - -{{% influxql/table-meta %}} -name: h2o_quality -tags: location=santa_monica, randtag=3 -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 1970-01-01T00:00:00Z | 49.9991990388 | - -The query uses the InfluxQL [MEAN() function](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) to calculate the average `index` for every possible -[tag](/influxdb/v2/reference/glossary/#tag) combination in the `h2o_quality` -measurement. - -{{% /expand %}} - -{{% expand "Group query results by tags that start with `l`" %}} - -```sql -SELECT MAX("water_level"),location FROM "h2o_feet" GROUP BY /l/ -``` - -This query uses a regular expression to group by tags that start with `l`. -With the sample NOAA water dataset, results are grouped by the `location` tag. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## GROUP BY time intervals - -`GROUP BY time()` group query results by a user-specified time interval. -When using aggregate or selector functions in the `SELECT` clause, the operation is applied to each interval. - -### Basic GROUP BY time() syntax - -#### Syntax - -```sql -SELECT () FROM_clause WHERE GROUP BY time(),[tag_key] [fill()] -``` - -Basic `GROUP BY time()` queries require an InfluxQL [function](/influxdb/v2/query-data/influxql/functions) -in the `SELECT` clause and a time range in the `WHERE` clause. -Note that the `GROUP BY` clause must come **after** the `WHERE` clause. - -##### `time(time_interval)` - -The `time_interval` in the `GROUP BY time()` clause is a -[duration literal](/influxdb/v2/reference/glossary/#duration). -It determines how InfluxDB groups query results over time. -For example, a `time_interval` of `5m` groups query results into five-minute -time groups across the time range specified in the `WHERE` clause. - -##### `fill()` - -`fill()` is optional. -It changes the value reported for time intervals with no data. -See [GROUP BY time intervals and `fill()`](#group-by-time-intervals-and-fill) -for more information. - -**Coverage:** - -Basic `GROUP BY time()` queries rely on the `time_interval` and InfluxDB's -preset time boundaries to determine the raw data included in each time interval -and the timestamps returned by the query. - -### Examples of basic syntax - -The examples below use the following subsample of the sample data: - -```sql -SELECT "water_level","location" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | location | -| :------------------- | -----------: | :----------- | -| 2019-08-18T00:00:00Z | 8.5040000000 | coyote_creek | -| 2019-08-18T00:00:00Z | 2.3520000000 | santa_monica | -| 2019-08-18T00:06:00Z | 8.4190000000 | coyote_creek | -| 2019-08-18T00:06:00Z | 2.3790000000 | santa_monica | -| 2019-08-18T00:12:00Z | 8.3200000000 | coyote_creek | -| 2019-08-18T00:12:00Z | 2.3430000000 | santa_monica | -| 2019-08-18T00:18:00Z | 8.2250000000 | coyote_creek | -| 2019-08-18T00:18:00Z | 2.3290000000 | santa_monica | -| 2019-08-18T00:24:00Z | 8.1300000000 | coyote_creek | -| 2019-08-18T00:24:00Z | 2.2640000000 | santa_monica | -| 2019-08-18T00:30:00Z | 8.0120000000 | coyote_creek | -| 2019-08-18T00:30:00Z | 2.2670000000 | santa_monica | - -{{< expand-wrapper >}} - -{{% expand "Group query results into 12 minute intervals" %}} - -```sql -SELECT COUNT("water_level") FROM "h2o_feet" WHERE "location"='coyote_creek' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' GROUP BY time(12m) -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | count | -| :------------------- | :----------: | -| 2019-08-18T00:00:00Z | 2.0000000000 | -| 2019-08-18T00:12:00Z | 2.0000000000 | -| 2019-08-18T00:24:00Z | 2.0000000000 | - -The query uses the InfluxQL [COUNT() function](/influxdb/v2/query-data/influxql/functions/aggregates/#count) to count the number of `water_level` points per location, per 12-minute interval. - -Each output row represents a single 12 minute interval. -The count for the first timestamp covers the raw data between `2019-08-18T00:00:00Z` -and up to, but not including, `2019-08-18T00:12:00Z`. -The count for the second timestamp covers the raw data between `2019-08-18T00:12:00Z` -and up to, but not including, `2019-08-18T00:24:00Z.` - -{{% /expand %}} - -{{% expand "Group query results into 12 minute intervals and by a tag key" %}} - -```sql -SELECT COUNT("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' GROUP BY time(12m),"location" -``` -Output: -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | count | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.0000000000 | -| 2019-08-18T00:12:00Z | 2.0000000000 | -| 2019-08-18T00:24:00Z | 2.0000000000 | - - -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=santa_monica -{{% /influxql/table-meta %}} - -| time | count | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.0000000000 | -| 2019-08-18T00:12:00Z | 2.0000000000 | -| 2019-08-18T00:24:00Z | 2.0000000000 | - -The query uses the InfluxQL [COUNT() function](/influxdb/v2/query-data/influxql/functions/aggregates/#count) -to count the number of `water_level` points per location, per 12 minute interval. -Note that the time interval and the tag key are separated by a comma in the -`GROUP BY` clause. - -The query returns two [series](/influxdb/v2/reference/glossary/#series) of results: one for each -[tag value](/influxdb/v2/reference/glossary/#tag-value) of the `location` tag. -The result for each timestamp represents a single 12 minute interval. -Each output row represents a single 12 minute interval. -and up to, but not including, `2019-08-18T00:12:00Z`. -The count for the second timestamp covers the raw data between `2019-08-18T00:12:00Z` -and up to, but not including, `2019-08-18T00:24:00Z.` - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Common issues with basic syntax - -##### Unexpected timestamps and values in query results - -With the basic syntax, InfluxDB relies on the `GROUP BY time()` interval -and on the system's preset time boundaries to determine the raw data included -in each time interval and the timestamps returned by the query. -In some cases, this can lead to unexpected results. - -**Example** - -Raw data: - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE "location"='coyote_creek' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:18:00Z' -``` - -Output: -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 8.5040000000 | -| 2019-08-18T00:06:00Z | 8.4190000000 | -| 2019-08-18T00:12:00Z | 8.3200000000 | -| 2019-08-18T00:18:00Z | 8.2250000000 | - -Query and results: - -The following example queries a 12-minute time range and groups results into 12-minute time intervals, but it returns **two** results: - -```sql -SELECT COUNT("water_level") FROM "h2o_feet" WHERE "location"='coyote_creek' AND time >= '2019-08-18T00:06:00Z' AND time < '2019-08-18T00:18:00Z' GROUP BY time(12m) -``` - -Output: -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | count | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 1.0000000000 | -| 2019-08-18T00:12:00Z | 1.0000000000 | - -{{% note %}} -**Note:** The timestamp in the first row of data occurs before the start of the queried time range. -{{% /note %}} - -Explanation: - -InfluxDB uses preset round-number time boundaries for `GROUP BY` intervals that are -independent of any time conditions in the `WHERE` clause. -When it calculates the results, all returned data must occur within the query's -explicit time range but the `GROUP BY` intervals will be based on the preset -time boundaries. - -The table below shows the preset time boundary, the relevant `GROUP BY time()` interval, the -points included, and the returned timestamp for each `GROUP BY time()` -interval in the results. - -| Time Interval Number | Preset Time Boundary | `GROUP BY time()` Interval | Points Included | Returned Timestamp | -| :------------------- | :------------------------------------------------------------- | :------------------------------------------------------------- | :-------------- | :--------------------- | -| 1 | `time >= 2019-08-18T00:00:00Z AND time < 2019-08-18T00:12:00Z` | `time >= 2019-08-18T00:06:00Z AND time < 2019-08-18T00:12:00Z` | `8.005` | `2019-08-18T00:00:00Z` | -| 2 | `time >= 2019-08-12T00:12:00Z AND time < 2019-08-18T00:24:00Z` | `time >= 2019-08-12T00:12:00Z AND time < 2019-08-18T00:18:00Z` | `7.887` | `2019-08-18T00:12:00Z` | - -The first preset 12-minute time boundary begins at `00:00` and ends just before -`00:12`. -Only one raw point (`8.005`) falls both within the query's first `GROUP BY time()` interval and in that -first time boundary. -Note that while the returned timestamp occurs before the start of the queried time range, -the query result excludes data that occur before the queried time range. - -The second preset 12-minute time boundary begins at `00:12` and ends just before -`00:24`. -Only one raw point (`7.887`) falls both within the query's second `GROUP BY time()` interval and in that -second time boundary. - -The [advanced `GROUP BY time()` syntax](#advanced-group-by-time-syntax) allows users to shift -the start time of the InfluxDB database's preset time boundaries. It shifts forward the preset time boundaries by six minutes such that -InfluxDB returns: - -Output: -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | count | -| :------------------- | ----: | -| 2019-08-18T00:06:00Z | 2 | - -### Advanced GROUP BY time() syntax - -#### Syntax - -```sql -SELECT () FROM_clause WHERE GROUP BY time(,),[tag_key] [fill()] -``` - -Advanced `GROUP BY time()` queries require an InfluxQL [function](/influxdb/v2/query-data/influxql/functions/) -in the `SELECT` clause and a time range in the -`WHERE` clause). Note that the `GROUP BY` clause must come after the `WHERE` clause. - -##### `time(time_interval,offset_interval)` - -See the [Basic GROUP BY time() Syntax](#basic-group-by-time-syntax) -for details on the `time_interval`. - -The `offset_interval` is a [duration literal](/influxdb/v2/reference/glossary/#duration). -It shifts forward or back the InfluxDB database's preset time boundaries. -The `offset_interval` can be positive or negative. - -##### `fill()` - -`fill()` is optional. -It changes the value reported for time intervals with no data. -See [GROUP BY time intervals and `fill()`](#group-by-time-intervals-and-fill) -for more information. - -**Coverage:** - -Advanced `GROUP BY time()` queries rely on the `time_interval`, the `offset_interval` -, and on the InfluxDB database's preset time boundaries to determine the raw data included in each time interval -and the timestamps returned by the query. - -### Examples of advanced syntax - -The examples below use the following subsample of the sample data: - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE "location"='coyote_creek' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:54:00Z' -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 8.5040000000 | -| 2019-08-18T00:06:00Z | 8.4190000000 | -| 2019-08-18T00:12:00Z | 8.3200000000 | -| 2019-08-18T00:18:00Z | 8.2250000000 | -| 2019-08-18T00:24:00Z | 8.1300000000 | -| 2019-08-18T00:30:00Z | 8.0120000000 | -| 2019-08-18T00:36:00Z | 7.8940000000 | -| 2019-08-18T00:42:00Z | 7.7720000000 | -| 2019-08-18T00:48:00Z | 7.6380000000 | -| 2019-08-18T00:54:00Z | 7.5100000000 | - -{{< expand-wrapper >}} - -{{% expand "Group query results into 18 minute intervals and shift the preset time boundaries forward" %}} - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" WHERE "location"='coyote_creek' AND time >= '2019-08-18T00:06:00Z' AND time <= '2019-08-18T00:54:00Z' GROUP BY time(18m,6m) -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | -----------: | -| 2019-08-18T00:06:00Z | 8.3213333333 | -| 2019-08-18T00:24:00Z | 8.0120000000 | -| 2019-08-18T00:42:00Z | 7.6400000000 | - -The query uses the InfluxQL [MEAN() function](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) -to calculate the average `water_level`, grouping results into 18 minute time intervals, and offsetting the preset time boundaries by 6 minutes. - -The time boundaries and returned timestamps for the query **without** the `offset_interval` adhere to the InfluxDB database's preset time boundaries. Let's first examine the results without the offset: - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" WHERE "location"='coyote_creek' AND time >= '2019-08-18T00:06:00Z' AND time <= '2019-08-18T00:54:00Z' GROUP BY time(18m) -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 8.3695000000 | -| 2019-08-18T00:18:00Z | 8.1223333333 | -| 2019-08-18T00:36:00Z | 7.7680000000 | -| 2019-08-18T00:54:00Z | 7.5100000000 | - -The time boundaries and returned timestamps for the query **without** the -`offset_interval` adhere to the InfluxDB database's preset time boundaries: - -| Time Interval Number | Preset Time Boundary | `GROUP BY time()` Interval | Points Included | Returned Timestamp | -| :------------------- | :------------------------------------------------------------- | :------------------------------------------------------------- | :--------------------- | :--------------------- | -| 1 | `time >= 2019-08-18T00:00:00Z AND time < 2019-08-18T00:18:00Z` | `time >= 2019-08-18T00:06:00Z AND time < 2019-08-18T00:18:00Z` | `8.005`,`7.887` | `2019-08-18T00:00:00Z` | -| 2 | `time >= 2019-08-18T00:18:00Z AND time < 2019-08-18T00:36:00Z` | <--- same | `7.762`,`7.635`,`7.5` | `2019-08-18T00:18:00Z` | -| 3 | `time >= 2019-08-18T00:36:00Z AND time < 2019-08-18T00:54:00Z` | <--- same | `7.372`,`7.234`,`7.11` | `2019-08-18T00:36:00Z` | -| 4 | `time >= 2019-08-18T00:54:00Z AND time < 2019-08-18T01:12:00Z` | `time = 2019-08-18T00:54:00Z` | `6.982` | `2019-08-18T00:54:00Z` | - -The first preset 18-minute time boundary begins at `00:00` and ends just before -`00:18`. Two raw points (`8.005` and `7.887`) fall both within the first `GROUP BY time()` interval and in that -first time boundary. While the returned timestamp occurs before the start of the queried time range, -the query result excludes data that occur before the queried time range. - -The second preset 18-minute time boundary begins at `00:18` and ends just before -`00:36`. Three raw points (`7.762` and `7.635` and `7.5`) fall both within the second `GROUP BY time()` interval and in that -second time boundary. In this case, the boundary time range and the interval's time range are the same. - -The fourth preset 18-minute time boundary begins at `00:54` and ends just before -`1:12:00`. One raw point (`6.982`) falls both within the fourth `GROUP BY time()` interval and in that -fourth time boundary. - -The time boundaries and returned timestamps for the query **with** the `offset_interval` adhere to the offset time boundaries: - -| Time Interval Number | Offset Time Boundary | `GROUP BY time()` Interval | Points Included | Returned Timestamp | -| :------------------- | :------------------------------------------------------------- | :------------------------- | :---------------------- | ---------------------- | -| 1 | `time >= 2019-08-18T00:06:00Z AND time < 2019-08-18T00:24:00Z` | <--- same | `8.005`,`7.887`,`7.762` | `2019-08-18T00:06:00Z` | -| 2 | `time >= 2019-08-18T00:24:00Z AND time < 2019-08-18T00:42:00Z` | <--- same | `7.635`,`7.5`,`7.372` | `2019-08-18T00:24:00Z` | -| 3 | `time >= 2019-08-18T00:42:00Z AND time < 2019-08-18T01:00:00Z` | <--- same | `7.234`,`7.11`,`6.982` | `2019-08-18T00:42:00Z` | -| 4 | `time >= 2019-08-18T01:00:00Z AND time < 2019-08-18T01:18:00Z` | NA | NA | NA | - -The six-minute offset interval shifts forward the preset boundary's time range -such that the boundary time ranges and the relevant `GROUP BY time()` interval time ranges are -always the same. -With the offset, each interval performs the calculation on three points, and -the timestamp returned matches both the start of the boundary time range and the -start of the `GROUP BY time()` interval time range. - -Note that `offset_interval` forces the fourth time boundary to be outside -the queried time range so the query returns no results for that last interval. - -{{% /expand %}} - -{{% expand "Group query results into 12 minute intervals and shift the preset time boundaries back" %}} - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" WHERE "location"='coyote_creek' AND time >= '2019-08-18T00:06:00Z' AND time <= '2019-08-18T00:54:00Z' GROUP BY time(18m,-12m) -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | -----------: | -| 2019-08-18T00:06:00Z | 8.3213333333 | -| 2019-08-18T00:24:00Z | 8.0120000000 | -| 2019-08-18T00:42:00Z | 7.6400000000 | - - -The query uses the InfluxQL [MEAN() function](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) to calculate the average `water_level`, grouping results into 18 minute -time intervals, and offsetting the preset time boundaries by -12 minutes. - -{{% note %}} -**Note:** The query in Example 2 returns the same results as the query in Example 1, but -the query in Example 2 uses a negative `offset_interval` instead of a positive -`offset_interval`. -There are no performance differences between the two queries; feel free to choose the most -intuitive option when deciding between a positive and negative `offset_interval`. -{{% /note %}} - -The time boundaries and returned timestamps for the query **without** the `offset_interval` adhere to InfluxDB database's preset time boundaries. Let's first examine the results without the offset: - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" WHERE "location"='coyote_creek' AND time >= '2019-08-18T00:06:00Z' AND time <= '2019-08-18T00:54:00Z' GROUP BY time(18m) -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 8.3695000000 | -| 2019-08-18T00:18:00Z | 8.1223333333 | -| 2019-08-18T00:36:00Z | 7.7680000000 | -| 2019-08-18T00:54:00Z | 7.5100000000 | - -The time boundaries and returned timestamps for the query **without** the -`offset_interval` adhere to the InfluxDB database's preset time boundaries: - -| Time Interval Number | Preset Time Boundary | `GROUP BY time()` Interval | Points Included | Returned Timestamp | -| :------------------- | :------------------------------------------------------------- | :------------------------------------------------------------- | :--------------------- | :--------------------- | -| 1 | `time >= 2019-08-18T00:00:00Z AND time < 2019-08-18T00:18:00Z` | `time >= 2019-08-18T00:06:00Z AND time < 2019-08-18T00:18:00Z` | `8.005`,`7.887` | `2019-08-18T00:00:00Z` | -| 2 | `time >= 2019-08-18T00:18:00Z AND time < 2019-08-18T00:36:00Z` | <--- same | `7.762`,`7.635`,`7.5` | `2019-08-18T00:18:00Z` | -| 3 | `time >= 2019-08-18T00:36:00Z AND time < 2019-08-18T00:54:00Z` | <--- same | `7.372`,`7.234`,`7.11` | `2019-08-18T00:36:00Z` | -| 4 | `time >= 2019-08-18T00:54:00Z AND time < 2019-08-18T01:12:00Z` | `time = 2019-08-18T00:54:00Z` | `6.982` | `2019-08-18T00:54:00Z` | - -The first preset 18-minute time boundary begins at `00:00` and ends just before -`00:18`. -Two raw points (`8.005` and `7.887`) fall both within the first `GROUP BY time()` interval and in that -first time boundary. -Note that while the returned timestamp occurs before the start of the queried time range, -the query result excludes data that occur before the queried time range. - -The second preset 18-minute time boundary begins at `00:18` and ends just before -`00:36`. -Three raw points (`7.762` and `7.635` and `7.5`) fall both within the second `GROUP BY time()` interval and in that -second time boundary. In this case, the boundary time range and the interval's time range are the same. - -The fourth preset 18-minute time boundary begins at `00:54` and ends just before -`1:12:00`. -One raw point (`6.982`) falls both within the fourth `GROUP BY time()` interval and in that -fourth time boundary. - -The time boundaries and returned timestamps for the query **with** the -`offset_interval` adhere to the offset time boundaries: - -| Time Interval Number | Offset Time Boundary | `GROUP BY time()` Interval | Points Included | Returned Timestamp | -| :------------------- | :------------------------------------------------------------- | :------------------------- | :---------------------- | ---------------------- | -| 1 | `time >= 2019-08-17T23:48:00Z AND time < 2019-08-18T00:06:00Z` | NA | NA | NA | -| 2 | `time >= 2019-08-18T00:06:00Z AND time < 2019-08-18T00:24:00Z` | <--- same | `8.005`,`7.887`,`7.762` | `2019-08-18T00:06:00Z` | -| 3 | `time >= 2019-08-18T00:24:00Z AND time < 2019-08-18T00:42:00Z` | <--- same | `7.635`,`7.5`,`7.372` | `2019-08-18T00:24:00Z` | -| 4 | `time >= 2019-08-18T00:42:00Z AND time < 2019-08-18T01:00:00Z` | <--- same | `7.234`,`7.11`,`6.982` | `2019-08-18T00:42:00Z` | - -The negative 12-minute offset interval shifts back the preset boundary's time range -such that the boundary time ranges and the relevant `GROUP BY time()` interval time ranges are always the -same. -With the offset, each interval performs the calculation on three points, and -the timestamp returned matches both the start of the boundary time range and the -start of the `GROUP BY time()` interval time range. - -Note that `offset_interval` forces the first time boundary to be outside -the queried time range so the query returns no results for that first interval. - -{{% /expand %}} - -{{% expand "Group query results into 12 minute intervals and shift the preset time boundaries forward" %}} - -This example is a continuation of the scenario outlined in [Common Issues with Basic Syntax](#common-issues-with-basic-syntax). - -```sql -SELECT COUNT("water_level") FROM "h2o_feet" WHERE "location"='coyote_creek' AND time >= '2019-08-18T00:06:00Z' AND time < '2019-08-18T00:18:00Z' GROUP BY time(12m,6m) -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | count | -| :------------------- | -----------: | -| 2019-08-18T00:06:00Z | 2.0000000000 | - -The query uses the InfluxQL [COUNT() function](/influxdb/v2/query-data/influxql/functions/aggregates/#count) to count the number of `water_level` points per location, per 12-minute interval, and offset the preset time boundaries by six minutes. - -The time boundaries and returned timestamps for the query **without** the `offset_interval` adhere to InfluxDB database's preset time boundaries. Let's first examine the results without the offset: - -```sql -SELECT COUNT("water_level") FROM "h2o_feet" WHERE "location"='coyote_creek' AND time >= '2019-08-18T00:06:00Z' AND time < '2019-08-18T00:18:00Z' GROUP BY time(12m) -``` - -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | count | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 1.0000000000 | -| 2019-08-18T00:12:00Z | 1.0000000000 | - -The time boundaries and returned timestamps for the query **without** the `offset_interval` adhere to InfluxDB database's preset time boundaries: - -| Time Interval Number | Preset Time Boundary | `GROUP BY time()` Interval | Points Included | Returned Timestamp | -| :------------------- | :------------------------------------------------------------- | :------------------------------------------------------------- | :-------------- | :--------------------- | -| 1 | `time >= 2019-08-18T00:00:00Z AND time < 2019-08-18T00:12:00Z` | `time >= 2019-08-18T00:06:00Z AND time < 2019-08-18T00:12:00Z` | `8.005` | `2019-08-18T00:00:00Z` | -| 2 | `time >= 2019-08-12T00:12:00Z AND time < 2019-08-18T00:24:00Z` | `time >= 2019-08-12T00:12:00Z AND time < 2019-08-18T00:18:00Z` | `7.887` | `2019-08-18T00:12:00Z` | - -The first preset 12-minute time boundary begins at `00:00` and ends just before -`00:12`. -Only one raw point (`8.005`) falls both within the query's first `GROUP BY time()` interval and in that -first time boundary. -Note that while the returned timestamp occurs before the start of the queried time range, -the query result excludes data that occur before the queried time range. - -The second preset 12-minute time boundary begins at `00:12` and ends just before -`00:24`. -Only one raw point (`7.887`) falls both within the query's second `GROUP BY time()` interval and in that -second time boundary. - -The time boundaries and returned timestamps for the query **with** the -`offset_interval` adhere to the offset time boundaries: - -| Time Interval Number | Offset Time Boundary | `GROUP BY time()` Interval | Points Included | Returned Timestamp | -| :------------------- | :------------------------------------------------------------- | :------------------------- | :-------------- | :--------------------- | -| 1 | `time >= 2019-08-18T00:06:00Z AND time < 2019-08-18T00:18:00Z` | <--- same | `8.005`,`7.887` | `2019-08-18T00:06:00Z` | -| 2 | `time >= 2019-08-18T00:18:00Z AND time < 2019-08-18T00:30:00Z` | NA | NA | NA | - -The six-minute offset interval shifts forward the preset boundary's time range -such that the preset boundary time range and the relevant `GROUP BY time()` interval time range are the -same. With the offset, the query returns a single result, and the timestamp returned -matches both the start of the boundary time range and the start of the `GROUP BY time()` interval -time range. - -Note that `offset_interval` forces the second time boundary to be outside -the queried time range so the query returns no results for that second interval. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## `GROUP BY` time intervals and `fill()` - -`fill()` changes the value reported for time intervals with no data. - -#### Syntax - -```sql -SELECT () FROM_clause WHERE GROUP BY time(time_interval,[])[,tag_key] [fill()] -``` - -By default, a `GROUP BY time()` interval with no data reports `null` as its -value in the output column. -`fill()` changes the value reported for time intervals with no data. -Note that `fill()` must go at the end of the `GROUP BY` clause if you're -`GROUP(ing) BY` several things (for example, both [tags](/influxdb/v2/reference/glossary/#tag) and a time interval). - -##### fill_option - - - Any numerical value - Reports the given numerical value for time intervals with no data. - - `linear` - Reports the results of [linear interpolation](https://en.wikipedia.org/wiki/Linear_interpolation) for time intervals with no data. - - `none` - Reports no timestamp and no value for time intervals with no data. - - `null` - Reports null for time intervals with no data but returns a timestamp. This is the same as the default behavior. - - `previous` - Reports the value from the previous time interval for time intervals with no data. - -### Examples - -{{< tabs-wrapper >}} -{{% tabs "even-wrap" %}} -[fill(100)](#) -[fill(linear)](#) -[fill(none)](#) -[fill(null)](#) -[fill(previous)](#) -{{% /tabs %}} -{{% tab-content %}} - -Without `fill(100)`: - -```sql -SELECT MEAN("index") FROM "h2o_quality" WHERE "location"='santa_monica' AND time >= '2019-08-19T08:42:00Z' AND time <= '2019-08-19T09:30:00Z' GROUP BY time(5m) -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_quality -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 2019-08-19T08:40:00Z | 68.0000000000 | -| 2019-08-19T08:45:00Z | 29.0000000000 | -| 2019-08-19T08:50:00Z | 47.0000000000 | -| 2019-08-19T08:55:00Z | | -| 2019-08-19T09:00:00Z | 84.0000000000 | -| 2019-08-19T09:05:00Z | 0.0000000000 | -| 2019-08-19T09:10:00Z | 41.0000000000 | -| 2019-08-19T09:15:00Z | 13.0000000000 | -| 2019-08-19T09:20:00Z | 9.0000000000 | -| 2019-08-19T09:25:00Z | | -| 2019-08-19T09:30:00Z | 6.0000000000 | - -With `fill(100)`: -```sql -SELECT MEAN("index") FROM "h2o_quality" WHERE "location"='santa_monica' AND time >= '2019-08-19T08:42:00Z' AND time <= '2019-08-19T09:30:00Z' GROUP BY time(5m) fill(100) -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_quality -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | -------------: | -| 2019-08-19T08:40:00Z | 68.0000000000 | -| 2019-08-19T08:45:00Z | 29.0000000000 | -| 2019-08-19T08:50:00Z | 47.0000000000 | -| 2019-08-19T08:55:00Z | 100.0000000000 | -| 2019-08-19T09:00:00Z | 84.0000000000 | -| 2019-08-19T09:05:00Z | 0.0000000000 | -| 2019-08-19T09:10:00Z | 41.0000000000 | -| 2019-08-19T09:15:00Z | 13.0000000000 | -| 2019-08-19T09:20:00Z | 9.0000000000 | -| 2019-08-19T09:25:00Z | 100.0000000000 | -| 2019-08-19T09:30:00Z | 6.0000000000 | - -`fill(100)` changes the value reported for the time interval with no data to `100`. - -{{% /tab-content %}} - -{{% tab-content %}} - -Without `fill(linear)`: - -```sql -SELECT MEAN("tadpoles") FROM "pond" WHERE time >= '2019-11-11T21:00:00Z' AND time <= '2019-11-11T22:06:00Z' GROUP BY time(12m) -``` -Output: -{{% influxql/table-meta %}} -Name: pond -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ---: | -| 2019-11-11T21:00:00Z | 1 | -| 2019-11-11T21:12:00Z | | -| 2019-11-11T21:24:00Z | 3 | -| 2019-11-11T21:36:00Z | | -| 2019-11-11T21:48:00Z | | -| 2019-11-11T22:00:00Z | 6 | - -With `fill(linear)`: - -```sql -SELECT MEAN("tadpoles") FROM "pond" WHERE time >= '2019-11-11T21:00:00Z' AND time <= '2019-11-11T22:06:00Z' GROUP BY time(12m) fill(linear) -``` - -Output: -{{% influxql/table-meta %}} -Name: pond -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ---: | -| 2019-11-11T21:00:00Z | 1 | -| 2019-11-11T21:12:00Z | 2 | -| 2019-11-11T21:24:00Z | 3 | -| 2019-11-11T21:36:00Z | 4 | -| 2019-11-11T21:48:00Z | 5 | -| 2019-11-11T22:00:00Z | 6 | - -`fill(linear)` changes the value reported for the time interval with no data -to the results of [linear interpolation](https://en.wikipedia.org/wiki/Linear_interpolation). - -{{% note %}} -**Note:** The data in this example is not in the `noaa` database. -{{% /note %}} - -{{% /tab-content %}} - -{{% tab-content %}} - -Without `fill(none)`: - -```sql -SELECT MEAN("index") FROM "h2o_quality" WHERE "location"='santa_monica' AND time >= '2019-08-19T08:42:00Z' AND time <= '2019-08-19T09:30:00Z' GROUP BY time(5m) -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_quality -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 2019-08-19T08:40:00Z | 68.0000000000 | -| 019-08-19T08:45:00Z | 29.0000000000 | -| 2019-08-19T08:50:00Z | 47.0000000000 | -| 2019-08-19T08:55:00Z | | -| 2019-08-19T09:00:00Z | 84.0000000000 | -| 2019-08-19T09:05:00Z | 0.0000000000 | -| 2019-08-19T09:10:00Z | 41.0000000000 | -| 2019-08-19T09:15:00Z | 13.0000000000 | -| 2019-08-19T09:20:00Z | 9.0000000000 | -| 2019-08-19T09:25:00Z | | -| 2019-08-19T09:30:00Z | 6.0000000000 | - -With `fill(none)`: - -```sql -SELECT MEAN("index") FROM "h2o_quality" WHERE "location"='santa_monica' AND time >= '2019-08-19T08:42:00Z' AND time <= '2019-08-19T09:30:00Z' GROUP BY time(5m) fill(none) -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_quality -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 2019-08-19T08:40:00Z | 68.0000000000 | -| 2019-08-19T08:45:00Z | 29.0000000000 | -| 2019-08-19T08:50:00Z | 47.0000000000 | -| 2019-08-19T09:00:00Z | 84.0000000000 | -| 2019-08-19T09:05:00Z | 0.0000000000 | -| 2019-08-19T09:10:00Z | 41.0000000000 | -| 2019-08-19T09:15:00Z | 13.0000000000 | -| 2019-08-19T09:20:00Z | 9.0000000000 | -| 2019-08-19T09:30:00Z | 6.0000000000 | -``` - -`fill(none)` reports no value and no timestamp for the time interval with no data. - -{{% /tab-content %}} - -{{% tab-content %}} - -Without `fill(null)`: - -```sql -SELECT MEAN("index") FROM "h2o_quality" WHERE "location"='santa_monica' AND time >= '2019-08-19T08:42:00Z' AND time <= '2019-08-19T09:30:00Z' GROUP BY time(5m) -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_quality -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 2019-08-19T08:40:00Z | 68.0000000000 | -| 019-08-19T08:45:00Z | 29.0000000000 | -| 2019-08-19T08:50:00Z | 47.0000000000 | -| 2019-08-19T08:55:00Z | | -| 2019-08-19T09:00:00Z | 84.0000000000 | -| 2019-08-19T09:05:00Z | 0.0000000000 | -| 2019-08-19T09:10:00Z | 41.0000000000 | -| 2019-08-19T09:15:00Z | 13.0000000000 | -| 2019-08-19T09:20:00Z | 9.0000000000 | -| 2019-08-19T09:25:00Z | | -| 2019-08-19T09:30:00Z | 6.0000000000 | - -With `fill(null)`: - -```sql -SELECT MEAN("index") FROM "h2o_quality" WHERE "location"='santa_monica' AND time >= '2019-08-19T08:42:00Z' AND time <= '2019-08-19T09:30:00Z' GROUP BY time(5m) fill(null) -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_quality -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 2019-08-19T08:40:00Z | 68.0000000000 | -| 019-08-19T08:45:00Z | 29.0000000000 | -| 2019-08-19T08:50:00Z | 47.0000000000 | -| 2019-08-19T08:55:00Z | null | -| 2019-08-19T09:00:00Z | 84.0000000000 | -| 2019-08-19T09:05:00Z | 0.0000000000 | -| 2019-08-19T09:10:00Z | 41.0000000000 | -| 2019-08-19T09:15:00Z | 13.0000000000 | -| 2019-08-19T09:20:00Z | 9.0000000000 | -| 2019-08-19T09:25:00Z | null | -| 2019-08-19T09:30:00Z | 6.0000000000 | - -`fill(null)` reports `null` as the value for the time interval with no data. -That result matches the result of the query without `fill(null)`. - -{{% /tab-content %}} - -{{% tab-content %}} - -Without `fill(previous)`: - -```sql - SELECT MEAN("index") FROM "h2o_quality" WHERE "location"='santa_monica' AND time >= '2019-08-19T08:42:00Z' AND time <= '2019-08-19T09:30:00Z' GROUP BY time(5m) - ``` -Output: -{{% influxql/table-meta %}} -Name: h2o_quality -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 2019-08-19T08:40:00Z | 68.0000000000 | -| 019-08-19T08:45:00Z | 29.0000000000 | -| 2019-08-19T08:50:00Z | 47.0000000000 | -| 2019-08-19T08:55:00Z | | -| 2019-08-19T09:00:00Z | 84.0000000000 | -| 2019-08-19T09:05:00Z | 0.0000000000 | -| 2019-08-19T09:10:00Z | 41.0000000000 | -| 2019-08-19T09:15:00Z | 13.0000000000 | -| 2019-08-19T09:20:00Z | 9.0000000000 | -| 2019-08-19T09:25:00Z | | - -With `fill(previous)`: - -```sql -SELECT MEAN("index") FROM "h2o_quality" WHERE "location"='santa_monica' AND time >= '2019-08-19T08:42:00Z' AND time <= '2019-08-19T09:30:00Z' GROUP BY time(5m) fill(previous) - ``` -Output: -{{% influxql/table-meta %}} -Name: h2o_quality -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ------------: | -| 2019-08-19T08:40:00Z | 68.0000000000 | -| 019-08-19T08:45:00Z | 29.0000000000 | -| 2019-08-19T08:50:00Z | 47.0000000000 | -| 2019-08-19T08:55:00Z | 47.0000000000 | -| 2019-08-19T09:00:00Z | 84.0000000000 | -| 2019-08-19T09:05:00Z | 0.0000000000 | -| 2019-08-19T09:10:00Z | 41.0000000000 | -| 2019-08-19T09:15:00Z | 13.0000000000 | -| 2019-08-19T09:20:00Z | 9.0000000000 | -| 2019-08-19T09:25:00Z | 9.0000000000 | - -`fill(previous)` changes the value reported for the time interval with no data to `3.235`, -the value from the previous time interval. - -{{% /tab-content %}} -{{< /tabs-wrapper >}} - -### Common issues with `fill()` - -##### Queries with no data in the queried time range - -Currently, queries ignore `fill()` if no data exists in the queried time range. -This is the expected behavior. An open -[feature request](https://github.com/influxdata/influxdb/issues/6967) on GitHub -proposes that `fill()` should force a return of values even if the queried time -range covers no data. - -**Example** - -The following query returns no data because `water_level` has no points within -the queried time range. -Note that `fill(800)` has no effect on the query results. - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" WHERE "location" = 'coyote_creek' AND time >= '2019-09-18T22:00:00Z' AND time <= '2019-09-18T22:18:00Z' GROUP BY time(12m) fill(800) -> no results -``` - -##### Queries with `fill(previous)` when the previous result is outside the queried time range - -`fill(previous)` doesn’t fill the result for a time interval if the previous -value is outside the query’s time range. - -**Example** - -The following example queries the time range between `2019-09-18T16:24:00Z` and `2019-09-18T16:54:00Z`. -Note that `fill(previous)` fills the result for `2019-09-18T16:36:00Z` with the -result from `2019-09-18T16:24:00Z`. - -```sql -SELECT MAX("water_level") FROM "h2o_feet" WHERE location = 'coyote_creek' AND time >= '2019-09-18T16:24:00Z' AND time <= '2019-09-18T16:54:00Z' GROUP BY time(12m) fill(previous) -``` - -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | max | -| :------------------- | ----: | -| 2019-09-18T16:24:00Z | 3.235 | -| 2019-09-18T16:36:00Z | 3.235 | -| 2019-09-18T16:48:00Z | 4 | - - -The next example queries the time range between `2019-09-18T16:36:00Z` and `2019-09-18T16:54:00Z`. -Note that `fill(previous)` doesn't fill the result for `2019-09-18T16:36:00Z` with the -result from `2019-09-18T16:24:00Z`; the result for `2019-09-18T16:24:00Z` is outside the query's -shorter time range. - -```sql -SELECT MAX("water_level") FROM "h2o_feet" WHERE location = 'coyote_creek' AND time >= '2019-09-18T16:36:00Z' AND time <= '2019-09-18T16:54:00Z' GROUP BY time(12m) fill(previous) -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | max | -| :------------------- | --: | -| 2019-09-18T16:36:00Z | | -| 2019-09-18T16:48:00Z | 4 | - -##### `fill(linear)` when the previous or following result is outside the queried time range - -`fill(linear)` doesn't fill the result for a time interval with no data if the -previous result or the following result is outside the queried time range. - -**Example** - -The following example queries the time range between `2019-11-11T21:24:00Z` and -`2019-11-11T22:06:00Z`. Note that `fill(linear)` fills the results for the -`2019-11-11T21:36:00Z` time interval and the `2019-11-11T21:48:00Z` time interval -using the values from the `2019-11-11T21:24:00Z` time interval and the -`2019-11-11T22:00:00Z` time interval. - -```sql -SELECT MEAN("tadpoles") FROM "pond" WHERE time > '2019-11-11T21:24:00Z' AND time <= '2019-11-11T22:06:00Z' GROUP BY time(12m) fill(linear) -``` -Output: -{{% influxql/table-meta %}} -Name: pond -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ---: | -| 2019-11-11T21:24:00Z | 3 | -| 2019-11-11T21:36:00Z | 4 | -| 2019-11-11T21:48:00Z | 5 | -| 2019-11-11T22:00:00Z | 6 | - -The next query shortens the time range in the previous query. -It now covers the time between `2019-11-11T21:36:00Z` and `2019-11-11T22:06:00Z`. -Note that `fill()` previous doesn't fill the results for the `2019-11-11T21:36:00Z` -time interval and the `2019-11-11T21:48:00Z` time interval; the result for -`2019-11-11T21:24:00Z` is outside the query's shorter time range and InfluxDB -cannot perform the linear interpolation. - -```sql -SELECT MEAN("tadpoles") FROM "pond" WHERE time >= '2019-11-11T21:36:00Z' AND time <= '2019-11-11T22:06:00Z' GROUP BY time(12m) fill(linear) -``` -Output: -{{% influxql/table-meta %}} -Name: pond -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | ---: | -| 2019-11-11T21:36:00Z | | -| 2019-11-11T21:48:00Z | | -| 2019-11-11T22:00:00Z | 6 | - -{{% note %}} -**Note:** The data in Issue 3 are not in `NOAA` database. We had to create a dataset with less regular data to work with `fill(linear)`. -{{% /note %}} + diff --git a/content/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit.md b/content/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit.md index db1d4b2c7..ed8beddb9 100644 --- a/content/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit.md +++ b/content/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit.md @@ -11,231 +11,8 @@ list_code_example: | ```sql SELECT_clause FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] LIMIT ``` +source: /shared/influxdb-v2/query-data/influxql/explore-data/limit-and-slimit.md --- -Use `LIMIT` and `SLIMIT` to limit the number of [points](/influxdb/v2/reference/glossary/#point) and [series](/influxdb/v2/reference/glossary/#series) returned per query. - -- [LIMIT clause](#limit-clause) - - [Syntax](#syntax) - - [Examples](#examples) -- [SLIMIT clause](#slimit-clause) - - [Syntax](#syntax-1) - - [Examples](#examples-2) -- [Use LIMIT and SLIMIT together](#use-limit-and-slimit-together) - -## LIMIT clause - -`LIMIT ` returns the first `N` points from the specified [measurement](/influxdb/v2/reference/glossary/#measurement). - -### Syntax - -```sql -SELECT_clause FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] LIMIT -``` - -`N` specifies the number of points to return from the specified measurement . If `N` is greater than the number of points in a measurement, InfluxDB returns all points from the measurement. - -{{% note %}} -**IMPORTANT:** The `LIMIT` clause must appear in the order outlined in the syntax above. -{{% /note %}} - -### Examples - -{{< expand-wrapper >}} - -{{% expand "Limit the number of points returned" %}} - -```sql -SELECT "water_level","location" FROM "h2o_feet" LIMIT 3 -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | location | -| :-------------- | :-------------------| ------------------:| -| 2019-08-17T00:00:00Z | 8.1200000000 | coyote_creek| -| 2019-08-17T00:00:00Z | 2.0640000000 |santa_monica | -| 2019-08-17T00:06:00Z | 8.0050000000 |coyote_creek | - -The query returns the three oldest points, determined by timestamp, from the `h2o_feet` [measurement](/influxdb/v2/reference/glossary/#measurement). - -{{% /expand %}} - -{{% expand "Limit the number of points returned and include a `GROUP BY` clause" %}} - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:42:00Z' GROUP BY *,time(12m) LIMIT 2 -``` -Output: -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | :-------------------------- | -| 2019-08-18T00:00:00Z | 8.4615000000 | -| 2019-08-18T00:12:00Z | 8.2725000000 | - -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=santa_monica -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | :-------------------------- | -| 2019-08-18T00:00:00Z | 2.3655000000 | -| 2019-08-18T00:12:00Z | 2.3360000000 | - -This query uses the InfluxQL [MEAN() function](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) and a `GROUP BY` clause to calculate the average `water_level` for each [tag](/influxdb/v2/reference/glossary/#tag) and for each 12-minute interval in the queried time range. `LIMIT 2` requests the two oldest 12-minute averages (determined by timestamp). - -Note that without `LIMIT 2`, the query would return four points per series; one for each 12-minute interval in the queried time range. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## SLIMIT clause - -`SLIMIT ` returns every [point](/influxdb/v2/reference/glossary/#point) from `N` [series](//influxdb/v2/reference/glossary/#series) in the specified [measurement](/influxdb/v2/reference/glossary/#measurement). - -### Syntax - -```sql -SELECT_clause FROM_clause [WHERE_clause] GROUP BY *[,time()] [ORDER_BY_clause] SLIMIT -``` - -`N` specifies the number of series to return from the specified measurement. If `N` is greater than the number of series in a measurement, InfluxDB returns all series from that measurement. - -`SLIMIT` queries must include `GROUP BY *`. Note that the `SLIMIT` clause must appear in the order outlined in the syntax above. - -### Examples - -{{< expand-wrapper >}} - -{{% expand "Limit the number of series returned" %}} - -```sql -SELECT "water_level" FROM "h2o_feet" GROUP BY * SLIMIT 1 -``` -Output: -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------ | ---------------------:| -| 2019-08-17T00:00:00Z | 8.1200000000| -| 2019-08-17T00:06:00Z | 8.0050000000| -| 2019-08-17T00:12:00Z | 7.8870000000| -| 2019-08-17T00:18:00Z | 7.7620000000| -| 2019-08-17T00:24:00Z | 7.6350000000| -| 2019-08-17T00:30:00Z | 7.5000000000| -| 2019-08-17T00:36:00Z | 7.3720000000| - -The results above include only the first few rows, as the data set is quite large. The query returns all `water_level` [points](/influxdb/v2/reference/glossary/#point) from one of the [series](/influxdb/v2/reference/glossary/#series) associated with the `h2o_feet` [measurement](/influxdb/v2/reference/glossary/#measurement). - -{{% /expand %}} - -{{% expand "Limit the number of series returned and include a `GROUP BY time()` clause" %}} - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:42:00Z' GROUP BY *,time(12m) SLIMIT 1 -``` - -Output: -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------ | ---------------------:| -| 2019-08-18T00:00:00Z | 8.4615000000| -| 2019-08-18T00:12:00Z | 8.2725000000| -| 2019-08-18T00:24:00Z | 8.0710000000| -| 2019-08-18T00:36:00Z | 7.8330000000| - -The query uses the InfluxQL [MEAN() function](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) -and a time interval in the [GROUP BY clause](/influxdb/v2/query-data/influxql/explore-data/group-by/) -to calculate the average `water_level` for each 12-minute -interval in the queried time range. - -`SLIMIT 1` requests a single series associated with the `h2o_feet` measurement. - -Note that without `SLIMIT 1`, the query would return results for the two series -associated with the `h2o_feet` measurement: `location=coyote_creek` and -`location=santa_monica`. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## Use LIMIT and SLIMIT together - -`LIMIT ` followed by `SLIMIT <2>` returns the first `N1` [points](/influxdb/v2/reference/glossary/#point) from `N2` series in the specified measurement. - -### Syntax - -```sql -SELECT_clause FROM_clause [WHERE_clause] GROUP BY *[,time()] [ORDER_BY_clause] LIMIT SLIMIT -``` - -`N1` specifies the number of points to return per measurement. If `N1` is greater than the number of points in a measurement, InfluxDB returns all points from that measurement. - -`N2` specifies the number of series to return from the specified measurement. If `N2` is greater than the number of series in a measurement, InfluxDB returns all series from that measurement. - -`SLIMIT` queries must include `GROUP BY *`. Note that the `SLIMIT` clause must appear in the order outlined in the syntax above. - -### Examples - -{{< expand-wrapper >}} - -{{% expand "Limit the number of points and series returned" %}} - -```sql -SELECT "water_level" FROM "h2o_feet" GROUP BY * LIMIT 3 SLIMIT 1 -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -Tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------ | ---------------------:| -| 2019-08-17T00:00:00Z | 8.1200000000| -| 2019-08-17T00:06:00Z | 8.0050000000| -| 2019-08-17T00:12:00Z | 7.8870000000| - -The query returns the three oldest points, determined by timestamp, from one of the series associated with the measurement `h2o_feet`. - -{{% /expand %}} - -{{% expand "Limit the number of points and series returned and include a `GROUP BY time()` clause" %}} - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:42:00Z' GROUP BY *,time(12m) LIMIT 2 SLIMIT 1 -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -Tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------ | ---------------------:| -| 2019-08-18T00:00:00Z | 8.4615000000| -| 2019-08-18T00:12:00Z | 8.2725000000| - -The query uses the InfluxQL function MEAN() and a time interval in the GROUP BY clause to calculate the average `water_level` for each 12-minute interval in the queried time range. `LIMIT 2` requests the two oldest 12-minute averages (determined by -timestamp) and `SLIMIT 1` requests a single series associated with the `h2o_feet` measurement. - -Note that without `LIMIT 2 SLIMIT 1`, the query would return four points for each of the two series associated with the `h2o_feet` measurement. - -{{% /expand %}} - -{{< /expand-wrapper >}} + diff --git a/content/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset.md b/content/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset.md index 7e9798221..65dae415f 100644 --- a/content/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset.md +++ b/content/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset.md @@ -11,197 +11,8 @@ list_code_example: | ```sql SELECT_clause FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] LIMIT_clause OFFSET [SLIMIT_clause] ``` +source: /shared/influxdb-v2/query-data/influxql/explore-data/offset-and-soffset.md --- -Use `OFFSET` and `SOFFSET` to paginate [points](/influxdb/v2/reference/glossary/#point) and [series](/influxdb/v2/reference/glossary/#series) returned. - - - [OFFSET clause](#offset-clause) - - [Syntax](#syntax) - - [Examples](#examples) - - [The SOFFSET clause](#soffset-clause) - - [Syntax](#syntax-1) - - [Examples](#examples-1) - -## `OFFSET` clause - -`OFFSET ` paginates `N` [points](/influxdb/v2/reference/glossary/#point) in the query results. - -### Syntax - -```sql -SELECT_clause FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] LIMIT_clause OFFSET [SLIMIT_clause] -``` - -`N` specifies the number of points to paginate. The `OFFSET` clause requires a [`LIMIT` clause](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/#limit-clause). - -{{% note %}} -**Note:** InfluxDB returns no results if the `WHERE clause` includes a time range and the `OFFSET clause` would cause InfluxDB to return points with timestamps outside of that time range. -{{% /note %}} - -### Examples - -{{< expand-wrapper >}} - -{{% expand "Paginate points" %}} - -```sql -SELECT "water_level","location" FROM "h2o_feet" LIMIT 3 OFFSET 3 -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | location | -| :-------------- | -------------------:| :------------------| -| 2019-08-17T00:06:00Z | 2.1160000000 | santa_monica| -| 2019-08-17T00:12:00Z | 7.8870000000 | coyote_creek| -| 2019-08-17T00:12:00Z | 2.0280000000 | santa_monica| - -The query returns the fourth, fifth, and sixth points from the `h2o_feet` [measurement](/influxdb/v2/reference/glossary/#measurement). If the query did not include `OFFSET 3`, it would return the first, second, -and third points from that measurement. - -{{% /expand %}} - -{{% expand "Paginate points and include several clauses" %}} - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:42:00Z' GROUP BY *,time(12m) ORDER BY time DESC LIMIT 2 OFFSET 2 SLIMIT 1 -``` -Output: -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------ | ---------------------:| -| 2019-08-18T00:12:00Z | 8.2725000000 | -| 2019-08-18T00:00:00Z | 8.4615000000 | - -In this example: - - - The [`SELECT clause`](/influxdb/v2/query-data/influxql/explore-data/select/) specifies the InfluxQL [MEAN() function](/influxdb/v2/query-data/influxql/functions/aggregates/#mean). - - The [`FROM clause`] (/influxdb/v2/query-data/influxql/explore-data/select/#from-clause) specifies a single measurement. - - The [`WHERE` clause](/influxdb/v2/query-data/influxql/explore-data/where/) specifies the time range for the query. - - The [`GROUP BY` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/) groups results by all tags (`*`) and into 12-minute intervals. - - The [`ORDER BY time DESC` clause](/influxdb/v2/query-data/influxql/explore-data/order-by/#order-by-time-desc) returns results in descending timestamp order. - - The [`LIMIT 2` clause](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) limits the number of points returned to two. - - The `OFFSET 2` clause excludes the first two averages from the query results. - - The [`SLIMIT 1` clause](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) limits the number of series returned to one. - -Without `OFFSET 2`, the query would return the first two averages of the query results: - -Output: -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------ | ---------------------:| -| 2019-08-18T00:36:00Z | 7.8330000000 | -| 2019-08-18T00:24:00Z | 8.0710000000 | - -{{< /expand >}} - -{{< /expand-wrapper >}} - -## `SOFFSET` clause - -`SOFFSET ` paginates `N` [series](/influxdb/v2/reference/glossary/#series) in the query results. - -### Syntax - -```sql -SELECT_clause FROM_clause [WHERE_clause] GROUP BY *[,time(time_interval)] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] SLIMIT_clause SOFFSET -``` - -`N` specifies the number of [series](/influxdb/v2/reference/glossary/#series) to paginate. -The `SOFFSET` clause requires an [`SLIMIT` clause](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/. -Using the `SOFFSET` clause without an `SLIMIT` clause can cause [inconsistent -query results](https://github.com/influxdata/influxdb/issues/7578). -`SLIMIT` queries must include `GROUP BY *`. -{{% note %}} -**Note:** InfluxDB returns no results if the `SOFFSET` clause paginates through more than the total number of series. -{{% /note %}} - -### Examples - -{{< expand-wrapper >}} - -{{% expand "Paginate series" %}} - -#### Paginate series - -```sql -SELECT "water_level" FROM "h2o_feet" GROUP BY * SLIMIT 1 SOFFSET 1 -``` -Output: -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=santa_monica -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------ | ---------------------:| -| 2019-08-17T00:00:00Z | 2.0640000000| -| 2019-08-17T00:06:00Z | 2.1160000000| -| 2019-08-17T00:12:00Z | 2.0280000000| -| 2019-08-17T00:18:00Z | 2.1260000000| -| 2019-08-17T00:24:00Z | 2.0410000000| -| 2019-08-17T00:30:00Z | 2.0510000000| -| 2019-08-17T00:36:00Z | 2.0670000000| -| 2019-08-17T00:42:00Z | 2.0570000000| - -The results above are partial, as the data set is quite large. The query returns data for the series associated with the `h2o_feet` -measurement and the `location = santa_monica` tag. Without `SOFFSET 1`, the query returns data for the series associated with the `h2o_feet` measurement and the `location = coyote_creek` tag. - -{{% /expand %}} - -{{% expand "Paginate points and include several clauses" %}} - -#### Paginate series and include all clauses - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:42:00Z' GROUP BY *,time(12m) ORDER BY time DESC LIMIT 2 OFFSET 2 SLIMIT 1 SOFFSET 1 -``` -Output: -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=santa_monica -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------ | ---------------------:| -| 2019-08-18T00:12:00Z | 2.3360000000| -| 2019-08-18T00:00:00Z | 2.3655000000| - -In this example: - - - The [`SELECT` clause](/influxdb/v2/query-data/influxql/explore-data/select/) specifies an InfluxQL [function](/influxdb/v2/query-data/influxql/functions/). - - The [`FROM` clause](/influxdb/v2/query-data/influxql/explore-data/select/#from-clause) specifies a single measurement. - - The [`WHERE` clause](/influxdb/v2/query-data/influxql/explore-data/where/) specifies the time range for the query. - - The [`GROUP BY` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/) groups results by all tags (`*`) and into 12-minute intervals. - - The [`ORDER BY time DESC` clause](/influxdb/v2/query-data/influxql/explore-data/order-by/#order-by-time-desc) returns results in descending timestamp order. - - The [`LIMIT 2` clause](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) limits the number of points returned to two. - - The [`OFFSET 2` clause](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) excludes the first two averages from the query results. - - The [`SLIMIT 1` clause](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) limits the number of series returned to one. - - The [`SOFFSET 1`](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) clause paginates the series returned. - -Without `SOFFSET 1`, the query would return the results for a different series: - -Output: -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------ | ---------------------:| -| 2019-08-18T00:12:00Z | 8.2725000000 | -| 2019-08-18T00:00:00Z | 8.4615000000 | - -{{% /expand %}} - -{{< /expand-wrapper >}} + diff --git a/content/influxdb/v2/query-data/influxql/explore-data/order-by.md b/content/influxdb/v2/query-data/influxql/explore-data/order-by.md index 07a83bdbf..d1bb38f66 100644 --- a/content/influxdb/v2/query-data/influxql/explore-data/order-by.md +++ b/content/influxdb/v2/query-data/influxql/explore-data/order-by.md @@ -12,108 +12,8 @@ list_code_example: | ```sql SELECT_clause FROM_clause [WHERE_clause] [GROUP_BY_clause] ORDER BY time DESC ``` +source: /shared/influxdb-v2/query-data/influxql/explore-data/order-by.md --- -Use the `ORDER BY` clause to sort data. - -- [Syntax](#syntax) -- [Examples](#examples) - -## ORDER BY time DESC - -By default, InfluxDB returns results in ascending time order; the first [point](/influxdb/v2/reference/glossary/#point) -returned has the oldest [timestamp](/influxdb/v2/reference/glossary/#timestamp) and -the last point returned has the most recent timestamp. -`ORDER BY time DESC` reverses that order such that InfluxDB returns the points -with the most recent timestamps first. - -### Syntax - -```sql -SELECT_clause FROM_clause [WHERE_clause] [GROUP_BY_clause] ORDER BY time DESC -``` - -If the query includes a `GROUP BY` clause, `ORDER by time DESC` must appear **after** the `GROUP BY` clause. -If the query includes a `WHERE` clause and no `GROUP BY` clause, `ORDER by time DESC` must appear **after** the `WHERE` clause. - -### Examples - -{{< expand-wrapper >}} - -{{% expand "Return the newest points first" %}} - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE "location" = 'santa_monica' ORDER BY time DESC -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :-------------- | ------------------:| -| 2019-09-17T21:42:00Z | 4.9380000000| -| 2019-09-17T21:36:00Z | 5.0660000000| -| 2019-09-17T21:30:00Z | 5.0100000000| -| 2019-09-17T21:24:00Z | 5.0130000000| -| 2019-09-17T21:18:00Z | 5.0720000000| - -The query returns the points with the most recent timestamps from the -`h2o_feet` [measurement](/influxdb/v2/reference/glossary/#measurement) first. -Without `ORDER by time DESC`, the query would return the following output: - -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :-------------- | ------------------:| -| 2019-08-17T00:00:00Z | 2.0640000000| -| 2019-08-17T00:06:00Z | 2.1160000000| -| 2019-08-17T00:12:00Z | 2.0280000000| -| 2019-08-17T00:18:00Z | 2.1260000000| - -{{% /expand %}} - -{{% expand "Return the newest points first and include a `GROUP BY time()` clause" %}} - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:42:00Z' GROUP BY time(12m) ORDER BY time DESC -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | mean | -| :-------------- | ------------------:| -| 2019-08-18T00:36:00Z | 4.9712860355| -| 2019-08-18T00:24:00Z | 5.1682500000| -| 2019-08-18T00:12:00Z | 5.3042500000| -| 2019-08-18T00:00:00Z | 5.4135000000| - -The query uses the InfluxQL [MEAN() function](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) -and a time interval in the [GROUP BY clause](/influxdb/v2/query-data/influxql/explore-data/group-by/) -to calculate the average `water_level` for each 12-minute -interval in the queried time range. -[`ORDER BY time DESC`](/influxdb/v2/query-data/influxql/explore-data/order-by/#order-by-time-desc) returns the most recent 12-minute time intervals -first. - -Without `ORDER BY time DESC`, the query would return the following output: - -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | mean | -| :-------------- | ------------------:| -| 2019-08-18T00:00:00Z | 5.4135000000| -| 2019-08-18T00:12:00Z | 5.3042500000| -| 2019-08-18T00:24:00Z | 5.1682500000| -| 2019-08-18T00:36:00Z | 4.9712860355| - -{{% /expand %}} - -{{< /expand-wrapper >}} + diff --git a/content/influxdb/v2/query-data/influxql/explore-data/regular-expressions.md b/content/influxdb/v2/query-data/influxql/explore-data/regular-expressions.md index 8a4bce275..24712ee28 100644 --- a/content/influxdb/v2/query-data/influxql/explore-data/regular-expressions.md +++ b/content/influxdb/v2/query-data/influxql/explore-data/regular-expressions.md @@ -13,267 +13,8 @@ list_code_example: | ```sql SELECT // FROM // WHERE [ // | //] GROUP BY // ``` +source: /shared/influxdb-v2/query-data/influxql/explore-data/regular-expressions.md --- -InfluxQL supports using regular expressions when specifying: - -- [field keys](/influxdb/v2/reference/glossary/#field-key) and [tag keys](/influxdb/v2/reference/glossary/#tag-key) in the [`SELECT` clause](/influxdb/v2/query-data/influxql/explore-data/select/). -- [measurements](/influxdb/v2/reference/glossary/#measurement) in the [`FROM` clause](/influxdb/v2/query-data/influxql/explore-data/select/#from-clause). -- [tag values](/influxdb/v2/reference/glossary/#tag-value) and string [field values](/influxdb/v2/reference/glossary/#field-value) in the [`WHERE` clause](/influxdb/v2/query-data/influxql/explore-data/where/). -- [tag keys](/influxdb/v2/reference/glossary/#tag-key) in the [`GROUP BY` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/) - -Regular expressions in InfluxQL only support string comparisons and can only evaluate [fields](/influxdb/v2/reference/glossary/#field) with string values. - -{{% note %}} -**Note:** Regular expression comparisons are more computationally intensive than exact -string comparisons. Queries with regular expressions are not as performant -as those without. -{{% /note %}} - -- [Syntax](#syntax) -- [Examples](#examples) - -## Syntax - -```sql -SELECT // FROM // WHERE [ // | //] GROUP BY // -``` - -Regular expressions are surrounded by `/` characters and use the -[Go regular expression syntax](http://golang.org/pkg/regexp/syntax/). - -## Supported operators - -`=~`: matches against -`!~`: doesn't match against - -### Examples - - - -{{< expand-wrapper >}} - -{{% expand "Use a regular expression to specify field keys and tag keys in the SELECT clause" %}} - -```sql -SELECT /l/ FROM "h2o_feet" LIMIT 1 -``` - - - -Output: - -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | level description | location | water_level| -| :------------ | :----------------| :--------------| --------------:| -| 2019-08-17T00:00:00Z | below 3 feet | santa_monica | 2.0640000000| - -The query selects all field keys and tag keys that include an `l`. -Note that the regular expression in the `SELECT` clause must match at least one -field key in order to return results for a tag key that matches the regular -expression. - -Currently, there is no syntax to distinguish between regular expressions for -field keys and regular expressions for tag keys in the `SELECT` clause. -The syntax `//::[field | tag]` is not supported. - -{{% /expand %}} - -{{% expand "Use a regular expression to specify field keys and tag keys in function arguments" %}} - -```sql -SELECT MAX(/_level/) FROM "h2o_feet" LIMIT 1 -``` - - - -Output: - -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | max_water_level | -| :------------------- | ---------------------:| -| 2019-08-28T07:24:00Z | 9.964 - -This query uses the InfluxQL [`MAX()` selector function](/influxdb/v2/query-data/influxql/functions/selectors/#max) -to find the greatest field value out of all field keys that match the regular expression. - -{{% /expand %}} - -{{% expand "Use a regular expression to specify measurements in the FROM clause" %}} - -```sql -SELECT MEAN("degrees") FROM /temperature/ -``` - -Output: - -{{% influxql/table-meta %}} -Name: average_temperature -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------ | ---------------------:| -| 1970-01-01T00:00:00Z | 79.9847293223 | - -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------ | ---------------------:| -| 1970-01-01T00:00:00Z | 64.9980273540 | - -This query uses the InfluxQL [MEAN() function](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) to calculate the average `degrees` for every [measurement](/influxdb/v2/reference/glossary/#measurement) in the [NOAA sample data] that contains the word `temperature`. - -{{% /expand %}} - -{{% expand "Use a regular expression to specify tag values in the WHERE clause" %}} - -```sql -SELECT MEAN(water_level) FROM "h2o_feet" WHERE "location" =~ /[m]/ AND "water_level" > 3 -``` - -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------ | ---------------------:| -| 1970-01-01T00:00:00Z | 4.4710766395| - -This query uses the InfluxQL [MEAN() function](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) to calculate the average `water_level` where the [tag value](/influxdb/v2/reference/glossary/#measurement) of `location` includes an `m` and `water_level` is greater than three. - -{{% /expand %}} - -{{% expand "Use a regular expression to specify a tag with no value in the WHERE clause" %}} - -```sql -SELECT * FROM "h2o_feet" WHERE "location" !~ /./ -> -``` - -The query selects all data from the `h2o_feet` measurement where the `location` -[tag](/influxdb/v2/reference/glossary/#tag) has no value. -Every data [point](/influxdb/v2/reference/glossary/#point) in the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data) has a tag value for `location`. -It's possible to perform this same query without a regular expression. -See the [Frequently Asked Questions](/influxdb/v2/reference/faq/#how-do-i-query-data-by-a-tag-with-a-null-value) -document for more information. - -{{% /expand %}} - -{{% expand "Use a regular expression to specify a tag with a value in the WHERE clause" %}} - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" WHERE "location" =~ /./ -``` - -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------ | ---------------------:| -| 1970-01-01T00:00:00Z | 4.4418434585| - -This query uses the InfluxQL [MEAN() function](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) to calculate the average `water_level` across all data with a tag value for `location`. - -{{% /expand %}} - -{{% expand "Use a regular expression to specify a field value in the WHERE clause" %}} - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" WHERE "location" = 'santa_monica' AND "level description" =~ /between/ -``` - -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------ | ---------------------:| -| 1970-01-01T00:00:00Z | 4.4713666916 - - -This query uses the InfluxQL [MEAN() function](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) -to calculate the average `water_level` for all data where the field value of `level description` includes the word `between`. - -{{% /expand %}} - -{{% expand "Use a regular expression to specify tag keys in the GROUP BY clause" %}} - -```sql -SELECT FIRST("index") FROM "h2o_quality" GROUP BY /l/ -``` - -Output: -{{% influxql/table-meta %}} -name: h2o_quality -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------ |-------------------:| -| 2019-08-17T00:00:00Z | 41.0000000000 | - - -{{% influxql/table-meta %}} -name: h2o_quality -tags: location=santa_monica -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------ |-------------------:| -| 2019-08-17T00:00:00Z | 99.0000000000 | - -This query uses the InfluxQL [FIRST() function](/influxdb/v2/query-data/influxql/functions/selectors/#first) - -to select the first value of `index` for every tag that includes the letter `l` -in its tag key. - -{{% /expand %}} - -{{< /expand-wrapper >}} + diff --git a/content/influxdb/v2/query-data/influxql/explore-data/select.md b/content/influxdb/v2/query-data/influxql/explore-data/select.md index 6c43ab5c9..0420383e1 100644 --- a/content/influxdb/v2/query-data/influxql/explore-data/select.md +++ b/content/influxdb/v2/query-data/influxql/explore-data/select.md @@ -12,592 +12,8 @@ list_code_example: | ```sql SELECT [,,] FROM [,] ``` +source: /shared/influxdb-v2/query-data/influxql/explore-data/select.md --- -Use the `SELECT` statement to query data from a particular [measurement](/influxdb/v2/reference/glossary/#measurement) or measurements. - -- [Syntax](#syntax) -- [Examples](#examples) -- [Common issues](#common-issues-with-the-select-statement) -- [Regular expressions](#regular-expressions) -- [Data types and cast operations](#data-types-and-cast-operations) -- [Merge behavior](#merge-behavior) -- [Multiple statements](#multiple-statements) - -## Syntax - -```sql -SELECT [,,] FROM [,] -``` -{{% note %}} -**Note:** The `SELECT` statement **requires** a `SELECT` clause and a `FROM` clause. -{{% /note %}} - -### `SELECT` clause - -The `SELECT` clause supports several formats for specifying data: - -- `SELECT *` - Returns all [fields](/influxdb/v2/reference/glossary/#field) and [tags](/influxdb/v2/reference/glossary/#tag). -- `SELECT ""` - Returns a specific field. -- `SELECT "",""` - Returns more than one field. -- `SELECT "",""` - Returns a specific field and tag. The `SELECT` clause must specify at least one field when it includes a tag. -- `SELECT ""::field,""::tag` - Returns a specific field and tag. -The `::[field | tag]` syntax specifies the [identifier's](/influxdb/v2/reference/syntax/influxql/spec/#identifiers) type. -Use this syntax to differentiate between field keys and tag keys with the same name. - -Other supported features include: - -- [Functions](/influxdb/v2/query-data/influxql/functions/) -- [Basic cast operations](#data-types-and-cast-operations) -- [Regular expressions](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/) - -{{% note %}} -**Note:** The SELECT statement cannot include an aggregate function **and** a non-aggregate function, field key, or tag key. For more information, see [error about mixing aggregate and non-aggregate queries](/enterprise_influxdb/v1/troubleshooting/errors/#error-parsing-query-mixing-aggregate-and-non-aggregate-queries-is-not-supported). -{{% /note %}} - -### `FROM` clause - -The `SELECT` clause specifies the measurement to query. -This clause supports several formats for specifying a [measurement](/influxdb/v2/reference/glossary/#measurement): - -- `FROM ` - Returns data from a measurement. -- `FROM ,` - Returns data from more than one measurement. -- `FROM ..` - Returns data from a fully qualified measurement. -- `FROM ..` - Returns data from a measurement. - -#### Quoting - -[Identifiers](/influxdb/v2/reference/syntax/influxql/spec/#identifiers) **must** be double quoted if they contain characters other than `[A-z,0-9,_]`, -begin with a digit, or are an [InfluxQL keyword](https://github.com/influxdata/influxql/blob/master/README.md#keywords). -While not always necessary, we recommend that you double quote identifiers. - -{{% note %}} -**Note:** InfluxQL quoting guidelines differ from [line protocol quoting guidelines](/influxdb/v2/reference/syntax/line-protocol/#quotes). -Please review the [rules for single and double-quoting](/influxdb/v2/reference/syntax/line-protocol/#quotes) in queries. -{{% /note %}} - -### Examples - -{{< expand-wrapper >}} -{{% expand "Select all fields and tags from a measurement" %}} - -```sql -SELECT * FROM "h2o_feet" -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | level description | location | water_level | -| :-------------- |:----------------------| :-------------------| ------------------:| -| 2019-08-17T00:00:00Z | below 3 feet |santa_monica | 2.0640000000| -| 2019-08-17T00:00:00Z | between 6 and 9 feet | coyote_creek | 8.1200000000| -| 2019-08-17T00:06:00Z | below 3 feet| santa_monica | 2.1160000000| -| 2019- 08-17T00:06:00Z | between 6 and 9 feet |coyote_creek |8.0050000000| -| 2019-08-17T00:12:00Z | below 3 feet | santa_monica | 2.0280000000| -| 2019-08-17T00:12:00Z | between 6 and 9 feet | coyote_creek | 7.8870000000| -| 2019-08-17T00:18:00Z | below 3 feet |santa_monica | 2.1260000000| - -The data above is a partial listing of the query output, as the result set is quite large. The query selects all [fields](/influxdb/v2/reference/glossary/#field) and -[tags](/influxdb/v2/reference/glossary/#tag) from the `h2o_feet` -[measurement](/influxdb/v2/reference/glossary/#measurement). - -{{% /expand %}} - -{{% expand "Select specific tags and fields from a measurement" %}} - -```sql -SELECT "level description","location","water_level" FROM "h2o_feet" -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | level description | location | water_level | -| :-------------- |:----------------------| :-------------------| ------------------:| -| 2019-08-17T00:00:00Z | below 3 feet |santa_monica | 2.0640000000| -| 2019-08-17T00:00:00Z | between 6 and 9 feet | coyote_creek | 8.1200000000| - -The query selects the `level description` field, the `location` tag, and the -`water_level` field. - -{{% note %}} -**Note:** The `SELECT` clause must specify at least one field when it includes -a tag. -{{% /note %}} - -{{% /expand %}} - -{{% expand "Select specific tags and fields from a measurement and provide their identifier type" %}} - -```sql -SELECT "level description"::field,"location"::tag,"water_level"::field FROM "h2o_feet" -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | level description | location | water_level | -| :-------------- |:----------------------| :-------------------| ------------------:| -| 2019-08-17T00:24:00Z | between 6 and 9 feet | coyote_creek | 7.6350000000| -| 2019-08-17T00:30:00Z | below 3 feet | santa_monica | 2.0510000000| -| 2019-08-17T00:30:00Z | between 6 and 9 feet | coyote_creek | 7.5000000000| -| 2019-08-17T00:36:00Z | below 3 feet | santa_monica | 2.0670000000 | -| 2019-08-17T00:36:00Z | between 6 and 9 feet | coyote_creek | 7.3720000000 | -| 2019-08-17T00:42:00Z | below 3 feet | santa_monica | 2.0570000000 | - -The query selects the `level description` field, the `location` tag, and the -`water_level` field from the `h2o_feet` measurement. -The `::[field | tag]` syntax specifies if the -[identifier](/influxdb/v2/reference/syntax/influxql/spec/#identifiers) is a field or tag. -Use `::[field | tag]` to differentiate between [an identical field key and tag key ](/v2.4/reference/faq/#how-do-i-query-data-with-an-identical-tag-key-and-field-key). -That syntax is not required for most use cases. - -{{% /expand %}} - -{{% expand "Select all fields from a measurement" %}} - -```sql -SELECT *::field FROM "h2o_feet" -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | level description| water_level | -| :-------------- | :-------------------| ------------------:| -| 2019-08-17T00:00:00Z | below 3 feet | 2.0640000000 | -| 2019-08-17T00:00:00Z | between 6 and 9 feet | 8.1200000000| -| 2019-08-17T00:06:00Z | below 3 feet | 2.1160000000| -| 2019-08-17T00:06:00Z | between 6 and 9 feet | 8.0050000000| -| 2019-08-17T00:12:00Z | below 3 feet | 2.0280000000| -| 2019-08-17T00:12:00Z | between 6 and 9 feet | 7.8870000000| - -The query selects all fields from the `h2o_feet` measurement. -The `SELECT` clause supports combining the `*` syntax with the `::` syntax. - -{{% /expand %}} - -{{% expand "Select a specific field from a measurement and perform basic arithmetic" %}} - -```sql -SELECT ("water_level" * 2) + 4 FROM "h2o_feet" -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :-------------- | ------------------:| -| 2019-08-17T00:00:00Z | 20.2400000000 | -| 2019-08-17T00:00:00Z | 8.1280000000 | -| 2019-08-17T00:06:00Z | 20.0100000000 | -| 2019-08-17T00:06:00Z | 8.2320000000 | -| 2019-08-17T00:12:00Z | 19.7740000000 | -| 2019-08-17T00:12:00Z | 8.0560000000 | - -The query multiplies `water_level`'s field values by two and adds four to those -values. - -{{% note %}} -**Note:** InfluxDB follows the standard order of operations. -See [InfluxQL mathematical operators](/influxdb/v2/query-data/influxql/math-operators/) -for more on supported operators. -{{% /note %}} - -{{% /expand %}} - -{{% expand "Select all data from more than one measurement" %}} - -```sql -SELECT * FROM "h2o_feet","h2o_pH" -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | level description | location | pH | water_level | -| :-------------- |:-------------| :----------------| :-------------| --------------:| -| 2019-08-17T00:00:00Z | below 3 feet | santa_monica | | 2.0640000000| -| 2019-08-17T00:00:00Z | between 6 and 9 feet | coyote_creek | | 8.1200000000| -| 2019-08-17T00:06:00Z | below 3 feet | santa_monica | | 2.1160000000| -| 2019-08-17T00:06:00Z | between 6 and 9 feet | coyote_creek | | 8.0050000000| -| 2019-08-17T00:12:00Z | below 3 feet | santa_monica | | 2.0280000000 | -| 2019-08-17T00:12:00Z | between 6 and 9 feet | coyote_creek | | 7.8870000000| -| 2019-08-17T00:18:00Z | below 3 feet | santa_monica | | 2.1260000000| -| 2019-08-17T00:18:00Z | between 6 and 9 feet | coyote_creek | | 7.7620000000| - -{{% influxql/table-meta %}} -Name: h2o_pH -{{% /influxql/table-meta %}} - -| time | level description | location | pH | water_level | -| :-------------- |:-------------| :----------------| :-------------| --------------:| -| 2019-08-17T00:00:00Z | | coyote_creek | 7.00| | -| 2019-08-17T00:06:00Z | |coyote_creek | 8.00 | | -| 2019-08-17T00:06:00Z | |santa_monica | 6.00 | | -| 2019-08-17T00:12:00Z | |coyote_creek |8.00 | | - - -The query selects all fields and tags from two measurements: `h2o_feet` and -`h2o_pH`. -Separate multiple measurements with a comma (`,`). - -{{% /expand %}} - -{{% expand "Select all data from a measurement in a particular database" %}} - -```sql -SELECT * FROM noaa.."h2o_feet" -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | level description | location | water_level | -| :-------------- |:----------------------| :-------------------| ------------------:| -| 2019-08-17T00:00:00Z | below 3 feet |santa_monica | 2.0640000000| -| 2019-08-17T00:00:00Z | between 6 and 9 feet | coyote_creek | 8.1200000000| -| 2019-08-17T00:06:00Z | below 3 feet| santa_monica | 2.1160000000| -| 2019- 08-17T00:06:00Z | between 6 and 9 feet |coyote_creek |8.0050000000| -| 2019-08-17T00:12:00Z | below 3 feet | santa_monica | 2.0280000000| -| 2019-08-17T00:12:00Z | between 6 and 9 feet | coyote_creek | 7.8870000000| - -The query selects data from the `h2o_feet` measurement in the `noaa` database. -The `..` indicates the `DEFAULT` retention policy for the specified database. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## Common issues with the SELECT statement - -### Selecting tag keys in the SELECT statement - -A query requires at least one [field key](/influxdb/v2/reference/glossary/#field-key) -in the `SELECT` clause to return data. -If the `SELECT` clause only includes a single [tag key](/influxdb/v2/reference/glossary/#tag-key) or several tag keys, the -query returns an empty response. - -#### Example - -The following query returns no data because it specifies a single tag key (`location`) in -the `SELECT` clause: - -```sql -SELECT "location" FROM "h2o_feet" -> No results -``` -To return any data associated with the `location` tag key, the query's `SELECT` -clause must include at least one field key (`water_level`): - -```sql -SELECT "water_level","location" FROM "h2o_feet" -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | location | -| :-------------- | :-------------------| ------------------:| -| 2019-08-17T00:00:00Z | 8.1200000000 | coyote_creek | -| 2019-08-17T00:00:00Z | 2.0640000000 | santa_monica | -| 2019-08-17T 00:06:00Z | 8.0050000000 | coyote_creek | -| 2019-08-17T00:06:00Z | 2.1160000000 | santa_monica | -| 2019-08-17T00:12:00Z | 7.8870000000 | coyote_creek | -| 2019-08-17T00:12:00Z | 2.0280000000 | santa_monica | -| 2019-08-17T00:18:00Z | 7.7620000000 | coyote_creek | -| 2019-08-17T00:18:00Z | 2.1260000000 | santa_monica | - -## Regular expressions - -InfluxQL supports using [regular expressions](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/) when specifying: -- [field keys](/influxdb/v2/reference/glossary/#field-key) and [tag keys](/influxdb/v2/reference/glossary/#tag-key) in the [`SELECT` clause](/influxdb/v2/query-data/influxql/explore-data/select/) -- [measurements](/influxdb/v2/reference/glossary/#measurement) in the [`FROM` clause](/influxdb/v2/query-data/influxql/explore-data/select/#from-clause) -- [tag values](/influxdb/v2/reference/glossary/#tag-value) and string [field values](/influxdb/v2/reference/glossary/#field-value) in the [`WHERE` clause](/influxdb/v2/query-data/influxql/explore-data/where/). -- [tag keys](/influxdb/v2/reference/glossary/#tag-key) in the [`GROUP BY` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/) - -## Syntax - -```sql -SELECT // FROM // WHERE [ // | //] GROUP BY // -``` - -See [regular expressions](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/) for more information. - -## Data types and cast operations - -The [`SELECT` clause](#select-clause) supports specifying a [field's](/influxdb/v2/reference/glossary/#field) type and basic cast operations with the `::` syntax. - - - [Data types](#data-types) - - [Cast operations](#cast-operations) - -### Data types - -[Field values](/influxdb/v2/reference/glossary/#field-value) can be floats, integers, strings, or booleans. -The `::` syntax allows users to specify the field's type in a query. - -{{% note %}} -**Note:** Generally, it is not necessary to specify the field value type in the [`SELECT` clause](/influxdb/v2/query-data/influxql/explore-data/select/). In most cases, InfluxDB rejects any writes that attempt to write a [field value](/influxdb/v2/reference/glossary/#field-value) to a field that previously accepted field values of a different type. -{{% /note %}} - -It is possible for field value types to differ across [shard groups](/influxdb/v2/reference/glossary/#shard-group). -In these cases, it may be necessary to specify the field value type in the -`SELECT` clause. -Please see the -[Frequently Asked Questions](/influxdb/v2/reference/faq/#how-does-influxdb-handle-field-type-discrepancies-across-shards) -document for more information on how InfluxDB handles field value type discrepancies. - -### Syntax - -```sql -SELECT_clause :: FROM_clause -``` - -`type` can be `float`, `integer`, `string`, or `boolean`. -In most cases, InfluxDB returns no data if the `field_key` does not store data of the specified -`type`. See [Cast Operations](#cast-operations) for more information. - -### Example - -```sql -SELECT "water_level"::float FROM "h2o_feet" LIMIT 4 -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -|time | water_level | -| :------------------ |-------------------:| -| 2019-08-17T00:00:00Z | 8.1200000000 | -| 2019-08-17T00:00:00Z | 2.0640000000 | -| 2019-08-17T00:06:00Z | 8.0050000000 | -| 2019-08-17T00:06:00Z | 2.1160000000 | - -The query returns values of the `water_level` field key that are floats. - -## Cast operations - -The `::` syntax allows users to perform basic cast operations in queries. -Currently, InfluxDB supports casting [field values](/influxdb/v2/reference/glossary/#field-value) from integers to -floats or from floats to integers. - -### Syntax - -```sql -SELECT_clause :: FROM_clause -``` - -`type` can be `float` or `integer`. - -InfluxDB returns no data if the query attempts to cast an integer or float to a string or boolean. - -### Examples - -{{< expand-wrapper >}} - -{{% expand "Cast float field values to integers" %}} - -```sql -SELECT "water_level"::integer FROM "h2o_feet" LIMIT 4 -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -|time | water_level | -| :------------------ |-------------------:| -| 2019-08-17T00:00:00Z | 8.0000000000 | -| 2019-08-17T00:00:00Z | 2.0000000000 | -| 2019-08-17T00:06:00Z | 8.0000000000 | -| 2019-08-17T00:06:00Z | 2.0000000000 | - -The query returns the integer form of `water_level`'s float [field values](/influxdb/v2/reference/glossary/#field-value). - -{{% /expand %}} - -{{% expand "Cast float field values to strings (this functionality is not supported)" %}} - -```sql -SELECT "water_level"::string FROM "h2o_feet" LIMIT 4 -> No results -``` - -The query returns no data as casting a float field value to a string is not yet supported. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## Merge behavior - -InfluxQL merges [series](/influxdb/v2/reference/glossary/#series) automatically. - -### Example - -{{< expand-wrapper >}} - -{{% expand "Merge behavior" %}} - -The `h2o_feet` [measurement](/influxdb/v2/reference/glossary/#measurement) in the `noaa` is part of two [series](/influxdb/v2/reference/glossary/#series). -The first series is made up of the `h2o_feet` measurement and the `location = coyote_creek` [tag](/influxdb/v2/reference/glossary/#tag). The second series is made of up the `h2o_feet` measurement and the `location = santa_monica` tag. - -The following query automatically merges those two series when it calculates the average `water_level` using the [MEAN() function](/influxdb/v2/query-data/influxql/functions/aggregates/#mean): - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -|time | mean | -| :------------------ |-------------------:| -| 1970-01-01T00:00:00Z | 4.4419314021 | - -If you want the average `water_level` for the first series only, specify the relevant tag in the [`WHERE` clause](/influxdb/v2/query-data/influxql/explore-data/where/): - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" WHERE "location" = 'coyote_creek' -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -|time | mean | -| :------------------ |-------------------:| -| 1970-01-01T00:00:00Z | 5.3591424203 | - -If you want the average `water_level` for each individual series, include a [`GROUP BY` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/): - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" GROUP BY "location" -``` -Output: -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------ |-------------------:| - | 1970-01-01T00:00:00Z | 5.3591424203 | - -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=santa_monica -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------ |-------------------:| -| 1970-01-01T00:00:00Z | 3.5307120942 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## Multiple statements - -Separate multiple `SELECT` statements in a query with a semicolon (`;`). - -### Examples - -{{< tabs-wrapper >}} -{{% tabs %}} -[InfluxQL shell](#) -[InfluxDB API](#) -{{% /tabs %}} - -{{% tab-content %}} - -In the [InfluxQL shell](/influxdb/v2/tools/influxql-shell/): - -```sql -SELECT MEAN("water_level") FROM "h2o_feet"; SELECT "water_level" FROM "h2o_feet" LIMIT 2 -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -|time | mean | -| :------------------ |-------------------:| -| 1970-01-01T00:00:00Z | 4.4419314021 | - - -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -|time | water_level | -| :------------------ |-------------------:| -| 2019-08-17T00:00:00Z | 8.12 | -| 2015-08-18T00:00:00Z | 2.064 | - -{{% /tab-content %}} - -{{% tab-content %}} - -With the [InfluxDB API](/influxdb/v2/reference/api/influxdb-1x/): - -```json -{ - "results": [ - { - "statement_id": 0, - "series": [ - { - "name": "h2o_feet", - "columns": [ - "time", - "mean" - ], - "values": [ - [ - "1970-01-01T00:00:00Z", - 4.442107025822522 - ] - ] - } - ] - }, - { - "statement_id": 1, - "series": [ - { - "name": "h2o_feet", - "columns": [ - "time", - "water_level" - ], - "values": [ - [ - "2015-08-18T00:00:00Z", - 8.12 - ], - [ - "2015-08-18T00:00:00Z", - 2.064 - ] - ] - } - ] - } - ] -} -``` - -{{% /tab-content %}} -{{< /tabs-wrapper >}} + diff --git a/content/influxdb/v2/query-data/influxql/explore-data/subqueries.md b/content/influxdb/v2/query-data/influxql/explore-data/subqueries.md index 6f48d4f77..f3ddb3722 100644 --- a/content/influxdb/v2/query-data/influxql/explore-data/subqueries.md +++ b/content/influxdb/v2/query-data/influxql/explore-data/subqueries.md @@ -11,284 +11,8 @@ list_code_example: | ```sql SELECT_clause FROM ( SELECT_statement ) [...] ``` +source: /shared/influxdb-v2/query-data/influxql/explore-data/subqueries.md --- -A subquery is a query that is nested in the `FROM` clause of another query. Use a subquery to apply a query as a condition in the enclosing query. Subqueries offer functionality similar to nested functions and the SQL [`HAVING` clause](https://en.wikipedia.org/wiki/Having_%28SQL%29). - -{{% note %}} -**Note:** InfluxQL does not support a `HAVING` clause. -{{% /note %}} - -- [Syntax](#syntax) -- [Examples](#examples) -- [Common Issues](#common-issues-with-subqueries) - -### Syntax - -```sql -SELECT_clause FROM ( SELECT_statement ) [...] -``` - -InfluxDB **performs the subquery first** and the main query second. - -The main query surrounds the subquery and requires at least the [`SELECT` clause](/influxdb/v2/query-data/influxql/explore-data/select/) and the [`FROM` clause](/influxdb/v2/query-data/influxql/explore-data/select/#from-clause). -The main query supports all clauses listed in InfluxQL 2.x documentation. - -The subquery appears in the main query's `FROM` clause, and it requires surrounding parentheses. -The subquery also supports all clauses listed in InfluxQL 2.x documentation. - -InfluxQL supports multiple nested subqueries per main query. -Sample syntax for multiple subqueries: - -```sql -SELECT_clause FROM ( SELECT_clause FROM ( SELECT_statement ) [...] ) [...] -``` - -{{% note %}} -**Note:** #### Improve performance of time-bound subqueries -To improve the performance of InfluxQL queries with time-bound subqueries, -apply the `WHERE time` clause to the outer query instead of the inner query. -For example, the following queries return the same results, but **the query with -time bounds on the outer query is more performant than the query with time -bounds on the inner query**: - -##### Time bounds on the outer query (recommended) -```sql -SELECT inner_value AS value FROM (SELECT raw_value as inner_value) -WHERE time >= '2022-07-19T21:00:00Z' -AND time <= '2022-07-20T22:00:00Z' -``` - -##### Time bounds on the inner query -```sql -SELECT inner_value AS value FROM ( - SELECT raw_value as inner_value - WHERE time >= '2022-07-19T21:00:00Z' - AND time <= '2022-07-20T22:00:00Z' -) -``` -{{% /note %}} - -### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the SUM() of several MAX() values" %}} - -```sql -SELECT SUM("max") FROM (SELECT MAX("water_level") FROM "h2o_feet" GROUP BY "location") -``` - -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | sum | -| :--------------| ------------------:| -|1970-01-01T00:00:00Z | 17.169 | - - -The query returns the sum of the maximum `water_level` values across every tag value of `location`. - -InfluxDB first performs the subquery; it calculates the maximum value of `water_level` for each tag value of `location`: - -```sql -SELECT MAX("water_level") FROM "h2o_feet" GROUP BY "location" -``` - -Output: -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | max | -| :--------------------------- | ------------------: | -| 2015-08-29T07:24:00Z | 9.9640000000 | - -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=santa_monica -{{% /influxql/table-meta %}} - -| time | max | -| :--------------------------- | ------------------: | -| 2015-08-29T03:54:00Z | 7.2050000000 | - -Next, InfluxDB performs the main query and calculates the sum of those maximum values: `9.9640000000` + `7.2050000000` = `17.169`. -Notice that the main query specifies `max`, not `water_level`, as the field key in the `SUM()` function. - -{{% /expand %}} - -{{% expand "Calculate the MEAN() difference between two fields" %}} - -```sql -SELECT MEAN("difference") FROM (SELECT "cats" - "dogs" AS "difference" FROM "pet_daycare") -``` - -Output: -{{% influxql/table-meta %}} -Name: pet_daycare -{{% /influxql/table-meta %}} - -| time | max | -| :--------------------------- | ------------------: | -| 1970-01-01T00:00:00Z | 1.75 | - - -The query returns the average of the differences between the number of `cats` and `dogs` in the `pet_daycare` measurement. - -InfluxDB first performs the subquery. -The subquery calculates the difference between the values in the `cats` field and the values in the `dogs` field, -and it names the output column `difference`: - -```sql -SELECT "cats" - "dogs" AS "difference" FROM "pet_daycare" -``` -Output: -{{% influxql/table-meta %}} -Name: pet_daycare -{{% /influxql/table-meta %}} - -| time | difference | -| :--------------------------- | ------------------: | -| 2017-01-20T00:55:56Z | -1 | -2017-01-21T00:55:56Z | -49 | -2017-01-22T00:55:56Z | 66 | -2017-01-23T00:55:56Z | -9 | - - -Next, InfluxDB performs the main query and calculates the average of those differences. -Notice that the main query specifies `difference` as the field key in the [`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) function. - -{{% /expand %}} - -{{% expand "Calculate several MEAN() values and place a condition on those mean values" %}} - -```sql -SELECT "all_the_means" FROM (SELECT MEAN("water_level") AS "all_the_means" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' GROUP BY time(12m) ) WHERE "all_the_means" > 5 -``` - -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | all_the_means | -| :--------------------------- | ------------------: | -| 2019-08-18T00:00:00Z | 5.4135000000 | -| 2019-08-18T00:12:00Z | 5.3042500000 | -| 2019-08-18T00:24:00Z | 5.1682500000 | - - -The query returns all mean values of the `water_level` field that are greater than five. - -InfluxDB first performs the subquery. -The subquery calculates `MEAN()` values of `water_level` from `2019-08-18T00:00:00Z` through `2019-08-18T00:30:00Z` and groups the results into 12-minute intervals. It also names the output column `all_the_means`: - -```sql -SELECT MEAN("water_level") AS "all_the_means" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' GROUP BY time(12m) -``` - -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | all_the_means | -| :--------------------------- | ------------------: | -| 2019-08-18T00:00:00Z | 5.4135000000 | -| 2019-08-18T00:12:00Z | 5.3042500000 | -| 2019-08-18T00:24:00Z | 5.1682500000 | - -Next, InfluxDB performs the main query and returns only those mean values that are greater than five. -Notice that the main query specifies `all_the_means` as the field key in the `SELECT` clause. - -{{% /expand %}} - -{{% expand "Calculate the SUM() of several DERIVATIVE() values" %}} - -```sql -SELECT SUM("water_level_derivative") AS "sum_derivative" FROM (SELECT DERIVATIVE(MEAN("water_level")) AS "water_level_derivative" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' GROUP BY time(12m),"location") GROUP BY "location" -``` - -Output: -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | sum_derivative | -| :--------------------------- | ------------------: | -| 1970-01-01T00:00:00Z | -0.5315000000 | - -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=santa_monica -{{% /influxql/table-meta %}} - -| time | sum_derivative | -| :--------------------------- | ------------------: | -| 1970-01-01T00:00:00Z | -0.2375000000 | - -The query returns the sum of the derivative of average `water_level` values for each tag value of `location`. - -InfluxDB first performs the subquery. -The subquery calculates the derivative of average `water_level` values taken at 12-minute intervals. -It performs that calculation for each tag value of `location` and names the output column `water_level_derivative`: - -```sql -SELECT DERIVATIVE(MEAN("water_level")) AS "water_level_derivative" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' GROUP BY time(12m),"location" -``` -Output: -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | water_level_derivative | -| :--------------------------- | ------------------: | -| 2019-08-18T00:00:00Z | -0.1410000000 | -| 2019-08-18T00:12:00Z | -0.1890000000 | -| 2019-08-18T00:24:00Z | -0.2015000000 | - - -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=santa_monica -{{% /influxql/table-meta %}} - -| time | water_level_derivative | -| :--------------------------- | ------------------: | -| 2019-08-18T00:00:00Z | -0.1375000000 | -| 2019-08-18T00:12:00Z | -0.0295000000 | -| 2019-08-18T00:24:00Z | -0.0705000000 | - - -Next, InfluxDB performs the main query and calculates the sum of the `water_level_derivative` values for each tag value of `location`. -Notice that the main query specifies `water_level_derivative`, not `water_level` or `derivative`, as the field key in the [`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum) function. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Common issues with subqueries - -#### Multiple statements in a subquery - -InfluxQL supports multiple nested subqueries per main query: - -```sql -SELECT_clause FROM ( SELECT_clause FROM ( SELECT_statement ) [...] ) [...] - ------------------ ---------------- - Subquery 1 Subquery 2 -``` - -InfluxQL does not support multiple [`SELECT` statements](/influxdb/v2/query-data/influxql/explore-data/select/) per subquery: - -```sql -SELECT_clause FROM (SELECT_statement; SELECT_statement) [...] -``` - -The system returns a parsing error if a subquery includes multiple `SELECT` statements. + diff --git a/content/influxdb/v2/query-data/influxql/explore-data/time-and-timezone.md b/content/influxdb/v2/query-data/influxql/explore-data/time-and-timezone.md index a1aef44c6..5bfefa5d8 100644 --- a/content/influxdb/v2/query-data/influxql/explore-data/time-and-timezone.md +++ b/content/influxdb/v2/query-data/influxql/explore-data/time-and-timezone.md @@ -12,430 +12,8 @@ list_code_example: | ```sql SELECT_clause FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] tz('') ``` +source: /shared/influxdb-v2/query-data/influxql/explore-data/time-and-timezone.md --- -InfluxQL is designed for working with time series data and includes features specifically for working with time. -You can review the following ways to work with time and timestamps in your InfluxQL queries: - -- [Configuring returned timestamps](#configuring-returned-timestamps) -- [Time syntax](#time-syntax) -- [Absolute time](#absolute-time) -- [Relative time](#relative-time) -- [The Time Zone clause](#the-time-zone-clause) -- [Common issues with time syntax](#common-issues-with-time-syntax) - -## Configuring returned timestamps - -The [InfluxQL shell](/influxdb/v2/tools/influxql-shell/) returns timestamps in -nanosecond UNIX epoch format by default. -Specify alternative formats with the -[`precision ` command](/influxdb/v2/tools/influxql-shell/#precision). - -If you are using the [InfluxQL shell](/influxdb/v2/tools/influxql-shell/), use the precision helper command `precision rfc3339` to view results in human readable format. - -The [InfluxDB API](/influxdb/v2/reference/api/influxdb-1x/) returns timestamps -in [RFC3339](https://www.ietf.org/rfc/rfc3339.txt) format by default. -Specify alternative formats with the -[`epoch` query string parameter](/influxdb/v2/reference/api/influxdb-1x/). - -## Time syntax - -For most `SELECT` statements, the default time range is between [`1677-09-21 00:12:43.145224194` and `2262-04-11T23:47:16.854775806Z` UTC](/influxdb/v2/reference/faq/#what-are-the-minimum-and-maximum-timestamps-that-influxdb-can-store). -For `SELECT` statements with a [`GROUP BY time()` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/), -the default time range is between `1677-09-21 00:12:43.145224194` UTC and [`now()`](/influxdb/v2/reference/glossary/#now). -The following sections detail how to specify alternative time ranges in the `SELECT` -statement's [`WHERE` clause](/influxdb/v2/query-data/influxql/explore-data/where/). - -Other supported features include: -[Absolute time](#absolute-time) -[Relative time](#relative-time) - -## Absolute time - -Specify absolute time with date-time strings and epoch time. - -### Syntax - -```sql -SELECT_clause FROM_clause WHERE time ['' | '' | ] [AND ['' | '' | ] [...]] -``` - -#### Supported operators - -| Operator | Meaning | -|:--------:|:------- | -| `=` | equal to | -| `<>` | not equal to | -| `!=` | not equal to | -| `>` | greater than | -| `>=` | greater than or equal to | -| `<` | less than | -| `<=` | less than or equal to | - -Currently, InfluxDB does not support using `OR` with absolute time in the `WHERE` -clause. See the [Frequently Asked Questions](/influxdb/v2/reference/faq/#why-is-my-query-with-a-where-or-time-clause-returning-empty-results) -document and the [GitHub Issue](https://github.com/influxdata/influxdb/issues/7530) -for more information. - -#### `rfc3339_date_time_string` - -```sql -'YYYY-MM-DDTHH:MM:SS.nnnnnnnnnZ' -``` - -`.nnnnnnnnn` is optional and is set to `.000000000` if not included. -The [RFC3339](https://www.ietf.org/rfc/rfc3339.txt) date-time string requires single quotes. - -#### `rfc3339_like_date_time_string` - -```sql -'YYYY-MM-DD HH:MM:SS.nnnnnnnnn' -``` - -`HH:MM:SS.nnnnnnnnn.nnnnnnnnn` is optional and is set to `00:00:00.000000000` if not included. -The RFC3339-like date-time string requires single quotes. - -#### `epoch_time` - -Epoch time is the amount of time that has elapsed since 00:00:00 -Coordinated Universal Time (UTC), Thursday, 1 January 1970. - -By default, InfluxDB assumes that all epoch timestamps are in **nanoseconds**. Include a [duration literal](/influxdb/v2/reference/glossary/#duration) at the end of the epoch timestamp to indicate a precision other than nanoseconds. - -#### Basic arithmetic - -All timestamp formats support basic arithmetic. -Add (`+`) or subtract (`-`) a time from a timestamp with a [duration literal](/influxdb/v2/reference/glossary/#duration). -Note that InfluxQL requires a whitespace between the `+` or `-` and the -duration literal. - -### Examples - -{{< expand-wrapper >}} - -{{% expand "Specify a time range with RFC3339 date-time strings" %}} - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00.000000000Z' AND time <= '2019-08-18T00:12:00Z' -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------ | ------------------:| -| 2019-08-18T00:00:00Z | 2.3520000000| -| 2019-08-18T00:06:00Z | 2.3790000000| -| 2019-08-18T00:12:00Z | 2.3430000000| - -The query returns data with timestamps between August 18, 2019 at 00:00:00.000000000 and -August 18, 2019 at 00:12:00. - -Note that the single quotes around the RFC3339 date-time strings are required. - -{{% /expand %}} - -{{% expand "Specify a time range with RFC3339-like date-time strings" %}} - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18' AND time <= '2019-08-18 00:12:00' -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------ | ------------------:| -| 2019-08-18T00:00:00Z | 2.3520000000| -| 2019-08-18T00:06:00Z | 2.3790000000| -| 2019-08-18T00:12:00Z | 2.3430000000| - -The query returns data with timestamps between August 18, 2019 at 00:00:00 and August 18, 2019 -at 00:12:00. -The first date-time string does not include a time; InfluxDB assumes the time -is 00:00:00. - -Note that the single quotes around the RFC3339-like date-time strings are -required. - -{{% /expand %}} - -{{% expand "Specify a time range with epoch timestamps" %}} - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= 1564635600000000000 AND time <= 1566190800000000000 -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------ | ------------------:| -| 2019-08-17T00:00:00Z | 2.0640000000| -| 2019-08-17T00:06:00Z | 2.1160000000| -| 2019-08-17T00:12:00Z | 2.0280000000| -| 2019-08-17T00:18:00Z | 2.1260000000| -| 2019-08-17T00:24:00Z | 2.0410000000| -| 2019-08-17T00:30:00Z | 2.0510000000| -| 2019-08-17T00:36:00Z | 2.0670000000| -| 2019-08-17T00:42:00Z | 2.0570000000| -| 2019-08-17T00:48:00Z | 1.9910000000| -| 2019-08-17T00:54:00Z | 2.0540000000| -| 2019-08-17T01:00:00Z | 2.0180000000| -| 2019-08-17T01:06:00Z | 2.0960000000| -| 2019-08-17T01:12:00Z | 2.1000000000| -| 2019-08-17T01:18:00Z | 2.1060000000| -| 2019-08-17T01:24:00Z | 2.1261441460| - -The query returns data with timestamps that occur between August 1, 2019 -at 00:00:00 and August 19, 2019 at 00:12:00. By default InfluxDB assumes epoch timestamps are in nanoseconds. - -{{% /expand %}} - -{{% expand "Specify a time range with second-precision epoch timestamps" %}} - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= 1566190800s AND time <= 1566191520s -``` -Output: -| time | water_level | -| :------------------ | ------------------:| -| 2019-08-19T05:00:00Z | 3.2320000000| -| 2019-08-19T05:06:00Z | 3.2320000000| -| 2019-08-19T05:12:00Z | 3.2910000000| - -The query returns data with timestamps that occur between August 19, 2019 -at 00:00:00 and August 19, 2019 at 00:12:00. -The `s` duration literal at the end of the epoch timestamps indicate that the epoch timestamps are in seconds. - -{{% /expand %}} - -{{% expand "Perform basic arithmetic on an RFC3339-like date-time string" %}} - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE time > '2019-09-17T21:24:00Z' + 6m -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------ | ------------------:| -| 2019-09-17T21:36:00Z | 5.0660000000| -| 2019-09-17T21:42:00Z | 4.9380000000| - -The query returns data with timestamps that occur at least six minutes after -September 17, 2019 at 21:24:00. -Note that the whitespace between the `+` and `6m` is required. - -{{% /expand %}} - -{{% expand "Perform basic arithmetic on an epoch timestamp" %}} - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE time > 24043524m - 6m -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------ | ------------------:| -| 2019-08-17T00:00:00Z | 8.1200000000| -| 2019-08-17T00:00:00Z | 2.0640000000| -| 2019-08-17T00:06:00Z | 8.0050000000| -| 2019-08-17T00:06:00Z | 2.1160000000| -| 2019-08-17T00:12:00Z | 7.8870000000| -| 2019-08-17T00:12:00Z | 2.0280000000| -| 2019-08-17T00:18:00Z | 7.7620000000| -| 2019-08-17T00:18:00Z | 2.1260000000| - -The query returns data with timestamps that occur at least six minutes before -September 18, 2019 at 21:24:00. Note that the whitespace between the `-` and `6m` is required. Note that the results above are partial as the dataset is large. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## Relative time - -Use [`now()`](/influxdb/v2/reference/glossary/#now) to query data with [timestamps](/influxdb/v2/reference/glossary/#timestamp) relative to the server's current timestamp. - -### Syntax - -```sql -SELECT_clause FROM_clause WHERE time now() [[ - | + ] ] [(AND|OR) now() [...]] -``` - -`now()` is the Unix time of the server at the time the query is executed on that server. -The whitespace between `-` or `+` and the [duration literal](/influxdb/v2/reference/glossary/#duration) is required. - -#### Supported operators -| Operator | Meaning | -|:--------:|:------- | -| `=` | equal to | -| `<>` | not equal to | -| `!=` | not equal to | -| `>` | greater than | -| `>=` | greater than or equal to | -| `<` | less than | -| `<=` | less than or equal to | - -#### `duration_literal` - -- microseconds: `u` or `µ` -- milliseconds: `ms` -- seconds`s` -- minutes`m` -- hours:`h` -- days:`d` -- weeks:`w` - -### Examples - -{{< expand-wrapper >}} - -{{% expand "Specify a time range with relative time" %}} - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE time > now() - 1h -``` - -The query returns data with timestamps that occur within the past hour. -The whitespace between `-` and `1h` is required. - -{{% /expand %}} - -{{% expand "Specify a time range with absolute time and relative time" %}} - -#### Specify a time range with absolute time and relative time - -```sql -SELECT "level description" FROM "h2o_feet" WHERE time > '2019-09-17T21:18:00Z' AND time < now() + 1000d -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | level description | -| :------------------ |--------------------:| -|2019-09-17T21:24:00Z | between 3 and 6 feet | -|2019-09-17T21:30:00Z | between 3 and 6 feet | -|2019-09-17T21:36:00Z | between 3 and 6 feet | -|2019-09-17T21:42:00Z | between 3 and 6 feet | - -The query returns data with timestamps that occur between September 17, 2019 at 21:18:00 and 1000 days from `now()`. The whitespace between `+` and `1000d` is required. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## The Time Zone clause - -Use the `tz()` clause to return the UTC offset for the specified timezone. - -### Syntax - -```sql -SELECT_clause FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] tz('') -``` - -By default, InfluxDB stores and returns timestamps in UTC. -The `tz()` clause includes the UTC offset or, if applicable, the UTC Daylight Savings Time (DST) offset to the query's returned timestamps. The returned timestamps must be in `RFC3339` format for the UTC offset or UTC DST to appear. -The `time_zone` parameter follows the TZ syntax in the [Internet Assigned Numbers Authority time zone database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List) and it requires single quotes. - -### Examples - -{{< expand-wrapper >}} - -{{% expand "Return the UTC offset for Chicago's time zone" %}} - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:18:00Z' tz('America/Chicago') -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :-------------- | -------------------:| -| 2019-08-17T19:00:00-05:00 | 2.3520000000| -| 2019-08-17T19:06:00-05:00 | 2.3790000000| -| 2019-08-17T19:12:00-05:00 | 2.3430000000| -| 2019-08-17T19:18:00-05:00 | 2.3290000000| - -The query results include the UTC offset (`-05:00`) for the `America/Chicago` time zone in the timestamps. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## Common issues with time syntax - -### Using `OR` to select time multiple time intervals - -InfluxDB does not support using the `OR` operator in the `WHERE` clause to specify multiple time intervals. - -For more information, see [Frequently asked questions](/influxdb/v2/reference/faq/#why-is-my-query-with-a-where-or-time-clause-returning-empty-results). - -### Querying data that occur after `now()` with a `GROUP BY time()` clause - -Most `SELECT` statements have a default time range between [`1677-09-21 00:12:43.145224194` and `2262-04-11T23:47:16.854775806Z` UTC](/influxdb/v2/reference/faq/#what-are-the-minimum-and-maximum-timestamps-that-influxdb-can-store). -For `SELECT` statements with a [`GROUP BY time()` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals), -the default time range is between `1677-09-21 00:12:43.145224194` UTC and [`now()`](/influxdb/v2/reference/glossary/#now). - -To query data with timestamps that occur after `now()`, `SELECT` statements with -a `GROUP BY time()` clause must provide an alternative upper bound in the -`WHERE` clause. - - + diff --git a/content/influxdb/v2/query-data/influxql/explore-data/where.md b/content/influxdb/v2/query-data/influxql/explore-data/where.md index d29476fd0..3885ee711 100644 --- a/content/influxdb/v2/query-data/influxql/explore-data/where.md +++ b/content/influxdb/v2/query-data/influxql/explore-data/where.md @@ -12,303 +12,8 @@ list_code_example: | ```sql SELECT_clause FROM_clause WHERE [(AND|OR) [...]] ``` +source: /shared/influxdb-v2/query-data/influxql/explore-data/where.md --- -Use the `WHERE` clause to filter data based on -[fields](/influxdb/v2/reference/glossary/#field), -[tags](/influxdb/v2/reference/glossary/#tag), and/or -[timestamps](/influxdb/v2/reference/glossary/#timestamp). - -- [Syntax](#syntax) -- [Examples](#examples) -- [Common issues](#common-issues-with-the-where-clause) - -### Syntax - -```sql -SELECT_clause FROM_clause WHERE [(AND|OR) [...]] -``` - -The `WHERE` clause supports `conditional_expressions` on fields, tags, and timestamps. - -{{% note %}} -**Note:** InfluxDB does not support using OR in the WHERE clause to specify multiple time ranges. For example, InfluxDB returns an empty response for the following query: - -```sql -SELECT * FROM "mydb" WHERE time = '2020-07-31T20:07:00Z' OR time = '2020-07-31T23:07:17Z'` -``` -{{% /note %}} - -#### Fields - -``` -field_key ['string' | boolean | float | integer] -``` - -The `WHERE` clause supports comparisons against string, boolean, float, and integer [field values](/influxdb/v2/reference/glossary/#field-value). - -Single quote string field values in the `WHERE` clause. -Queries with unquoted string field values or double quoted string field values will not return any data and, in most cases, -[will not return an error](#common-issues-with-the-where-clause). - -#### Supported operators - -| Operator | Meaning | -|:--------:|:-------- | -| `=` | equal to | -| `<>` | not equal to | -| `!=` | not equal to | -| `>` | greater than | -| `>=` | greater than or equal to | -| `<` | less than | -| `<=` | less than or equal to | - -InfluxQL also supports [Regular Expressions](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/). - -#### Tags - -```sql -tag_key ['tag_value'] -``` - -Single quote [tag values](/influxdb/v2/reference/glossary/#tag-value) in -the `WHERE` clause. -Queries with unquoted tag values or double quoted tag values will not return -any data and, in most cases, -[will not return an error](#common-issues-with-the-where-clause). - -#### Supported operators - -| Operator | Meaning | -|:--------:|:------- | -| `=` | equal to | -| `<>` | not equal to | -| `!=` | not equal to | - -#### Timestamps - -For most `SELECT` statements, the default time range is between [`1677-09-21 00:12:43.145224194` and `2262-04-11T23:47:16.854775806Z` UTC](/influxdb/v2/reference/faq/#what-are-the-minimum-and-maximum-integers-that-influxdb-can-store). -For `SELECT` statements with a [`GROUP BY time()` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/), the default time -range is between `1677-09-21 00:12:43.145224194` UTC and [`now()`](/influxdb/v2/reference/glossary/#now). - -See [Time Syntax](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) for information on how to specify alternative time ranges in the `WHERE` clause. - -### Examples - -{{< expand-wrapper >}} -{{% expand "Select data with specific field key-values" %}} - - -```sql -SELECT * FROM "h2o_feet" WHERE "water_level" > 9 -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | level description | location | water_level | -| :-------------- | :-------------------| :------------------| -------: | -| 2019-08-25T04:00:00Z | at or greater than 9 feet | coyote_creek | 9.0320000000| -| 2019-08-25T04:06:00Z | at or greater than 9 feet | coyote_creek | 9.0780000000| -| 2019-08-25T04:12:00Z | at or greater than 9 feet | coyote_creek | 9.1110000000| -| 2019-08-25T04:18:00Z | at or greater than 9 feet | coyote_creek | 9.1500000000| -| 2019-08-25T04:24:00Z | at or greater than 9 feet | coyote_creek | 9.1800000000| - -The query returns data from the `h2o_feet` measurement with field values of `water_level` that are greater than nine. -This is a partial data set. - -{{% /expand %}} - -{{% expand "Select data with a specific string field key-value" %}} - -```sql -SELECT * FROM "h2o_feet" WHERE "level description" = 'below 3 feet' -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | level description | location | water_level | -| :-------------- | :-------------------| :------------------| :------------------ | -| 2019-08-17T00:00:00Z | below 3 feet | santa_monica | 2.0640000000| -| 2019-08-17T00:06:00Z | below 3 feet | santa_monica | 2.1160000000| -| 2019-08-17T00:12:00Z | below 3 feet | santa_monica | 2.0280000000| -| 2019-08-17T00:18:00Z | below 3 feet | santa_monica | 2.1260000000| -| 2019-08-17T00:24:00Z | below 3 feet | santa_monica | 2.0410000000| -| 2019-08-17T00:30:00Z | below 3 feet | santa_monica | 2.0510000000| - -The query returns data from the `h2o_feet` measurement with field values of `level description` that equal the `below 3 feet` string. InfluxQL requires single quotes around string field values in the `WHERE` clause. - -{{% /expand %}} - -{{% expand "Select data with a specific field key-value and perform basic arithmetic" %}} - -```sql -SELECT * FROM "h2o_feet" WHERE "water_level" + 2 > 11.9 -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | level description | location | water_level | -| :-------------- | :-------------------| :------------------|---------------: | -| 2019-08-28T07:06:00Z | at or greater than 9 feet | coyote_creek | 9.9020000000| -| 2019-08-28T07:12:00Z | at or greater than 9 feet | coyote_creek | 9.9380000000| -| 2019-08-28T07:18:00Z | at or greater than 9 feet | coyote_creek | 9.9570000000| -| 2019-08-28T07:24:00Z | at or greater than 9 feet | coyote_creek | 9.9640000000| -| 2019-08-28T07:30:00Z | at or greater than 9 feet | coyote_creek | 9.9540000000| -| 2019-08-28T07:36:00Z | at or greater than 9 feet | coyote_creek | 9.9410000000| -| 2019-08-28T07:42:00Z | at or greater than 9 feet | coyote_creek | 9.9250000000| -| 2019-08-28T07:48:00Z | at or greater than 9 feet | coyote_creek | 9.9020000000| -| 2019-09-01T23:30:00Z | at or greater than 9 feet | coyote_creek | 9.9020000000| - -The query returns data from the `h2o_feet` measurement with field values of -`water_level` plus two that are greater than 11.9. Note that InfluxDB follows the standard order of operations. - -See [Mathematical operators](/influxdb/v2/query-data/influxql/math-operators/) -for more on supported operators. - -{{% /expand %}} - -{{% expand "Select data with a specific tag key-value" %}} - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE "location" = 'santa_monica' -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :-------------- | -------------------:| -| 2019-08-17T00:00:00Z | 2.0640000000| -| 2019-08-17T00:06:00Z | 2.1160000000| -| 2019-08-17T00:12:00Z | 2.0280000000| -| 2019-08-17T00:18:00Z | 2.1260000000| -| 2019-08-17T00:24:00Z | 2.0410000000| - - - -The query returns data from the `h2o_feet` measurement where the -[tag key](/influxdb/v2/reference/glossary/#tag-key) `location` is set to `santa_monica`. -InfluxQL requires single quotes around tag values in the `WHERE` clause. - -{{% /expand %}} - -{{% expand "Select data with specific field key-values and tag key-valuest" %}} - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE "location" <> 'santa_monica' AND (water_level < -0.59 OR water_level > 9.95) -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-28T07:18:00Z | 9.9570000000| -| 2019-08-28T07:24:00Z | 9.9640000000| -| 2019-08-28T07:30:00Z | 9.9540000000| -| 2019-08-28T14:30:00Z | -0.6100000000| -| 2019-08-28T14:36:00Z | -0.5910000000| -| 2019-08-29T15:18:00Z | -0.5940000000| - -The query returns data from the `h2o_feet` measurement where the tag key -`location` is not set to `santa_monica` and where the field values of -`water_level` are either less than -0.59 or greater than 9.95. -The `WHERE` clause supports the operators `AND` and `OR`, and supports -separating logic with parentheses. - -{{% /expand %}} - - -{{< /expand-wrapper >}} - -```sql -SELECT * FROM "h2o_feet" WHERE time > now() - 7d -``` - -The query returns data from the `h2o_feet` measurement with [timestamps](/influxdb/v2/reference/glossary/#timestamp) -within the past seven days. See [Time Syntax](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) for more in-depth information on supported time syntax in the `WHERE` clause. - -### Common issues with the `WHERE` clause - -#### A `WHERE` clause query unexpectedly returns no data - -In most cases, this issue is the result of missing single quotes around -tag values or string field values. -Queries with unquoted or double quoted tag values or string field values will -not return any data and, in most cases, will not return an error. - -The first two queries in the code block below attempt to specify the tag value -`santa_monica` without any quotes and with double quotes. -Those queries return no results. -The third query single quotes `santa_monica` (this is the supported syntax) -and returns the expected results. - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE "location" = santa_monica -No results - -SELECT "water_level" FROM "h2o_feet" WHERE "location" = "santa_monica" -No results - -SELECT "water_level" FROM "h2o_feet" WHERE "location" = 'santa_monica' -``` -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-17T00:00:00Z | 2.0640000000 | -| 2019-08-17T00:06:00Z | 2.1160000000 | -| 2019-08-17T00:12:00Z | 2.0280000000 | -| 2019-08-17T00:18:00Z | 2.1260000000 | -| 2019-08-17T00:24:00Z | 2.0410000000 | -| 2019-08-17T00:30:00Z | 2.0510000000 | - -The first two queries in the code block below attempt to specify the string -field value `at or greater than 9 feet` without any quotes and with double -quotes. -The first query returns an error because the string field value includes -white spaces. -The second query returns no results. -The third query single quotes `at or greater than 9 feet` (this is the -supported syntax) and returns the expected results. - -```sql -SELECT "level description" FROM "h2o_feet" WHERE "level description" = at or greater than 9 feet -ERR: 400 Bad Request: failed to parse query: found than, expected ; at line 1, char 86 - -SELECT "level description" FROM "h2o_feet" WHERE "level description" = "at or greater than 9 feet" -No results - -SELECT "level description" FROM "h2o_feet" WHERE "level description" = 'at or greater than 9 feet' -``` - -Output: -{{% influxql/table-meta %}} -Name: h2o_feet -{{% /influxql/table-meta %}} - -| time | level_description | -| :---------------------------| ------: | -| 2019-08-25T04:00:00Z | at or greater than 9 feet | -| 2019-08-25T04:06:00Z | at or greater than 9 feet | -| 019-08-25T04:12:00Z | at or greater than 9 feet | -| 2019-08-25T04:18:00Z | at or greater than 9 feet | -| 2019-08-25T04:24:00Z | at or greater than 9 feet | \ No newline at end of file + diff --git a/content/influxdb/v2/query-data/influxql/explore-schema.md b/content/influxdb/v2/query-data/influxql/explore-schema.md index 915811eeb..32c3c81f9 100644 --- a/content/influxdb/v2/query-data/influxql/explore-schema.md +++ b/content/influxdb/v2/query-data/influxql/explore-schema.md @@ -8,585 +8,8 @@ menu: parent: Query with InfluxQL identifier: explore-schema-influxql weight: 202 +source: /shared/influxdb-v2/query-data/influxql/explore-schema.md --- -Use InfluxQL to explore the schema of your time series data. -Use the following InfluxQL commands to explore your schema: - -- [SHOW SERIES](#show-series) -- [SHOW MEASUREMENTS](#show-measurements) -- [SHOW TAG KEYS](#show-tag-keys) -- [SHOW TAG VALUES](#show-tag-values) -- [SHOW FIELD KEYS](#show-field-keys) -- [SHOW FIELD KEY CARDINALITY](#show-field-key-cardinality) -- [SHOW TAG KEY CARDINALITY](#show-tag-key-cardinality) - -{{% note %}} -Command examples use the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data). -{{% /note %}} - -## SHOW SERIES - -Return a list of [series](/influxdb/v2/reference/glossary/#series) for -the specified [database](/influxdb/v2/reference/glossary/#database). - -### Syntax - -```sql -SHOW SERIES [ON ] [FROM_clause] [WHERE [ '' | ]] [LIMIT_clause] [OFFSET_clause] -``` - -- `ON ` is optional. - If the query does not include `ON `, you must specify the - database with the `db` query string parameter in the - [InfluxDB API](/influxdb/v2/reference/api/influxdb-1x/) request. -- `FROM`, `WHERE`, `LIMIT`, and `OFFSET` clauses are optional. -- The `WHERE` clause in `SHOW SERIES` supports tag comparisons but not field comparisons. - - **Supported operators in the `WHERE` clause**: - - - `=`: equal to - - `<>`: not equal to - - `!=`: not equal to - - `=~`: matches against - - `!~`: doesn't match against - -See [Explore data using InfluxQL](/influxdb/v2/query-data/influxql/explore-data/) for documentation on the -[`FROM` clause](/influxdb/v2/query-data/influxql/explore-data/select/#from-clause), -[`LIMIT` clause](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/), -[`OFFSET` clause](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/), -and [Regular Expressions](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/). - -### Examples - -#### Run SHOW SERIES with the ON clause - -```sql -SHOW SERIES ON noaa -``` - -**Output:** - -The query returns all series in the `noaa` database. -The query's output is similar to the [line protocol](/influxdb/v2/reference/syntax/line-protocol/) format. -Everything before the first comma is the [measurement](/influxdb/v2/reference/glossary/#measurement) name. -Everything after the first comma is either a [tag key](/influxdb/v2/reference/glossary/#tag-key) or a [tag value](/influxdb/v2/reference/glossary/#tag-value). -The `noaa` database has 5 different measurements and 13 different series. - -| key | -| :------------------------------------------ | -| average_temperature,location=coyote_creek | -| average_temperature,location=santa_monica | -| h2o_feet,location=coyote_creek | -| h2o_feet,location=santa_monica | -| h2o_pH,location=coyote_creek | -| h2o_pH,location=santa_monica | -| h2o_quality,location=coyote_creek,randtag=1 | -| h2o_quality,location=coyote_creek,randtag=2 | -| h2o_quality,location=coyote_creek,randtag=3 | -| h2o_quality,location=santa_monica,randtag=1 | -| h2o_quality,location=santa_monica,randtag=2 | -| h2o_quality,location=santa_monica,randtag=3 | -| h2o_temperature,location=coyote_creek | - -#### Run SHOW SERIES with several clauses - -```sql -SHOW SERIES ON noaa FROM "h2o_quality" WHERE "location" = 'coyote_creek' LIMIT 2 -``` - -**Output:** - -The query returns all series in the `noaa` database that are -associated with the `h2o_quality` measurement and the tag `location = coyote_creek`. -The `LIMIT` clause limits the number of series returned to two. - -| key | -| :------------------------------------------ | -|h2o_quality,location=coyote_creek,randtag=1 | -|h2o_quality,location=coyote_creek,randtag=2 | - -## SHOW MEASUREMENTS - -Returns a list of [measurements](/influxdb/v2/reference/glossary/#measurement) -for the specified [database](/influxdb/v2/reference/glossary/#database). - -### Syntax - -```sql -SHOW MEASUREMENTS [ON ] [WITH MEASUREMENT ['' | ]] [WHERE ['' | ]] [LIMIT_clause] [OFFSET_clause] -``` - -- `ON ` is optional. - If the query does not include `ON `, you must specify the - database with the `db` query string parameter in the - [InfluxDB API](/influxdb/v2/reference/api/influxdb-1x/) request. - -- The `WITH`, `WHERE`, `LIMIT` and `OFFSET` clauses are optional. -- The `WHERE` in `SHOW MEASUREMENTS` supports tag comparisons, but not field comparisons. - - **Supported operators in the `WHERE` clause:** - - - `=` : equal to - - `<>`: not equal to - - `!=`: not equal to - - `=~`: matches against - - `!~`: doesn't match against - -See [Explore data using InfluxQL](/influxdb/v2/query-data/influxql/explore-data/) for documentation on the -[`FROM` clause](/influxdb/v2/query-data/influxql/explore-data/select/#from-clause), -[`LIMIT` clause](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/), -[`OFFSET` clause](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/), -and [Regular Expressions](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/). - -### Examples - -#### Run SHOW MEASUREMENTS with the ON clause - -```sql -SHOW MEASUREMENTS ON noaa -``` - -**Output:** - -The query returns the list of measurements in the `noaa` database. -The database has five measurements: `average_temperature`, `h2o_feet`, `h2o_pH`, -`h2o_quality`, and `h2o_temperature`. - -| name | -| :------------------ | -| average_temperature | -| h2o_feet | -| h2o_pH | -| h2o_quality | -| h2o_temperature | - - -#### Run SHOW MEASUREMENTS with several clauses (i) - -```sql -SHOW MEASUREMENTS ON noaa WITH MEASUREMENT =~ /h2o.*/ LIMIT 2 OFFSET 1 -``` - -**Output:** - -The query returns the measurements in the `noaa` database that start with `h2o`. -The `LIMIT` and `OFFSET` clauses limit the number of measurement names returned to -two and offset the results by one, skipping the `h2o_feet` measurement. - -| name | -| :---------- | -| h2o_pH | -| h2o_quality | - -#### Run SHOW MEASUREMENTS with several clauses (ii) - -```sql -SHOW MEASUREMENTS ON noaa WITH MEASUREMENT =~ /h2o.*/ WHERE "randtag" =~ /\d/ -``` - -The query returns all measurements in the `noaa` that start with `h2o` and have -values for the tag key `randtag` that include an integer. - -| name | -| :---------- | -| h2o_quality | - -## SHOW TAG KEYS - -Returns a list of [tag keys](/influxdb/v2/reference/glossary/#tag-key) -associated with the specified [database](/influxdb/v2/reference/glossary/#database). - -### Syntax - -```sql -SHOW TAG KEYS [ON ] [FROM_clause] WITH KEY [ [ "" | ] | [IN ("","")]] [WHERE ['' | ]] [LIMIT_clause] [OFFSET_clause] -``` - -- `ON ` is optional. - If the query does not include `ON `, you must specify the - database with `db` query string parameter in the [InfluxDB API](/influxdb/v2/reference/api/influxdb-1x/) request. -- The `FROM` clause and the `WHERE` clause are optional. -- The `WHERE` clause in `SHOW TAG KEYS` supports tag comparisons, but not field comparisons. - - **Supported operators in the `WHERE` clause:** - - - `=` : equal to - - `<>`: not equal to - - `!=`: not equal to - - `=~`: matches against - - `!~`: doesn't match against - -See [Explore data using InfluxQL](/influxdb/v2/query-data/influxql/explore-data/) for documentation on the -[`FROM` clause](/influxdb/v2/query-data/influxql/explore-data/select/#from-clause), -[`LIMIT` clause](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/), -[`OFFSET` clause](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/), -and [Regular Expressions](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/). - -### Examples - -#### Run SHOW TAG KEYS with the ON clause - -```sql -SHOW TAG KEYS ON noaa -``` - -**Output:** - -The query returns the list of tag keys in the `noaa` database. -The output groups tag keys by measurement name; -it shows that every measurement has the `location` tag key and that the -`h2o_quality` measurement has an additional `randtag` tag key. - -| name | tagKey | -| :------------------ | :------- | -| average_temperature | location | -| h2o_feet | location | -| h2o_pH | location | -| h2o_quality | location | -| h2o_quality | randtag | -| h2o_temperature | location | - - -#### Run SHOW TAG KEYS with several clauses - -```sql -SHOW TAG KEYS ON noaa FROM "h2o_quality" LIMIT 1 OFFSET 1 -``` - -**Output:** - -The query returns tag keys from the `h2o_quality` measurement in the `noaa` database. -The `LIMIT` and `OFFSET` clauses limit the number of tag keys returned to one -and offsets the results by one. - -| name | tagKey | -| :---------- | :------ | -| h2o_quality | randtag | - -#### Run SHOW TAG KEYS with a WITH KEY IN clause - -```sql -SHOW TAG KEYS ON noaa WITH KEY IN ("location") -``` - -**Output:** - -| measurement | tagKey | -| :------------------ | :------- | -| average_temperature | location | -| h2o_feet | location | -| h2o_pH | location | -| h2o_quality | location | -| h2o_quality | randtag | -| h2o_temperature | location | - - -## SHOW TAG VALUES - -Returns the list of [tag values](/influxdb/v2/reference/glossary/#tag-value) -for the specified [tag key(s)](/influxdb/v2/reference/glossary/#tag-key) in the database. - -### Syntax - -```sql -SHOW TAG VALUES [ON ][FROM_clause] WITH KEY [ [ "" | ] | [IN ("","")]] [WHERE ['' | ]] [LIMIT_clause] [OFFSET_clause] -``` - -- `ON ` is optional. - If the query does not include `ON `, you must specify the - database with the `db` query string parameter in the [InfluxDB API](/influxdb/v2/reference/api/influxdb-1x/) request. -- The `WITH` clause is required. - It supports specifying a single tag key, a regular expression, and multiple tag keys. -- The `FROM`, `WHERE`, `LIMIT`, and `OFFSET` clauses are optional. -- The `WHERE` clause in `SHOW TAG KEYS` supports tag comparisons, but not field comparisons. - - **Supported operators in the `WITH` and `WHERE` clauses:** - - - `=` : equal to - - `<>`: not equal to - - `!=`: not equal to - - `=~`: matches against - - `!~`: doesn't match against - -See [Explore data using InfluxQL](/influxdb/v2/query-data/influxql/explore-data/) for documentation on the -[`FROM` clause](/influxdb/v2/query-data/influxql/explore-data/select/#from-clause), -[`LIMIT` clause](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/), -[`OFFSET` clause](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/), -and [Regular Expressions](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/). - -### Examples - -#### Run SHOW TAG VALUES with the ON clause - -```sql -SHOW TAG VALUES ON noaa WITH KEY = "randtag" -``` - -**Output:** - -The query returns all tag values of the `randtag` tag key in the `noaa` database. -`SHOW TAG VALUES` groups query results by measurement name. - -{{% influxql/table-meta %}} -name: h2o_quality -{{% /influxql/table-meta %}} - -| key | value | -| :------ | ----: | -| randtag | 1 | -| randtag | 2 | -| randtag | 3 | - -#### Run a `SHOW TAG VALUES` query with several clauses - -```sql -SHOW TAG VALUES ON noaa WITH KEY IN ("location","randtag") WHERE "randtag" =~ /./ LIMIT 3 -``` - -**Output:** - -The query returns the tag values of the tag keys `location` and `randtag` for -all measurements in the `noaa` database where `randtag` has tag values. -The `LIMIT` clause limits the number of tag values returned to three. - -{{% influxql/table-meta %}} -name: h2o_quality -{{% /influxql/table-meta %}} - -| key | value | -| :------- | -----------: | -| location | coyote_creek | -| location | santa_monica | -| randtag | 1 | - -## SHOW FIELD KEYS - -Returns the [field keys](/influxdb/v2/reference/glossary/#field-key) and the -[data type](/influxdb/v2/reference/glossary/#data-type) of their -[field values](/influxdb/v2/reference/glossary/#field-value). - -### Syntax - -```sql -SHOW FIELD KEYS [ON ] [FROM ] -``` - -- `ON ` is optional. - If the query does not include `ON `, you must specify the - database with `USE ` when using the [InfluxQL shell](/influxdb/v2/tools/influxql-shell/) - or with the `db` query string parameter in the - [InfluxDB 1.x compatibility API](/influxdb/v2/reference/api/influxdb-1x/) request. -- The `FROM` clause is optional. - See the Data Exploration page for documentation on the -[` FROM` clause](/influxdb/v2/query-data/influxql/explore-data/select/#from-clause). - -{{% note %}} -**Note:** A field's data type [can differ](/influxdb/v2/reference/faq/#how-does-influxdb-handle-field-type-discrepancies-across-shards) across -[shards](/influxdb/v2/reference/glossary/#shard). -If your field has more than one type, `SHOW FIELD KEYS` returns the type that -occurs first in the following list: float, integer, string, boolean. -{{% /note %}} - -### Examples - -#### Run SHOW FIELD KEYS with the ON clause - -```sql -SHOW FIELD KEYS ON noaa -``` - -**Output:** - -The query returns the field keys and field value data types for each -measurement in the `noaa` database. - -| name | fieldKey | fieldType | -| :------------------ | :---------------- | :-------- | -| average_temperature | degrees | float | -| h2o_feet | level description | string | -| h2o_feet | water_level | float | -| h2o_pH | pH | float | -| h2o_quality | index | float | -| hh2o_temperature | degrees | float | - -#### Run SHOW FIELD KEYS with the FROM clause - -```sql -SHOW FIELD KEYS ON noaa FROM h2o_feet -``` - -**Output:** - -The query returns the fields keys and field value data types for the `h2o_feet` -measurement in the `noaa` database. - -| name | fieldKey | fieldType | -| :------- | :---------------- | :-------- | -| h2o_feet | level description | string | -| h2o_feet | water_level | float | - -### Common Issues with SHOW FIELD KEYS - -#### SHOW FIELD KEYS and field type discrepancies - -Field value [data types](/influxdb/v2/reference/glossary/#data-type) -cannot differ within a [shard](/influxdb/v2/reference/glossary/#shard) but they -can differ across shards. -`SHOW FIELD KEYS` returns every data type, across every shard, associated with -the field key. - -##### Example - -The `all_the_types` field stores four different data types: - -```sql -SHOW FIELD KEYS -``` - -{{% influxql/table-meta %}} -name: mymeas -{{% /influxql/table-meta %}} - -| fieldKey | fieldType | -| :------------ | :-------- | -| all_the_types | integer | -| all_the_types | float | -| all_the_types | string | -| all_the_types | boolean | - -Note that `SHOW FIELD KEYS` handles field type discrepancies differently from -`SELECT` statements. -For more information, see the -[How does InfluxDB handle field type discrepancies across shards?](/enterprise_influxdb/v1/troubleshooting/frequently-asked-questions/#how-does-influxdb-handle-field-type-discrepancies-across-shards). - -## SHOW FIELD KEY CARDINALITY - -Cardinality is the product of all unique databases, retention policies, measurements, field keys and tag values in your Influx instance. Managing cardinality is important, as high cardinality leads to greater resource usage. - -```sql --- show estimated cardinality of the field key set of current database -SHOW FIELD KEY CARDINALITY --- show exact cardinality on field key set of specified database -SHOW FIELD KEY EXACT CARDINALITY ON noaa -``` - -## SHOW TAG KEY CARDINALITY - -```sql --- show estimated tag key cardinality -SHOW TAG KEY CARDINALITY --- show exact tag key cardinality -SHOW TAG KEY EXACT CARDINALITY -``` - - - - + diff --git a/content/influxdb/v2/query-data/influxql/functions/_index.md b/content/influxdb/v2/query-data/influxql/functions/_index.md index 5ceedb20e..7b58d61b8 100644 --- a/content/influxdb/v2/query-data/influxql/functions/_index.md +++ b/content/influxdb/v2/query-data/influxql/functions/_index.md @@ -7,69 +7,8 @@ menu: name: InfluxQL functions parent: Query with InfluxQL weight: 203 +source: /shared/influxdb-v2/query-data/influxql/functions/_index.md --- -Use InfluxQL functions to aggregate, select, transform, analyze, and predict data. - -{{% note %}} -To query with InfluxQL, the bucket you query must be mapped to a database and retention policy (DBRP). For more information, see how to [Query data with InfluxQL](/influxdb/v2/query-data/influxql/). -{{%/ note %}} - -## InfluxQL functions (by type) - -- [Aggregates](/influxdb/v2/query-data/influxql/functions/aggregates/) - - [COUNT()](/influxdb/v2/query-data/influxql/functions/aggregates/#count) - - [DISTINCT()](/influxdb/v2/query-data/influxql/functions/aggregates/#distinct) - - [INTEGRAL()](/influxdb/v2/query-data/influxql/functions/aggregates/#integral) - - [MEAN()](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) - - [MEDIAN()](/influxdb/v2/query-data/influxql/functions/aggregates/#median) - - [MODE()](/influxdb/v2/query-data/influxql/functions/aggregates/#mode) - - [SPREAD()](/influxdb/v2/query-data/influxql/functions/aggregates/#spread) - - [STDDEV()](/influxdb/v2/query-data/influxql/functions/aggregates/#stddev) - - [SUM()](/influxdb/v2/query-data/influxql/functions/aggregates/#sum) -- [Selectors](/influxdb/v2/query-data/influxql/functions/selectors/) - - [BOTTOM()](/influxdb/v2/query-data/influxql/functions/selectors/#bottom) - - [FIRST()](/influxdb/v2/query-data/influxql/functions/selectors/#first) - - [LAST()](/influxdb/v2/query-data/influxql/functions/selectors/#last) - - [MAX()](/influxdb/v2/query-data/influxql/functions/selectors/#max) - - [MIN()](/influxdb/v2/query-data/influxql/functions/selectors/#min) - - [PERCENTILE()](/influxdb/v2/query-data/influxql/functions/selectors/#percentile) - - [SAMPLE()](/influxdb/v2/query-data/influxql/functions/selectors/#sample) - - [TOP()](/influxdb/v2/query-data/influxql/functions/selectors/#top) -- [Transformations](/influxdb/v2/query-data/influxql/functions/transformations/) - - [ABS()](/influxdb/v2/query-data/influxql/functions/transformations/#abs) - - [ACOS()](/influxdb/v2/query-data/influxql/functions/transformations/#acos) - - [ASIN()](/influxdb/v2/query-data/influxql/functions/transformations/#asin) - - [ATAN()](/influxdb/v2/query-data/influxql/functions/transformations/#atan) - - [ATAN2()](/influxdb/v2/query-data/influxql/functions/transformations/#atan2) - - [CEIL()](/influxdb/v2/query-data/influxql/functions/transformations/#ceil) - - [COS()](/influxdb/v2/query-data/influxql/functions/transformations/#cos) - - [CUMULATIVE_SUM()](/influxdb/v2/query-data/influxql/functions/transformations/#cumulative_sum) - - [DERIVATIVE()](/influxdb/v2/query-data/influxql/functions/transformations/#derivative) - - [DIFFERENCE()](/influxdb/v2/query-data/influxql/functions/transformations/#difference) - - [ELAPSED()](/influxdb/v2/query-data/influxql/functions/transformations/#elapsed) - - [EXP()](/influxdb/v2/query-data/influxql/functions/transformations/#exp) - - [FLOOR()](/influxdb/v2/query-data/influxql/functions/transformations/#floor) - - [HISTOGRAM()](/influxdb/v2/query-data/influxql/functions/transformations/#histogram) - - [LN()](/influxdb/v2/query-data/influxql/functions/transformations/#ln) - - [LOG()](/influxdb/v2/query-data/influxql/functions/transformations/#log) - - [LOG2()](/influxdb/v2/query-data/influxql/functions/transformations/#log2) - - [LOG10()](/influxdb/v2/query-data/influxql/functions/transformations/#log10) - - [MOVING_AVERAGE()](/influxdb/v2/query-data/influxql/functions/transformations/#moving_average) - - [NON_NEGATIVE_DERIVATIVE()](/influxdb/v2/query-data/influxql/functions/transformations/#non_negative_derivative) - - [NON_NEGATIVE_DIFFERENCE()](/influxdb/v2/query-data/influxql/functions/transformations/#non_negative_difference) - - [POW()](/influxdb/v2/query-data/influxql/functions/transformations/#pow) - - [ROUND()](/influxdb/v2/query-data/influxql/functions/transformations/#round) - - [SIN()](/influxdb/v2/query-data/influxql/functions/transformations/#sin) - - [SQRT()](/influxdb/v2/query-data/influxql/functions/transformations/#sqrt) - - [TAN()](/influxdb/v2/query-data/influxql/functions/transformations/#tan) -- [Technical analysis](/influxdb/v2/query-data/influxql/functions/technical-analysis/) - - (Predictive analysis) [HOLT_WINTERS()](/influxdb/v2/query-data/influxql/functions/technical-analysis/#holt_winters) - - [CHANDE_MOMENTUM_OSCILLATOR()](/influxdb/v2/query-data/influxql/functions/technical-analysis/#chande_momentum_oscillator) - - [EXPONENTIAL_MOVING_AVERAGE()](/influxdb/v2/query-data/influxql/functions/technical-analysis/#exponential_moving_average) - - [DOUBLE_EXPONENTIAL_MOVING_AVERAGE()](/influxdb/v2/query-data/influxql/functions/technical-analysis/#double_exponential_moving_average) - - [KAUFMANS_EFFICIENCY_RATIO()](/influxdb/v2/query-data/influxql/functions/technical-analysis/#kaufmans_adaptive_moving_average) - - [KAUFMANS_ADAPTIVE_MOVING_AVERAGE()](/influxdb/v2/query-data/influxql/functions/technical-analysis/#kaufmans_adaptive_moving_average) - - [TRIPLE_EXPONENTIAL_MOVING_AVERAGE()](/influxdb/v2/query-data/influxql/functions/technical-analysis/#triple_exponential_moving_average) - - [TRIPLE_EXPONENTIAL_DERIVATIVE()](/influxdb/v2/query-data/influxql/functions/technical-analysis/#triple_exponential_derivative) - - [RELATIVE_STRENGTH_INDEX()](/influxdb/v2/query-data/influxql/functions/technical-analysis/#relative_strength_index) + diff --git a/content/influxdb/v2/query-data/influxql/functions/aggregates.md b/content/influxdb/v2/query-data/influxql/functions/aggregates.md index 17d67d46f..3e03316a2 100644 --- a/content/influxdb/v2/query-data/influxql/functions/aggregates.md +++ b/content/influxdb/v2/query-data/influxql/functions/aggregates.md @@ -8,1017 +8,8 @@ menu: name: Aggregates parent: InfluxQL functions weight: 205 +source: /shared/influxdb-v2/query-data/influxql/functions/aggregates.md --- -Use aggregate functions to assess, aggregate, and return values in your data. -Aggregate functions return one row containing the aggregate values from each InfluxQL group. - -Each aggregate function below covers **syntax** including parameters to pass to the function, and **examples** of how to use the function. Examples use [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data). - -- [COUNT()](#count) -- [DISTINCT()](#distinct) -- [INTEGRAL()](#integral) -- [MEAN()](#mean) -- [MEDIAN()](#median) -- [MODE()](#mode) -- [SPREAD()](#spread) -- [STDDEV()](#stddev) -- [SUM()](#sum) - -## COUNT() - -Returns the number of non-null [field values](/influxdb/v2/reference/glossary/#field-value). Supports all field value [data types](/influxdb/v2/reference/glossary/#data-type). - -### Syntax - -```sql -SELECT COUNT( [ * | | // ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`COUNT(*)` - -Returns the number of field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`COUNT(field_key)` - -Returns the number of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`COUNT(/regular_expression/)` - -Returns the number of field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/#regular-expressions). - -#### Examples - -{{< expand-wrapper >}} -{{% expand "Count values for a field" %}} - -Return the number of non-null field values in the `water_level` field key in the `h2o_feet` measurement. - -```sql -SELECT COUNT("water_level") FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | count | -| :------------------- | ---------------: | -| 1970-01-01T00:00:00Z | 61026.0000000000 | - -{{% /expand %}} - -{{% expand "Count values for each field in a measurement" %}} - -Return the number of non-null field values for each field key associated with the `h2o_feet` measurement. -The `h2o_feet` measurement has two field keys: `level description` and `water_level`. - -```sql -SELECT COUNT(*) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | count_level description | count_water_level | -| :------------------- | ----------------------: | ----------------: | -| 1970-01-01T00:00:00Z | 61026.0000000000 | 61026.0000000000 | - -{{% /expand %}} - -{{% expand "Count the values that match a regular expression" %}} - -Return the number of non-null field values for every field key that contains the -word `water` in the `h2o_feet` measurement. - -```sql -SELECT COUNT(/water/) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | count_water_level | -| :------------------- | ----------------: | -| 1970-01-01T00:00:00Z | 61026.0000000000 | - -{{% /expand %}} - -{{% expand "Count distinct values for a field" %}} - -Return the number of unique field values for the `level description` field key -and the `h2o_feet` measurement. -InfluxQL supports nesting [DISTINCT()](#distinct) in `COUNT()`. - -```sql -SELECT COUNT(DISTINCT("level description")) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | count | -| :------------------- | -----------: | -| 1970-01-01T00:00:00Z | 4.0000000000 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## DISTINCT() - -Returns the list of unique [field values](/influxdb/v2/reference/glossary/#field-value). -Supports all field value [data types](/influxdb/v2/reference/glossary/#data-type). - -InfluxQL supports nesting `DISTINCT()` with [`COUNT()`](#count). - -### Syntax - -```sql -SELECT DISTINCT( [ | // ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`DISTINCT(field_key)` - -Returns the unique field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -#### Examples - -{{< expand-wrapper >}} -{{% expand "List the distinct field values associated with a field key" %}} - -Return a tabular list of the unique field values in the `level description` -field key in the `h2o_feet` measurement. - -```sql -SELECT DISTINCT("level description") FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | distinct | -| :------------------- | :------------------------ | -| 1970-01-01T00:00:00Z | between 6 and 9 feet | -| 1970-01-01T00:00:00Z | below 3 feet | -| 1970-01-01T00:00:00Z | between 3 and 6 feet | -| 1970-01-01T00:00:00Z | at or greater than 9 feet | - -{{% /expand %}} - - -{{% expand "List the distinct field values associated with each field key in a measurement" %}} - -Return a tabular list of the unique field values for each field key in the `h2o_feet` measurement. -The `h2o_feet` measurement has two field keys: `level description` and `water_level`. - -```sql -SELECT DISTINCT(*) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | distinct_level description | distinct_water_level | -| :------------------- | :------------------------- | -------------------: | -| 1970-01-01T00:00:00Z | between 6 and 9 feet | 8.12 | -| 1970-01-01T00:00:00Z | between 3 and 6 feet | 8.005 | -| 1970-01-01T00:00:00Z | at or greater than 9 feet | 7.887 | -| 1970-01-01T00:00:00Z | below 3 feet | 7.762 | - -{{% /expand %}} ---> - -{{< /expand-wrapper >}} - -## INTEGRAL() - -Returns the area under the curve for subsequent [field values](/influxdb/v2/reference/glossary/#field-value). - -{{% note %}} -`INTEGRAL()` does not support [`fill()`](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals-and-fill). `INTEGRAL()` supports int64 and float64 field value [data types](/influxdb/v2/reference/glossary/#data-type). -{{% /note %}} - -### Syntax - -```sql -SELECT INTEGRAL( [ * | | // ] [ , ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -InfluxDB calculates the area under the curve for subsequent field values and converts those results into the summed area per `unit`. -The `unit` argument is an integer followed by an optional [duration literal](/influxdb/v2/reference/syntax/influxql/spec/#literals). -If the query does not specify the `unit`, the unit defaults to one second (`1s`). - -`INTEGRAL(field_key)` - -Returns the area under the curve for subsequent field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`INTEGRAL(/regular_expression/)` - -Returns the area under the curve for subsequent field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/#regular-expressions). - -`INTEGRAL(*)` - -Returns the average field value associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -#### Examples - -The following examples use a subset of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data) data: - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:30:00Z | 2.2670000000 | - -{{< expand-wrapper >}} -{{% expand "Calculate the integral for the field values associated with a field key" %}} - -Return the area under the curve (in seconds) for the field values associated -with the `water_level` field key and in the `h2o_feet` measurement. - -```sql -SELECT INTEGRAL("water_level") FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | integral | -| :------------------- | --------------: | -| 1970-01-01T00:00:00Z | 4184.8200000000 | - -{{% /expand %}} - -{{% expand "Calculate the integral for the field values associated with a field key and specify the unit option" %}} - -Return the area under the curve (in minutes) for the field values associated -with the `water_level` field key and in the `h2o_feet` measurement. - -```sql -SELECT INTEGRAL("water_level",1m) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | integral | -| :------------------- | ------------: | -| 1970-01-01T00:00:00Z | 69.7470000000 | - -{{% /expand %}} - -{{% expand "Calculate the integral for the field values associated with each field key in a measurement and specify the unit option" %}} - -Return the area under the curve (in minutes) for the field values associated -with each field key that stores numeric values in the `h2o_feet` measurement. -The `h2o_feet` measurement has on numeric field: `water_level`. - -```sql -SELECT INTEGRAL(*,1m) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | integral_water_level | -| :------------------- | -------------------: | -| 1970-01-01T00:00:00Z | 69.7470000000 | - -{{% /expand %}} - -{{% expand "Calculate the integral for the field values associated with each field key that matches a regular expression and specify the unit option" %}} - -Return the area under the curve (in minutes) for the field values associated -with each field key that stores numeric values includes the word `water` in -the `h2o_feet` measurement. - -```sql -SELECT INTEGRAL(/water/,1m) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | integral_water_level | -| :------------------- | -------------------: | -| 1970-01-01T00:00:00Z | 69.7470000000 | - -{{% /expand %}} - -{{% expand "Calculate the integral for the field values associated with a field key and include several clauses" %}} - -Return the area under the curve (in minutes) for the field values associated -with the `water_level` field key and in the `h2o_feet` measurement in the -[time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) between -`2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z`, [grouped](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) results into 12-minute intervals, and -[limit](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of results returned to one. - -```sql -SELECT INTEGRAL("water_level",1m) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' GROUP BY time(12m) LIMIT 1 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | integral | -| :------------------- | -------------: | -| 2019-08-18T00:00:00Z | 28.3590000000 | - -{{% /expand %}} -{{< /expand-wrapper >}} - -## MEAN() - -Returns the arithmetic mean (average) of [field values](/influxdb/v2/reference/glossary/#field-value). `MEAN()` supports int64 and float64 field value [data types](/influxdb/v2/reference/glossary/#data-type). - -### Syntax - -```sql -SELECT MEAN( [ * | | // ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`MEAN(field_key)` -Returns the average field value associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`MEAN(/regular_expression/) - -Returns the average field value associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/#regular-expressions). - -`MEAN(*)` -Returns the average field value associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -#### Examples - -{{< expand-wrapper >}} -{{% expand "Calculate the mean field value associated with a field key" %}} - -Return the average field value in the `water_level` field key in the `h2o_feet` measurement. - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | -----------: | -| 1970-01-01T00:00:00Z | 4.4418674882 | - -{{% /expand %}} - -{{% expand "Calculate the mean field value associated with each field key in a measurement" %}} - -Return the average field value for every field key that stores numeric values -in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT MEAN(*) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | mean_water_level | -| :------------------- | ---------------: | -| 1970-01-01T00:00:00Z | 4.4418674882 | - -{{% /expand %}} - -{{% expand "Calculate the mean field value associated with each field key that matches a regular expression" %}} - -Return the average field value for each field key that stores numeric values and -includes the word `water` in the `h2o_feet` measurement. - -```sql -SELECT MEAN(/water/) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | mean_water_level | -| :------------------- | ---------------: | -| 1970-01-01T00:00:00Z | 4.4418674882 | - -{{% /expand %}} - -{{% expand "Calculate the mean field value associated with a field key and include several clauses" %}} - -Return the average of the values in the `water_level` field key in the -[time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` and -[group](/influxdb/v2/query-data/influxql/explore-data/group-by/) -results into 12-minute time intervals and per tag. -Then [fill](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals-and-fill) -empty time intervals with `9.01` and -[limit](/influxdb/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points and series returned to seven and one. - -```sql -SELECT MEAN("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' GROUP BY time(12m),* fill(9.01) LIMIT 7 SLIMIT 1 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | mean | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 8.4615000000 | -| 2019-08-18T00:12:00Z | 8.2725000000 | -| 2019-08-18T00:24:00Z | 8.0710000000 | - -{{% /expand %}} -{{< /expand-wrapper >}} - -## MEDIAN() - -Returns the middle value from a sorted list of [field values](/influxdb/v2/reference/glossary/#field-value). `MEDIAN()` supports int64 and float64 field value [data types](/influxdb/v2/reference/glossary/#data-type). - -{{% note %}} -**Note:** `MEDIAN()` is nearly equivalent to [`PERCENTILE(field_key, 50)`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile), except `MEDIAN()` returns the average of the two middle field values if the field contains an even number of values. -{{% /note %}} - -### Syntax - -```sql -SELECT MEDIAN( [ * | | // ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`MEDIAN(field_key)` - -Returns the middle field value associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`MEDIAN(/regular_expression/)` - -Returns the middle field value associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/#regular-expressions). - -`MEDIAN(*)` - -Returns the middle field value associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -#### Examples - -{{< expand-wrapper >}} -{{% expand "Calculate the median field value associated with a field key" %}} - -Return the middle field value in the `water_level` field key and in the `h2o_feet` measurement. - -```sql -SELECT MEDIAN("water_level") FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | median | -| :------------------- | -----------: | -| 1970-01-01T00:00:00Z | 4.1240000000 | - -{{% /expand %}} - -{{% expand "Calculate the median field value associated with each field key in a measurement" %}} - -Return the middle field value for every field key that stores numeric values in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT MEDIAN(*) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | median_water_level | -| :------------------- | -----------------: | -| 1970-01-01T00:00:00Z | 4.1240000000 | - -{{% /expand %}} - -{{% expand "Calculate the median field value associated with each field key that matches a regular expression" %}} - -Return the middle field value for every field key that stores numeric values and -includes the word `water` in the `h2o_feet` measurement. - -```sql -SELECT MEDIAN(/water/) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | median_water_level | -| :------------------- | -----------------: | -| 1970-01-01T00:00:00Z | 4.1240000000 | - -{{% /expand %}} - -{{% expand "Calculate the median field value associated with a field key and include several clauses" %}} - -Return the middle field value in the `water_level` field key in the -[time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` and -[group](/influxdb/v2/query-data/influxql/explore-data/group-by/) -results into 12-minute time intervals and per tag. -Then [fill](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals-and-fill) -empty time intervals with `700 `, [limit](/influxdb/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points and series returned to seven and one, and [offset](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) the series returned by one. - -```sql -SELECT MEDIAN("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' GROUP BY time(12m),* fill(700) LIMIT 7 SLIMIT 1 SOFFSET 1 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=santa_monica -{{% /influxql/table-meta %}} - -| time | median | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3655000000 | -| 2019-08-18T00:12:00Z | 2.3360000000 | -| 2019-08-18T00:24:00Z | 2.2655000000 | - -{{% /expand %}} -{{< /expand-wrapper >}} - -## MODE() - -Returns the most frequent value in a list of [field values](/influxdb/v2/reference/glossary/#field-value). `MODE()` supports all field value [data types](/influxdb/v2/reference/glossary/#data-type). - -{{% note %}} -**Note:** `MODE()` returns the field value with the earliest [timestamp](/influxdb/v2/reference/glossary/#timestamp) if there's a tie between two or more values for the maximum number of occurrences. -{{% /note %}} - -### Syntax - -```sql -SELECT MODE( [ * | | // ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`MODE(field_key)` - -Returns the most frequent field value associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`MODE(/regular_expression/)` - -Returns the most frequent field value associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/#regular-expressions). - -`MODE(*)` - -Returns the most frequent field value associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the mode field value associated with a field key" %}} - -Return the most frequent field value in the `level description` field key and in -the `h2o_feet` measurement. - -```sql -SELECT MODE("level description") FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | mode | -| :------------------- | :------------------- | -| 1970-01-01T00:00:00Z | between 3 and 6 feet | - -{{% /expand %}} - -{{% expand "Calculate the mode field value associated with each field key in a measurement" %}} - -Return the most frequent field value for every field key in the `h2o_feet` measurement. -The `h2o_feet` measurement has two field keys: `level description` and `water_level`. - -```sql -SELECT MODE(*) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | mode_level description | mode_water_level | -| :------------------- | :--------------------- | ---------------: | -| 1970-01-01T00:00:00Z | between 3 and 6 feet | 2.6900000000 | - -{{% /expand %}} - -{{% expand "Calculate the mode field value associated with each field key that matches a regular expression" %}} - -Return the most frequent field value for every field key that includes the word -`/water/` in the `h2o_feet` measurement. - -```sql -SELECT MODE(/water/) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | mode_water_level | -| :------------------- | ---------------: | -| 1970-01-01T00:00:00Z | 2.6900000000 | - -{{% /expand %}} - -{{% expand "Calculate the mode field value associated with a field key and include several clauses" %}} - -Return the mode of the values associated with the `water_level` field key in the -[time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` and -[group](/influxdb/v2/query-data/influxql/explore-data/group-by/) -results into 12-minute time intervals and per tag. -Then [limits](/influxdb/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points and series returned to three and one, and it [offsets](/influxdb/v2/query-data/influxql/explore-data -#the-offset-and-soffset-clauses) the series returned by one. - -```sql -SELECT MODE("level description") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' GROUP BY time(12m),* LIMIT 3 SLIMIT 1 SOFFSET 1 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=santa_monica -{{% /influxql/table-meta %}} - -| time | mode | -| :------------------- | :----------- | -| 2019-08-18T00:00:00Z | below 3 feet | -| 2019-08-18T00:12:00Z | below 3 feet | -| 2019-08-18T00:24:00Z | below 3 feet | - -{{% /expand %}} -{{< /expand-wrapper >}} - -## SPREAD() - -Returns the difference between the minimum and maximum [field values](/influxdb/v2/reference/glossary/#field-value). `SPREAD()` supports int64 and float64 field value [data types](/influxdb/v2/reference/glossary/#data-type). - -### Syntax - -```sql -SELECT SPREAD( [ * | | // ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`SPREAD(field_key)` - -Returns the difference between the minimum and maximum field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`SPREAD(/regular_expression/)` - -Returns the difference between the minimum and maximum field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/#regular-expressions). - -`SPREAD(*)` - -Returns the difference between the minimum and maximum field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the spread for the field values associated with a field key" %}} - -Return the difference between the minimum and maximum field values in the -`water_level` field key and in the `h2o_feet` measurement. - -```sql -SELECT SPREAD("water_level") FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | spread | -| :------------------- | ------------: | -| 1970-01-01T00:00:00Z | 10.5740000000 | - -{{% /expand %}} - -{{% expand "Calculate the spread for the field values associated with each field key in a measurement" %}} - -Return the difference between the minimum and maximum field values for every -field key that stores numeric values in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT SPREAD(*) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | spread_water_level | -| :------------------- | -----------------: | -| 1970-01-01T00:00:00Z | 10.5740000000 | - -{{% /expand %}} - -{{% expand "Calculate the spread for the field values associated with each field key that matches a regular expression" %}} - -Return the difference between the minimum and maximum field values for every -field key that stores numeric values and includes the word `water` in the `h2o_feet` measurement. - -```sql -SELECT SPREAD(/water/) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | spread_water_level | -| :------------------- | -----------------: | -| 1970-01-01T00:00:00Z | 10.5740000000 | - -{{% /expand %}} - -{{% expand "Calculate the spread for the field values associated with a field key and include several clauses" %}} - -Return the difference between the minimum and maximum field values in the `water_level` field key in the -[time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` and -[group](/influxdb/v2/query-data/influxql/explore-data/group-by/) -results into 12-minute time intervals and per tag. -Then [fill](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals-and-fill) -empty time intervals with `18`, [lim -ts](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points and series returned to three and one, and [offsets](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) the series returned by one. - -```sql -SELECT SPREAD("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' GROUP BY time(12m),* fill(18) LIMIT 3 SLIMIT 1 SOFFSET 1 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=santa_monica -{{% /influxql/table-meta %}} - -| time | spread | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 0.0270000000 | -| 2019-08-18T00:12:00Z | 0.0140000000 | -| 2019-08-18T00:24:00Z | 0.0030000000 | - -{{% /expand %}} -{{< /expand-wrapper >}} - -## STDDEV() - -Returns the standard deviation of [field values](/influxdb/v2/reference/glossary/#field-value). `STDDEV()` supports int64 and float64 field value [data types](/influxdb/v2/reference/glossary/#data-type). - -### Syntax - -```sql -SELECT STDDEV( [ * | | // ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`STDDEV(field_key)` - -Returns the standard deviation of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`STDDEV(/regular_expression/)` - -Returns the standard deviation of field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/#regular-expressions). - -`STDDEV(*)` - -Returns the standard deviation of field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -#### Examples - -{{< expand-wrapper >}} -{{% expand "Calculate the standard deviation for the field values associated with a field key" %}} - -Return the standard deviation of the field values in the `water_level` field key -and in the `h2o_feet` measurement. - -```sql -SELECT STDDEV("water_level") FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | stddev | -| :------------------- | -----------: | -| 1970-01-01T00:00:00Z | 2.2789744110 | - -{{% /expand %}} - -{{% expand "Calculate the standard deviation for the field values associated with each field key in a measurement" %}} - -Return the standard deviation of numeric fields in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT STDDEV(*) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | stddev_water_level | -| :------------------- | -----------------: | -| 1970-01-01T00:00:00Z | 2.2789744110 | - -{{% /expand %}} - -{{% expand "Calculate the standard deviation for the field values associated with each field key that matches a regular expression" %}} - -Return the standard deviation of numeric fields with `water` in the field key in the `h2o_feet` measurement. - -```sql -SELECT STDDEV(/water/) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | stddev_water_level | -| :------------------- | -----------------: | -| 1970-01-01T00:00:00Z | 2.2789744110 | - -{{% /expand %}} - -{{% expand "Calculate the standard deviation for the field values associated with a field key and include several clauses" %}} - -Return the standard deviation of the field values in the `water_level` field key in the -[time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` and -[group](/influxdb/v2/query-data/influxql/explore-data/group-by/) -results into 12-minute time intervals and per tag. -Then [fill](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals-and-fill) -empty time intervals with `18000`, [limit](/influxdb/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points and series returned to two and one, and [offsets](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) the series returned by one. - -```sql -SELECT STDDEV("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' GROUP BY time(12m),* fill(18000) LIMIT 2 SLIMIT 1 SOFFSET 1 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=santa_monica -{{% /influxql/table-meta %}} - -| time | stddev | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 0.0190918831 | -| 2019-08-18T00:12:00Z | 0.0098994949 | - -{{% /expand %}} -{{< /expand-wrapper >}} - -## SUM() - -Returns the sum of [field values](/influxdb/v2/reference/glossary/#field-value). `SUM()` supports int64 and float64 field value [data types](/influxdb/v2/reference/glossary/#data-type). - -### Syntax - -```sql -SELECT SUM( [ * | | // ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`SUM(field_key)` - -Returns the sum of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`SUM(/regular_expression/)` - -Returns the sum of field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/#regular-expressions). - -`SUM(*)` - -Returns the sums of field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -#### Examples - -{{< expand-wrapper >}} -{{% expand "Calculate the sum of the field values associated with a field key" %}} - -Return the summed total of the field values in the `water_level` field key and -in the `h2o_feet` measurement. - -```sql -SELECT SUM("water_level") FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | sum | -| :------------------- | ----------------: | -| 1970-01-01T00:00:00Z | 271069.4053333958 | - -{{% /expand %}} - -{{% expand "Calculate the sum of the field values associated with each field key in a measurement" %}} - -Return the summed total of numeric fields in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT SUM(*) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | sum_water_level | -| :------------------- | ----------------: | -| 1970-01-01T00:00:00Z | 271069.4053333958 | - -{{% /expand %}} - -{{% expand "Calculate the sum of the field values associated with each field key that matches a regular expression" %}} - -Return the summed total of numeric fields with `water` in the field key in the `h2o_feet` measurement. - -```sql -SELECT SUM(/water/) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | sum_water_level | -| :------------------- | ----------------: | -| 1970-01-01T00:00:00Z | 271069.4053333958 | - -{{% /expand %}} - -{{% expand "Calculate the sum of the field values associated with a field key and include several clauses" %}} - -Return the summed total of the field values in the `water_level` field key in the -[time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` and -[group](/influxdb/v2/query-data/influxql/explore-data/group-by/) -results into 12-minute time intervals and per tag. -Then [fill](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals-and-fill) -empty time intervals with 18000, and [limit](/influxdb/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points and series returned to four and one. - -```sql -SELECT SUM("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' GROUP BY time(12m),* fill(18000) LIMIT 4 SLIMIT 1 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | sum | -| :------------------- | ------------: | -| 2019-08-18T00:00:00Z | 16.9230000000 | -| 2019-08-18T00:12:00Z | 16.5450000000 | -| 2019-08-18T00:24:00Z | 16.1420000000 | - -{{% /expand %}} -{{< /expand-wrapper >}} + diff --git a/content/influxdb/v2/query-data/influxql/functions/selectors.md b/content/influxdb/v2/query-data/influxql/functions/selectors.md index 06c804f37..b02ebca09 100644 --- a/content/influxdb/v2/query-data/influxql/functions/selectors.md +++ b/content/influxdb/v2/query-data/influxql/functions/selectors.md @@ -8,1294 +8,8 @@ menu: name: Selectors parent: InfluxQL functions weight: 205 +source: /shared/influxdb-v2/query-data/influxql/functions/selectors.md --- -Use selector functions to assess, select, and return values in your data. -Selector functions return one or more rows with the selected values from each InfluxQL group. - -Each selector function below covers **syntax**, including parameters to pass to the function, and **examples** of how to use the function. Examples use [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data). - -- [BOTTOM()](#bottom) -- [FIRST()](#first) -- [LAST()](#last) -- [MAX()](#max) -- [MIN()](#min) -- [PERCENTILE()](#percentile) -- [SAMPLE()](#sample) -- [TOP()](#top) - -## BOTTOM() - -Returns the smallest `N` [field values](/influxdb/v2/reference/glossary/#field-value). `BOTTOM()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -{{% note %}} -**Note:** `BOTTOM()` returns the field value with the earliest timestamp if there's a tie between two or more values for the smallest value. -{{% /note %}} - -### Syntax - -```sql -SELECT BOTTOM([,], )[,|] FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`BOTTOM(field_key,N)` -Returns the smallest N field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`BOTTOM(field_key,tag_key,N)` -Returns the smallest field value for N tag values of the [tag key](/influxdb/v2/reference/glossary/#tag-key). Add a comma between multiple tag keys: `tag_key,tag_key`. - -`BOTTOM((field_key,N),tag_key,field_key)` -Returns the smallest N field values associated with the field key in the parentheses and the relevant [tag](/influxdb/v2/reference/glossary/#tag) and/or [field](/influxdb/v2/reference/glossary/#field). Add a comma between multiple tag or field keys: `tag_key,tag_key,field_key,field_key`. - -#### Examples - -{{< expand-wrapper >}} -{{% expand "Select the bottom three field values associated with a field key" %}} - -Return the smallest three field values in the `water_level` field key and in the -`h2o_feet` [measurement](/influxdb/v2/reference/glossary/#measurement). - -```sql -SELECT BOTTOM("water_level",3) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | bottom | -| :------------------- | -----: | -| 2019-08-29T14:30:00Z | -0.610 | -| 2019-08-29T14:36:00Z | -0.591 | -| 2019-08-30T15:18:00Z | -0.594 | - -{{% /expand %}} - -{{% expand "Select the bottom field value associated with a field key for two tags" %}} - -Return the smallest field values in the `water_level` field key for two tag -values associated with the `location` tag key. - -```sql -SELECT BOTTOM("water_level","location",2) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | bottom | location | -| :------------------- | -----: | :----------- | -| 2019-08-29T10:36:00Z | -0.243 | santa_monica | -| 2019-08-29T14:30:00Z | -0.610 | coyote_creek | - -{{% /expand %}} - -{{% expand "Select the bottom four field values associated with a field key and the relevant tags and fields" %}} - -Return the smallest four field values in the `water_level` field key and the -relevant values of the `location` tag key and the `level description` field key. - -```sql -SELECT BOTTOM("water_level",4),"location","level description" FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | bottom | location | level description | -| :------------------- | -----: | :----------- | :---------------- | -| 2019-08-29T14:24:00Z | -0.587 | coyote_creek | below 3 feet | -| 2019-08-29T14:30:00Z | -0.610 | coyote_creek | below 3 feet | -| 2019-08-29T14:36:00Z | -0.591 | coyote_creek | below 3 feet | -| 2019-08-30T15:18:00Z | -0.594 | coyote_creek | below 3 feet | - -{{% /expand %}} - -{{% expand "Select the bottom three field values associated with a field key and include several clauses" %}} - -Return the smallest three values in the `water_level` field key for each 24-minute -[interval](/influxdb/v2/query-data/influxql/explore-data/group-by/#basic-group-by-time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:54:00Z` with results in -[descending timestamp](/influxdb/v2/query-data/influxql/explore-data/order-by/) order. - -```sql -SELECT BOTTOM("water_level",3),"location" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:54:00Z' GROUP BY time(24m) ORDER BY time DESC -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | bottom | location | -| :------------------- | -----------: | :----------- | -| 2019-08-18T00:54:00Z | 2.172 | santa_monica | -| 2019-08-18T00:54:00Z | 7.510 | coyote_creek | -| 2019-08-18T00:48:00Z | 2.087 | santa_monica | -| 2019-08-18T00:42:00Z | 2.093 | santa_monica | -| 2019-08-18T00:36:00Z | 2.1261441420 | santa_monica | -| 2019-08-18T00:24:00Z | 2.264 | santa_monica | -| 2019-08-18T00:18:00Z | 2.329 | santa_monica | -| 2019-08-18T00:12:00Z | 2.343 | santa_monica | -| 2019-08-18T00:00:00Z | 2.352 | santa_monica | - -Notice that the [GROUP BY time() clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) -does not override the points’ original timestamps. -See [Issue 1](#bottom-with-a-group-by-time-clause) in the section below for a -more detailed explanation of that behavior. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Common issues with BOTTOM() - -#### BOTTOM() with a GROUP BY time() clause - -Queries with `BOTTOM()` and a `GROUP BY time()` clause return the specified -number of points per `GROUP BY time()` interval. -For [most `GROUP BY time()` queries](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals), -the returned timestamps mark the start of the `GROUP BY time()` interval. -`GROUP BY time()` queries with the `BOTTOM()` function behave differently; -they maintain the timestamp of the original data point. - -##### Example - -The query below returns two points per 18-minute -`GROUP BY time()` interval. -Notice that the returned timestamps are the points' original timestamps; they -are not forced to match the start of the `GROUP BY time()` intervals. - -```sql -SELECT BOTTOM("water_level",2) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(18m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | bottom | -| :------------------- | -----: | -| 2019-08-18T00:00:00Z | 2.064 | -| 2019-08-18T00:12:00Z | 2.028 | -| 2019-08-18T00:24:00Z | 2.041 | -| 2019-08-18T00:30:00Z | 2.051 | - -_Notice that the first two rows contain the smallest values from the first time interval -and the last two rows contains the smallest values for the second time interval._ - -#### BOTTOM() and a tag key with fewer than N tag values - -Queries with the syntax `SELECT BOTTOM(,,)` can return fewer points than expected. -If the tag key has `X` tag values, the query specifies `N` values, and `X` is smaller than `N`, then the query returns `X` points. - -##### Example - -The query below asks for the smallest field values of `water_level` for three tag values of the `location` tag key. -Because the `location` tag key has two tag values (`santa_monica` and `coyote_creek`), the query returns two points instead of three. - -```sql -SELECT BOTTOM("water_level","location",3) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | bottom | location | -| :------------------- | -----: | :----------- | -| 2019-08-29T10:36:00Z | -0.243 | santa_monica | -| 2019-08-29T14:30:00Z | -0.610 | coyote_creek | - -## FIRST() - -Returns the [field value ](/influxdb/v2/reference/glossary/#field-value) with the oldest timestamp. - -### Syntax - -```sql -SELECT FIRST()[,|] FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`FIRST(field_key)` -Returns the oldest field value (determined by timestamp) associated with the field key. - -`FIRST(/regular_expression/)` -Returns the oldest field value (determined by timestamp) associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/). - -`FIRST(*)` -Returns the oldest field value (determined by timestamp) associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`FIRST(field_key),tag_key(s),field_key(s)` -Returns the oldest field value (determined by timestamp) associated with the field key in the parentheses and the relevant [tag](/influxdb/v2/reference/glossary/#tag) and/or [field](/influxdb/v2/reference/glossary/#field). - -`FIRST()` supports all field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Select the first field value associated with a field key" %}} - -Return the oldest field value (determined by timestamp) associated with the -`level description` field key and in the `h2o_feet` measurement. - -```sql -SELECT FIRST("level description") FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | first | -| :------------------- | :------------------- | -| 2019-08-17T00:00:00Z | between 6 and 9 feet | - -{{% /expand %}} - -{{% expand "Select the first field value associated with each field key in a measurement" %}} - -Return the oldest field value (determined by timestamp) for each field key in the `h2o_feet` measurement. -The `h2o_feet` measurement has two field keys: `level description` and `water_level`. - -```sql -SELECT FIRST(*) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | first_level description | first_water_level | -| :------------------- | :---------------------- | ----------------: | -| 1970-01-01T00:00:00Z | between 6 and 9 feet | 8.120 | - -{{% /expand %}} - -{{% expand "Select the first field value associated with each field key that matches a regular expression" %}} - -Return the oldest field value for each field key that includes the word `level` in the `h2o_feet` measurement. - -```sql -SELECT FIRST(/level/) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | first_level description | first_water_level | -| :------------------- | :---------------------- | ----------------: | -| 1970-01-01T00:00:00Z | between 6 and 9 feet | 8.120 | - -{{% /expand %}} - -{{% expand "Select the first value associated with a field key and the relevant tags and fields" %}} - -Return the oldest field value (determined by timestamp) in the `level description` -field key and the relevant values of the `location` tag key and the `water_level` field key. - -```sql -SELECT FIRST("level description"),"location","water_level" FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | first | location | water_level | -| :------------------- | :------------------- | :----------- | ----------: | -| 2019-08-17T00:00:00Z | between 6 and 9 feet | coyote_creek | 8.120 | - -{{% /expand %}} - -{{% expand "Select the first field value associated with a field key and include several clauses" %}} - -Returns the oldest field value (determined by timestamp) in the `water_level` -field key in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-17T23:48:00Z` and `2019-08-18T00:54:00Z` and -[groups](/influxdb/v2/query-data/influxql/explore-data/group-by/) results into -12-minute time intervals and per tag. -Then [fill](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals-and-fill) -empty time intervals with `9.01`, and it [limit](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points and series returned to four and one. - -```sql -SELECT FIRST("water_level") FROM "h2o_feet" WHERE time >= '2019-08-17T23:48:00Z' AND time <= '2019-08-18T00:54:00Z' GROUP BY time(12m),* fill(9.01) LIMIT 4 SLIMIT 1 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | first | -| :------------------- | ----: | -| 2019-08-17T23:48:00Z | 8.635 | -| 2019-08-18T00:00:00Z | 8.504 | -| 2019-08-18T00:12:00Z | 8.320 | -| 2019-08-18T00:24:00Z | 8.130 | - -Notice that the [`GROUP BY time()` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) overrides the points' original timestamps. -The timestamps in the results indicate the the start of each 12-minute time interval; -the first point in the results covers the time interval between `2019-08-17T23:48:00Z` and just before `2019-08-18T00:00:00Z` and the last point in the results covers the time interval between `2019-08-18T00:24:00Z` and just before `2019-08-18T00:36:00Z`. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## LAST() - -Returns the [field value](/influxdb/v2/reference/glossary/#field-value) with the most recent timestamp. - -### Syntax - -```sql -SELECT LAST()[,|] FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`LAST(field_key)` -Returns the newest field value (determined by timestamp) associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`LAST(/regular_expression/)` -Returns the newest field value (determined by timestamp) associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/). - -`LAST(*)` -Returns the newest field value (determined by timestamp) associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`LAST(field_key),tag_key(s),field_key(s)` -Returns the newest field value (determined by timestamp) associated with the field key in the parentheses and the relevant [tag](/influxdb/v2/reference/glossary/#tag) and/or [field](/influxdb/v2/reference/glossary/#field). - -`LAST()` supports all field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Select the last field values associated with a field key" %}} - -Return the newest field value (determined by timestamp) associated with the -`level description` field key and in the `h2o_feet` measurement. - -```sql -SELECT LAST("level description") FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | last | -| :------------------- | :------------------- | -| 2019-09-17T21:42:00Z | between 3 and 6 feet | - -{{% /expand %}} - -{{% expand "Select the last field values associated with each field key in a measurement" %}} - -Return the newest field value (determined by timestamp) for each field key in the `h2o_feet` measurement. -The `h2o_feet` measurement has two field keys: `level description` and `water_level`. - -```sql -SELECT LAST(*) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | last_level description | last_water_level | -| :------------------- | :--------------------- | ---------------: | -| 1970-01-01T00:00:00Z | between 3 and 6 feet | 4.938 | - -{{% /expand %}} - -{{% expand "Select the last field value associated with each field key that matches a regular expression" %}} - -Return the newest field value for each field key that includes the word `level` -in the `h2o_feet` measurement. - -```sql -SELECT LAST(/level/) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | last_level description | last_water_level | -| :------------------- | :--------------------- | ---------------: | -| 1970-01-01T00:00:00Z | between 3 and 6 feet | 4.938 | - -{{% /expand %}} - -{{% expand "Select the last field value associated with a field key and the relevant tags and fields" %}} - -Return the newest field value (determined by timestamp) in the `level description` -field key and the relevant values of the `location` tag key and the `water_level` field key. - -```sql -SELECT LAST("level description"),"location","water_level" FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | last | location | water_level | -| :------------------- | :------------------- | :----------- | ----------: | -| 2019-09-17T21:42:00Z | between 3 and 6 feet | santa_monica | 4.938 | - -{{% /expand %}} - -{{% expand "Select the last field value associated with a field key and include several clauses" %}} - -Return the newest field value (determined by timestamp) in the `water_level` -field key in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-17T23:48:00Z` and `2019-08-18T00:54:00Z` and -[groups](/influxdb/v2/query-data/influxql/explore-data/group-by/) results into -12-minute time intervals and per tag. -Then [fill](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals-and-fill) -empty time intervals with `9.01`, and it [limit](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points and series returned to four and one. - -```sql -SELECT LAST("water_level") FROM "h2o_feet" WHERE time >= '2019-08-17T23:48:00Z' AND time <= '2019-08-18T00:54:00Z' GROUP BY time(12m),* fill(9.01) LIMIT 4 SLIMIT 1 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | last | -| :------------------- | ----: | -| 2019-08-17T23:48:00Z | 8.570 | -| 2019-08-18T00:00:00Z | 8.419 | -| 2019-08-18T00:12:00Z | 8.225 | -| 2019-08-18T00:24:00Z | 8.012 | - -Notice that the [`GROUP BY time()` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) overrides the points' original timestamps. -The timestamps in the results indicate the the start of each 12-minute time interval; -the first point in the results covers the time interval between `2019-08-17T23:48:00Z` and just before `2019-08-18T00:00:00Z` and the last point in the results covers the time interval between `2019-08-18T00:24:00Z` and just before `2019-08-18T00:36:00Z`. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## MAX() - -Returns the greatest [field value](/influxdb/v2/reference/glossary/#field-value). - -### Syntax - -```sql -SELECT MAX()[,|] FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`MAX(field_key)` -Returns the greatest field value associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`MAX(/regular_expression/)` -Returns the greatest field value associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/). - -`MAX(*)` -Returns the greatest field value associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`MAX(field_key),tag_key(s),field_key(s)` -Returns the greatest field value associated with the field key in the parentheses and the relevant [tag](/influxdb/v2/reference/glossary/#tag) and/or [field](/influxdb/v2/reference/glossary/#field). - -`MAX()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Select the maximum field value associated with a field key" %}} - -Return the greatest field value in the `water_level` field key and in the `h2o_feet` measurement. - -```sql -SELECT MAX("water_level") FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | max | -| :------------------- | ----: | -| 2019-08-28T07:24:00Z | 9.964 | - -{{% /expand %}} - -{{% expand "Select the maximum field value associated with each field key in a measurement" %}} - -Return the greatest field value for each field key that stores numeric values -in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT MAX(*) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | max_water_level | -| :------------------- | --------------: | -| 2019-08-28T07:24:00Z | 9.964 | - -{{% /expand %}} - -{{% expand "Select the maximum field value associated with each field key that matches a regular expression" %}} - -Return the greatest field value for each field key that stores numeric values -and includes the word `water` in the `h2o_feet` measurement. - -```sql -SELECT MAX(/level/) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | max_water_level | -| :------------------- | --------------: | -| 2019-08-28T07:24:00Z | 9.964 | - -{{% /expand %}} - -{{% expand "Select the maximum field value associated with a field key and the relevant tags and fields" %}} - -Return the greatest field value in the `water_level` field key and the relevant -values of the `location` tag key and the `level description` field key. - -```sql -SELECT MAX("water_level"),"location","level description" FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | max | location | level description | -| :------------------- | ----: | :----------- | :------------------------ | -| 2019-08-28T07:24:00Z | 9.964 | coyote_creek | at or greater than 9 feet | - -{{% /expand %}} - -{{% expand "Select the maximum field value associated with a field key and include several clauses" %}} - -Return the greatest field value in the `water_level` field key in the -[time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-17T23:48:00Z` and `2019-08-18T00:54:00Z` and -[groups](/influxdb/v2/query-data/influxql/explore-data/group-by/) results into -12-minute time intervals and per tag. -Then [fill](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals-and-fill) -empty time intervals with `9.01`, and it [limit](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points and series returned to four and one. - -```sql -SELECT MAX("water_level") FROM "h2o_feet" WHERE time >= '2019-08-17T23:48:00Z' AND time <= '2019-08-18T00:54:00Z' GROUP BY time(12m),* fill(9.01) LIMIT 4 SLIMIT 1 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | max | -| :------------------- | ----: | -| 2019-08-17T23:48:00Z | 8.635 | -| 2019-08-18T00:00:00Z | 8.504 | -| 2019-08-18T00:12:00Z | 8.320 | -| 2019-08-18T00:24:00Z | 8.130 | - -Notice that the [`GROUP BY time()` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) overrides the points’ original timestamps. -The timestamps in the results indicate the the start of each 12-minute time interval; -the first point in the results covers the time interval between `2019-08-17T23:48:00Z` and just before `2019-08-18T00:00:00Z` and the last point in the results covers the time interval between `2019-08-18T00:24:00Z` and just before `2019-08-18T00:36:00Z`. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## MIN() - -Returns the lowest [field value](/influxdb/v2/reference/glossary/#field-value). - -### Syntax - -```sql -SELECT MIN()[,|] FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`MIN(field_key)` -Returns the lowest field value associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`MIN(/regular_expression/)` -Returns the lowest field value associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/). - -`MIN(*)` -Returns the lowest field value associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`MIN(field_key),tag_key(s),field_key(s)` -Returns the lowest field value associated with the field key in the parentheses and the relevant [tag](/influxdb/v2/reference/glossary/#tag) and/or [field](/influxdb/v2/reference/glossary/#field). - -`MIN()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Select the minimum field value associated with a field key" %}} - -Return the lowest field value in the `water_level` field key and in the `h2o_feet` measurement. - -```sql -SELECT MIN("water_level") FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | min | -| :------------------- | -----: | -| 2019-08-28T14:30:00Z | -0.610 | - -{{% /expand %}} - -{{% expand "Select the minimum field value associated with each field key in a measurement" %}} - -Return the lowest field value for each field key that stores numeric values in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT MIN(*) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | min_water_level | -| :------------------- | --------------: | -| 2019-08-28T14:30:00Z | -0.610 | - -{{% /expand %}} - -{{% expand "Select the minimum field value associated with each field key that matches a regular expression" %}} - -Return the lowest field value for each numeric field with `water` in the field -key in the `h2o_feet` measurement. - -```sql -SELECT MIN(/level/) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | min_water_level | -| :------------------- | --------------: | -| 2019-08-28T14:30:00Z | -0.610 | - -{{% /expand %}} - -{{% expand "Select the minimum field value associated with a field key and the relevant tags and fields" %}} - -Return the lowest field value in the `water_level` field key and the relevant -values of the `location` tag key and the `level description` field key. - -```sql -SELECT MIN("water_level"),"location","level description" FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | min | location | level description | -| :------------------- | -----: | :----------- | :---------------- | -| 2019-08-28T14:30:00Z | -0.610 | coyote_creek | below 3 feet | - -{{% /expand %}} - -{{% expand "Select the minimum field value associated with a field key and include several clauses" %}} - -Return the lowest field value in the `water_level` field key in the -[time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-17T23:48:00Z` and `2019-08-18T00:54:00Z` and -[groups](/influxdb/v2/query-data/influxql/explore-data/group-by/) results into -12-minute time intervals and per tag. -Then [fill](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals-and-fill) -empty time intervals with `9.01`, and it [limit](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points and series returned to four and one. - -```sql -SELECT MIN("water_level") FROM "h2o_feet" WHERE time >= '2019-08-17T23:48:00Z' AND time <= '2019-08-18T00:54:00Z' GROUP BY time(12m),* fill(9.01) LIMIT 4 SLIMIT 1 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -tags: location=coyote_creek -{{% /influxql/table-meta %}} - -| time | min | -| :------------------- | ----: | -| 2019-08-17T23:48:00Z | 8.570 | -| 2019-08-18T00:00:00Z | 8.419 | -| 2019-08-18T00:12:00Z | 8.225 | -| 2019-08-18T00:24:00Z | 8.012 | - -Notice that the [`GROUP BY time()` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) overrides the points’ original timestamps. -The timestamps in the results indicate the the start of each 12-minute time interval; -the first point in the results covers the time interval between `2019-08-17T23:48:00Z` and just before `2019-08-18T00:00:00Z` and the last point in the results covers the time interval between `2019-08-18T00:24:00Z` and just before `2019-08-18T00:36:00Z`. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## PERCENTILE() - -Returns the `N`th percentile [field value](/influxdb/v2/reference/glossary/#field-value). - -### Syntax - -```sql -SELECT PERCENTILE(, )[,|] FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`PERCENTILE(field_key,N)` -Returns the Nth percentile field value associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`PERCENTILE(/regular_expression/,N)` -Returns the Nth percentile field value associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/). - -`PERCENTILE(*,N)` -Returns the Nth percentile field value associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`PERCENTILE(field_key,N),tag_key(s),field_key(s)` -Returns the Nth percentile field value associated with the field key in the parentheses and the relevant [tag](/influxdb/v2/reference/glossary/#tag) and/or [field](/influxdb/v2/reference/glossary/#field). - -`N` must be an integer or floating point number between `0` and `100`, inclusive. -`PERCENTILE()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Select the fifth percentile field value associated with a field key" %}} - -Return the field value that is larger than five percent of the field values in -the `water_level` field key and in the `h2o_feet` measurement. - -```sql -SELECT PERCENTILE("water_level",5) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | percentile | -| :------------------- | ---------: | -| 2019-09-01T17:54:00Z | 1.122 | - -{{% /expand %}} - -{{% expand "Select the fifth percentile field value associated with each field key in a measurement" %}} - -Return the field value that is larger than five percent of the field values in -each field key that stores numeric values in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT PERCENTILE(*,5) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | percentile_water_level | -| :------------------- | ---------------------: | -| 2019-09-01T17:54:00Z | 1.122 | - -{{% /expand %}} - -{{% expand "Select fifth percentile field value associated with each field key that matches a regular expression" %}} - -Return the field value that is larger than five percent of the field values in -each numeric field with `water` in the field key. - -```sql -SELECT PERCENTILE(/level/,5) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | percentile_water_level | -| :------------------- | ---------------------: | -| 2019-09-01T17:54:00Z | 1.122 | - -{{% /expand %}} - -{{% expand "Select the fifth percentile field values associated with a field key and the relevant tags and fields" %}} - -Return the field value that is larger than five percent of the field values in -the `water_level` field key and the relevant values of the `location` tag key -and the `level description` field key. - -```sql -SELECT PERCENTILE("water_level",5),"location","level description" FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | percentile | location | level description | -| :------------------- | ---------: | :----------- | :---------------- | -| 2019-08-24T10:18:00Z | 1.122 | coyote_creek | below 3 feet | - -{{% /expand %}} - -{{% expand "Select the twentieth percentile field value associated with a field key and include several clauses" %}} - -Return the field value that is larger than 20 percent of the values in the -`water_level` field in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-17T23:48:00Z` and `2019-08-18T00:54:00Z` and [group](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) results into 24-minute intervals. -Then [fill](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals-and-fill) -empty time intervals with `15` and [limit](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to two. - -```sql -SELECT PERCENTILE("water_level",20) FROM "h2o_feet" WHERE time >= '2019-08-17T23:48:00Z' AND time <= '2019-08-18T00:54:00Z' GROUP BY time(24m) fill(15) LIMIT 2 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | percentile | -| :------------------- | ---------: | -| 2019-08-17T23:36:00Z | 2.398 | -| 2019-08-18T00:00:00Z | 2.343 | - -Notice that the [`GROUP BY time()` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) overrides the points’ original timestamps. -The timestamps in the results indicate the the start of each 24-minute time interval; the first point in the results covers the time interval between `2019-08-17T23:36:00Z` and just before `2019-08-18T00:00:00Z` and the last point in the results covers the time interval between `2019-08-18T00:00:00Z` and just before `2019-08-18T00:24:00Z`. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Common issues with PERCENTILE() - -#### PERCENTILE() compared to other InfluxQL functions - -- `PERCENTILE(,100)` is equivalent to [`MAX()`](#max). -- `PERCENTILE(, 50)` is nearly equivalent to [`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), except the `MEDIAN()` function returns the average of the two middle values if the field key contains an even number of field values. -- `PERCENTILE(,0)` is not equivalent to [`MIN()`](#min). This is a known [issue](https://github.com/influxdata/influxdb/issues/4418). - -## SAMPLE() - -Returns a random sample of `N` [field values](/influxdb/v2/reference/glossary/#field-value). -`SAMPLE()` uses [reservoir sampling](https://en.wikipedia.org/wiki/Reservoir_sampling) to generate the random points. - -### Syntax - -```sql -SELECT SAMPLE(, )[,|] FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`SAMPLE(field_key,N)` -Returns N randomly selected field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`SAMPLE(/regular_expression/,N)` -Returns N randomly selected field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/). - -`SAMPLE(*,N)` -Returns N randomly selected field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`SAMPLE(field_key,N),tag_key(s),field_key(s)` -Returns N randomly selected field values associated with the field key in the parentheses and the relevant [tag](/influxdb/v2/reference/glossary/#tag) and/or [field](/influxdb/v2/reference/glossary/#field). - -`N` must be an integer. -`SAMPLE()` supports all field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Select a sample of the field values associated with a field key" %}} - -Return two randomly selected points from the `water_level` field key and in the `h2o_feet` measurement. - -```sql -SELECT SAMPLE("water_level",2) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | sample | -| :------------------- | -----: | -| 2019-08-22T03:42:00Z | 7.218 | -| 2019-08-28T20:18:00Z | 2.848 | - -{{% /expand %}} - -{{% expand "Select a sample of the field values associated with each field key in a measurement" %}} - -Return two randomly selected points for each field key in the `h2o_feet` measurement. -The `h2o_feet` measurement has two field keys: `level description` and `water_level`. - -```sql -SELECT SAMPLE(*,2) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | sample_level description | sample_water_level | -| :------------------- | :----------------------- | -----------------: | -| 2019-08-23T17:30:00Z | below 3 feet | | -| 2019-09-08T19:18:00Z | | 8.379 | -| 2019-09-09T03:54:00Z | between 6 and 9 feet | | -| 2019-09-16T04:48:00Z | | 1.437 | - -{{% /expand %}} - -{{% expand "Select a sample of the field values associated with each field key that matches a regular expression" %}} - -Return two randomly selected points for each field key that includes the word -`level` in the `h2o_feet` measurement. - -```sql -SELECT SAMPLE(/level/,2) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | sample_level description | sample_water_level | -| :------------------- | :----------------------- | -----------------: | -| 2019-08-19T20:24:00Z | | 4.951 | -| 2019-08-26T06:30:00Z | below 3 feet | | -| 2019-09-10T09:06:00Z | | 1.312 | -| 2019-09-16T21:00:00Z | between 3 and 6 feet | | - -{{% /expand %}} - -{{% expand "Select a sample of the field values associated with a field key and the relevant tags and fields" %}} - -Return two randomly selected points from the `water_level` field key and the -relevant values of the `location` tag and the `level description` field. - -```sql -SELECT SAMPLE("water_level",2),"location","level description" FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | sample | location | level description | -| :------------------- | -----: | :----------- | :------------------- | -| 2019-08-31T04:30:00Z | 4.954 | santa_monica | between 3 and 6 feet | -| 2019-09-13T01:24:00Z | 3.389 | santa_monica | between 3 and 6 feet | - -{{% /expand %}} - -{{% expand "Select a sample of the field values associated with a field key and include several clauses" %}} - -Return one randomly selected point from the `water_level` field key in the -[time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` and -[group](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) -results into 18-minute intervals. - -```sql -SELECT SAMPLE("water_level",1) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(18m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | sample | -| :------------------- | -----: | -| 2019-08-18T00:12:00Z | 2.343 | -| 2019-08-18T00:24:00Z | 2.264 | - -Notice that the [`GROUP BY time()` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) does not override the points' original timestamps. -See [Issue 1](#sample-with-a-group-by-time-clause) in the section below for a -more detailed explanation of that behavior. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Common issues with SAMPLE() - -#### SAMPLE() with a GROUP BY time() clause - -Queries with `SAMPLE()` and a `GROUP BY time()` clause return the specified -number of points (`N`) per `GROUP BY time()` interval. -For [most `GROUP BY time()` queries](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals), -the returned timestamps mark the start of the `GROUP BY time()` interval. -`GROUP BY time()` queries with the `SAMPLE()` function behave differently; -they maintain the timestamp of the original data point. - -##### Example - -The query below returns two randomly selected points per 18-minute -`GROUP BY time()` interval. -Notice that the returned timestamps are the points' original timestamps; they -are not forced to match the start of the `GROUP BY time()` intervals. - -```sql -SELECT SAMPLE("water_level",2) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(18m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | sample | -| :------------------- | -----: | -| 2019-08-18T00:06:00Z | 2.116 | -| 2019-08-18T00:12:00Z | 2.028 | -| 2019-08-18T00:18:00Z | 2.126 | -| 2019-08-18T00:30:00Z | 2.051 | - -Notice that the first two rows are randomly-selected points from the first time -interval and the last two rows are randomly-selected points from the second time interval. - -## TOP() - -Returns the greatest `N` [field values](/influxdb/v2/reference/glossary/#field-value). - -### Syntax - -```sql -SELECT TOP( [,], )[,|] FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`TOP(field_key,N)` -Returns the greatest N field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`TOP(field_key,tag_key(s),N)` -Returns the greatest field value for N tag values of the [tag key](/influxdb/v2/reference/glossary/#tag-key). - -`TOP(field_key,N),tag_key(s),field_key(s)` -Returns the greatest N field values associated with the field key in the parentheses and the relevant [tag](/influxdb/v2/reference/glossary/#tag) and/or [field](/influxdb/v2/reference/glossary/#field). - -`TOP()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -{{% note %}} -**Note:** `TOP()` returns the field value with the earliest timestamp if there's a tie between two or more values for the greatest value. -{{% /note %}} - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Select the top three field values associated with a field key" %}} - -Return the greatest three field values in the `water_level` field key and in the -`h2o_feet` [measurement](/influxdb/v2/reference/glossary/#measurement). - -```sql -SELECT TOP("water_level",3) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | top | -| :------------------- | ----: | -| 2019-08-28T07:18:00Z | 9.957 | -| 2019-08-28T07:24:00Z | 9.964 | -| 2019-08-28T07:30:00Z | 9.954 | - -{{% /expand %}} - -{{% expand "Select the top field value associated with a field key for two tags" %}} - -Return the greatest field values in the `water_level` field key for two tag -values associated with the `location` tag key. - -```sql -SELECT TOP("water_level","location",2) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | top | location | -| :------------------- | ----: | :----------- | -| 2019-08-28T03:54:00Z | 7.205 | santa_monica | -| 2019-08-28T07:24:00Z | 9.964 | coyote_creek | - -{{% /expand %}} - -{{% expand "Select the top four field values associated with a field key and the relevant tags and fields" %}} - -Return the greatest four field values in the `water_level` field key and the -relevant values of the `location` tag key and the `level description` field key. - -```sql -SELECT TOP("water_level",4),"location","level description" FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | top | location | level description | -| :------------------- | ----: | :----------- | :------------------------ | -| 2019-08-28T07:18:00Z | 9.957 | coyote_creek | at or greater than 9 feet | -| 2019-08-28T07:24:00Z | 9.964 | coyote_creek | at or greater than 9 feet | -| 2019-08-28T07:30:00Z | 9.954 | coyote_creek | at or greater than 9 feet | -| 2019-08-28T07:36:00Z | 9.941 | coyote_creek | at or greater than 9 feet | - -{{% /expand %}} - -{{% expand "Select the top three field values associated with a field key and include several clauses" %}} - -Return the greatest three values in the `water_level` field key for each 24-minute -[interval](/influxdb/v2/query-data/influxql/explore-data/group-by/#basic-group-by-time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:54:00Z` with results in -[descending timestamp](/influxdb/v2/query-data/influxql/explore-data/order-by/) order. - -```sql -SELECT TOP("water_level",3),"location" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:54:00Z' GROUP BY time(24m) ORDER BY time DESC -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | top | location | -| :------------------- | ----: | :----------- | -| 2019-08-18T00:54:00Z | 6.982 | coyote_creek | -| 2019-08-18T00:54:00Z | 2.054 | santa_monica | -| 2019-08-18T00:48:00Z | 7.110 | coyote_creek | -| 2019-08-18T00:36:00Z | 7.372 | coyote_creek | -| 2019-08-18T00:30:00Z | 7.500 | coyote_creek | -| 2019-08-18T00:24:00Z | 7.635 | coyote_creek | -| 2019-08-18T00:12:00Z | 7.887 | coyote_creek | -| 2019-08-18T00:06:00Z | 8.005 | coyote_creek | -| 2019-08-18T00:00:00Z | 8.120 | coyote_creek | - -Notice that the [GROUP BY time() clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) does not override the points’ original timestamps. -See [Issue 1](#top-with-a-group-by-time-clause) in the section below for a more detailed explanation of that behavior. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Common issues with `TOP()` - -#### `TOP()` with a `GROUP BY time()` clause - -Queries with `TOP()` and a `GROUP BY time()` clause return the specified -number of points per `GROUP BY time()` interval. -For [most `GROUP BY time()` queries](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals), -the returned timestamps mark the start of the `GROUP BY time()` interval. -`GROUP BY time()` queries with the `TOP()` function behave differently; -they maintain the timestamp of the original data point. - -##### Example - -The query below returns two points per 18-minute -`GROUP BY time()` interval. -Notice that the returned timestamps are the points' original timestamps; they -are not forced to match the start of the `GROUP BY time()` intervals. - -```sql -SELECT TOP("water_level",2) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(18m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | top | -| :------------------- | ----: | -| 2019-08-18T00:00:00Z | 2.064 | -| 2019-08-18T00:06:00Z | 2.116 | -| 2019-08-18T00:18:00Z | 2.126 | -| 2019-08-18T00:30:00Z | 2.051 | - -Notice that the first two rows are the greatest points for the first time interval -and the last two rows are the greatest points for the second time interval. - -#### TOP() and a tag key with fewer than N tag values - -Queries with the syntax `SELECT TOP(,,)` can return fewer points than expected. -If the tag key has `X` tag values, the query specifies `N` values, and `X` is smaller than `N`, then the query returns `X` points. - -##### Example - -The query below asks for the greatest field values of `water_level` for three tag values of the `location` tag key. -Because the `location` tag key has two tag values (`santa_monica` and `coyote_creek`), the query returns two points instead of three. - -```sql -SELECT TOP("water_level","location",3) FROM "h2o_feet" -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | top | location | -| :------------------- | ----: | :----------- | -| 2019-08-29T03:54:00Z | 7.205 | santa_monica | -| 2019-08-29T07:24:00Z | 9.964 | coyote_creek | - - + diff --git a/content/influxdb/v2/query-data/influxql/functions/technical-analysis.md b/content/influxdb/v2/query-data/influxql/functions/technical-analysis.md index 82400d05a..1b42e7a07 100644 --- a/content/influxdb/v2/query-data/influxql/functions/technical-analysis.md +++ b/content/influxdb/v2/query-data/influxql/functions/technical-analysis.md @@ -8,652 +8,8 @@ menu: name: Technical analysis parent: InfluxQL functions weight: 205 +source: /shared/influxdb-v2/query-data/influxql/functions/technical-analysis.md --- -Use technical analysis functions to apply algorithms to your data--often used to analyze financial and investment data. - -Each analysis function below covers **syntax**, including parameters to pass to the function, and **examples** of how to use the function. Examples use [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data). - -- [Predictive analysis](#predictive-analysis): - - [HOLT_WINTERS()](#holt_winters) -- [Technical analysis](#technical-analysis-functions): - - [CHANDE_MOMENTUM_OSCILLATOR()](#chande_momentum_oscillator) - - [EXPONENTIAL_MOVING_AVERAGE()](#exponential_moving_average) - - [DOUBLE_EXPONENTIAL_MOVING_AVERAGE()](#double_exponential_moving_average) - - [KAUFMANS_EFFICIENCY_RATIO()](#kaufmans_efficiency_ratio) - - [KAUFMANS_ADAPTIVE_MOVING_AVERAGE()](#kaufmans_adaptive_moving_average) - - [TRIPLE_EXPONENTIAL_MOVING_AVERAGE()](#triple_exponential_moving_average) - - [TRIPLE_EXPONENTIAL_DERIVATIVE()](#triple_exponential_derivative) - - [RELATIVE_STRENGTH_INDEX()](#relative_strength_index) - -## Predictive analysis - -Predictive analysis functions are a type of technical analysis algorithms that -predict and forecast future values. - -### HOLT_WINTERS() - -Returns N number of predicted [field values](/influxdb/v2/reference/glossary/#field-value) -using the [Holt-Winters](https://www.otexts.org/fpp/7/5) seasonal method. -Supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). -Works with data that occurs at consistent time intervals. -Requires an InfluxQL function and the `GROUP BY time()` clause to ensure that -the Holt-Winters function operates on regular data. - -Use `HOLT_WINTERS()` to: - -- Predict when data values will cross a given threshold -- Compare predicted values with actual values to detect anomalies in your data - -#### Syntax - -``` -SELECT HOLT_WINTERS[_WITH-FIT]((),,) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`HOLT_WINTERS(function(field_key),N,S)` returns `N` seasonally adjusted -predicted field values for the specified [field key](/influxdb/v2/reference/glossary/#field-key). - -The `N` predicted values occur at the same interval as the [`GROUP BY time()` interval](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -If your `GROUP BY time()` interval is `6m` and `N` is `3` you'll -receive three predicted values that are each six minutes apart. - -`S` is the seasonal pattern parameter and delimits the length of a seasonal -pattern according to the `GROUP BY time()` interval. -If your `GROUP BY time()` interval is `2m` and `S` is `3`, then the -seasonal pattern occurs every six minutes, that is, every three data points. -If you do not want to seasonally adjust your predicted values, set `S` to `0` -or `1.` - -`HOLT_WINTERS_WITH_FIT(function(field_key),N,S)` returns the fitted values in -addition to `N` seasonally adjusted predicted field values for the specified field key. - -#### Examples - -{{< expand-wrapper >}} -{{% expand "Predict field values associated with a field key" %}} - -##### Sample data - -The examples use the following subset of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "noaa"."autogen"."h2o_feet" WHERE "location"='santa_monica' AND time >= '2019-08-17T00:00:00Z' AND time <= '2019-08-22T00:00:00Z' -``` - -##### Step 1: Match the trends of the raw data - -Write a `GROUP BY time()` query that matches the general trends of the raw `water_level` data. -Here, we use the [`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first) function: - -```sql -SELECT FIRST("water_level") FROM "noaa"."autogen"."h2o_feet" WHERE "location"='santa_monica' and time >= '2019-08-17T00:00:00Z' AND time <= '2019-08-22T00:00:00Z' GROUP BY time(6h,6h) -``` - -In the `GROUP BY time()` clause, the first argument (`6h`) matches -the length of time that occurs between each peak and trough in the `water_level` data. -The second argument (`6h`) is the -[offset interval](/influxdb/v2/query-data/influxql/explore-data/group-by/#advanced-group-by-time-syntax). -The offset interval alters the default `GROUP BY time()` boundaries to -match the time range of the raw data. - -{{< img-hd src="/img/influxdb/2-4-influxql-holtwinters-1.png" alt="Holt Winters base data" />}} - -###### Step 2: Determine the seasonal pattern - -Identify the seasonal pattern in the data using the information from the -query in step 1. - -The pattern in the `water_level` data repeats about every 12 hours. -There are two data points per season, so `2` is the seasonal pattern argument. - -{{< img-hd src="/img/influxdb/2-4-influxql-holtwinters-2.png" alt="Holt Winters seasonal data" />}} - -###### Step 3: Apply the HOLT_WINTERS() function - -Add the Holt-Winters function to the query. -Here, we use `HOLT_WINTERS_WITH_FIT()` to view both the fitted values and the predicted values: - -```sql -SELECT HOLT_WINTERS_WITH_FIT(FIRST("water_level"),10,2) FROM "noaa"."autogen"."h2o_feet" WHERE "location"='santa_monica' AND time >= '2019-08-17 00:00:00' AND time <= '2019-08-22 00:00:00' GROUP BY time(6h,6h) -``` - -In the `HOLT_WINTERS_WITH_FIT()` function, the first argument (`10`) requests 10 predicted field values. -Each predicted point is `6h` apart, the same interval as the first argument in the `GROUP BY time()` clause. -The second argument in the `HOLT_WINTERS_WITH_FIT()` function (`2`) is the seasonal pattern that we determined in the previous step. - -{{< img-hd src="/img/influxdb/2-4-influxql-holtwinters-3.png" alt="Holt Winters predicted data" />}} - -{{% /expand %}} -{{< /expand-wrapper >}} - -#### Common issues with `HOLT_WINTERS()` - -##### Receiving fewer than `N` points - -In some cases, you may receive fewer predicted points than requested by the `N` parameter. -That behavior typically occurs when the math becomes unstable and cannot forecast more -points. In this case, `HOLT_WINTERS()` may not be suited for the dataset or the seasonal adjustment parameter is invalid. - -## Technical analysis functions - -Technical analysis functions apply widely used algorithms to your data. -While they are primarily used in finance and investing, they have -application in other industries. - -For technical analysis functions, consider whether to include the `PERIOD`, `HOLD_PERIOD`, and `WARMUP_TYPE` arguments: - -#### `PERIOD` - -**Required, integer, min=1** - -The sample size for the algorithm, which is the number of historical samples with significant -effect on the output of the algorithm. -For example, `2` means the current point and the point before it. -The algorithm uses an exponential decay rate to determine the weight of a historical point, -generally known as the alpha (α). The `PERIOD` controls the decay rate. - -{{% note %}} -**Note:** Older points can still have an impact. -{{% /note %}} - -#### `HOLD_PERIOD` - -**integer, min=-1** - -How many samples the algorithm needs before emitting results. -The default of `-1` means the value is based on the algorithm, the `PERIOD`, -and the `WARMUP_TYPE`. Verify this value is enough for the algorithm to emit meaningful results. - -_**Default hold periods:**_ - -For most technical analysis functions, the default `HOLD_PERIOD` is -determined by the function and the [`WARMUP_TYPE`](#warmup_type) shown in the following table: - -| Algorithm \ Warmup Type | simple | exponential | none | -| --------------------------------- | ---------------------- | ----------- |:----------: | -| [EXPONENTIAL_MOVING_AVERAGE](#exponential_moving_average) | PERIOD - 1 | PERIOD - 1 | n/a | -| [DOUBLE_EXPONENTIAL_MOVING_AVERAGE](#double_exponential_moving_average) | ( PERIOD - 1 ) * 2 | PERIOD - 1 | n/a | -| [TRIPLE_EXPONENTIAL_MOVING_AVERAGE](#triple_exponential_moving_average) | ( PERIOD - 1 ) * 3 | PERIOD - 1 | n/a | -| [TRIPLE_EXPONENTIAL_DERIVATIVE](#triple_exponential_derivative) | ( PERIOD - 1 ) * 3 + 1 | PERIOD | n/a | -| [RELATIVE_STRENGTH_INDEX](#relative_strength_index) | PERIOD | PERIOD | n/a | -| [CHANDE_MOMENTUM_OSCILLATOR](#chande_momentum_oscillator) | PERIOD | PERIOD | PERIOD - 1 | - -_**Kaufman algorithm default hold periods:**_ - -| Algorithm | Default Hold Period | -| --------- | ------------------- | -| [KAUFMANS_EFFICIENCY_RATIO()](#kaufmans_efficiency_ratio) | PERIOD | -| [KAUFMANS_ADAPTIVE_MOVING_AVERAGE()](#kaufmans_adaptive_moving_average) | PERIOD | - -#### `WARMUP_TYPE` - -**default='exponential'** - -Controls how the algorithm initializes for the first `PERIOD` samples. -It is essentially the duration for which it has an incomplete sample set. - -##### simple - -Simple moving average (SMA) of the first `PERIOD` samples. -This is the method used by [ta-lib](https://www.ta-lib.org/). - -##### exponential - -Exponential moving average (EMA) with scaling alpha (α). -Uses an EMA with `PERIOD=1` for the first point, `PERIOD=2` -for the second point, and so on, until the algorithm has consumed `PERIOD` number of points. -As the algorithm immediately starts using an EMA, when this method is used and -`HOLD_PERIOD` is unspecified or `-1`, the algorithm may start emitting points -after a much smaller sample size than with `simple`. - -##### none - -The algorithm does not perform any smoothing at all. -Method used by [ta-lib](https://www.ta-lib.org/). -When this method is used and `HOLD_PERIOD` is unspecified, `HOLD_PERIOD` -defaults to `PERIOD - 1`. - -{{% note %}} -**Note:** The `none` warmup type is only available with the [`CHANDE_MOMENTUM_OSCILLATOR()`](#chande_momentum_oscillator) function. -{{% /note %}} - -## CHANDE_MOMENTUM_OSCILLATOR() - -The Chande Momentum Oscillator (CMO) is a technical momentum indicator developed by Tushar Chande. -The CMO indicator is created by calculating the difference between the sum of all -recent higher data points and the sum of all recent lower data points, -then dividing the result by the sum of all data movement over a given time period. -The result is multiplied by 100 to give the -100 to +100 range. -Source - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). To use `CHANDE_MOMENTUM_OSCILLATOR()` with a `GROUP BY time()` clause, see [Advanced syntax](/influxdb/v2/query-data/influxql/functions/transformations/#advanced-syntax). - -### Basic syntax - -``` -CHANDE_MOMENTUM_OSCILLATOR([ * | | /regular_expression/ ], [, , [warmup_type]]) -``` - -### Arguments - -- [period](#period) -- (Optional) [hold_period](#hold_period) -- (Optional) [warmup_type](#warmup_type) - -`CHANDE_MOMENTUM_OSCILLATOR(field_key, 2)` -Returns the field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) -processed using the Chande Momentum Oscillator algorithm with a 2-value period -and the default hold period and warmup type. - -`CHANDE_MOMENTUM_OSCILLATOR(field_key, 10, 9, 'none')` -Returns the field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) -processed using the Chande Momentum Oscillator algorithm with a 10-value period -a 9-value hold period, and the `none` warmup type. - -`CHANDE_MOMENTUM_OSCILLATOR(MEAN(), 2) ... GROUP BY time(1d)` -Returns the mean of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) -processed using the Chande Momentum Oscillator algorithm with a 2-value period -and the default hold period and warmup type. - -{{% note %}} -**Note:** When aggregating data with a `GROUP BY` clause, you must include an [aggregate function](/influxdb/v2/query-data/influxql/functions/aggregates/) in your call to the `CHANDE_MOMENTUM_OSCILLATOR()` function. -{{% /note %}} - -`CHANDE_MOMENTUM_OSCILLATOR(/regular_expression/, 2)` -Returns the field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/) -processed using the Chande Momentum Oscillator algorithm with a 2-value period -and the default hold period and warmup type. - -`CHANDE_MOMENTUM_OSCILLATOR(*, 2)` -Returns the field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement) -processed using the Chande Momentum Oscillator algorithm with a 2-value period -and the default hold period and warmup type. - -`CHANDE_MOMENTUM_OSCILLATOR()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -## EXPONENTIAL_MOVING_AVERAGE() - -An exponential moving average (EMA) (or exponentially weighted moving average) is a type of moving average similar to a [simple moving average](/influxdb/v2/query-data/influxql/functions/transformations/#moving_average), -except more weight is given to the latest data. - -This type of moving average reacts faster to recent data changes than a simple moving average. -Source - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `EXPONENTIAL_MOVING_AVERAGE()` with a `GROUP BY time()` clause, see [Advanced syntax](/influxdb/v2/query-data/influxql/functions/transformations/#advanced-syntax). - -### Basic syntax - -```sql -EXPONENTIAL_MOVING_AVERAGE([ * | | /regular_expression/ ], [, ), 2) ... GROUP BY time(1d)` -Returns the mean of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) -processed using the Exponential Moving Average algorithm with a 2-value period -and the default hold period and warmup type. - -{{% note %}} -**Note:** When aggregating data with a `GROUP BY` clause, you must include an [aggregate function](/influxdb/v2/query-data/influxql/functions/aggregates/) in your call to the `EXPONENTIAL_MOVING_AVERAGE()` function. -{{% /note %}} - -`EXPONENTIAL_MOVING_AVERAGE(/regular_expression/, 2)` -Returns the field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/) -processed using the Exponential Moving Average algorithm with a 2-value period -and the default hold period and warmup type. - -`EXPONENTIAL_MOVING_AVERAGE(*, 2)` -Returns the field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement) -processed using the Exponential Moving Average algorithm with a 2-value period -and the default hold period and warmup type. - -`EXPONENTIAL_MOVING_AVERAGE()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -### Arguments - -- [period](#period) -- (Optional) [hold_period](#hold_period) -- (Optional) [warmup_type](#warmup_type) - -## DOUBLE_EXPONENTIAL_MOVING_AVERAGE() - -The Double Exponential Moving Average (DEMA) attempts to remove the inherent lag -associated with moving averages by placing more weight on recent values. -The name suggests this is achieved by applying a double exponential smoothing which is not the case. -The value of an [EMA](#exponential_moving_average) is doubled. -To keep the value in line with the actual data and to remove the lag, the value "EMA of EMA" -is subtracted from the previously doubled EMA. -Source - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `DOUBLE_EXPONENTIAL_MOVING_AVERAGE()` with a `GROUP BY time()` clause, see [Advanced syntax](/influxdb/v2/query-data/influxql/functions/transformations/#advanced-syntax). - -### Basic syntax - -``` -DOUBLE_EXPONENTIAL_MOVING_AVERAGE([ * | | /regular_expression/ ], [, ), 2) ... GROUP BY time(1d)` -Returns the mean of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) -processed using the Double Exponential Moving Average algorithm with a 2-value period -and the default hold period and warmup type. - -{{% note %}} -**Note:** When aggregating data with a `GROUP BY` clause, you must include an [aggregate function](/influxdb/v2/query-data/influxql/functions/aggregates/) in your call to the `DOUBLE_EXPONENTIAL_MOVING_AVERAGE()` function. -{{% /note %}} - -`DOUBLE_EXPONENTIAL_MOVING_AVERAGE(/regular_expression/, 2)` -Returns the field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/) -processed using the Double Exponential Moving Average algorithm with a 2-value period -and the default hold period and warmup type. - -`DOUBLE_EXPONENTIAL_MOVING_AVERAGE(*, 2)` -Returns the field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement) -processed using the Double Exponential Moving Average algorithm with a 2-value period -and the default hold period and warmup type. - -`DOUBLE_EXPONENTIAL_MOVING_AVERAGE()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -### Arguments - -- [period](#period) -- (Optional) [hold_period](#hold_period) -- (Optional) [warmup_type](#warmup_type) - -## KAUFMANS_EFFICIENCY_RATIO() - -Kaufman's Efficiency Ration, or simply "Efficiency Ratio" (ER), is calculated by -dividing the data change over a period by the absolute sum of the data movements -that occurred to achieve that change. -The resulting ratio ranges between 0 and 1 with higher values representing a -more efficient or trending market. - -The ER is very similar to the [Chande Momentum Oscillator](#chande_momentum_oscillator) (CMO). -The difference is that the CMO takes market direction into account, but if you take the absolute CMO and divide by 100, you you get the Efficiency Ratio. -Source - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `KAUFMANS_EFFICIENCY_RATIO()` with a `GROUP BY time()` clause, see [Advanced syntax](/influxdb/v2/query-data/influxql/functions/transformations/#advanced-syntax). - -### Basic syntax - -``` -KAUFMANS_EFFICIENCY_RATIO([ * | | /regular_expression/ ], [, ]) -``` - -`KAUFMANS_EFFICIENCY_RATIO(field_key, 2)` -Returns the field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) -processed using the Efficiency Index algorithm with a 2-value period -and the default hold period and warmup type. - -`KAUFMANS_EFFICIENCY_RATIO(field_key, 10, 10)` -Returns the field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) -processed using the Efficiency Index algorithm with a 10-value period and -a 10-value hold period. - -`KAUFMANS_EFFICIENCY_RATIO(MEAN(), 2) ... GROUP BY time(1d)` -Returns the mean of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) -processed using the Efficiency Index algorithm with a 2-value period -and the default hold period. - -{{% note %}} -**Note:** When aggregating data with a `GROUP BY` clause, you must include an [aggregate function](/influxdb/v2/query-data/influxql/functions/aggregates/) in your call to the `KAUFMANS_EFFICIENCY_RATIO()` function. -{{% /note %}} - -`KAUFMANS_EFFICIENCY_RATIO(/regular_expression/, 2)` -Returns the field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/) -processed using the Efficiency Index algorithm with a 2-value period -and the default hold period and warmup type. - -`KAUFMANS_EFFICIENCY_RATIO(*, 2)` -Returns the field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement) -processed using the Efficiency Index algorithm with a 2-value period -and the default hold period and warmup type. - -`KAUFMANS_EFFICIENCY_RATIO()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -**Arguments:** - -- [period](#period) -- (Optional) [hold_period](#hold_period) - -## KAUFMANS_ADAPTIVE_MOVING_AVERAGE() - -Kaufman's Adaptive Moving Average (KAMA) is a moving average designed to -account for sample noise or volatility. -KAMA will closely follow data points when the data swings are relatively small and noise is low. -KAMA will adjust when the data swings widen and follow data from a greater distance. -This trend-following indicator can be used to identify the overall trend, -time turning points and filter data movements. -Source - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `KAUFMANS_ADAPTIVE_MOVING_AVERAGE()` with a `GROUP BY time()` clause, see [Advanced syntax](/influxdb/v2/query-data/influxql/functions/transformations/#advanced-syntax). - -### Basic syntax - -``` -KAUFMANS_ADAPTIVE_MOVING_AVERAGE([ * | | /regular_expression/ ], [, ]) -``` - -`KAUFMANS_ADAPTIVE_MOVING_AVERAGE(field_key, 2)` -Returns the field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) -processed using the Kaufman Adaptive Moving Average algorithm with a 2-value period -and the default hold period and warmup type. - -`KAUFMANS_ADAPTIVE_MOVING_AVERAGE(field_key, 10, 10)` -Returns the field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) -processed using the Kaufman Adaptive Moving Average algorithm with a 10-value period -and a 10-value hold period. - -`KAUFMANS_ADAPTIVE_MOVING_AVERAGE(MEAN(), 2) ... GROUP BY time(1d)` -Returns the mean of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) -processed using the Kaufman Adaptive Moving Average algorithm with a 2-value period -and the default hold period. - -{{% note %}} -**Note:** When aggregating data with a `GROUP BY` clause, you must include an [aggregate function](/influxdb/v2/query-data/influxql/functions/aggregates/) in your call to the `KAUFMANS_ADAPTIVE_MOVING_AVERAGE()` function. -{{% /note %}} - -`KAUFMANS_ADAPTIVE_MOVING_AVERAGE(/regular_expression/, 2)` -Returns the field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/) -processed using the Kaufman Adaptive Moving Average algorithm with a 2-value period -and the default hold period and warmup type. - -`KAUFMANS_ADAPTIVE_MOVING_AVERAGE(*, 2)` -Returns the field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement) -processed using the Kaufman Adaptive Moving Average algorithm with a 2-value period -and the default hold period and warmup type. - -`KAUFMANS_ADAPTIVE_MOVING_AVERAGE()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -**Arguments:** -- [period](#period) -- (Optional) [hold_period](#hold_period) - -## TRIPLE_EXPONENTIAL_MOVING_AVERAGE() - -The triple exponential moving average (TEMA) filters out -volatility from conventional moving averages. -While the name implies that it's a triple exponential smoothing, it's actually a -composite of a [single exponential moving average](#exponential_moving_average), -a [double exponential moving average](#double_exponential_moving_average), -and a triple exponential moving average. -Source - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `TRIPLE_EXPONENTIAL_MOVING_AVERAGE()` with a `GROUP BY time()` clause, see [Advanced syntax](/influxdb/v2/query-data/influxql/functions/transformations/#advanced-syntax). - -### Basic syntax - -``` -TRIPLE_EXPONENTIAL_MOVING_AVERAGE([ * | | /regular_expression/ ], [, ), 2) ... GROUP BY time(1d)` -Returns the mean of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) -processed using the Triple Exponential Moving Average algorithm with a 2-value period -and the default hold period and warmup type. - -{{% note %}} -**Note:** When aggregating data with a `GROUP BY` clause, you must include an [aggregate function](/influxdb/v2/query-data/influxql/functions/aggregates/) in your call to the `TRIPLE_EXPONENTIAL_MOVING_AVERAGE()` function. -{{% /note %}} - -`TRIPLE_EXPONENTIAL_MOVING_AVERAGE(/regular_expression/, 2)` -Returns the field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/) -processed using the Triple Exponential Moving Average algorithm with a 2-value period -and the default hold period and warmup type. - -`TRIPLE_EXPONENTIAL_MOVING_AVERAGE(*, 2)` -Returns the field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement) -processed using the Triple Exponential Moving Average algorithm with a 2-value period -and the default hold period and warmup type. - -`TRIPLE_EXPONENTIAL_MOVING_AVERAGE()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -**Arguments:** -- [period](#period) -- (Optional) [hold_period](#hold_period) -- (Optional) [warmup_type](#warmup_type) - -## TRIPLE_EXPONENTIAL_DERIVATIVE() - -The triple exponential derivative indicator, commonly referred to as "TRIX," is -an oscillator used to identify oversold and overbought markets, and can also be -used as a momentum indicator. -TRIX calculates a [triple exponential moving average](#triple_exponential_moving_average) -of the [log](/influxdb/v2/query-data/influxql/functions/transformations/#log) -of the data input over the period of time. -The previous value is subtracted from the previous value. -This prevents cycles that are shorter than the defined period from being considered by the indicator. - -Like many oscillators, TRIX oscillates around a zero line. When used as an oscillator, -a positive value indicates an overbought market while a negative value indicates an oversold market. -When used as a momentum indicator, a positive value suggests momentum is increasing -while a negative value suggests momentum is decreasing. -Many analysts believe that when the TRIX crosses above the zero line it gives a -buy signal, and when it closes below the zero line, it gives a sell signal. -Source - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `TRIPLE_EXPONENTIAL_DERIVATIVE()` with a `GROUP BY time()` clause, see [Advanced syntax](/influxdb/v2/query-data/influxql/functions/transformations/#advanced-syntax). - -### Basic syntax - -``` -TRIPLE_EXPONENTIAL_DERIVATIVE([ * | | /regular_expression/ ], [, ), 2) ... GROUP BY time(1d)` -Returns the mean of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) -processed using the Triple Exponential Derivative algorithm with a 2-value period -and the default hold period and warmup type. - -{{% note %}} -**Note:** When aggregating data with a `GROUP BY` clause, you must include an [aggregate function](/influxdb/v2/query-data/influxql/functions/aggregates/) in your call to the `TRIPLE_EXPONENTIAL_DERIVATIVE()` function. -{{% /note %}} - -`TRIPLE_EXPONENTIAL_DERIVATIVE(/regular_expression/, 2)` -Returns the field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/) -processed using the Triple Exponential Derivative algorithm with a 2-value period -and the default hold period and warmup type. - -`TRIPLE_EXPONENTIAL_DERIVATIVE(*, 2)` -Returns the field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement) -processed using the Triple Exponential Derivative algorithm with a 2-value period -and the default hold period and warmup type. - -`TRIPLE_EXPONENTIAL_DERIVATIVE()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -## RELATIVE_STRENGTH_INDEX() - -The relative strength index (RSI) is a momentum indicator that compares the magnitude of recent increases and decreases over a specified time period to measure speed and change of data movements. -Source - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). - -To use `RELATIVE_STRENGTH_INDEX()` with a `GROUP BY time()` clause, see [Advanced syntax](/influxdb/v2/query-data/influxql/functions/transformations/#advanced-syntax). - -### Basic syntax - -``` -RELATIVE_STRENGTH_INDEX([ * | | /regular_expression/ ], [, ), 2) ... GROUP BY time(1d)` -Returns the mean of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) -processed using the Relative Strength Index algorithm with a 2-value period -and the default hold period and warmup type. - -{{% note %}} -**Note:** When aggregating data with a `GROUP BY` clause, you must include an [aggregate function](/influxdb/v2/query-data/influxql/functions/aggregates/) in your call to the `RELATIVE_STRENGTH_INDEX()` function. -{{% /note %}} - -`RELATIVE_STRENGTH_INDEX(/regular_expression/, 2)` -Returns the field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/) -processed using the Relative Strength Index algorithm with a 2-value period -and the default hold period and warmup type. - -`RELATIVE_STRENGTH_INDEX(*, 2)` -Returns the field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement) -processed using the Relative Strength Index algorithm with a 2-value period -and the default hold period and warmup type. - -`RELATIVE_STRENGTH_INDEX()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -**Arguments:** -- [period](#period) -- (Optional) [hold_period](#hold_period) -- (Optional) [warmup_type](#warmup_type) + diff --git a/content/influxdb/v2/query-data/influxql/functions/transformations.md b/content/influxdb/v2/query-data/influxql/functions/transformations.md index 031e3441d..aecee0a58 100644 --- a/content/influxdb/v2/query-data/influxql/functions/transformations.md +++ b/content/influxdb/v2/query-data/influxql/functions/transformations.md @@ -8,4258 +8,8 @@ menu: name: Transformations parent: InfluxQL functions weight: 205 +source: /shared/influxdb-v2/query-data/influxql/functions/transformations.md --- -InfluxQL transformation functions modify and return values each row of queried data. - -Each transformation function below covers **syntax**, including parameters to pass to the function, and **examples** of how to use the function. Examples use [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data) and data from [sample_test.txt](https://gist.github.com/sanderson/244e3dc2d778d5c37783483c6c2b548a). - -- [ABS()](#abs) -- [ACOS()](#acos) -- [ASIN()](#asin) -- [ATAN()](#atan) -- [ATAN2()](#atan2) -- [CEIL()](#ceil) -- [COS()](#cos) -- [CUMULATIVE_SUM()](#cumulative_sum) -- [DERIVATIVE()](#derivative) -- [DIFFERENCE()](#difference) -- [ELAPSED()](#elapsed) -- [EXP()](#exp) -- [FLOOR()](#floor) -- [HISTOGRAM()](#histogram) -- [LN()](#ln) -- [LOG()](#log) -- [LOG2()](#log2) -- [LOG10()](#log10) -- [MOVING_AVERAGE()](#moving_average) -- [NON_NEGATIVE_DERIVATIVE()](#non_negative_derivative) -- [NON_NEGATIVE_DIFFERENCE](#non_negative_difference) -- [POW](#pow) -- [ROUND](#round) -- [SIN](#sin) -- [SQRT](#sqrt) -- [TAN](#tan) - -## ABS() - -Returns the absolute value of the field value. Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). - -### Basic syntax - -```sql -SELECT ABS( [ * | ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`ABS(field_key)` -Returns the absolute values of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`ABS(*)` -Returns the absolute values of field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`ABS()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the absolute values of field values associated with a field key" %}} - -Return the absolute values of field values in the `water_level` field key in the `h2o_feet` measurement. - -```sql -SELECT ABS("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:15:00Z' -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | abs | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 8.5040000000 | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 8.4190000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 8.3200000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | - -{{% /expand %}} - -{{% expand "Calculate the absolute values of field values associated with each field key in a measurement" %}} - -Return the absolute values of field values for each field key that stores numeric values in the `data` measurement. -The `h2o_feet` measurement has one numeric field `water_level`. - -```sql -SELECT ABS(*) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:15:00Z' -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | abs_water_level | -| :------------------- | --------------: | -| 2019-08-18T00:00:00Z | 8.5040000000 | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 8.4190000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 8.3200000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | - - -{{% /expand %}} - -{{% expand "Calculate the absolute values of field values associated with a field key and include several clauses" %}} - -Return the absolute values of field values associated with the `water_level` -field key in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -```sql -SELECT ABS("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | abs | -| :------------------- | -----------: | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:24:00Z | 8.1300000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:18:00Z | 8.2250000000 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT ABS(( [ * | ] )) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `ABS()` function to those results. - -`ABS()` supports the following nested functions: - -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the absolute values of mean values" %}} - -Return the absolute values of [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `water_level`s that are calculated at 12-minute intervals. - -```sql -SELECT ABS(MEAN("water_level")) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | abs | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 5.4135000000 | -| 2019-08-18T00:12:00Z | 5.3042500000 | -| 2019-08-18T00:24:00Z | 5.1682500000 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## ACOS() - -Returns the arccosine (in radians) of the field value. Field values must be between -1 and 1. Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but does not support [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). - -### Basic syntax - -```sql -SELECT ACOS( [ * | ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`ACOS(field_key)` -Returns the arccosine of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`ACOS(*)` -Returns the arccosine of field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`ACOS()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types) with values between -1 and 1. - -#### Examples - -The examples below use a subset of data from [sample_test.txt](https://gist.github.com/sanderson/244e3dc2d778d5c37783483c6c2b548a), which only includes field values within the calculable range (-1 to 1). This value range is required for the `ACOS()` function: - -| time | a | -| :------------------- | -----------------: | -| 2018-06-24T12:01:00Z | -0.774984088561186 | -| 2018-06-24T12:02:00Z | -0.921037167720451 | -| 2018-06-24T12:04:00Z | -0.905980032168252 | -| 2018-06-24T12:05:00Z | -0.891164752631417 | -| 2018-06-24T12:09:00Z | 0.416579917279588 | -| 2018-06-24T12:10:00Z | 0.328968116955350 | -| 2018-06-24T12:11:00Z | 0.263585064411983 | - - -{{< expand-wrapper >}} - -{{% expand "Calculate the arccosine of field values associated with a field key" %}} - -Return the arccosine of field values in the `a` field key in the `data` measurement. - -```sql -SELECT ACOS("a") FROM "data" WHERE time >= '2018-06-24T00:00:00Z' AND time <= '2018-06-25T00:00:00Z' -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | acos | -| :------------------- | -----------: | -| 2018-06-24T12:00:00Z | | -| 2018-06-24T12:01:00Z | 2.4574862443 | -| 2018-06-24T12:02:00Z | 2.7415314737 | -| 2018-06-24T12:03:00Z | | -| 2018-06-24T12:04:00Z | 2.7044854503 | -| 2018-06-24T12:05:00Z | 2.6707024029 | -| 2018-06-24T12:06:00Z | | -| 2018-06-24T12:07:00Z | | -| 2018-06-24T12:08:00Z | | -| 2018-06-24T12:09:00Z | 1.1411163210 | -| 2018-06-24T12:10:00Z | 1.2355856616 | -| 2018-06-24T12:11:00Z | 1.3040595066 | - -{{% /expand %}} - -{{% expand "Calculate the arccosine of field values associated with each field key in a measurement" %}} - -Return the arccosine of field values for each field key that stores numeric values in the `data` measurement, field `a` and `b`. - -```sql -SELECT ACOS(*) FROM "data" WHERE time >= '2018-06-24T00:00:00Z' AND time <= '2018-06-25T00:00:00Z' -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | acos_a | acos_b | -| :------------------- | -----------: | -----------: | -| 2018-06-24T12:00:00Z | | 1.7351786976 | -| 2018-06-24T12:01:00Z | 2.4574862443 | 1.4333294161 | -| 2018-06-24T12:02:00Z | 2.7415314737 | 2.0748091141 | -| 2018-06-24T12:03:00Z | | 1.6438345404 | -| 2018-06-24T12:04:00Z | 2.7044854503 | | -| 2018-06-24T12:05:00Z | 2.6707024029 | 0.7360183965 | -| 2018-06-24T12:06:00Z | | 1.2789990384 | -| 2018-06-24T12:07:00Z | | 2.1522589654 | -| 2018-06-24T12:08:00Z | | 0.6128438977 | -| 2018-06-24T12:09:00Z | 1.1411163210 | | -| 2018-06-24T12:10:00Z | 1.2355856616 | | -| 2018-06-24T12:11:00Z | 1.3040595066 | 1.7595349692 | -| 2018-06-24T12:12:00Z | 1.8681669412 | 2.5213034266 | - -{{% /expand %}} - -{{% expand "Calculate the arccosine of field values associated with a field key and include several clauses" %}} - -Return the arccosine of field values associated with the `a` field key in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) between `2018-06-24T00:00:00Z` and `2018-06-25T00:00:00Z` with results in [descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) results by two points. - -```sql -SELECT ACOS("a") FROM "data" WHERE time >= '2018-06-24T00:00:00Z' AND time <= '2018-06-25T00:00:00Z' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | acos | -| :------------------- | -----------: | -| 2018-06-24T23:58:00Z | 1.5361053361 | -| 2018-06-24T23:57:00Z | | -| 2018-06-24T23:56:00Z | 0.5211076815 | -| 2018-06-24T23:55:00Z | 1.647695085 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT ACOS(( [ * | ] )) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `ACOS()` function to those results. - -`ACOS()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the arccosine of mean values" %}} - -Return the arccosine of [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `a` that are calculated at 3 hour intervals. - -```sql -SELECT ACOS(MEAN("a")) FROM "data" WHERE time >= '2018-06-24T00:00:00Z' AND time <= '2018-06-25T00:00:00Z' GROUP BY time(3h) -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | acos | -| :------------------- | -----------: | -| 2018-06-24T00:00:00Z | | -| 2018-06-24T03:00:00Z | | -| 2018-06-24T06:00:00Z | | -| 2018-06-24T09:00:00Z | | -| 2018-06-24T12:00:00Z | 1.5651603194 | -| 2018-06-24T15:00:00Z | 1.6489104619 | -| 2018-06-24T18:00:00Z | 1.4851295699 | -| 2018-06-24T21:00:00Z | 1.6209901549 | -| 2018-06-25T00:00:00Z | 1.7149309371 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## ASIN() - -Returns the arcsine (in radians) of the field value. Field values must be between -1 and 1. - -### Basic syntax - -```sql -SELECT ASIN( [ * | ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`ASIN(field_key)` -Returns the arcsine of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`ASIN(*)` -Returns the arcsine of field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`ASIN()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types) with values between -1 and 1. - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `ASIN()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples below use the following data from [sample_test.txt](https://gist.github.com/sanderson/244e3dc2d778d5c37783483c6c2b548a). - -The following data from this data set only includes field value within the calculable range (-1 to 1) required for the `ASIN()` function: - -| time | a | -| :------------------- | -----------------: | -| 2018-06-24T12:01:00Z | -0.774984088561186 | -| 2018-06-24T12:02:00Z | -0.921037167720451 | -| 2018-06-24T12:04:00Z | -0.905980032168252 | -| 2018-06-24T12:05:00Z | -0.891164752631417 | -| 2018-06-24T12:09:00Z | 0.416579917279588 | -| 2018-06-24T12:10:00Z | 0.328968116955350 | -| 2018-06-24T12:11:00Z | 0.263585064411983 | - -{{< expand-wrapper >}} - -{{% expand "Calculate the arcsine of field values associated with a field key" %}} - -Return the arcsine of field values in the `a` field key in the `data` measurement. - -```sql -SELECT ASIN("a") FROM "data" WHERE time >= '2018-06-24T00:00:00Z' AND time <= '2018-06-25T00:00:00Z' -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | asin | -| :------------------- | ------------: | -| 2018-06-24T12:00:00Z | | -| 2018-06-24T12:01:00Z | -0.8866899175 | -| 2018-06-24T12:02:00Z | -1.1707351469 | -| 2018-06-24T12:03:00Z | | -| 2018-06-24T12:04:00Z | -1.1336891235 | -| 2018-06-24T12:05:00Z | -1.0999060761 | -| 2018-06-24T12:06:00Z | | -| 2018-06-24T12:07:00Z | | -| 2018-06-24T12:08:00Z | | -| 2018-06-24T12:09:00Z | 0.4296800058 | -| 2018-06-24T12:10:00Z | 0.3352106652 | -| 2018-06-24T12:11:00Z | 0.2667368202 | -| 2018-06-24T12:12:00Z | -0.2973706144 | - -{{% /expand %}} - -{{% expand "Calculate the arcsine of field values associated with each field key in a measurement" %}} - -Return the arcsine of field values for each field key that stores numeric values in the `data` measurement. -The `data` measurement has one numeric field: `a`. - -```sql -SELECT ASIN(*) FROM "data" WHERE time >= '2018-06-24T00:00:00Z' AND time <= '2018-06-25T00:00:00Z' -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | asin_a | asin_b | -| :------------------- | ------------: | ------------: | -| 2018-06-24T12:00:00Z | | -0.1643823708 | -| 2018-06-24T12:01:00Z | -0.8866899175 | 0.1374669107 | -| 2018-06-24T12:02:00Z | -1.1707351469 | -0.5040127873 | -| 2018-06-24T12:03:00Z | | -0.0730382136 | -| 2018-06-24T12:04:00Z | -1.1336891235 | | -| 2018-06-24T12:05:00Z | -1.0999060761 | 0.8347779303 | -| 2018-06-24T12:06:00Z | | 0.2917972884 | -| 2018-06-24T12:07:00Z | | -0.5814626386 | -| 2018-06-24T12:08:00Z | | 0.9579524291 | -| 2018-06-24T12:09:00Z | 0.4296800058 | | -| 2018-06-24T12:10:00Z | 0.3352106652 | | -| 2018-06-24T12:11:00Z | 0.2667368202 | -0.1887386424 | -| 2018-06-24T12:12:00Z | -0.2973706144 | -0.9505070998 | - -{{% /expand %}} - -{{% expand "Calculate the arcsine of field values associated with a field key and include several clauses" %}} - -Return the arcsine of field values associated with the `a` field key in the -[time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2018-06-24T00:00:00Z` and `2018-06-25T00:00:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -```sql -SELECT ASIN("a") FROM "data" WHERE time >= '2018-06-24T00:00:00Z' AND time <= '2018-06-25T00:00:00Z' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | asin | -| :------------------- | -----------: | -| 2018-06-24T23:58:00Z | 0.0346909907 | -| 2018-06-24T23:57:00Z | | -| 2018-06-24T23:56:00Z | 1.0496886453 | -| 2018-06-24T23:55:00Z | 0.0768987583 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT ASIN(( [ * | ] )) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `ASIN()` function to those results. - -`ASIN()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the arcsine of mean values" %}} - -Return the arcsine of [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `a`s that are calculated at 3-hour intervals. - -```sql -SELECT ASIN(MEAN("a")) FROM "data" WHERE time >= '2018-06-24T00:00:00Z' AND time <= '2018-06-25T00:00:00Z' GROUP BY time(3h) -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | asin | -| :------------------- | ------------: | -| 2018-06-24T00:00:00Z | | -| 2018-06-24T03:00:00Z | | -| 2018-06-24T06:00:00Z | | -| 2018-06-24T09:00:00Z | | -| 2018-06-24T12:00:00Z | 0.0056360073 | -| 2018-06-24T15:00:00Z | -0.0781141351 | -| 2018-06-24T18:00:00Z | 0.0856667569 | -| 2018-06-24T21:00:00Z | -0.0501938281 | -| 2018-06-25T00:00:00Z | -0.1441346103 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## ATAN() - -Returns the arctangent (in radians) of the field value. Field values must be between -1 and 1. - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `ATAN()` with a `GROUP BY time()` clause, see the [Advanced syntax](#advanced-syntax). - -### Basic syntax - -```sql -SELECT ATAN( [ * | ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`ATAN(field_key)` -Returns the arctangent of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - - - -`ATAN(*)` -Returns the arctangent of field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`ATAN()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types) with values between -1 and 1. - -#### Examples - -The examples below use a subset of data from [sample_test.txt](https://gist.github.com/sanderson/244e3dc2d778d5c37783483c6c2b548a) that only includes field values within the calculable range (-1 to 1) required for the of the `ATAN()` function. - -{{< expand-wrapper >}} - -{{% expand "Calculate the arctangent of field values associated with a field key" %}} - -Return the arctangent of field values in the `a` field key in the `data` measurement. - -```sql -SELECT ATAN("a") FROM "data" WHERE time >= '2018-06-24T00:00:00Z' AND time <= '2018-06-25T00:00:00Z' -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | atan | -| :------------------- | ------------: | -| 2018-06-24T12:00:00Z | 0.9293622934 | -| 2018-06-24T12:01:00Z | -0.6593001275 | -| 2018-06-24T12:02:00Z | -0.7443170184 | -| 2018-06-24T12:03:00Z | -1.0488818071 | -| 2018-06-24T12:04:00Z | -0.7361091801 | -| 2018-06-24T12:05:00Z | -0.7279122495 | -| 2018-06-24T12:06:00Z | 0.8379907133 | -| 2018-06-24T12:07:00Z | -0.9117032768 | -| 2018-06-24T12:08:00Z | -1.0364006848 | -| 2018-06-24T12:09:00Z | 0.3947172008 | -| 2018-06-24T12:10:00Z | 0.3178167283 | -| 2018-06-24T12:11:00Z | 0.2577231762 | -| 2018-06-24T12:12:00Z | -0.2850291359 | - -{{% /expand %}} - -{{% expand "Calculate the arctangent of field values associated with each field key in a measurement" %}} - -Return the arctangent of field values for each field key that stores numeric values in the `data` measurement--fields `a` and `b`. - -```sql -SELECT ATAN(*) FROM "data" WHERE time >= '2018-06-24T00:00:00Z' AND time <= '2018-06-25T00:00:00Z' -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | atan_a | atan_b | -| :------------------- | ------------: | ------------: | -| 2018-06-24T12:00:00Z | 0.9293622934 | -0.1622053541 | -| 2018-06-24T12:01:00Z | -0.6593001275 | 0.1361861379 | -| 2018-06-24T12:02:00Z | -0.7443170184 | -0.4499093122 | -| 2018-06-24T12:03:00Z | -1.0488818071 | -0.0728441751 | -| 2018-06-24T12:04:00Z | -0.7361091801 | 1.0585985451 | -| 2018-06-24T12:05:00Z | -0.7279122495 | 0.6378113578 | -| 2018-06-24T12:06:00Z | 0.8379907133 | 0.2801105336 | -| 2018-06-24T12:07:00Z | -0.9117032768 | -0.5022647489 | -| 2018-06-24T12:08:00Z | -1.0364006848 | 0.6856298940 | -| 2018-06-24T12:09:00Z | 0.3947172008 | -0.8711781065 | -| 2018-06-24T12:10:00Z | 0.3178167283 | -0.8273348593 | -| 2018-06-24T12:11:00Z | 0.2577231762 | -0.1854639556 | -| 2018-06-24T12:12:00Z | -0.2850291359 | -0.6830451940 | - -{{% /expand %}} - -{{% expand "Calculate the arctangent of field values associated with a field key and include several clauses" %}} - -Return the arctangent of field values associated with the `a` field key in -[time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2017-05-01T00:00:00Z` and `2017-05-09T00:00:00Z` and returns results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -```sql -SELECT ATAN("a") FROM "data" WHERE time >= '2018-06-24T00:00:00Z' AND time <= '2018-06-25T00:00:00Z' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | atan | -| :------------------- | ------------: | -| 2018-06-24T23:58:00Z | 0.0346701348 | -| 2018-06-24T23:57:00Z | -0.8582372146 | -| 2018-06-24T23:56:00Z | 0.7144341473 | -| 2018-06-24T23:55:00Z | -0.0766723939 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT ATAN(( [ * | ] )) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `ATAN()` function to those results. - -`ATAN()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples of advanced syntax - -{{< expand-wrapper >}} - -{{% expand "Calculate the arctangent of mean values" %}} - -Return the arctangent of [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `a`s that are calculated at 3-hour intervals. - -```sql -SELECT ATAN(MEAN("a")) FROM "data" WHERE time >= '2018-06-24T00:00:00Z' AND time <= '2018-06-25T00:00:00Z' GROUP BY time(3h) -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | atan | -| :------------------- | ------------: | -| 2018-06-24T00:00:00Z | | -| 2018-06-24T03:00:00Z | | -| 2018-06-24T06:00:00Z | | -| 2018-06-24T09:00:00Z | | -| 2018-06-24T12:00:00Z | 0.0056359178 | -| 2018-06-24T15:00:00Z | -0.0778769005 | -| 2018-06-24T18:00:00Z | 0.0853541301 | -| 2018-06-24T21:00:00Z | -0.0501307176 | -| 2018-06-25T00:00:00Z | -0.1426603174 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## ATAN2() - -Returns the the arctangent of `y/x` in radians. - -### Basic syntax - -```sql -SELECT ATAN2( [ * | | num ], [ | num ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`ATAN2(field_key_y, field_key_x)` -Returns the arctangent of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key), `field_key_y`, divided by field values associated with `field_key_x`. - -`ATAN2(*, field_key_x)` -Returns the field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement) -divided by field values associated with `field_key_x`. - -`ATAN2()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `ATAN2()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples below use [sample_test.txt](https://gist.github.com/sanderson/244e3dc2d778d5c37783483c6c2b548a). - -{{< expand-wrapper >}} - -{{% expand "Calculate the arctangent of field_key_b over field_key_a" %}} - -Return the arctangents of field values in the `a` field key divided by values in the `b` field key. Both are part of the `data` measurement. - -```sql -SELECT ATAN2("a", "b") FROM "data" WHERE time >= '2018-06-24T00:00:00Z' AND time <= '2018-06-25T00:00:00Z' -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | atan2 | -| :------------------- | ------------: | -| 2018-06-24T12:00:00Z | 1.6923979639 | -| 2018-06-24T12:01:00Z | -1.3957831900 | -| 2018-06-24T12:02:00Z | -2.0537314089 | -| 2018-06-24T12:03:00Z | -1.6127391493 | -| 2018-06-24T12:04:00Z | -0.4711275404 | -| 2018-06-24T12:05:00Z | -0.8770454978 | -| 2018-06-24T12:06:00Z | 1.3174573347 | -| 2018-06-24T12:07:00Z | -1.9730696643 | -| 2018-06-24T12:08:00Z | -1.1199236554 | -| 2018-06-24T12:09:00Z | 2.8043757212 | -| 2018-06-24T12:10:00Z | 2.8478694533 | -| 2018-06-24T12:11:00Z | 2.1893985296 | -| 2018-06-24T12:12:00Z | -2.7959592806 | - -{{% /expand %}} - -{{% expand "Calculate the arctangent of values associated with each field key in a measurement divided by field_key_a" %}} - -Return the arctangents of all numeric field values in the `data` measurement divided by values in the `a` field key. -The `data` measurement has two numeric fields: `a` and `b`. - -```sql -SELECT ATAN2(*, "a") FROM "data" WHERE time >= '2018-06-24T00:00:00Z' AND time <= '2018-06-25T00:00:00Z' -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | atan2_a | atan2_b | -| :------------------- | ------------: | ------------: | -| 2018-06-24T12:00:00Z | 0.7853981634 | -0.1216016371 | -| 2018-06-24T12:01:00Z | -2.3561944902 | 2.9665795168 | -| 2018-06-24T12:02:00Z | -2.3561944902 | -2.6586575715 | -| 2018-06-24T12:03:00Z | -2.3561944902 | -3.0996498311 | -| 2018-06-24T12:04:00Z | -2.3561944902 | 2.0419238672 | -| 2018-06-24T12:05:00Z | -2.3561944902 | 2.4478418246 | -| 2018-06-24T12:06:00Z | 0.7853981634 | 0.2533389921 | -| 2018-06-24T12:07:00Z | -2.3561944902 | -2.7393193161 | -| 2018-06-24T12:08:00Z | -2.3561944902 | 2.6907199822 | -| 2018-06-24T12:09:00Z | 0.7853981634 | -1.2335793944 | -| 2018-06-24T12:10:00Z | 0.7853981634 | -1.2770731265 | -| 2018-06-24T12:11:00Z | 0.7853981634 | -0.6186022028 | -| 2018-06-24T12:12:00Z | -2.3561944902 | -1.9164296997 | - -{{% /expand %}} - -{{% expand "Calculate the arctangents of field values and include several clauses" %}} - -Return the arctangent of field values associated with the `a` field key divided -by the `b` field key in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2018-05-16T12:10:00Z` and `2018-05-16T12:10:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -```sql -SELECT ATAN2("a", "b") FROM "data" WHERE time >= '2018-06-24T00:00:00Z' AND time <= '2018-06-25T00:00:00Z' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | atan2 | -| :------------------- | ------------: | -| 2018-06-24T23:58:00Z | 0.0166179004 | -| 2018-06-24T23:57:00Z | -2.3211306482 | -| 2018-06-24T23:56:00Z | 1.8506549463 | -| 2018-06-24T23:55:00Z | -0.0768444917 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT ATAN2(, ) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `ATAN2()` function to those results. - -`ATAN2()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate arctangents of mean values" %}} - -Return the arctangents of [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `a`s divided by average `b`s. Averages are calculated at 2-hour intervals. - -```sql -SELECT ATAN2(MEAN("b"), MEAN("a")) FROM "data" WHERE time >= '2018-06-24T12:00:00Z' AND time <= '2018-06-25T00:00:00Z' GROUP BY time(2h) -``` - -{{% influxql/table-meta %}} -name: data -{{% /influxql/table-meta %}} - -| time | atan2 | -| :------------------- | ------------: | -| 2018-06-24T12:00:00Z | -0.8233039154 | -| 2018-06-24T14:00:00Z | 1.6676707651 | -| 2018-06-24T16:00:00Z | 2.3853882606 | -| 2018-06-24T18:00:00Z | -1.0180694195 | -| 2018-06-24T20:00:00Z | -0.2601965301 | -| 2018-06-24T22:00:00Z | 2.1893237434 | -| 2018-06-25T00:00:00Z | -2.5572285037 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## CEIL() - -Returns the subsequent value rounded up to the nearest integer. - -### Basic syntax - -```sql -SELECT CEIL( [ * | ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`CEIL(field_key)` -Returns the field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) rounded up to the nearest integer. - -`CEIL(*)` -Returns the field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement) rounded up to the nearest integer. - -`CEIL()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `CEIL()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples below use the following subsample of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:30:00Z | 2.2670000000 | - -{{< expand-wrapper >}} - -{{% expand "Calculate the ceiling of field values associated with a field key" %}} - -Return field values in the `water_level` field key in the `h2o_feet` measurement rounded up to the nearest integer. - -```sql -SELECT CEIL("water_level") FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | ceil | -| :------------------- | -----------: | -| 2019-08-17T00:00:00Z | 3.0000000000 | -| 2019-08-17T00:06:00Z | 3.0000000000 | -| 2019-08-17T00:12:00Z | 3.0000000000 | -| 2019-08-17T00:18:00Z | 3.0000000000 | -| 2019-08-17T00:24:00Z | 3.0000000000 | -| 2019-08-17T00:30:00Z | 3.0000000000 | - -{{% /expand %}} - -{{% expand "Calculate the ceiling of field values associated with each field key in a measurement" %}} - -Return field values for each field key that stores numeric values in the `h2o_feet` -measurement rounded up to the nearest integer. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT CEIL(*) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | ceil_water_level | -| :------------------- | ---------------: | -| 2019-08-17T00:00:00Z | 3.0000000000 | -| 2019-08-17T00:06:00Z | 3.0000000000 | -| 2019-08-17T00:12:00Z | 3.0000000000 | -| 2019-08-17T00:18:00Z | 3.0000000000 | -| 2019-08-17T00:24:00Z | 3.0000000000 | -| 2019-08-17T00:30:00Z | 3.0000000000 | - -{{% /expand %}} - -{{% expand "Calculate the ceiling of field values associated with a field key and include several clauses" %}} - -Return field values associated with the `water_level` field key rounded up to the -nearest integer in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -```sql -SELECT CEIL("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | ceil | -| :------------------- | -----------: | -| 2019-08-17T00:18:00Z | 3.0000000000 | -| 2019-08-17T00:12:00Z | 3.0000000000 | -| 2019-08-17T00:06:00Z | 3.0000000000 | -| 2019-08-17T00:00:00Z | 3.0000000000 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT CEIL(( [ * | | // ] )) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `CEIL()` function to those results. - -`CEIL()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate mean values rounded up to the nearest integer" %}} - -Return the [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `water_level`s that are calculated at 12-minute intervals and rounds them up to the nearest integer. - -```sql -SELECT CEIL(MEAN("water_level")) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | ceil | -| :------------------- | -----------: | -| 2019-08-17T00:00:00Z | 3.0000000000 | -| 2019-08-17T00:12:00Z | 3.0000000000 | -| 2019-08-17T00:24:00Z | 3.0000000000 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## COS() - -Returns the cosine of the field value. - -### Basic syntax - -```sql -SELECT COS( [ * | ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`COS(field_key)` -Returns the cosine of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`COS(*)` -Returns the cosine of field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`COS()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `COS()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples below use the following subsample of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:30:00Z | 2.2670000000 | - -{{< expand-wrapper >}} - -{{% expand "Calculate the cosine of field values associated with a field key" %}} - -Return the cosine of field values in the `water_level` field key in the `h2o_feet` measurement. - -```sql -SELECT COS("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | cos | -| :------------------- | ------------: | -| 2019-08-18T00:00:00Z | -0.7041346171 | -| 2019-08-18T00:06:00Z | -0.7230474420 | -| 2019-08-18T00:12:00Z | -0.6977155876 | -| 2019-08-18T00:18:00Z | -0.6876182920 | -| 2019-08-18T00:24:00Z | -0.6390047316 | -| 2019-08-18T00:30:00Z | -0.6413094611 | - -{{% /expand %}} - -{{% expand "Calculate the cosine of field values associated with each field key in a measurement" %}} - -Return the cosine of field values for each numeric field in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT COS(*) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | cos_water_level | -| :------------------- | --------------: | -| 2019-08-18T00:00:00Z | -0.7041346171 | -| 2019-08-18T00:06:00Z | -0.7230474420 | -| 2019-08-18T00:12:00Z | -0.6977155876 | -| 2019-08-18T00:18:00Z | -0.6876182920 | -| 2019-08-18T00:24:00Z | -0.6390047316 | -| 2019-08-18T00:30:00Z | -0.6413094611 | - -{{% /expand %}} - -{{% expand "Calculate the cosine of field values associated with a field key and include several clauses" %}} - -Return the cosine of field values associated with the `water_level` field key -in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -```sql -SELECT COS("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | cos | -| :------------------- | ------------: | -| 2019-08-18T00:18:00Z | -0.6876182920 | -| 2019-08-18T00:12:00Z | -0.6977155876 | -| 2019-08-18T00:06:00Z | -0.7230474420 | -| 2019-08-18T00:00:00Z | -0.7041346171 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT COS(( [ * | ] )) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `COS()` function to those results. - -`COS()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the cosine of mean values" %}} - -Return the cosine of [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `water_level`s that are calculated at 12-minute intervals. - -```sql -SELECT COS(MEAN("water_level")) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | cos | -| ---- | --- | -| 2019-08-18T00:00:00Z | -0.7136560605 | -| 2019-08-18T00:12:00Z | -0.6926839105 | -| 2019-08-18T00:24:00Z | -0.6401578165 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## CUMULATIVE_SUM() - -Returns the running total of subsequent [field values](/influxdb/v2/reference/glossary/#field-value). - -### Basic syntax - -```sql -SELECT CUMULATIVE_SUM( [ * | | // ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`CUMULATIVE_SUM(field_key)` -Returns the running total of subsequent field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`CUMULATIVE_SUM(/regular_expression/)` -Returns the running total of subsequent field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/). - -`CUMULATIVE_SUM(*)` -Returns the running total of subsequent field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`CUMULATIVE_SUM()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `CUMULATIVE_SUM()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples below use the following subsample of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:30:00Z | 2.2670000000 | - -{{< expand-wrapper >}} - -{{% expand "Calculate the cumulative sum of the field values associated with a field key" %}} - -Return the running total of the field values in the `water_level` field key and in the `h2o_feet` measurement. - -```sql -SELECT CUMULATIVE_SUM("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | cumulative_sum | -| :------------------- | -------------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 4.7310000000 | -| 2019-08-18T00:12:00Z | 7.0740000000 | -| 2019-08-18T00:18:00Z | 9.4030000000 | -| 2019-08-18T00:24:00Z | 11.6670000000 | -| 2019-08-18T00:30:00Z | 13.9340000000 | - -{{% /expand %}} - -{{% expand "Calculate the cumulative sum of the field values associated with each field key in a measurement" %}} - -Return the running total of the field values for each numeric field in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT CUMULATIVE_SUM(*) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | cumulative_sum_water_level | -| :------------------- | -------------------------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 4.7310000000 | -| 2019-08-18T00:12:00Z | 7.0740000000 | -| 2019-08-18T00:18:00Z | 9.4030000000 | -| 2019-08-18T00:24:00Z | 11.6670000000 | -| 2019-08-18T00:30:00Z | 13.9340000000 | - -{{% /expand %}} - -{{% expand "Calculate the cumulative sum of the field values associated with each field key that matches a regular expression" %}} - -Return the running total of the field values for each field key that stores -numeric values and includes the word `water` in the `h2o_feet` measurement. - -```sql -SELECT CUMULATIVE_SUM(/water/) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | cumulative_sum_water_level | -| :------------------- | -------------------------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 4.7310000000 | -| 2019-08-18T00:12:00Z | 7.0740000000 | -| 2019-08-18T00:18:00Z | 9.4030000000 | -| 2019-08-18T00:24:00Z | 11.6670000000 | -| 2019-08-18T00:30:00Z | 13.9340000000 | - -{{% /expand %}} - -{{% expand "Calculate the cumulative sum of the field values associated with a field key and include several clauses" %}} - -Return the running total of the field values associated with the `water_level` -field key in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -```sql -SELECT CUMULATIVE_SUM("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | cumulative_sum | -| :------------------- | -------------: | -| 2019-08-18T00:18:00Z | 6.8600000000 | -| 2019-08-18T00:12:00Z | 9.2030000000 | -| 2019-08-18T00:06:00Z | 11.5820000000 | -| 2019-08-18T00:00:00Z | 13.9340000000 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT CUMULATIVE_SUM(( [ * | | // ] )) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `CUMULATIVE_SUM()` function to those results. - -`CUMULATIVE_SUM()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the cumulative sum of mean values" %}} - -Return the running total of [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `water_level`s that are calculated at 12-minute intervals. - -```sql -SELECT CUMULATIVE_SUM(MEAN("water_level")) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | cumulative_sum | -| :------------------- | -------------: | -| 2019-08-18T00:00:00Z | 2.3655000000 | -| 2019-08-18T00:12:00Z | 4.7015000000 | -| 2019-08-18T00:24:00Z | 6.9670000000 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## DERIVATIVE() - -Returns the rate of change between subsequent [field values](/influxdb/v2/reference/glossary/#field-value). - -### Basic syntax - -```sql -SELECT DERIVATIVE( [ * | | // ] [ , ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -InfluxDB calculates the difference between subsequent field values and converts those results into the rate of change per `unit`. -The `unit` argument is an integer followed by a [duration](/influxdb/v2/reference/glossary/#duration) and it is optional. -If the query does not specify the `unit` the unit defaults to one second (`1s`). - -`DERIVATIVE(field_key)` -Returns the rate of change between subsequent field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`DERIVATIVE(/regular_expression/)` -Returns the rate of change between subsequent field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/). - -`DERIVATIVE(*)` -Returns the rate of change between subsequent field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`DERIVATIVE()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `DERIVATIVE()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples in this section use the following subsample of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:30:00Z | 2.2670000000 | - -{{< expand-wrapper >}} - -{{% expand "Calculate the derivative between the field values associated with a field key" %}} - -Return the one-second rate of change between the `water_level` field values in the `h2o_feet` measurement. - -```sql -SELECT DERIVATIVE("water_level") FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | derivative | -| :------------------- | ------------: | -| 2019-08-18T00:06:00Z | 0.0000750000 | -| 2019-08-18T00:12:00Z | -0.0001000000 | -| 2019-08-18T00:18:00Z | -0.0000388889 | -| 2019-08-18T00:24:00Z | -0.0001805556 | -| 2019-08-18T00:30:00Z | 0.0000083333 | - -The first result (`0.0000750000`) is the one-second rate of change between the first two subsequent field values in the raw data. InfluxDB calculates the difference between the field values (subtracts the first field value from the second field value) and then normalizes that value to the one-second rate of change (dividing the difference between the field values' timestamps in seconds (`360s`) by the default unit (`1s`)): - -``` -(2.379 - 2.352) / (360s / 1s) -``` - -{{% /expand %}} - -{{% expand "Calculate the derivative between the field values associated with a field key and specify the unit option" %}} - -Return the six-minute rate of change between the field values in the `water_level` field in the `h2o_feet` measurement. - -```sql -SELECT DERIVATIVE("water_level",6m) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | derivative | -| :------------------- | ------------: | -| 2019-08-18T00:06:00Z | 0.0270000000 | -| 2019-08-18T00:12:00Z | -0.0360000000 | -| 2019-08-18T00:18:00Z | -0.0140000000 | -| 2019-08-18T00:24:00Z | -0.0650000000 | -| 2019-08-18T00:30:00Z | 0.0030000000 | - -The first result (`0.0270000000`) is the six-minute rate of change between the first two subsequent field values in the raw data. InfluxDB calculates the difference between the field values (subtracts the first field value from the second field value) and then normalizes that value to the six-minute rate of change (dividing the difference between the field values' timestamps in minutes (`6m`) by the specified interval (`6m`)): - -``` -(2.379 - 2.352) / (6m / 6m) -``` - -{{% /expand %}} - -{{% expand "Calculate the derivative between the field values associated with each field key in a measurement and specify the unit option" %}} - -Returns three-minute rate of change between the field values associated with each field key that stores numeric values in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT DERIVATIVE(*,3m) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | derivative_water_level | -| :------------------- | ---------------------: | -| 2019-08-18T00:06:00Z | 0.0135000000 | -| 2019-08-18T00:12:00Z | -0.0180000000 | -| 2019-08-18T00:18:00Z | -0.0070000000 | -| 2019-08-18T00:24:00Z | -0.0325000000 | -| 2019-08-18T00:30:00Z | 0.0015000000 | - -The first result (`0.0135000000`) is the three-minute rate of change between the first two subsequent field values in the raw data. - -InfluxDB calculates the difference between the field values (subtracts the first field value from the second field value) and then normalizes that value to the three-minute rate of change (dividing the difference between the field values' timestamps in minutes (`6m`) by the specified interval (`3m`)): - -``` -(2.379 - 2.352) / (6m / 3m) -``` - -{{% /expand %}} - -{{% expand "Calculate the derivative between the field values associated with each field key that matches a regular expression and specify the unit option" %}} - -Return the two-minute rate of change between the field values associated with -each field key that stores numeric values and includes the word `water` in the -`h2o_feet` measurement. - -```sql -SELECT DERIVATIVE(/water/,2m) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | derivative_water_level | -| :------------------- | ---------------------: | -| 2019-08-18T00:06:00Z | 0.0090000000 | -| 2019-08-18T00:12:00Z | -0.0120000000 | -| 2019-08-18T00:18:00Z | -0.0046666667 | -| 2019-08-18T00:24:00Z | -0.0216666667 | -| 2019-08-18T00:30:00Z | 0.0010000000 | - -The first result (`0.0090000000`) is the two-minute rate of change between the first two subsequent field values in the raw data. - -InfluxDB calculates the difference between the field values (subtracts the first field value from the second field value) and then normalizes that value to the three-minute rate of change (dividing the difference between the field values' timestamps in minutes (`6m`) by the specified interval (`2m`)): - -``` -(2.379 - 2.352) / (6m / 2m) -``` - -{{% /expand %}} - -{{% expand "Calculate the derivative between the field values associated with a field key and include several clauses" %}} - -Return the one-second rate of change between `water_level` field values in the -`h2o_feet` measurement in [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) the number of points returned to one and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) results by two points. - -```sql -SELECT DERIVATIVE("water_level") FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' ORDER BY time DESC LIMIT 1 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | derivative | -| -------------------- | ------------ | -| 2019-08-18T00:12:00Z | 0.0000388889 | - -The only result (`0.0000388889`) is the one-second rate of change between the relevant subsequent field values in the raw data. InfluxDB calculates the difference between the field values (subtracts the first field value from the second field value) and then normalizes that value to the one-second rate of change (dividing the difference between the field values' timestamps in seconds (`360`) by the specified rate of change (`1s`)): - -``` -(2.379 - 2.352) / (360s / 1s) -``` - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT DERIVATIVE( ([ * | | // ]) [ , ] ) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time()` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `DERIVATIVE()` function to those results. - -The `unit` argument is an integer followed by a [duration](//influxdb/v2/reference/glossary/#duration) and it is optional. -If the query does not specify the `unit` the `unit` defaults to the `GROUP BY time()` interval. -Note that this behavior is different from the [basic syntax's](#basic-syntax-1) default behavior. - -`DERIVATIVE()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples -{{< expand-wrapper >}} - -{{% expand "Calculate the derivative of mean values" %}} - -Return the 12-minute rate of change between [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `water_level`s that are calculated at 12-minute intervals. - -```sql -SELECT DERIVATIVE(MEAN("water_level")) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | derivative | -| :------------------- | ------------: | -| 2019-08-18T00:00:00Z | -0.1375000000 | -| 2019-08-18T00:12:00Z | -0.0295000000 | -| 2019-08-18T00:24:00Z | -0.0705000000 | - -{{% /expand %}} - -{{% expand "Calculate the derivative of mean values and specify the unit option" %}} - -Return the six-minute rate of change between average `water_level`s that are calculated at 12-minute intervals. - -```sql -SELECT DERIVATIVE(MEAN("water_level"),6m) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | derivative | -| :------------------- | ------------: | -| 2019-08-18T00:00:00Z | -0.0687500000 | -| 2019-08-18T00:12:00Z | -0.0147500000 | -| 2019-08-18T00:24:00Z | -0.0352500000 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## DIFFERENCE() - -Returns the result of subtraction between subsequent [field values](/influxdb/v2/reference/glossary/#field-value). - -### Syntax - -```sql -SELECT DIFFERENCE( [ * | | // ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`DIFFERENCE(field_key)` -Returns the difference between subsequent field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`DIFFERENCE(/regular_expression/)` -Returns the difference between subsequent field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/). - -`DIFFERENCE(*)` -Returns the difference between subsequent field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`DIFFERENCE()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `DIFFERENCE()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples below use the following subsample of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:30:00Z | 2.2670000000 | - -{{< expand-wrapper >}} - -{{% expand "Calculate the difference between the field values associated with a field key" %}} - -Return the difference between the subsequent field values in the `water_level` field key and in the `h2o_feet` measurement. - -```sql -SELECT DIFFERENCE("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | difference | -| :------------------- | ------------: | -| 2019-08-18T00:06:00Z | 0.0270000000 | -| 2019-08-18T00:12:00Z | -0.0360000000 | -| 2019-08-18T00:18:00Z | -0.0140000000 | -| 2019-08-18T00:24:00Z | -0.0650000000 | -| 2019-08-18T00:30:00Z | 0.0030000000 | - -{{% /expand %}} - -{{% expand "Calculate the difference between the field values associated with each field key in a measurement" %}} - -Return the difference between the subsequent field values for each field key -that stores numeric values in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT DIFFERENCE(*) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | difference_water_level | -| :------------------- | ---------------------: | -| 2019-08-18T00:06:00Z | 0.0270000000 | -| 2019-08-18T00:12:00Z | -0.0360000000 | -| 2019-08-18T00:18:00Z | -0.0140000000 | -| 2019-08-18T00:24:00Z | -0.0650000000 | -| 2019-08-18T00:30:00Z | 0.0030000000 | - -{{% /expand %}} - -{{% expand "Calculate the difference between the field values associated with each field key that matches a regular expression" %}} - -Return the difference between the subsequent field values for each field key -that stores numeric values and includes the word `water` in the `h2o_feet` measurement. - -```sql -SELECT DIFFERENCE(/water/) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | difference_water_level | -| :------------------- | ---------------------: | -| 2019-08-18T00:06:00Z | 0.0270000000 | -| 2019-08-18T00:12:00Z | -0.0360000000 | -| 2019-08-18T00:18:00Z | -0.0140000000 | -| 2019-08-18T00:24:00Z | -0.0650000000 | -| 2019-08-18T00:30:00Z | 0.0030000000 | - -{{% /expand %}} - -{{% expand "Calculate the difference between the field values associated with a field key and include several clauses" %}} - -```sql -SELECT DIFFERENCE("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' ORDER BY time DESC LIMIT 2 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | difference | -| :------------------- | -----------: | -| 2019-08-18T00:12:00Z | 0.0140000000 | -| 2019-08-18T00:06:00Z | 0.0360000000 | - -Return the difference between the subsequent field values in the `water_level` -field key in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -They query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to two and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT DIFFERENCE(( [ * | | // ] )) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `DIFFERENCE()` function to those results. - -`DIFFERENCE()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the difference between maximum values" %}} - -Return the difference between [maximum](/influxdb/v2/query-data/influxql/functions/selectors/#max) `water_level`s that are calculated at 12-minute intervals. - -```sql -SELECT DIFFERENCE(MAX("water_level")) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | difference | -| :------------------- | ------------: | -| 2019-08-18T00:00:00Z | -0.2290000000 | -| 2019-08-18T00:12:00Z | -0.0360000000 | -| 2019-08-18T00:24:00Z | -0.0760000000 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## ELAPSED() - -Returns the difference between subsequent [field value's](/influxdb/v2/reference/glossary/#field-value) timestamps. - -### Syntax - -```sql -SELECT ELAPSED( [ * | | // ] [ , ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -InfluxDB calculates the difference between subsequent timestamps. -The `unit` option is an integer followed by a [duration](/influxdb/v2/reference/glossary/#duration) and it determines the unit of the returned difference. -If the query does not specify the `unit` option the query returns the difference between timestamps in nanoseconds. - -`ELAPSED(field_key)` -Returns the difference between subsequent timestamps associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`ELAPSED(/regular_expression/)` -Returns the difference between subsequent timestamps associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/). - -`ELAPSED(*)` -Returns the difference between subsequent timestamps associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`ELAPSED()` supports all field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -#### Examples - -The examples use the following subsample of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:12:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | - -{{< expand-wrapper >}} - -{{% expand "Calculate the elapsed time between field values associated with a field key" %}} - -Return the elapsed time (in nanoseconds) between subsequent timestamps in the `water_level` field key and in the `h2o_feet` measurement. - -```sql -SELECT ELAPSED("water_level") FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:12:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | elapsed | -| :------------------- | ----------------------: | -| 2019-08-18T00:06:00Z | 360000000000.0000000000 | -| 2019-08-18T00:12:00Z | 360000000000.0000000000 | - -{{% /expand %}} - -{{% expand "Calculate the elapsed time between field values associated with a field key and specify the unit option" %}} - -Return the elapsed time (in minutes) between subsequent timestamps in the `water_level` field key and in the `h2o_feet` measurement. - -```sql -SELECT ELAPSED("water_level",1m) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:12:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | elapsed | -| :------------------- | -----------: | -| 2019-08-18T00:06:00Z | 6.0000000000 | -| 2019-08-18T00:12:00Z | 6.0000000000 | - -{{% /expand %}} - -{{% expand "Calculate the elapsed time between field values associated with each field key in a measurement and specify the unit option" %}} - -Return the difference (in minutes) between subsequent timestamps associated with -each field key in the `h2o_feet`measurement. -The `h2o_feet` measurement has two field keys: `level description` and `water_level`. - -```sql -SELECT ELAPSED(*,1m) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:12:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | elapsed_level description | elapsed_water_level | -| :------------------- | ------------------------: | ------------------: | -| 2019-08-18T00:06:00Z | 6.0000000000 | 6.0000000000 | -| 2019-08-18T00:12:00Z | 6.0000000000 | 6.0000000000 | - -{{% /expand %}} - -{{% expand "Calculate the elapsed time between field values associated with each field key that matches a regular expression and specify the unit option" %}} - -Return the difference (in seconds) between subsequent timestamps associated with -each field key that includes the word `level` in the `h2o_feet` measurement. - -```sql -SELECT ELAPSED(/level/,1s) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:12:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | elapsed_level description | elapsed_water_level | -| :------------------- | ------------------------: | ------------------: | -| 2019-08-18T00:06:00Z | 360.0000000000 | 360.0000000000 | -| 2019-08-18T00:12:00Z | 360.0000000000 | 360.0000000000 | - -{{% /expand %}} - -{{% expand "Calculate the elapsed time between field values associated with a field key and include several clauses" %}} - -Return the difference (in milliseconds) between subsequent timestamps in the -`water_level` field key and in the `h2o_feet` measurement in the -[time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-17T00:00:00Z` and `2019-08-17T00:12:00Z` with timestamps in -[descending order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to one and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by one point. - -```sql -SELECT ELAPSED("water_level",1ms) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:12:00Z' ORDER BY time DESC LIMIT 1 OFFSET 1 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | elapsed | -| :------------------- | -----------------: | -| 2019-08-18T00:00:00Z | -360000.0000000000 | - -Notice that the result is negative; the [`ORDER BY time DESC` clause](/influxdb/v2/query-data/influxql/explore-data/order-by/) sorts timestamps in descending order so `ELAPSED()` calculates the difference between timestamps in reverse order. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Common issues with ELAPSED() - -#### ELAPSED() and units greater than the elapsed time - -InfluxDB returns `0` if the `unit` option is greater than the difference between the timestamps. - -##### Example - -The timestamps in the `h2o_feet` measurement occur at six-minute intervals. -If the query sets the `unit` option to one hour, InfluxDB returns `0`: - -```sql -SELECT ELAPSED("water_level",1h) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:12:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | elapsed | -| :------------------- | -----------: | -| 2019-08-18T00:06:00Z | 0.0000000000 | -| 2019-08-18T00:12:00Z | 0.0000000000 | - -#### ELAPSED() with GROUP BY time() clauses - -The `ELAPSED()` function supports the [`GROUP BY time()` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) but the query results aren't particularly useful. -Currently, an `ELAPSED()` query with a nested function and a `GROUP BY time()` clause simply returns the interval specified in the `GROUP BY time()` clause. - -The `GROUP BY time()` clause determines the timestamps in the results; each timestamp marks the start of a time interval. -That behavior also applies to nested selector functions (like [`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first) or [`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max)) which would, in all other cases, return a specific timestamp from the raw data. -Because the `GROUP BY time()` clause overrides the original timestamps, the `ELAPSED()` calculation always returns the same value as the `GROUP BY time()` interval. - -##### Example - -In the codeblock below, the first query attempts to use the `ELAPSED()` function with a `GROUP BY time()` clause to find the time elapsed (in minutes) between [minimum](/influxdb/v2/query-data/influxql/functions/selectors/#min) `water_level`s. -Returns 12 minutes for both time intervals. - -To get those results, InfluxDB first calculates the minimum `water_level`s at 12-minute intervals. -The second query in the codeblock shows the results of that step. -The step is the same as using the `MIN()` function with the `GROUP BY time()` clause and without the `ELAPSED()` function. -Notice that the timestamps returned by the second query are 12 minutes apart. -In the raw data, the first result (`2.0930000000`) occurs at `2019-08-18T00:42:00Z` but the `GROUP BY time()` clause overrides that original timestamp. -Because the timestamps are determined by the `GROUP BY time()` interval and not by the original data, the `ELAPSED()` calculation always returns the same value as the `GROUP BY time()` interval. - -```sql -SELECT ELAPSED(MIN("water_level"),1m) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:36:00Z' AND time <= '2019-08-18T00:54:00Z' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | elapsed | -| :------------------- | ------------: | -| 2019-08-18T00:36:00Z | 12.0000000000 | -| 2019-08-18T00:48:00Z | 12.0000000000 | - -```sql -SELECT MIN("water_level") FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:36:00Z' AND time <= '2019-08-18T00:54:00Z' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | min | -| -------------------- | ------------ | -| 2019-08-18T00:36:00Z | 2.0930000000 | -| 2019-08-18T00:48:00Z | 2.0870000000 | - -{{% note %}} -The first point actually occurs at 2019-08-18T00:42:00Z, not 2019-08-18T00:36:00Z. -{{% /note %}} - -## EXP() - -Returns the exponential of the field value. - -### Syntax - -```sql -SELECT EXP( [ * | ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`EXP(field_key)` -Returns the exponential of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - - - -`EXP(*)` -Returns the exponential of field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`EXP()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `EXP()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples below use the following subsample of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:30:00Z | 2.2670000000 | - -{{< expand-wrapper >}} - -{{% expand "Calculate the exponential of field values associated with a field key" %}} - -Return the exponential of field values in the `water_level` field key in the `h2o_feet` measurement. - -```sql -SELECT EXP("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | exp | -| :------------------- | ------------: | -| 2019-08-18T00:00:00Z | 10.5065618493 | -| 2019-08-18T00:06:00Z | 10.7941033617 | -| 2019-08-18T00:12:00Z | 10.4124270347 | -| 2019-08-18T00:18:00Z | 10.2676687288 | -| 2019-08-18T00:24:00Z | 9.6214982905 | -| 2019-08-18T00:30:00Z | 9.6504061254 | - -{{% /expand %}} - -{{% expand "Calculate the exponential of field values associated with each field key in a measurement" %}} - -Return the exponential of field values for each field key that stores numeric -values in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT EXP(*) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | exp_water_level | -| :------------------- | --------------: | -| 2019-08-18T00:00:00Z | 10.5065618493 | -| 2019-08-18T00:06:00Z | 10.7941033617 | -| 2019-08-18T00:12:00Z | 10.4124270347 | -| 2019-08-18T00:18:00Z | 10.2676687288 | -| 2019-08-18T00:24:00Z | 9.6214982905 | -| 2019-08-18T00:30:00Z | 9.6504061254 | - -{{% /expand %}} - -{{% expand "Calculate the exponential of field values associated with a field key and include several clauses" %}} - -```sql -SELECT EXP("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | exp | -| :------------------- | ------------: | -| 2019-08-18T00:18:00Z | 10.2676687288 | -| 2019-08-18T00:12:00Z | 10.4124270347 | -| 2019-08-18T00:06:00Z | 10.7941033617 | -| 2019-08-18T00:00:00Z | 10.5065618493 | - -Return the exponentials of field values associated with the `water_level` field key in -the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT EXP(( [ * | ] )) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `EXP()` function to those results. - -`EXP()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the exponential of mean values" %}} - -Return the exponential of [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `water_level`s that are calculated at 12-minute intervals. - -```sql -SELECT EXP(MEAN("water_level")) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | exp | -| :------------------- | ------------: | -| 2019-08-18T00:00:00Z | 10.6493621676 | -| 2019-08-18T00:12:00Z | 10.3397945558 | -| 2019-08-18T00:24:00Z | 9.6359413675 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## FLOOR() - -Returns the subsequent value rounded down to the nearest integer. - -### Syntax - -```sql -SELECT FLOOR( [ * | ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`FLOOR(field_key)` -Returns the field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) rounded down to the nearest integer. - -`FLOOR(*)` -Returns the field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement) rounded down to the nearest integer. - -`FLOOR()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `FLOOR()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples below use the following subsample of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:30:00Z | 2.2670000000 | - -{{< expand-wrapper >}} - -{{% expand "Calculate the floor of field values associated with a field key" %}} - -Return field values in the `water_level` field key in the `h2o_feet` measurement rounded down to the nearest integer. - -```sql -SELECT FLOOR("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | floor | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.0000000000 | -| 2019-08-18T00:06:00Z | 2.0000000000 | -| 2019-08-18T00:12:00Z | 2.0000000000 | -| 2019-08-18T00:18:00Z | 2.0000000000 | -| 2019-08-18T00:24:00Z | 2.0000000000 | -| 2019-08-18T00:30:00Z | 2.0000000000 | - -{{% /expand %}} - -{{% expand "Calculate the floor of field values associated with each field key in a measurement" %}} - -Return field values for each field key that stores numeric values in the -`h2o_feet` measurement rounded down to the nearest integer. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT FLOOR(*) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | floor_water_level | -| :------------------- | ----------------: | -| 2019-08-18T00:00:00Z | 2.0000000000 | -| 2019-08-18T00:06:00Z | 2.0000000000 | -| 2019-08-18T00:12:00Z | 2.0000000000 | -| 2019-08-18T00:18:00Z | 2.0000000000 | -| 2019-08-18T00:24:00Z | 2.0000000000 | -| 2019-08-18T00:30:00Z | 2.0000000000 | - -{{% /expand %}} - -{{% expand "Calculate the floor of field values associated with a field key and include several clauses" %}} - -Return field values associated with the `water_level` field key rounded down to -the nearest integer in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -```sql -SELECT FLOOR("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | floor | -| :------------------- | -----------: | -| 2019-08-18T00:18:00Z | 2.0000000000 | -| 2019-08-18T00:12:00Z | 2.0000000000 | -| 2019-08-18T00:06:00Z | 2.0000000000 | -| 2019-08-18T00:00:00Z | 2.0000000000 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT FLOOR(( [ * | ] )) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `FLOOR()` function to those results. - -`FLOOR()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate mean values rounded down to the nearest integer" %}} - -Return the [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `water_level`s that are calculated at 12-minute intervals and rounds them up to the nearest integer. - -```sql -SELECT FLOOR(MEAN("water_level")) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | floor | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.0000000000 | -| 2019-08-18T00:12:00Z | 2.0000000000 | -| 2019-08-18T00:24:00Z | 2.0000000000 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## HISTOGRAM() - -_InfluxQL does not currently support histogram generation. -For information about creating histograms with data stored in InfluxDB, see -[Flux's `histogram()` function](/flux/v0/stdlib/universe/histogram)._ - -## LN() - -Returns the natural logarithm of the field value. - -### Syntax - -```sql -SELECT LN( [ * | ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`LN(field_key)` -Returns the natural logarithm of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`LN(*)` -Returns the natural logarithm of field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`LN()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `LN()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples below use the following subsample of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:30:00Z | 2.2670000000 | - -{{< expand-wrapper >}} - -{{% expand "Calculate the natural logarithm of field values associated with a field key" %}} - -Return the natural logarithm of field values in the `water_level` field key in the `h2o_feet` measurement. - -```sql -SELECT LN("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | ln | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 0.8552660300 | -| 2019-08-18T00:06:00Z | 0.8666802313 | -| 2019-08-18T00:12:00Z | 0.8514321595 | -| 2019-08-18T00:18:00Z | 0.8454389909 | -| 2019-08-18T00:24:00Z | 0.8171331603 | -| 2019-08-18T00:30:00Z | 0.8184573715 | - -{{% /expand %}} - -{{% expand "Calculate the natural logarithm of field values associated with each field key in a measurement" %}} - -Return the natural logarithm of field values for each field key that stores -numeric values in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT LN(*) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | ln_water_level | -| :------------------- | -------------: | -| 2019-08-18T00:00:00Z | 0.8552660300 | -| 2019-08-18T00:06:00Z | 0.8666802313 | -| 2019-08-18T00:12:00Z | 0.8514321595 | -| 2019-08-18T00:18:00Z | 0.8454389909 | -| 2019-08-18T00:24:00Z | 0.8171331603 | -| 2019-08-18T00:30:00Z | 0.8184573715 | - -{{% /expand %}} - -{{% expand "Calculate the natural logarithm of field values associated with a field key and include several clauses" %}} - -```sql -SELECT LN("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | ln | -| :------------------- | -----------: | -| 2019-08-18T00:18:00Z | 0.8454389909 | -| 2019-08-18T00:12:00Z | 0.8514321595 | -| 2019-08-18T00:06:00Z | 0.8666802313 | -| 2019-08-18T00:00:00Z | 0.8552660300 | - -Return the natural logarithms of field values associated with the `water_level` -field key in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT LN(( [ * | ] )) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `LN()` function to those results. - -`LN()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the natural logarithm of mean values" %}} - -Return the natural logarithm of [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `water_level`s that are calculated at 12-minute intervals. - -```sql -SELECT LN(MEAN("water_level")) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | ln | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 0.8609894161 | -| 2019-08-18T00:12:00Z | 0.8484400650 | -| 2019-08-18T00:24:00Z | 0.8177954851 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## LOG() - -Returns the logarithm of the field value with base `b`. - -### Basic syntax - -```sql -SELECT LOG( [ * | ], ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`LOG(field_key, b)` -Returns the logarithm of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) with base `b`. - -`LOG(*, b)` -Returns the logarithm of field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement) with base `b`. - -`LOG()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `LOG()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples below use the following subsample of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:30:00Z | 2.2670000000 | - -{{< expand-wrapper >}} - -{{% expand "Calculate the logarithm base 4 of field values associated with a field key" %}} - -Return the logarithm base 4 of field values in the `water_level` field key in the `h2o_feet` measurement. - -```sql -SELECT LOG("water_level", 4) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | log | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 0.6169440301 | -| 2019-08-18T00:06:00Z | 0.6251776359 | -| 2019-08-18T00:12:00Z | 0.6141784771 | -| 2019-08-18T00:18:00Z | 0.6098553198 | -| 2019-08-18T00:24:00Z | 0.5894369791 | -| 2019-08-18T00:30:00Z | 0.5903921955 | - -{{% /expand %}} - -{{% expand "Calculate the logarithm base 4 of field values associated with each field key in a measurement" %}} - -Return the logarithm base 4 of field values for each numeric field in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT LOG(*, 4) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | log_water_level | -| :------------------- | --------------: | -| 2019-08-18T00:00:00Z | 0.6169440301 | -| 2019-08-18T00:06:00Z | 0.6251776359 | -| 2019-08-18T00:12:00Z | 0.6141784771 | -| 2019-08-18T00:18:00Z | 0.6098553198 | -| 2019-08-18T00:24:00Z | 0.5894369791 | -| 2019-08-18T00:30:00Z | 0.5903921955 | - -{{% /expand %}} - -{{% expand "Calculate the logarithm base 4 of field values associated with a field key and include several clauses" %}} - -Return the logarithm base 4 of field values associated with the `water_level` -field key in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -```sql -SELECT LOG("water_level", 4) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | log | -| :------------------- | -----------: | -| 2019-08-18T00:18:00Z | 0.6098553198 | -| 2019-08-18T00:12:00Z | 0.6141784771 | -| 2019-08-18T00:06:00Z | 0.6251776359 | -| 2019-08-18T00:00:00Z | 0.6169440301 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT LOG(( [ * | ] ), ) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `LOG()` function to those results. - -`LOG()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the logarithm base 4 of mean values" %}} - -Return the logarithm base 4 of [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `water_level`s that are calculated at 12-minute intervals. - -```sql -SELECT LOG(MEAN("water_level"), 4) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | log | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 0.6210725804 | -| 2019-08-18T00:12:00Z | 0.6120201371 | -| 2019-08-18T00:24:00Z | 0.5899147454 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## LOG2() - -Returns the logarithm of the field value to the base 2. - -### Basic syntax - -```sql -SELECT LOG2( [ * | ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`LOG2(field_key)` -Returns the logarithm of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) to the base 2. - -`LOG2(*)` -Returns the logarithm of field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement) to the base 2. - -`LOG2()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `LOG2()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples below use the following subsample of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:30:00Z | 2.2670000000 | - -{{< expand-wrapper >}} - -{{% expand "Calculate the logarithm base 2 of field values associated with a field key" %}} - -Return the logarithm base 2 of field values in the `water_level` field key in the `h2o_feet` measurement. - -```sql -SELECT LOG2("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | log2 | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 1.2338880602 | -| 2019-08-18T00:06:00Z | 1.2503552718 | -| 2019-08-18T00:12:00Z | 1.2283569542 | -| 2019-08-18T00:18:00Z | 1.2197106395 | -| 2019-08-18T00:24:00Z | 1.1788739582 | -| 2019-08-18T00:30:00Z | 1.1807843911 | - -{{% /expand %}} - -{{% expand "Calculate the logarithm base 2 of field values associated with each field key in a measurement" %}} - -```sql -SELECT LOG2(*) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | log2_water_level | -| :------------------- | ---------------: | -| 2019-08-18T00:00:00Z | 1.2338880602 | -| 2019-08-18T00:06:00Z | 1.2503552718 | -| 2019-08-18T00:12:00Z | 1.2283569542 | -| 2019-08-18T00:18:00Z | 1.2197106395 | -| 2019-08-18T00:24:00Z | 1.1788739582 | -| 2019-08-18T00:30:00Z | 1.1807843911 | - -Return the logarithm base 2 of field values for each numeric field in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -{{% /expand %}} - -{{% expand "Calculate the logarithm base 2 of field values associated with a field key and include several clauses" %}} - -Return the logarithm base 2 of field values associated with the `water_level` -field key in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -```sql -SELECT LOG2("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | log2 | -| :------------------- | -----------: | -| 2019-08-18T00:18:00Z | 1.2197106395 | -| 2019-08-18T00:12:00Z | 1.2283569542 | -| 2019-08-18T00:06:00Z | 1.2503552718 | -| 2019-08-18T00:00:00Z | 1.2338880602 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT LOG2(( [ * | ] )) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `LOG2()` function to those results. - -`LOG2()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the logarithm base 2 of mean values" %}} - -Return the logarithm base 2 of [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `water_level`s that are calculated at 12-minute intervals. - -```sql -SELECT LOG2(MEAN("water_level")) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | log2 | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 1.2421451608 | -| 2019-08-18T00:12:00Z | 1.2240402742 | -| 2019-08-18T00:24:00Z | 1.1798294909 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## LOG10() - -Returns the logarithm of the field value to the base 10. - -### Basic syntax - -```sql -SELECT LOG10( [ * | ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`LOG10(field_key)` -Returns the logarithm of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) to the base 10. - -`LOG10(*)` -Returns the logarithm of field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement) to the base 10. - -`LOG10()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `LOG10()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples below use the following subsample of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:30:00Z | 2.2670000000 | - -{{< expand-wrapper >}} - -{{% expand "Calculate the logarithm base 10 of field values associated with a field key" %}} - -Return the logarithm base 10 of field values in the `water_level` field key in the `h2o_feet` measurement. - -```sql -SELECT LOG10("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | log10 | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 0.3714373174 | -| 2019-08-18T00:06:00Z | 0.3763944420 | -| 2019-08-18T00:12:00Z | 0.3697722886 | -| 2019-08-18T00:18:00Z | 0.3671694885 | -| 2019-08-18T00:24:00Z | 0.3548764225 | -| 2019-08-18T00:30:00Z | 0.3554515201 | - -{{% /expand %}} - -{{% expand "Calculate the logarithm base 10 of field values associated with each field key in a measurement" %}} - -Return the logarithm base 10 of field values for each numeric field in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT LOG10(*) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | log10_water_level | -| :------------------- | ----------------: | -| 2019-08-18T00:00:00Z | 0.3714373174 | -| 2019-08-18T00:06:00Z | 0.3763944420 | -| 2019-08-18T00:12:00Z | 0.3697722886 | -| 2019-08-18T00:18:00Z | 0.3671694885 | -| 2019-08-18T00:24:00Z | 0.3548764225 | -| 2019-08-18T00:30:00Z | 0.3554515201 | - -{{% /expand %}} - -{{% expand "Calculate the logarithm base 10 of field values associated with a field key and include several clauses" %}} - -Return the logarithm base 10 of field values associated with the `water_level` -field key in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -```sql -SELECT LOG10("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | log10 | -| :------------------- | -----------: | -| 2019-08-18T00:18:00Z | 0.3671694885 | -| 2019-08-18T00:12:00Z | 0.3697722886 | -| 2019-08-18T00:06:00Z | 0.3763944420 | -| 2019-08-18T00:00:00Z | 0.3714373174 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT LOG10(( [ * | ] )) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `LOG10()` function to those results. - -`LOG10()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the logarithm base 10 of mean values" %}} - -Return the logarithm base 10 of [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `water_level`s that are calculated at 12-minute intervals. - -```sql -SELECT LOG10(MEAN("water_level")) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | log10 | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 0.3739229524 | -| 2019-08-18T00:12:00Z | 0.3684728384 | -| 2019-08-18T00:24:00Z | 0.3551640665 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## MOVING_AVERAGE() - -Returns the rolling average across a window of subsequent [field values](/influxdb/v2/reference/glossary/#field-value). - -### Basic syntax - -```sql -SELECT MOVING_AVERAGE( [ * | | // ] , ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`MOVING_AVERAGE()` calculates the rolling average across a window of `N` subsequent field values. -The `N` argument is an integer and it is required. - -`MOVING_AVERAGE(field_key,N)` -Returns the rolling average across `N` field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`MOVING_AVERAGE(/regular_expression/,N)` -Returns the rolling average across `N` field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/). - -`MOVING_AVERAGE(*,N)` -Returns the rolling average across `N` field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`MOVING_AVERAGE()` int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `MOVING_AVERAGE()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples below use the following subsample of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:30:00Z | 2.2670000000 | - -{{< expand-wrapper >}} - -{{% expand "Calculate the moving average of the field values associated with a field key" %}} - -Return the rolling average across a two-field-value window for the `water_level` field key and the `h2o_feet` measurement. - -```sql -SELECT MOVING_AVERAGE("water_level",2) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | moving_average | -| :------------------- | -------------: | -| 2019-08-18T00:06:00Z | 2.3655000000 | -| 2019-08-18T00:12:00Z | 2.3610000000 | -| 2019-08-18T00:18:00Z | 2.3360000000 | -| 2019-08-18T00:24:00Z | 2.2965000000 | -| 2019-08-18T00:30:00Z | 2.2655000000 | - -The first result (`2.3655000000`) is the average of the first two points in the raw data: (`2.3520000000 + 2.3790000000) / 2`). -The second result (`2.3610000000`) is the average of the second two points in the raw data: (`2.3790000000 + 2.3430000000) / 2`). - -{{% /expand %}} - -{{% expand "Calculate the moving average of the field values associated with each field key in a measurement" %}} - -Return the rolling average across a three-field-value window for each field key -that stores numeric values in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT MOVING_AVERAGE(*,3) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | moving_average_water_level | -| :------------------- | -------------------------: | -| 2019-08-18T00:12:00Z | 2.3580000000 | -| 2019-08-18T00:18:00Z | 2.3503333333 | -| 2019-08-18T00:24:00Z | 2.3120000000 | -| 2019-08-18T00:30:00Z | 2.2866666667 | - -{{% /expand %}} - -{{% expand "Calculate the moving average of the field values associated with each field key that matches a regular expression" %}} - -Return the rolling average across a four-field-value window for each numeric -field with a field key that includes the word `level` in the `h2o_feet` measurement. - -```sql -SELECT MOVING_AVERAGE(/level/,4) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | moving_average_water_level | -| :------------------- | -------------------------: | -| 2019-08-18T00:18:00Z | 2.3507500000 | -| 2019-08-18T00:24:00Z | 2.3287500000 | -| 2019-08-18T00:30:00Z | 2.3007500000 | - -{{% /expand %}} - -{{% expand "Calculate the moving average of the field values associated with a field key and include several clauses" %}} - -Return the rolling average across a two-field-value window for the `water_level` -field key in the `h2o_feet` measurement in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to two and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by three points. - -```sql -SELECT MOVING_AVERAGE("water_level",2) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' ORDER BY time DESC LIMIT 2 OFFSET 3 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | moving_average | -| :------------------- | -------------: | -| 2019-08-18T00:06:00Z | 2.3610000000 | -| 2019-08-18T00:00:00Z | 2.3655000000 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT MOVING_AVERAGE( ([ * | | // ]) , N ) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `MOVING_AVERAGE()` function to those results. - -`MOVING_AVERAGE()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the moving average of maximum values" %}} - -Return the rolling average across a two-value window of [maximum](/influxdb/v2/query-data/influxql/functions/selectors/#max) `water_level`s that are calculated at 12-minute intervals. - -```sql -SELECT MOVING_AVERAGE(MAX("water_level"),2) FROM "h2o_feet" WHERE "location" = 'santa_monica' AND time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | moving_average | -| :------------------- | -------------: | -| 2019-08-18T00:00:00Z | 2.4935000000 | -| 2019-08-18T00:12:00Z | 2.3610000000 | -| 2019-08-18T00:24:00Z | 2.3050000000 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## NON_NEGATIVE_DERIVATIVE() - -Returns the non-negative rate of change between subsequent [field values](/influxdb/v2/reference/glossary/#field-value). -Non-negative rates of change include positive rates of change and rates of change that equal zero. - -### Basic syntax - -```sql -SELECT NON_NEGATIVE_DERIVATIVE( [ * | | // ] [ , ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -InfluxDB calculates the difference between subsequent field values and converts those results into the rate of change per `unit`. -The `unit` argument is an integer followed by a [duration](/influxdb/v2/reference/glossary/#duration) and it is optional. -If the query does not specify the `unit`, the unit defaults to one second (`1s`). -`NON_NEGATIVE_DERIVATIVE()` returns only positive rates of change or rates of change that equal zero. - -`NON_NEGATIVE_DERIVATIVE(field_key)` -Returns the non-negative rate of change between subsequent field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`NON_NEGATIVE_DERIVATIVE(/regular_expression/)` -Returns the non-negative rate of change between subsequent field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/). - -`NON_NEGATIVE_DERIVATIVE(*)` -Returns the non-negative rate of change between subsequent field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`NON_NEGATIVE_DERIVATIVE()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `NON_NEGATIVE_DERIVATIVE()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -See the examples in the [`DERIVATIVE()` documentation](#basic-syntax-8). -`NON_NEGATIVE_DERIVATIVE()` behaves the same as the `DERIVATIVE()` function but `NON_NEGATIVE_DERIVATIVE()` returns only positive rates of change or rates of change that equal zero. - -### Advanced syntax - -```sql -SELECT NON_NEGATIVE_DERIVATIVE( ([ * | | // ]) [ , ] ) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `NON_NEGATIVE_DERIVATIVE()` function to those results. - -The `unit` argument is an integer followed by a [duration](/influxdb/v2/reference/glossary/#duration) and it is optional. -If the query does not specify the `unit`, the `unit` defaults to the `GROUP BY time()` interval. -Note that this behavior is different from the [basic syntax's](#basic-syntax-4) default behavior. -`NON_NEGATIVE_DERIVATIVE()` returns only positive rates of change or rates of change that equal zero. - -`NON_NEGATIVE_DERIVATIVE()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -See the examples in the [`DERIVATIVE()` documentation](#advanced-syntax-8). -`NON_NEGATIVE_DERIVATIVE()` behaves the same as the `DERIVATIVE()` function but `NON_NEGATIVE_DERIVATIVE()` returns only positive rates of change or rates of change that equal zero. - -## NON_NEGATIVE_DIFFERENCE() - -Returns the non-negative result of subtraction between subsequent [field values](/influxdb/v2/reference/glossary/#field-value). -Non-negative results of subtraction include positive differences and differences that equal zero. - -### Basic syntax - -```sql -SELECT NON_NEGATIVE_DIFFERENCE( [ * | | // ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`NON_NEGATIVE_DIFFERENCE(field_key)` -Returns the non-negative difference between subsequent field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`NON_NEGATIVE_DIFFERENCE(/regular_expression/)` -Returns the non-negative difference between subsequent field values associated with each field key that matches the [regular expression](/influxdb/v2/query-data/influxql/explore-data/regular-expressions/). - -`NON_NEGATIVE_DIFFERENCE(*)` -Returns the non-negative difference between subsequent field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`NON_NEGATIVE_DIFFERENCE()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `NON_NEGATIVE_DIFFERENCE()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -See the examples in the [`DIFFERENCE()` documentation](#basic-syntax-9). -`NON_NEGATIVE_DIFFERENCE()` behaves the same as the `DIFFERENCE()` function but `NON_NEGATIVE_DIFFERENCE()` returns only positive differences or differences that equal zero. - -### Advanced syntax - -```sql -SELECT NON_NEGATIVE_DIFFERENCE(( [ * | | // ] )) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `NON_NEGATIVE_DIFFERENCE()` function to those results. - -`NON_NEGATIVE_DIFFERENCE()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -See the examples in the [`DIFFERENCE()` documentation](#advanced-syntax-9). -`NON_NEGATIVE_DIFFERENCE()` behaves the same as the `DIFFERENCE()` function but `NON_NEGATIVE_DIFFERENCE()` returns only positive differences or differences that equal zero. - -## POW() - -Returns the field value to the power of `x`. - -### Basic syntax - -```sql -SELECT POW( [ * | ], ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`POW(field_key, x)` -Returns the field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) to the power of `x`. - -`POW(*, x)` -Returns the field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement) to the power of `x`. - -`POW()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `POW()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples below use the following subsample of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:30:00Z | 2.2670000000 | - -{{< expand-wrapper >}} - -{{% expand "Calculate field values associated with a field key to the power of 4" %}} - -Return field values in the `water_level` field key in the `h2o_feet` measurement -multiplied to a power of 4. - -```sql -SELECT POW("water_level", 4) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | pow | -| :------------------- | ------------: | -| 2019-08-18T00:00:00Z | 30.6019618652 | -| 2019-08-18T00:06:00Z | 32.0315362489 | -| 2019-08-18T00:12:00Z | 30.1362461432 | -| 2019-08-18T00:18:00Z | 29.4223904261 | -| 2019-08-18T00:24:00Z | 26.2727594844 | -| 2019-08-18T00:30:00Z | 26.4122914255 | - -{{% /expand %}} - -{{% expand "Calculate field values associated with each field key in a measurement to the power of 4" %}} - -Return field values for each field key that stores numeric values in the `h2o_feet` measurement multiplied to the power of 4. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT POW(*, 4) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | pow_water_level | -| :------------------- | --------------: | -| 2019-08-18T00:00:00Z | 30.6019618652 | -| 2019-08-18T00:06:00Z | 32.0315362489 | -| 2019-08-18T00:12:00Z | 30.1362461432 | -| 2019-08-18T00:18:00Z | 29.4223904261 | -| 2019-08-18T00:24:00Z | 26.2727594844 | -| 2019-08-18T00:30:00Z | 26.4122914255 | - -{{% /expand %}} - -{{% expand "Calculate field values associated with a field key to the power of 4 and include several clauses" %}} - -Return field values associated with the `water_level` field key multiplied to -the power of 4 in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -```sql -SELECT POW("water_level", 4) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | pow | -| :------------------- | ------------: | -| 2019-08-18T00:18:00Z | 29.4223904261 | -| 2019-08-18T00:12:00Z | 30.1362461432 | -| 2019-08-18T00:06:00Z | 32.0315362489 | -| 2019-08-18T00:00:00Z | 30.6019618652 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT POW(( [ * | ] ), ) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `POW()` function to those results. - -`POW()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate mean values to the power of 4" %}} - -Return [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `water_level`s that are calculated at 12-minute intervals multiplied to the power of 4. - -```sql -SELECT POW(MEAN("water_level"), 4) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | pow | -| :------------------- | ------------: | -| 2019-08-18T00:00:00Z | 31.3106302459 | -| 2019-08-18T00:12:00Z | 29.7777139548 | -| 2019-08-18T00:24:00Z | 26.3424561663 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## ROUND() - -Returns the subsequent value rounded to the nearest integer. - -### Basic syntax - -```sql -SELECT ROUND( [ * | ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`ROUND(field_key)` -Returns the field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key) rounded to the nearest integer. - -`ROUND(*)` -Returns the field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement) rounded to the nearest integer. - -`ROUND()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/. To use `ROUND()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples below use the following subsample of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:30:00Z | 2.2670000000 | - -{{< expand-wrapper >}} - -{{% expand "Round field values associated with a field key" %}} - -Return field values in the `water_level` field key in the `h2o_feet` measurement -rounded to the nearest integer. - -```sql -SELECT ROUND("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | round | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.0000000000 | -| 2019-08-18T00:06:00Z | 2.0000000000 | -| 2019-08-18T00:12:00Z | 2.0000000000 | -| 2019-08-18T00:18:00Z | 2.0000000000 | -| 2019-08-18T00:24:00Z | 2.0000000000 | -| 2019-08-18T00:30:00Z | 2.0000000000 | - -{{% /expand %}} - -{{% expand "Round field values associated with each field key in a measurement" %}} - -Return field values for each numeric field in the `h2o_feet` measurement rounded to the nearest integer. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT ROUND(*) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | round_water_level | -| :------------------- | ----------------: | -| 2019-08-18T00:00:00Z | 2.0000000000 | -| 2019-08-18T00:06:00Z | 2.0000000000 | -| 2019-08-18T00:12:00Z | 2.0000000000 | -| 2019-08-18T00:18:00Z | 2.0000000000 | -| 2019-08-18T00:24:00Z | 2.0000000000 | -| 2019-08-18T00:30:00Z | 2.0000000000 | - -{{% /expand %}} - -{{% expand "Round field values associated with a field key and include several clauses" %}} - -Return field values associated with the `water_level` field key rounded to the -nearest integer in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -```sql -SELECT ROUND("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | round | -| :------------------- | -----------: | -| 2019-08-18T00:18:00Z | 2.0000000000 | -| 2019-08-18T00:12:00Z | 2.0000000000 | -| 2019-08-18T00:06:00Z | 2.0000000000 | -| 2019-08-18T00:00:00Z | 2.0000000000 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT ROUND(( [ * | ] )) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `ROUND()` function to those results. - -`ROUND()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate mean values rounded to the nearest integer" %}} - -Return the [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `water_level`s that are calculated at 12-minute intervals and rounds to the nearest integer. - -```sql -SELECT ROUND(MEAN("water_level")) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | round | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.0000000000 | -| 2019-08-18T00:12:00Z | 2.0000000000 | -| 2019-08-18T00:24:00Z | 2.0000000000 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## SIN() - -Returns the sine of the field value. - -### Basic syntax - -```sql -SELECT SIN( [ * | ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`SIN(field_key)` -Returns the sine of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`SIN(*)` -Returns the sine of field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`SIN()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `SIN()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples below use the following subsample of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:30:00Z | 2.2670000000 | - -{{< expand-wrapper >}} - -{{% expand "Calculate the sine of field values associated with a field key" %}} - -Return the sine of field values in the `water_level` field key in the `h2o_feet` measurement. - -```sql -SELECT SIN("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | sin | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 0.7100665046 | -| 2019-08-18T00:06:00Z | 0.6907983763 | -| 2019-08-18T00:12:00Z | 0.7163748731 | -| 2019-08-18T00:18:00Z | 0.7260723687 | -| 2019-08-18T00:24:00Z | 0.7692028035 | -| 2019-08-18T00:30:00Z | 0.7672823308 | - -{{% /expand %}} - -{{% expand "Calculate the sine of field values associated with each field key in a measurement" %}} - -Return the sine of field values for each numeric field in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT SIN(*) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | sin_water_level | -| :------------------- | --------------: | -| 2019-08-18T00:00:00Z | 0.7100665046 | -| 2019-08-18T00:06:00Z | 0.6907983763 | -| 2019-08-18T00:12:00Z | 0.7163748731 | -| 2019-08-18T00:18:00Z | 0.7260723687 | -| 2019-08-18T00:24:00Z | 0.7692028035 | -| 2019-08-18T00:30:00Z | 0.7672823308 | - -{{% /expand %}} - -{{% expand "Calculate the sine of field values associated with a field key and include several clauses" %}} - -Return the sine of field values associated with the `water_level` -field key in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -```sql -SELECT SIN("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | sin | -| :------------------- | -----------: | -| 2019-08-18T00:18:00Z | 0.7260723687 | -| 2019-08-18T00:12:00Z | 0.7163748731 | -| 2019-08-18T00:06:00Z | 0.6907983763 | -| 2019-08-18T00:00:00Z | 0.7100665046 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT SIN(( [ * | ] )) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `SIN()` function to those results. - -`SIN()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the sine of mean values" %}} - -Return the sine of [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `water_level`s that are calculated at 12-minute intervals. - -```sql -SELECT SIN(MEAN("water_level")) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | sin | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 0.7004962722 | -| 2019-08-18T00:12:00Z | 0.7212412912 | -| 2019-08-18T00:24:00Z | 0.7682434314 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## SQRT() - -Returns the square root of field value. - -### Basic syntax - -```sql -SELECT SQRT( [ * | ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`SQRT(field_key)` -Returns the square root of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`SQRT(*)` -Returns the square root field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`SQRT()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `SQRT()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples below use the following subsample of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:30:00Z | 2.2670000000 | - -{{< expand-wrapper >}} - -{{% expand "Calculate the square root of field values associated with a field key" %}} - -Return the square roots of field values in the `water_level` field key in the `h2o_feet` measurement. - -```sql -SELECT SQRT("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | sqrt | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 1.5336231610 | -| 2019-08-18T00:06:00Z | 1.5424007261 | -| 2019-08-18T00:12:00Z | 1.5306861207 | -| 2019-08-18T00:18:00Z | 1.5261061562 | -| 2019-08-18T00:24:00Z | 1.5046594299 | -| 2019-08-18T00:30:00Z | 1.5056560032 | - -{{% /expand %}} - -{{% expand "Calculate the square root of field values associated with each field key in a measurement" %}} - -Return the square roots of field values for each numeric field in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT SQRT(*) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | sqrt_water_level | -| :------------------- | ---------------: | -| 2019-08-18T00:00:00Z | 1.5336231610 | -| 2019-08-18T00:06:00Z | 1.5424007261 | -| 2019-08-18T00:12:00Z | 1.5306861207 | -| 2019-08-18T00:18:00Z | 1.5261061562 | -| 2019-08-18T00:24:00Z | 1.5046594299 | -| 2019-08-18T00:30:00Z | 1.5056560032 | - -{{% /expand %}} - -{{% expand "Calculate the square root of field values associated with a field key and include several clauses" %}} - -Return the square roots of field values associated with the `water_level` -field key in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -```sql -SELECT SQRT("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | sqrt | -| :------------------- | -----------: | -| 2019-08-18T00:18:00Z | 1.5261061562 | -| 2019-08-18T00:12:00Z | 1.5306861207 | -| 2019-08-18T00:06:00Z | 1.5424007261 | -| 2019-08-18T00:00:00Z | 1.5336231610 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT SQRT(( [ * | ] )) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `SQRT()` function to those results. - -`SQRT()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the square root of mean values" %}} - -Return the square roots of [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `water_level`s that are calculated at 12-minute intervals. - -```sql -SELECT SQRT(MEAN("water_level")) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | sqrt | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 1.5380182054 | -| 2019-08-18T00:12:00Z | 1.5283978540 | -| 2019-08-18T00:24:00Z | 1.5051577990 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -## TAN() - -Returns the tangent of the field value. - -### Basic syntax - -```sql -SELECT TAN( [ * | ] ) FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -`TAN(field_key)` -Returns the tangent of field values associated with the [field key](/influxdb/v2/reference/glossary/#field-key). - -`TAN(*)` -Returns the tangent of field values associated with each field key in the [measurement](/influxdb/v2/reference/glossary/#measurement). - -`TAN()` supports int64 and float64 field value [data types](/influxdb/v2/query-data/influxql/explore-data/select/#data-types). - -Supports `GROUP BY` clauses that [group by tags](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-tags) but not `GROUP BY` clauses that [group by time](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals). -To use `TAN()` with a `GROUP BY time()` clause, see [Advanced syntax](#advanced-syntax). - -#### Examples - -The examples below use the following subsample of the [NOAA water sample data](/influxdb/v2/reference/sample-data/#noaa-water-sample-data): - -```sql -SELECT "water_level" FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | water_level | -| :------------------- | -----------: | -| 2019-08-18T00:00:00Z | 2.3520000000 | -| 2019-08-18T00:06:00Z | 2.3790000000 | -| 2019-08-18T00:12:00Z | 2.3430000000 | -| 2019-08-18T00:18:00Z | 2.3290000000 | -| 2019-08-18T00:24:00Z | 2.2640000000 | -| 2019-08-18T00:30:00Z | 2.2670000000 | - -{{< expand-wrapper >}} - -{{% expand "Calculate the tangent of field values associated with a field key" %}} - -Return the tangent of field values in the `water_level` field key in the `h2o_feet` measurement. - -```sql -SELECT TAN("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | tan | -| :------------------- | ------------: | -| 2019-08-18T00:00:00Z | -1.0084243657 | -| 2019-08-18T00:06:00Z | -0.9553984098 | -| 2019-08-18T00:12:00Z | -1.0267433979 | -| 2019-08-18T00:18:00Z | -1.0559235802 | -| 2019-08-18T00:24:00Z | -1.2037513424 | -| 2019-08-18T00:30:00Z | -1.1964307053 | - -{{% /expand %}} - -{{% expand "Calculate the tangent of field values associated with each field key in a measurement" %}} - -Return the tangent of field values for each numeric field in the `h2o_feet` measurement. -The `h2o_feet` measurement has one numeric field: `water_level`. - -```sql -SELECT TAN(*) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | tan_water_level | -| :------------------- | --------------: | -| 2019-08-18T00:00:00Z | -1.0084243657 | -| 2019-08-18T00:06:00Z | -0.9553984098 | -| 2019-08-18T00:12:00Z | -1.0267433979 | -| 2019-08-18T00:18:00Z | -1.0559235802 | -| 2019-08-18T00:24:00Z | -1.2037513424 | -| 2019-08-18T00:30:00Z | -1.1964307053 | - -{{% /expand %}} - -{{% expand "Calculate the tangent of field values associated with a field key and include several clauses" %}} - -Return the tangent of field values associated with the `water_level` -field key in the [time range](/influxdb/v2/query-data/influxql/explore-data/time-and-timezone/#time-syntax) -between `2019-08-18T00:00:00Z` and `2019-08-18T00:30:00Z` with results in -[descending timestamp order](/influxdb/v2/query-data/influxql/explore-data/order-by/). -The query also [limits](/influxdb/v2/query-data/influxql/explore-data/limit-and-slimit/) -the number of points returned to four and [offsets](/influxdb/v2/query-data/influxql/explore-data/offset-and-soffset/) -results by two points. - -```sql -SELECT TAN("water_level") FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' ORDER BY time DESC LIMIT 4 OFFSET 2 -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | tan | -| :------------------- | ------------: | -| 2019-08-18T00:18:00Z | -1.0559235802 | -| 2019-08-18T00:12:00Z | -1.0267433979 | -| 2019-08-18T00:06:00Z | -0.9553984098 | -| 2019-08-18T00:00:00Z | -1.0084243657 | - -{{% /expand %}} - -{{< /expand-wrapper >}} - -### Advanced syntax - -```sql -SELECT TAN(( [ * | ] )) FROM_clause [WHERE_clause] GROUP_BY_clause [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] -``` - -The advanced syntax requires a [`GROUP BY time() ` clause](/influxdb/v2/query-data/influxql/explore-data/group-by/#group-by-time-intervals) and a nested InfluxQL function. -The query first calculates the results for the nested function at the specified `GROUP BY time()` interval and then applies the `TAN()` function to those results. - -`TAN()` supports the following nested functions: -[`COUNT()`](/influxdb/v2/query-data/influxql/functions/aggregates/#count), -[`MEAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mean), -[`MEDIAN()`](/influxdb/v2/query-data/influxql/functions/aggregates/#median), -[`MODE()`](/influxdb/v2/query-data/influxql/functions/aggregates/#mode), -[`SUM()`](/influxdb/v2/query-data/influxql/functions/aggregates/#sum), -[`FIRST()`](/influxdb/v2/query-data/influxql/functions/selectors/#first), -[`LAST()`](/influxdb/v2/query-data/influxql/functions/selectors/#last), -[`MIN()`](/influxdb/v2/query-data/influxql/functions/selectors/#min), -[`MAX()`](/influxdb/v2/query-data/influxql/functions/selectors/#max), and -[`PERCENTILE()`](/influxdb/v2/query-data/influxql/functions/selectors/#percentile). - -#### Examples - -{{< expand-wrapper >}} - -{{% expand "Calculate the tangent of mean values" %}} - -Return the tangent of [mean](/influxdb/v2/query-data/influxql/functions/aggregates/#mean) `water_level`s that are calculated at 12-minute intervals. - -```sql -SELECT TAN(MEAN("water_level")) FROM "h2o_feet" WHERE time >= '2019-08-18T00:00:00Z' AND time <= '2019-08-18T00:30:00Z' AND "location" = 'santa_monica' GROUP BY time(12m) -``` - -{{% influxql/table-meta %}} -name: h2o_feet -{{% /influxql/table-meta %}} - -| time | tan | -| :------------------- | ------------: | -| 2019-08-18T00:00:00Z | -0.9815600413 | -| 2019-08-18T00:12:00Z | -1.0412271461 | -| 2019-08-18T00:24:00Z | -1.2000844348 | - -{{% /expand %}} - -{{< /expand-wrapper >}} + diff --git a/content/influxdb/v2/query-data/influxql/manage-data.md b/content/influxdb/v2/query-data/influxql/manage-data.md index 4eb27a5e7..4ae949aae 100644 --- a/content/influxdb/v2/query-data/influxql/manage-data.md +++ b/content/influxdb/v2/query-data/influxql/manage-data.md @@ -8,142 +8,8 @@ menu: parent: Query with InfluxQL identifier: manage-database weight: 204 +source: /shared/influxdb-v2/query-data/influxql/manage-data.md --- -Use the following data management commands to write and delete data with InfluxQL: - -- [Write data with INSERT](#write-data-with-insert) -- [Delete series with DELETE](#delete-series-with-delete) -- [Delete measurements with DROP MEASUREMENT](#delete-measurements-with-drop-measurement) - -## Write data with INSERT - -The `INSERT` statement writes [line protocol](/influxdb/v2/reference/syntax/line-protocol/) -to a database and retention policy. - -### Syntax -```sql -INSERT [INTO [.]] -``` - -- The `INTO` clause is optional. - If the command does not include `INTO`, you must specify the - database with `USE ` when using the [InfluxQL shell](/influxdb/v2/tools/influxql-shell/) - or with the `db` query string parameter in the - [InfluxDB 1.x compatibility API](/influxdb/v2/reference/api/influxdb-1x/) request. - -### Examples - -- [Insert data into the a specific database and retention policy](#insert-data-into-the-a-specific-database-and-retention-policy) -- [Insert data into the a the default retention policy of a database](#insert-data-into-the-a-the-default-retention-policy-of-a-database) -- [Insert data into the currently used database](#insert-data-into-the-currently-used-database) - -#### Insert data into the a specific database and retention policy - -```sql -INSERT INTO mydb.myrp example-m,tag1=value1 field1=1i 1640995200000000000 -``` - -#### Insert data into the a the default retention policy of a database - -```sql -INSERT INTO mydb example-m,tag1=value1 field1=1i 1640995200000000000 -``` - -#### Insert data into the currently used database - -The following example uses the [InfluxQL shell](/influxdb/v2/tools/influxql-shell). - -```sql -> USE mydb -> INSERT example-m,tag1=value1 field1=1i 1640995200000000000 -``` - -## Delete series with DELETE - -The `DELETE` statement deletes all points from a [series](/influxdb/v2/reference/glossary/#series) in a database. - -### Syntax - -```sql -DELETE FROM WHERE [=''] | [