Menu
Grafana Cloud

NSQ integration for Grafana Cloud

NSQ is a realtime distributed messaging platform designed to operate at scale, handling billions of messages per day.

This integration uses NSQ statsd integration to gather metrics.

This integration includes 2 useful alerts and 2 pre-built dashboards to help monitor and visualize NSQ metrics.

Before you begin

In order for the integration to work, point nsqd to Grafana Agent statsd exporter with -statsd-address, using nsqd command line flags, like this:

nsqd -statsd-address=agent.default.svc.cluster.local:9125

To enable e2e metrics with extra flags:

nsqd -e2e-processing-latency-percentile=1.0,0.99,0.95 -e2e-processing-latency-window-time=1m0s

To learn more, see end-to-end processing latency in nsq.

Install NSQ integration for Grafana Cloud

  1. In your Grafana Cloud stack, click Connections in the left-hand menu.
  2. Find NSQ and click its tile to open the integration.
  3. Review the prerequisites in the Configuration Details tab and set up Grafana Agent to send NSQ metrics to your Grafana Cloud instance.
  4. Click Install to add this integration’s pre-built dashboards and alerts to your Grafana Cloud instance, and you can start monitoring your NSQ setup.

Post-install configuration for the NSQ integration

This integration is configured to work with the statsd_exporter, which is embedded in Grafana Agent.

Enable the integration by adding the provided snippets to your agent configuration file.

For a full description of configuration options see how to configure the statsd_exporter_config block in the agent documentation.

Configuration snippets for Grafana Agent

Below integrations, insert the following lines and change the URLs according to your environment:

yaml
  statsd_exporter:
    enabled: true
    metric_relabel_configs:
      - source_labels: [exported_job]
        target_label: job
        replacement: 'integrations/$1'
      - source_labels: [exported_instance]
        target_label: instance
      - regex: (exported_instance|exported_job)
        action: labeldrop
    mapping_config:
      defaults:
        match_type: glob
        glob_disable_ordering: false
        ttl: 1m30s
      mappings:
      - match: "nsq.*.topic.*.channel.*.message_count"
        name: "nsq_topic_channel_message_count"
        match_metric_type: counter
        labels:
          instance: "$1"
          job: "nsq"
          topic: "$2"
          channel: "$3"
  
      - match: "nsq.*.topic.*.channel.*.requeue_count"
        name: "nsq_topic_channel_requeue_count"
        match_metric_type: counter
        labels:
          instance: "$1"
          job: "nsq"
          topic: "$2"
          channel: "$3"
  
      - match: "nsq.*.topic.*.channel.*.timeout_count"
        name: "nsq_topic_channel_timeout_count"
        match_metric_type: counter
        labels:
          instance: "$1"
          job: "nsq"
          topic: "$2"
          channel: "$3"
  
      - match: "nsq.*.topic.*.channel.*.*"
        name: "nsq_topic_channel_${4}"
        match_metric_type: gauge
        labels:
          instance: "$1"
          job: "nsq"
          topic: "$2"
          channel: "$3"
  
      #nsq.<nsq_host>_<nsq_port>.topic.<topic_name>.backend_depth [gauge]
      - match: "nsq.*.topic.*.message_count"
        name: "nsq_topic_message_count"
        help: Total number of messages for the topic
        match_metric_type: counter
        labels:
          instance: "$1"
          job: "nsq"
          topic: "$2"
  
      - match: "nsq.*.topic.*.message_bytes"
        name: "nsq_topic_message_bytes"
        help: Total number of bytes of all messages
        match_metric_type: counter
        labels:
          instance: "$1"
          job: "nsq"
          topic: "$2"
  
      - match: "nsq.*.topic.*.*" #depth or backend_depth
        name: "nsq_topic_${3}"
        match_metric_type: gauge
        labels:
          instance: "$1"
          job: "nsq"
          topic: "$2"
      # mem
      # nsq.<nsq_host>_<nsq_port>.mem.gc_runs
      - match: "nsq.*.mem.gc_runs"
        name: "nsq_mem_gc_runs"
        match_metric_type: counter
        labels:
          instance: "$1"
          job: "nsq"
  
      - match: "nsq.*.mem.*"
        name: "nsq_mem_${2}"
        match_metric_type: gauge
        labels:
          instance: "$1"
          job: "nsq"

Full example configuration for Grafana Agent

Refer to the following Grafana Agent configuration for a complete example that contains all the snippets used for the NSQ integration. This example also includes metrics that are sent to monitor your Grafana Agent instance.

yaml
integrations:
  prometheus_remote_write:
  - basic_auth:
      password: <your_prom_pass>
      username: <your_prom_user>
    url: <your_prom_url>
  agent:
    enabled: true
    relabel_configs:
    - action: replace
      source_labels:
      - agent_hostname
      target_label: instance
    - action: replace
      target_label: job
      replacement: "integrations/agent-check"
    metric_relabel_configs:
    - action: keep
      regex: (prometheus_target_sync_length_seconds_sum|prometheus_target_scrapes_.*|prometheus_target_interval.*|prometheus_sd_discovered_targets|agent_build.*|agent_wal_samples_appended_total|process_start_time_seconds)
      source_labels:
      - __name__
  # Add here any snippet that belongs to the `integrations` section.
  # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
  statsd_exporter:
    enabled: true
    metric_relabel_configs:
      - source_labels: [exported_job]
        target_label: job
        replacement: 'integrations/$1'
      - source_labels: [exported_instance]
        target_label: instance
      - regex: (exported_instance|exported_job)
        action: labeldrop
    mapping_config:
      defaults:
        match_type: glob
        glob_disable_ordering: false
        ttl: 1m30s
      mappings:
      - match: "nsq.*.topic.*.channel.*.message_count"
        name: "nsq_topic_channel_message_count"
        match_metric_type: counter
        labels:
          instance: "$1"
          job: "nsq"
          topic: "$2"
          channel: "$3"
  
      - match: "nsq.*.topic.*.channel.*.requeue_count"
        name: "nsq_topic_channel_requeue_count"
        match_metric_type: counter
        labels:
          instance: "$1"
          job: "nsq"
          topic: "$2"
          channel: "$3"
  
      - match: "nsq.*.topic.*.channel.*.timeout_count"
        name: "nsq_topic_channel_timeout_count"
        match_metric_type: counter
        labels:
          instance: "$1"
          job: "nsq"
          topic: "$2"
          channel: "$3"
  
      - match: "nsq.*.topic.*.channel.*.*"
        name: "nsq_topic_channel_${4}"
        match_metric_type: gauge
        labels:
          instance: "$1"
          job: "nsq"
          topic: "$2"
          channel: "$3"
  
      #nsq.<nsq_host>_<nsq_port>.topic.<topic_name>.backend_depth [gauge]
      - match: "nsq.*.topic.*.message_count"
        name: "nsq_topic_message_count"
        help: Total number of messages for the topic
        match_metric_type: counter
        labels:
          instance: "$1"
          job: "nsq"
          topic: "$2"
  
      - match: "nsq.*.topic.*.message_bytes"
        name: "nsq_topic_message_bytes"
        help: Total number of bytes of all messages
        match_metric_type: counter
        labels:
          instance: "$1"
          job: "nsq"
          topic: "$2"
  
      - match: "nsq.*.topic.*.*" #depth or backend_depth
        name: "nsq_topic_${3}"
        match_metric_type: gauge
        labels:
          instance: "$1"
          job: "nsq"
          topic: "$2"
      # mem
      # nsq.<nsq_host>_<nsq_port>.mem.gc_runs
      - match: "nsq.*.mem.gc_runs"
        name: "nsq_mem_gc_runs"
        match_metric_type: counter
        labels:
          instance: "$1"
          job: "nsq"
  
      - match: "nsq.*.mem.*"
        name: "nsq_mem_${2}"
        match_metric_type: gauge
        labels:
          instance: "$1"
          job: "nsq"
logs:
  configs:
  - clients:
    - basic_auth:
        password: <your_loki_pass>
        username: <your_loki_user>
      url: <your_loki_url>
    name: integrations
    positions:
      filename: /tmp/positions.yaml
    scrape_configs:
      # Add here any snippet that belongs to the `logs.configs.scrape_configs` section.
      # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
metrics:
  configs:
  - name: integrations
    remote_write:
    - basic_auth:
        password: <your_prom_pass>
        username: <your_prom_user>
      url: <your_prom_url>
    scrape_configs:
      # Add here any snippet that belongs to the `metrics.configs.scrape_configs` section.
      # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
  global:
    scrape_interval: 60s
  wal_directory: /tmp/grafana-agent-wal

Dashboards

The NSQ integration installs the following dashboards in your Grafana Cloud instance to help monitor your system.

  • NSQ Instances
  • NSQ Topics

NSQ topics dashboard

NSQ topics dashboard

NSQ instances dashboard

NSQ instances dashboard

Alerts

The NSQ integration includes the following useful alerts:

AlertDescription
NsqTopicDepthIncreasingCritical: Topic depth is increasing.
NsqChannelDepthIncreasingCritical: Topic channel depth is increasing.

Metrics

The most important metrics provided by the NSQ integration, which are used on the pre-built dashboards and Prometheus alerts, are as follows:

  • nsq_mem_gc_pause_usec_100
  • nsq_mem_gc_pause_usec_95
  • nsq_mem_gc_pause_usec_99
  • nsq_mem_heap_idle_bytes
  • nsq_mem_heap_in_use_bytes
  • nsq_mem_heap_objects
  • nsq_mem_heap_released_bytes
  • nsq_mem_next_gc_bytes
  • nsq_topic_backend_depth
  • nsq_topic_channel_backend_depth
  • nsq_topic_channel_clients
  • nsq_topic_channel_deferred_count
  • nsq_topic_channel_depth
  • nsq_topic_channel_e2e_processing_latency_99
  • nsq_topic_channel_in_flight_count
  • nsq_topic_channel_message_count
  • nsq_topic_channel_requeue_count
  • nsq_topic_channel_timeout_count
  • nsq_topic_depth
  • nsq_topic_e2e_processing_latency_99
  • nsq_topic_message_bytes
  • nsq_topic_message_count

Changelog

md
# 0.0.2 - September 2023

* New Filter Metrics option for configuring the Grafana Agent, which saves on metrics cost by dropping any metric not used by this integration. Beware that anything custom built using metrics that are not on the snippet will stop working.

# 0.0.1 - January 2022

* Initial release

Cost

By connecting your NSQ instance to Grafana Cloud, you might incur charges. To view information on the number of active series that your Grafana Cloud account uses for metrics included in each Cloud tier, see Active series and dpm usage and Cloud tier pricing.