NoClassDefFoundError when implementing a Prometheus Counter

Viewed 2051

I implemented a Prometheus Counter to get the no. of requests to a service. When I called the service I got the following error.

Exception in thread "HTTP-Listener I/O dispatcher-1" java.lang.NoClassDefFoundError: io/prometheus/client/Counter

I added the following dependencies to the pom.xml file.

      <dependency>
         <groupId>io.prometheus</groupId>
         <artifactId>simpleclient</artifactId>
         <version>0.8.1</version>
     </dependency>
     <!-- Hotspot JVM metrics-->
     <dependency>
         <groupId>io.prometheus</groupId>
         <artifactId>simpleclient_hotspot</artifactId>
         <version>0.8.1</version>
     </dependency>
     <!-- Exposition HTTPServer-->
     <dependency>
         <groupId>io.prometheus</groupId>
         <artifactId>simpleclient_httpserver</artifactId>
         <version>0.8.1</version>
     </dependency>

This is my java instrumentation

      private Counter requestsReceived;

      requestsReceived = Counter.build().name("requests_total_Sample").help("Total 
                                                       requests.").register();

      requestsReceived.inc(); 

How can I solve this issue?

1 Answers

You should always use consistent versions of the various parts of the simpleclient.

<!-- prometheus - core -->
<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient</artifactId>
    <version>${prometheus.version}</version>
</dependency>

<!-- prometheus - Exposition HTTPServer -->
<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient_httpserver</artifactId>
    <version>${prometheus.version}</version>
</dependency>

<!-- Hotspot JVM metrics -->
<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient_hotspot</artifactId>
    <version>${prometheus.version}</version>
</dependency>

<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient_servlet</artifactId>
    <version>${prometheus.version}</version>
</dependency>

<!-- prometheus - Pushgateway exposition -->
<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient_pushgateway</artifactId>
    <version>${prometheus.version}</version>
</dependency>
Related