Getting container name with Jolokia Plugin running in Kubernetes

I’ve got a Kubernetes cluster running some Springboot applications instrumented with the Jolokia JVM agent plugin. I’m running Telegraf as deployment alongside my Java containers to get the JVM metrics from Jolokia.

The problem I’m having is that the Jolokia plugin always reports the hostname as the Telegraf container running Telegraf collecting the Jolokia metrics and I want the payloads to contain the actual container hostname which is running the Jolokia agent. I’m aware of the inputs.server portion of the config where you can specify a name and host but the problem is when I have Jolokia running against multiple pods I can’t hardcode in the specific values.

For what it’s worth here here is my config map. Is it possible to get the container hostname within the payloads?

apiVersion: v1
kind: ConfigMap
  name: telegraf-config
  telegraf.conf: |+
      datacenter = "aws"
      interval = "10s"
      round_interval = true
      metric_batch_size = 1000
      metric_buffer_limit = 10000
      collection_jitter = "0s"
      flush_interval = "10s"
      flush_jitter = "0s"
      precision = ""
      omit_hostname = false
       urls = ["http://sample-tomcat.default.svc.cluster.local:8778/jolokia"]
       name_prefix = "tomcat."

      name  = "OperatingSystem"
      mbean = "java.lang:type=OperatingSystem"
      paths = ["ProcessCpuLoad","SystemLoadAverage","SystemCpuLoad"]

      name  = "jvm_runtime"
      mbean = "java.lang:type=Runtime"
      paths = ["Uptime"]

      name  = "jvm_memory"
      mbean = "java.lang:type=Memory"
      paths = ["HeapMemoryUsage", "NonHeapMemoryUsage", "ObjectPendingFinalizationCount"]

      name     = "jvm_garbage_collector"
      mbean    = "java.lang:name=*,type=GarbageCollector"
      paths    = ["CollectionTime", "CollectionCount"]
      tag_keys = ["name"]

      name       = "jvm_memory_pool"
      mbean      = "java.lang:name=*,type=MemoryPool"
      paths      = ["Usage", "PeakUsage", "CollectionUsage"]
      tag_keys   = ["name"]
      tag_prefix = "pool_"

      name     = "GlobalRequestProcessor"
      mbean    = "Catalina:name=*,type=GlobalRequestProcessor"
      paths    = ["requestCount","bytesReceived","bytesSent","processingTime","errorCount"]
      tag_keys = ["name"]

      name     = "JspMonitor"
      mbean    = "Catalina:J2EEApplication=*,J2EEServer=*,WebModule=*,name=jsp,type=JspMonitor"
      paths    = ["jspReloadCount","jspCount","jspUnloadCount"]
      tag_keys = ["J2EEApplication","J2EEServer","WebModule"]

      name     = "ThreadPool"
      mbean    = "Catalina:name=*,type=ThreadPool"
      paths    = ["maxThreads","currentThreadCount","currentThreadsBusy"]
      tag_keys = ["name"]

      name     = "Servlet"
      mbean    = "Catalina:J2EEApplication=*,J2EEServer=*,WebModule=*,j2eeType=Servlet,name=*"
      paths    = ["processingTime","errorCount","requestCount"]
      tag_keys = ["name","J2EEApplication","J2EEServer","WebModule"]

      name     = "Cache"
      mbean    = "Catalina:context=*,host=*,name=Cache,type=WebResourceRoot"
      paths    = ["hitCount","lookupCount"]
      tag_keys = ["context","host"]
apiVersion: apps/v1
kind: Deployment
  name: telegraf
      app: telegraf
  minReadySeconds: 5
        app: telegraf
        - image: telegraf:1.10.0
          name: telegraf
            - name: telegraf-config-volume
              mountPath: /etc/telegraf/telegraf.conf
              subPath: telegraf.conf
              readOnly: true
        - name: telegraf-config-volume
            name: telegraf-config


Telegraf sets the hostname tag when running by looking at the system you are running on, hence why telegraf is showing up currently. It sounds like you want to set the hostname dynamically for metrics, based on the jolokia system it was collected from.

I’m not entirely familiar with what data comes back from jolokia, but is there data in there that you could use to then update the hostname tag using a processor?