Any examples of configs for jmx_exporter for standard JVM beans?

550 views
Skip to first unread message

Gregory Golberg

unread,
Dec 4, 2019, 6:11:15 PM12/4/19
to Prometheus Users
Hi all,

Using JMX exporter and looking at config examples I am still having trouble with some rules. For example, with these rules:

rules:
 
- pattern: 'java.lang:type=OperatingSystem,OpenFileDescriptorCount'
 
- pattern: 'java.lang:type=OperatingSystem,SystemLoadAverage'
 
- pattern: 'java.lang:type=OperatingSystem,SystemCPULoad'
 
- pattern: 'java.lang:type=OperatingSystem,ProcessCPULoad'

I do get the FD count but not the rest. For memory usage, these work as I wanted:

 - pattern: 'java.lang:type=Memory,HeapMemoryUsage<used=(\w)>'
   value
: $1
 
- pattern: 'java.lang:type=Memory,NonHeapMemoryUsage<used=(\w)>'
   value
: $1


But I cannot figure out how to get garbage collection metrics (in particular, say, I wanted java_lang_GarbageCollector_LastGcInfo_duration{name="ParNew",} and java_lang_GarbageCollector_CollectionTime ?

Thank you.

-g

Brian Brazil

unread,
Dec 4, 2019, 6:16:08 PM12/4/19
to Gregory Golberg, Prometheus Users
On Wed, 4 Dec 2019 at 23:11, Gregory Golberg <deb...@gmail.com> wrote:
Hi all,

Using JMX exporter and looking at config examples I am still having trouble with some rules. For example, with these rules:

rules:
 
- pattern: 'java.lang:type=OperatingSystem,OpenFileDescriptorCount'
 
- pattern: 'java.lang:type=OperatingSystem,SystemLoadAverage'
 
- pattern: 'java.lang:type=OperatingSystem,SystemCPULoad'
 
- pattern: 'java.lang:type=OperatingSystem,ProcessCPULoad'

I do get the FD count but not the rest. For memory usage, these work as I wanted:

 - pattern: 'java.lang:type=Memory,HeapMemoryUsage<used=(\w)>'
   value
: $1
 
- pattern: 'java.lang:type=Memory,NonHeapMemoryUsage<used=(\w)>'
   value
: $1


The jmx exporter agent provides these metrics automatically as part of the standard JVM stuff client_java provides, you shouldn't need to configure these at all. 

--

Gregory Golberg

unread,
Dec 4, 2019, 6:23:37 PM12/4/19
to Prometheus Users
Perhaps I was unclear -- what if I wanted to narrow the metrics down to only the ones I want?

Brian Brazil

unread,
Dec 5, 2019, 4:17:32 AM12/5/19
to Gregory Golberg, Prometheus Users
On Wed, 4 Dec 2019 at 23:23, Gregory Golberg <deb...@gmail.com> wrote:
Perhaps I was unclear -- what if I wanted to narrow the metrics down to only the ones I want?

You can't from the binary, they're always exposed as they're likely as useful as any application metrics you're pulling and the philosophy of Prometheus is the expose metrics you might need.

If you don't want specific ones of those metrics, you'd have to tweak the source code and build your own binary - but there shouldn't be a need for that.

Brian
 
--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/c29b7c13-ccda-43b5-9c41-71848e2bbbbc%40googlegroups.com.


--

Gregory Golberg

unread,
Dec 14, 2019, 9:34:38 PM12/14/19
to Prometheus Users
I understand they are exposed but doesn't the JMX exporter config specifically provides for narrowing those down?
To unsubscribe from this group and stop receiving emails from it, send an email to promethe...@googlegroups.com.

Brian Brazil

unread,
Dec 15, 2019, 3:01:28 AM12/15/19
to Gregory Golberg, Prometheus Users
On Sun, 15 Dec 2019 at 02:34, Gregory Golberg <deb...@gmail.com> wrote:
I understand they are exposed but doesn't the JMX exporter config specifically provides for narrowing those down?

It's not the jmx exporter's collector providing those though, they come from the client library.

Brian
 
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/e85c842c-8480-4f95-96e3-c80295a326fb%40googlegroups.com.


--

Brian Candler

unread,
Dec 15, 2019, 4:57:01 AM12/15/19
to Prometheus Users
On Wednesday, 4 December 2019 23:23:37 UTC, Gregory Golberg wrote:
Perhaps I was unclear -- what if I wanted to narrow the metrics down to only the ones I want?


Alternatively, you can filter them out as part of the scrape job, so they are not ingested into the time series database, using metric relabelling.  e.g. drop all metrics starting "foo_" and "bar_":

  - job_name: jmx
  ...
    metric_relabel_configs:
      - source_labels: [__name__]
        regex: 'foo_.*|bar_.*'
        action: drop

For more complex policies you may need to be a little creative.  e.g. if you want to keep most metrics, drop all foo_* but keep foo_baz and foo_qux, this is how I'd do it:

  - job_name: jmx
  ...
    metric_relabel_configs:
      - source_labels: [__name__]
        regex: 'foo_(baz|qux)'
        target_label: __tmp_keep
        replacement: Y
      - source_labels: [__tmp_keep, __name__]
        regex: ';foo_.*'
        action: drop
      - regex: '__tmp.*'
        action: labeldrop

Reply all
Reply to author
Forward
0 new messages