Giter VIP home page Giter VIP logo

kafka-http-metrics-reporter's Introduction

Kafka Http Metrics Reporter

This is a http metrics reporter for kafka using Jetty with the metrics servlets (http://metrics.codahale.com/manual/servlets/kafka ) for exposing the metrics as JSON Objects. Instead of retrieving metrics through JMX with JConsole it is now possible to retrieve the metrics with curl or some other http / rest client. Code is tested with Kafka 2.12-0.11.0.0

Travis Build Status

Install On Broker

  1. Build the kafka-http-metrics-reporter-0.11.0.0.jar jar using mvn package or download here .
  2. Copy the jar kafka-http-metrics-reporter-0.11.0.0.jar to the libs/ directory of your kafka broker installation
  3. Configure the broker (see the configuration section below)
  4. Restart the broker

Configuration

Edit the server.properties file of your installation, activate the reporter by setting:

    kafka.metrics.reporters=nl.techop.kafka.KafkaHttpMetricsReporter[,kafka.metrics.KafkaCSVMetricsReporter[,....]]
    kafka.http.metrics.reporter.enabled=true
    kafka.http.metrics.host=localhost
    kafka.http.metrics.port=8080

URL List

url description
/api HTML admin menu with links
/api/healthcheck HealthCheckServlet responds to GET requests by running all the health checks and returning 501 Not Implemented if no health checks are registered, 200 OK if all pass, or 500 Internal Service Error if one or more fail. The results are returned as a human-readable text/plain entity.
/api/metrics exposes the state of the metrics in a particular registry as a JSON object.
/api/ping responds to GET requests with a text/plain/200 OK response of pong. This is useful for determining liveness for load balancers, etc.
api/threads responds to GET requests with a text/plain representation of all the live threads in the JVM, their states, their stack traces, and the state of any locks they may be waiting for.

Usage Examples

Curl

   curl -XGET -H "Content-type: application/json" -H "Accept: application/json" "http://localhost:8080/api/metrics"

kafka-http-metrics-reporter's People

Contributors

arnobroekhof avatar buggycode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

kafka-http-metrics-reporter's Issues

Service fails to start with KafkaHttpMetricsReporter enabled: java.lang.NoClassDefFoundError: com/yammer/metrics/reporting/AdminServlet

Error logs

Apr  3 15:35:30 kafka-1a-01 kafka-server-start.sh[23377]: [2017-04-03 15:35:30,232] INFO Initializing Kafka Http Metrics Reporter (nl.techop.kafka.KafkaHttpMetricsServer)
Apr  3 15:35:30 kafka-1a-01 kafka-server-start.sh[23377]: [2017-04-03 15:35:30,247] INFO Logging initialized @523ms (org.eclipse.jetty.util.log)
Apr  3 15:35:30 kafka-1a-01 kafka-server-start.sh[23377]: [2017-04-03 15:35:30,288] FATAL  (kafka.Kafka$)
Apr  3 15:35:30 kafka-1a-01 kafka-server-start.sh[23377]: java.lang.NoClassDefFoundError: com/yammer/metrics/reporting/AdminServlet
Apr  3 15:35:30 kafka-1a-01 kafka-server-start.sh[23377]: at nl.techop.kafka.KafkaHttpMetricsServer.init(KafkaHttpMetricsServer.java:78)
Apr  3 15:35:30 kafka-1a-01 kafka-server-start.sh[23377]: at nl.techop.kafka.KafkaHttpMetricsServer.<init>(KafkaHttpMetricsServer.java:55)
Apr  3 15:35:30 kafka-1a-01 kafka-server-start.sh[23377]: at nl.techop.kafka.KafkaHttpMetricsReporter.init(KafkaHttpMetricsReporter.java:62)
Apr  3 15:35:30 kafka-1a-01 kafka-server-start.sh[23377]: at kafka.metrics.KafkaMetricsReporter$$anonfun$startReporters$1.apply(KafkaMetricsReporter.scala:66)
Apr  3 15:35:30 kafka-1a-01 kafka-server-start.sh[23377]: at kafka.metrics.KafkaMetricsReporter$$anonfun$startReporters$1.apply(KafkaMetricsReporter.scala:64)
Apr  3 15:35:30 kafka-1a-01 kafka-server-start.sh[23377]: at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
Apr  3 15:35:30 kafka-1a-01 kafka-server-start.sh[23377]: at scala.collection.mutable.WrappedArray.foreach(WrappedArray.scala:35)
Apr  3 15:35:30 kafka-1a-01 kafka-server-start.sh[23377]: at kafka.metrics.KafkaMetricsReporter$.startReporters(KafkaMetricsReporter.scala:64)
Apr  3 15:35:30 kafka-1a-01 kafka-server-start.sh[23377]: at kafka.server.KafkaServerStartable$.fromProps(KafkaServerStartable.scala:27)
Apr  3 15:35:30 kafka-1a-01 systemd[1]: kafka.service: main process exited, code=exited, status=1/FAILURE
Apr  3 15:35:30 kafka-1a-01 systemd[1]: Unit kafka.service entered failed state.
Apr  3 15:35:30 kafka-1a-01 systemd[1]: kafka.service failed.

Install process:

# Download zip archive and build
wget https://github.com/arnobroekhof/kafka-http-metrics-reporter/archive/kafka_2.12-0.10.2.0.zip
unzip kafka_2.12-0.10.2.0.zip
cd kafka-http-metrics-reporter-kafka_2.12-0.10.2.0
mvn package

# Copy jar into `/libs` directory with other jars
cp target/kafka-http-metrics-reporter-0.10.2.0.jar /opt/kafka/kafka_2.11-0.10.2.0/libs/

# Edit kafka properties file
cat >> cat /opt/kafka/kafka_2.11-0.10.2.0/config/kafka.properties << EOF
############################# Metrics #############################
kafka.metrics.reporters=nl.techop.kafka.KafkaHttpMetricsReporter
kafka.http.metrics.reporter.enabled=true
kafka.http.metrics.host=localhost
kafka.http.metrics.port=8897
EOF

# Restart
service kafka restart

Maven version

mvn -v
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)
Maven home: /usr/local/apache-maven
Java version: 1.8.0_74, vendor: Oracle Corporation
Java home: /usr/java/jdk1.8.0_74/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-229.11.1.el7.x86_64", arch: "amd64", family: "unix"

/api/metrics fails with Kafka 1.0 and Java 9

The following exception is visible in the broker logs

[2017-11-13 10:20:52,018] WARN /api/metrics (org.eclipse.jetty.servlet.ServletHandler)
java.lang.reflect.InaccessibleObjectException: Unable to make public long com.sun.management.internal.OperatingSystemImpl.getOpenFileDescriptorCount() accessible: module jdk.management does not "opens com.sun.management.internal" to unnamed module @141e5bef
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:337)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:281)
at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:198)
at java.base/java.lang.reflect.Method.setAccessible(Method.java:192)
at com.yammer.metrics.core.VirtualMachineMetrics.fileDescriptorUsage(VirtualMachineMetrics.java:257)
at com.yammer.metrics.reporting.MetricsServlet.writeVmMetrics(MetricsServlet.java:253)
at com.yammer.metrics.reporting.MetricsServlet.doGet(MetricsServlet.java:175)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:258)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.base/java.lang.Thread.run(Thread.java:844)

Run error: Exception in thread "main" java.lang.NoSuchFieldError: USE_DEFAULTS

I generated jar file, put it in /usr/share/java/kafka/kafka-http-metrics-reporter-0.11.0.0.jar, then in the config server.properties wrote:
kafka.metrics.reporters = nl.techop.kafka. KafkaHttpMetricsReporter
kafka.http.metrics.reporter.enabled = true
kafka.http.metrics.host = localhost
kafka.http.metrics.port = 8897
After the start of the /var/log/kafka/kafkaServer.out error:
Exception in thread "main" java.lang.NoSuchFieldError: USE_DEFAULTS
    at com.fasterxml.jackson.annotation.JsonInclude $ Value. (JsonInclude.java:204)
    at com.fasterxml.jackson.databind.cfg.MapperConfig. (MapperConfig.java:44)
    at com.fasterxml.jackson.databind.ObjectMapper. (ObjectMapper.java:558)
    at com.fasterxml.jackson.databind.ObjectMapper. (ObjectMapper.java:474)
    at com.yammer.metrics.reporting.MetricsServlet. (MetricsServlet.java:91)
    at com.yammer.metrics.reporting.AdminServlet. (AdminServlet.java:47)
    at nl.techop.kafka.KafkaHttpMetricsServer.init (KafkaHttpMetricsServer.java:82)
    at nl.techop.kafka.KafkaHttpMetricsServer. (KafkaHttpMetricsServer.java:59)
    at nl.techop.kafka.KafkaHttpMetricsReporter.init (KafkaHttpMetricsReporter.java:62)
    at kafka.metrics.KafkaMetricsReporter $$ anonfun $ startReporters $ 1.apply (KafkaMetricsReporter.scala: 66)
    at kafka.metrics.KafkaMetricsReporter $$ anonfun $ startReporters $ 1.apply (KafkaMetricsReporter.scala: 64)
    at scala.collection.IndexedSeqOptimized $ class.foreach (IndexedSeqOptimized.scala: 33)
    at scala.collection.mutable.WrappedArray.foreach (WrappedArray.scala: 35)
    at kafka.metrics.KafkaMetricsReporter $ .startReporters (KafkaMetricsReporter.scala: 64)
    at io.confluent.support.metrics.SupportedServerStartable. (SupportedServerStartable.java:48)
    at io.confluent.support.metrics.SupportedKafka.main (SupportedKafka.java:39)

Linked releases do not include jars

Based on what is said in the README, I assume you intended to include these but accidentally left them out.

Zipfile:

$ wget https://github.com/arnobroekhof/kafka-http-metrics-reporter/archive/kafka_2.12-0.10.2.0.zip
--2017-04-03 15:51:02--  https://github.com/arnobroekhof/kafka-http-metrics-reporter/archive/kafka_2.12-0.10.2.0.zip
Resolving github.com (github.com)... 192.30.253.113, 192.30.253.112
Connecting to github.com (github.com)|192.30.253.113|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/arnobroekhof/kafka-http-metrics-reporter/zip/kafka_2.12-0.10.2.0 [following]
--2017-04-03 15:51:02--  https://codeload.github.com/arnobroekhof/kafka-http-metrics-reporter/zip/kafka_2.12-0.10.2.0
Resolving codeload.github.com (codeload.github.com)... 192.30.253.120, 192.30.253.121
Connecting to codeload.github.com (codeload.github.com)|192.30.253.120|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 13623 (13K) [application/zip]
Saving to: ‘kafka_2.12-0.10.2.0.zip.1’

100%[====================================================================================================================================================================================================>] 13,623      --.-K/s   in 0.01s

2017-04-03 15:51:03 (1.11 MB/s) - ‘kafka_2.12-0.10.2.0.zip.1’ saved [13623/13623]

$ unzip -l kafka_2.12-0.10.2.0.zip
Archive:  kafka_2.12-0.10.2.0.zip
2def1e280114d209ed8a7314a8b236051b4c503b
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  03-06-2017 20:27   kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/
      206  03-06-2017 20:27   kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/.gitignore
       38  03-06-2017 20:27   kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/.travis.yml
    11325  03-06-2017 20:27   kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/LICENSE
     2316  03-06-2017 20:27   kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/README.md
    10355  03-06-2017 20:27   kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/pom.xml
        0  03-06-2017 20:27   kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/src/
        0  03-06-2017 20:27   kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/src/main/
        0  03-06-2017 20:27   kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/src/main/java/
        0  03-06-2017 20:27   kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/src/main/java/nl/
        0  03-06-2017 20:27   kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/src/main/java/nl/techop/
        0  03-06-2017 20:27   kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/src/main/java/nl/techop/kafka/
     3584  03-06-2017 20:27   kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/src/main/java/nl/techop/kafka/KafkaHttpMetricsReporter.java
      949  03-06-2017 20:27   kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/src/main/java/nl/techop/kafka/KafkaHttpMetricsReporterMBean.java
     4054  03-06-2017 20:27   kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/src/main/java/nl/techop/kafka/KafkaHttpMetricsServer.java
---------                     -------
    32827                     15 files

Tarball:

$ wget https://github.com/arnobroekhof/kafka-http-metrics-reporter/archive/kafka_2.12-0.10.2.0.tar.gz
--2017-04-03 15:52:16--  https://github.com/arnobroekhof/kafka-http-metrics-reporter/archive/kafka_2.12-0.10.2.0.tar.gz
Resolving github.com (github.com)... 192.30.253.112, 192.30.253.113
Connecting to github.com (github.com)|192.30.253.112|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/arnobroekhof/kafka-http-metrics-reporter/tar.gz/kafka_2.12-0.10.2.0 [following]
--2017-04-03 15:52:17--  https://codeload.github.com/arnobroekhof/kafka-http-metrics-reporter/tar.gz/kafka_2.12-0.10.2.0
Resolving codeload.github.com (codeload.github.com)... 192.30.253.120, 192.30.253.121
Connecting to codeload.github.com (codeload.github.com)|192.30.253.120|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: ‘kafka_2.12-0.10.2.0.tar.gz’

    [ <=>                                                                                                                                                                                                 ] 9,006       --.-K/s   in 0s

2017-04-03 15:52:17 (67.0 MB/s) - ‘kafka_2.12-0.10.2.0.tar.gz’ saved [9006]

$ tar tvf kafka_2.12-0.10.2.0.tar.gz
drwxrwxr-x root/root         0 2017-03-06 20:27 kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/
-rwxrwxr-x root/root       206 2017-03-06 20:27 kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/.gitignore
-rw-rw-r-- root/root        38 2017-03-06 20:27 kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/.travis.yml
-rw-rw-r-- root/root     11325 2017-03-06 20:27 kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/LICENSE
-rw-rw-r-- root/root      2316 2017-03-06 20:27 kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/README.md
-rw-rw-r-- root/root     10355 2017-03-06 20:27 kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/pom.xml
drwxrwxr-x root/root         0 2017-03-06 20:27 kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/src/
drwxrwxr-x root/root         0 2017-03-06 20:27 kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/src/main/
drwxrwxr-x root/root         0 2017-03-06 20:27 kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/src/main/java/
drwxrwxr-x root/root         0 2017-03-06 20:27 kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/src/main/java/nl/
drwxrwxr-x root/root         0 2017-03-06 20:27 kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/src/main/java/nl/techop/
drwxrwxr-x root/root         0 2017-03-06 20:27 kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/src/main/java/nl/techop/kafka/
-rw-rw-r-- root/root      3584 2017-03-06 20:27 kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/src/main/java/nl/techop/kafka/KafkaHttpMetricsReporter.java
-rw-rw-r-- root/root       949 2017-03-06 20:27 kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/src/main/java/nl/techop/kafka/KafkaHttpMetricsReporterMBean.java
-rw-rw-r-- root/root      4054 2017-03-06 20:27 kafka-http-metrics-reporter-kafka_2.12-0.10.2.0/src/main/java/nl/techop/kafka/KafkaHttpMetricsServer.java

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.