Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter metrics by suffix #787

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Filter metrics by suffix #787

wants to merge 1 commit into from

Conversation

fstab
Copy link
Member

@fstab fstab commented May 20, 2022

Allow filtering metrics by suffix. For example, this can be used to filter out _created metrics.

There are different ways to configure this, depending on how you expose metrics:

Manual creation of the HTTPServer

    HTTPServer httpServer = new HTTPServer.Builder()
        .withRegistry(registry)
        .withSampleNameFilter(new SampleNameFilter.Builder()
            .nameMustNotEndWith("_created")
            .build())
        .build();

See TestHTTPServer.testCreatedMetricRemoved().

Exporter Servlet

    <servlet>
        <servlet-name>prometheus-exporter</servlet-name>
        <servlet-class>io.prometheus.client.servlet.jakarta.exporter.MetricsServlet</servlet-class>
        <init-param>
            <param-name>name-must-not-end-with</param-name>
            <param-value>_created</param-value>
        </init-param>
    </servlet>

jmx_exporter

We are working on a new configuration file format for jmx_exporter, see the new-config branch. The new config will have a section like this:

metricFilter:
  nameMustNotEndWith:
    - _created

Signed-off-by: Fabian Stäber <[email protected]>
@brian-brazil
Copy link
Contributor

We are working on a new configuration file format for jmx_exporter, see the new-config branch. The new config will have a section like this:

This seems redundant, you can already configure the jmx exporter to drop samples by setting name to empty.

However you likely don't even need that - _created samples will generally only be there if there's mBeans exposing them and you've rules covering that with the JMX exporter, which wouldn't be typical at all..

@fstab
Copy link
Member Author

fstab commented May 20, 2022

The main use case I had in mind for the metric filter was that some users want to filter out jvm_threads_deadlocked and jvm_threads_deadlocked_monitor because as the Javadoc says this might be an expensive operation under some circumstances. However, different users might want to filter different things, so I just exposed generic filtering by prefix/suffix/exact match.

One aspect that might be confusing: The name filters are applied after scraping the JMX bean. If you want to prevent the JMX bean from being scraped, there's the jmxBeanFilter (previously called blacklist / whitelist).

A complete example is test-config-new.yaml, but it's very early stages. I implemented a parser that's backwards-compatible with the current format. Next step is to write tests for different combinations of SSL config (both for the collector via jmxUrl and for the HTTPServer), but that's quite time consuming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants