time-seriesprometheusmonitoringtelegrafquestdb

Monitor QuestDB metrics using QuestDB


I know QuestDB exposes metrics in Prometheus format, but I've never used Prometheus, so I was wondering what would be the best way to scrape the metrics QuestDB exposes, so I can store the metrics in a table on QuestDB itself.

That way I can reuse what I already know about QuestDB and I can easily integrate with a Grafana dashboard as I already have one setup and connected to other QuestDB tables.

Is this possible?


Solution

  • By default, QuestDB doesn't expose any metrics, but setting up the metrics.enabled config variable, or setting up an env variable QDB_METRICS_ENABLED=TRUE will make them available on localhost:9003/metrics.

    You could use Prometheus to scrape those metrics, but you can also use any server agent that understands the Prometheus format. It turns out telegraf has input plugins for Prometheus and output plugins for QuestDB, so you can use it to get the metrics from the endpoint and insert them into a QuestDB table.

    This is a telegraf.conf configuration which works for me (using default ports)

    # Configuration for Telegraf agent
    [agent]
      ## Default data collection interval for all inputs
      interval = "5s"
      omit_hostname = true
      precision = "1ms"
      flush_interval = "5s"
    
    # -- INPUT PLUGINS ------------------------------------------------------ #
    [[inputs.prometheus]]
      ## An array of urls to scrape metrics from.
      urls = ["http://questdb-origin:9003/metrics"]
      url_tag=""
      metric_version = 2 # all entries will be on a single table
      ignore_timestamp = false
    
    # -- AGGREGATOR PLUGINS ------------------------------------------------- #
    # Merge metrics into multifield metrics by series key
    [[aggregators.merge]]
      ## If true, the original metric will be dropped by the
      ## aggregator and will not get sent to the output plugins.
      drop_original = true
    
    
    # -- OUTPUT PLUGINS ----------------------------------------------------- #
    [[outputs.socket_writer]]
      # Write metrics to a local QuestDB instance over TCP
      address = "tcp://questdb-target:9009"
    

    A few things to note: