1

Our system consists of multiple JAVA based microservices, each one reports its RT status leveraging io.prometheus simpleclient

The integration code looks pretty straightforward

// Initialize default JVM metrics for Prometheus
    DefaultExports.initialize();

    DeploymentInfo monitoringServletInfo = Servlets.deployment()
            .setClassLoader(MonitoringServer.class.getClassLoader())
            .setContextPath("/")
            .setDeploymentName("monitoring")
            .addServlet(Servlets.servlet(MetricsServlet.class).addMapping("/*"));

    DeploymentManager monitoringDeployment = Servlets.defaultContainer().addDeployment(monitoringServletInfo);
    monitoringDeployment.deploy();
    HttpHandler monitoringHandler = monitoringDeployment.start();

    server = Undertow.builder()
            .addHttpListener(port, "0.0.0.0")
            .setHandler(
                    Handlers.path().addExactPath(HEALTH_PATH, new HealthHandler())
                            .addExactPath(MONITORING_PATH, monitoringHandler))
            .build();

    server.start();

Since all microservices expose the same metrics name we are looking for a way to distinguish them by providing a custom label for each microservice

for example, this metrics has the following definition

jvm_buffer_pool_used_bytes{pool="direct",} 116776.0

our purpose is to add a custom label like, then it will be super easy to separate than in the Grafana.

jvm_buffer_pool_used_bytes{pool="direct",service="foo"} 116776.0

I want to believe the lib has to have such capability, unfortunately googling it for a while was not such successful

Any idea will be appreciated.

Denis Voloshin
  • 768
  • 10
  • 32

1 Answers1

1

I would stronly suggest to use Micrometer for that job. Which is

a) easier to integrate and

b) you can can also add so called "common tags" which is exactly what you are looking for (Micromether uses the term "tag" instead of "label" but the concept is the same).

registry.config().commonTags("service", "someService");

Especially for the "default" metrics that the JVM provides also via JMX it has an easy integration:

new JvmMemoryMetrics().bindTo(registry);

and you got all the memory metrics in your prometheus metrics. (see here for more information)

Jens Baitinger
  • 2,230
  • 14
  • 34
  • 1
    Thanks for answering my questions, however, we can't use an alternative library. Seems like I found the way to solve it by providing a custom MetricsServlet.class Implementation. – Denis Voloshin Apr 12 '21 at 18:29
  • just being curious, what hinders you using another library? – Jens Baitinger Apr 12 '21 at 18:36
  • 1
    our system is based on tens of microservices. as far as I know, Micrometer uses slightly different metric names, moving to Micrometer means, unjustified code refactoring and Grafana dashboards ajustment, it's not worth it. – Denis Voloshin Apr 12 '21 at 19:30