Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flux influxdb.cardinality fails: influxdb provider requires a host to be specified #21513

Closed
russorat opened this issue May 19, 2021 · 1 comment · Fixed by #22441
Closed

Comments

@russorat
Copy link
Contributor

The following query works just fine in cloud, but when trying this in a 2.0.6 instance running in docker, i get the following error:

failed to initialize execute state: influxdb provider requires a host to be specified

import "influxdata/influxdb"

influxdb.cardinality(bucket: "telegraf", start: -1h)

When i try to add the host information, it fails with the same error:

import "influxdata/influxdb"

influxdb.cardinality(bucket: "telegraf", start: -1h, host: "http://influxdb:8086", token: "mytoken", orgID: "f89a598ed3c38f35")

here is my docker compose file:

version: '3'
services:
  influxdb:
    image: influxdb:2.0.6
    volumes:
      # Mount for influxdb data directory and configuration
      - influxdbv2:/.influxdbv2
    ports:
      - "8086:8086"
  # Use the influx cli to set up an influxdb instance.
  influxdb_cli:
    links:
      - influxdb
    image: influxdb:2.0.6
    # Use these same configurations parameters in your telegraf configuration, mytelegraf.conf.
    entrypoint: influx setup --bucket telegraf -t mytoken -o InfluxData --username=russ --password=something --host=http://influxdb:8086 -f
    # Wait for the influxd service in the influxdb container has fully bootstrapped before trying to setup an influxdb instance with the influxdb_cli service.
    restart: on-failure:10
    depends_on:
      - influxdb
  telegraf:
    image: telegraf:latest
    links:
      - influxdb
    volumes:
      # Mount for telegraf config
      - ./telegraf.conf:/etc/telegraf/telegraf.conf:ro
    depends_on:
      - influxdb_cli
volumes:
  influxdbv2:

and here is my telegraf config:

[[inputs.internal]]

# Read metrics from one or many prometheus clients
[[inputs.prometheus]]
  name_override = "influxdb_oss"
  ## An array of urls to scrape metrics from.
  urls = ["http://influxdb:8086/metrics"]

  ## Metric version controls the mapping from Prometheus metrics into
  ## Telegraf metrics.  When using the prometheus_client output, use the same
  ## value in both plugins to ensure metrics are round-tripped without
  ## modification.
  ##
  ##   example: metric_version = 1;
  ##            metric_version = 2; recommended version
  metric_version = 2

  ## HTTP Basic Authentication username and password. ('bearer_token' and
  ## 'bearer_token_string' take priority)
  # username = ""
  # password = ""

  ## Specify timeout duration for slower prometheus clients (default is 3s)
  # response_timeout = "3s"

  ## Optional TLS Config
  # tls_ca = /path/to/cafile
  # tls_cert = /path/to/certfile
  # tls_key = /path/to/keyfile
  ## Use TLS but skip chain & host verification
  # insecure_skip_verify = false

# Output Configuration for telegraf agent
[[outputs.influxdb_v2]]
  ## Point to your influxdb container
 urls = ["http://influxdb:8086"]
  ## Token for authentication; created with the influxdb_cli service.
  token = "mytoken"
  ## Organization is the name of the organization you wish to write to; created with the influxdb_cli service.
  organization = "InfluxData"
  ## Destination bucket to write into; created with the influxdb_cli service.
  bucket = "telegraf"
@nylocx
Copy link

nylocx commented Aug 10, 2021

From the docs:
https://docs.influxdata.com/influxdb/v2.0/reference/flux/stdlib/influxdb/cardinality/

InfluxDB Cloud supports the influxdb.cardinality() function, but InfluxDB OSS does not.

So currently no way to get the cardinality in the OSS Version?

-- EDIT --
I found this on the web and it seems to work even if I do not fully understand it.

import "influxdata/influxdb"

from(bucket: "your-bucket")
  |> range(start: -3y)
  |> first()
  |> group()
  |> count()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants