HiveMQ InfluxDB Extension for Kubernetes

Hi Team,

I would like to implement InfluxDB extension on kubernetes environment to get metrics of hivemq on grafana dashboard and having issue to configure influxdb.properties file.

Below is config file

mode:http

host:10.10.123.X

port:8086

protocol:http

auth:

prefix:

database:hivemq

reportingInterval:1

connectTimeout:5000

tags:host=kube-pod-name;cluster=kube-hivemq4

I am not sure how to configure Tag:host parameter in above config file. because PODs will get scale up and scale down and IP addresses also get it changed.

Please help me on this.

Hey,

In general, i would advise you to use Prometheus as your monitoring solution instead, as it is much easier to use on K8s due to exactly what you are experiencing: InfluxDB uses a push paradigm instead of pulling metrics from pods. I’ll post some references below.

Regardless: I would advise you to not specify a (what is presumably) podIP for the InfluxDB host. The most resilient approach here would be creating a Service (you can just use the ClusterIP type) that targets your InfluxDB deployment by label and specifying its DNS name as the host (similar to how the DNS discovery works, except that it routes directly to instances)

As for the tag fields: We haven’t tried tagging HiveMQ nodes when using influxDB on K8s yet, but i suppose the best approach to tag your resources for the influxDB time-series would be using downwardAPI:
You could expose the pod name (and if you wish, other fields like IP) as environment variables and then write a pre-entry script that replaces the tags in the influxdb.properties file with sed before executing /opt/hivemq/bin/run.sh

References:
Prometheus Operator for getting started with prometheus on K8s easily: https://github.com/helm/charts/tree/master/stable/prometheus-operator
downwardAPI: https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-pod-fields-as-values-for-environment-variables

Some helpers if you choose to give prometheus-operator a try:

  • Use the Prometheus extension from our HiveMQ marketplace
  • You might need to patch your Prometheus custom resource’s “serviceMonitorSelector” field to allow it to find your ServiceMonitor (you can also set it to “{}” if i recall correctly to have it select any service monitor)
  • Here’s an example of a ServiceMonitor object you can use to have prometheus grab your metrics:
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: hivemq-monitoring-sm
spec:
  endpoints:
    - port: metrics
  selector:
    matchLabels:
      your-label: value

Note that:

  • your-label: value must be replaced by some label the monitor can select your HiveMQ pods by (all HiveMQ pods must have this label)
  • your pod specification must contain the named port metrics that forwards to the metrics endpoint port (9399 by default)
  • set metric_path=/ in prometheusConfiguration.properties of the prometheus extension to allow Prometheus to more easily pick up the path where metrics can be scraped.
1 Like