"Original" KAKFA metrics package source code Analysis

Source: Internet
Author: User

This package is mainly related to the Kafka metric.

First, Kafkatimer.scalaTiming the execution of a block of code. Only one method is provided: timer--runs an incoming function F for a period of time Second, Kafkametricsconfig.scalaSpecifies the reporter class, a comma-delimited class of reporter, such as kafka.metrics.KafkaCSVMetricsReporter, that must be specified in the Claasspath. In addition, the polling interval for the metric is specified, which is 10 seconds by default. Third, Kafkametricsreporter.scalaKafkametricsreportermbean is a basic trait. If the customer wants to customize the reporter, it is necessary to implement this mbean in addition to Kafkametricsreporter to meet the standard Mbean specification. The trait defines 3 abstract methods: 1. Startreporter: Call Yammer's csvreporter start method to turn on Reporter2. Stopreporter: Call Yammer's Csvreporter shutdown method to close Reporter3. Getmbeanname: Gets the name of the Mbean in the format: Kafka:type=kafka.metrics.kafkacsvmetricsreporter The Scala file also provides a second trait: Kafkametricsreporter, the trait has only one method Init, which implements the Init method in Kafkacsvmetricsreporter.scala Finally, the Scala also has an object: Kafkametricsreporter. The object maintains a Atomicboolean reporterstarted variable that identifies whether the reporter has been started and acts as a lock in the process of starting reporter. The only method startreporters the object is to start all reporter--defined in Metricconfig The method is to call the Utils.createobject method to create all the reporter through the reflection mechanism, initialize each reporter, and finally register the reporter with the Mbean. Iv. Kafkacsvmetricsreporter.scalaThe Scala can be said to Kafka a specific reporter provided by default. Altogether two Mbean:kafkacsvmetricsreportermbean and Kafkacsvmetricsreporter were provided. Let's start with the first one: Kafkacsvmetricsreportermbean. The trait is a private trait that simply inherits the Kafkametricsreportermbean. The second trait inherited the Kafkametricsmbean and Kafkacsvmetricsreportermbean, thus realizing the first two trait 4 methods, namely INIT, Getmbeanname, Startreporter and Stopreporter. It is worth mentioning that in the Init method it creates a subdirectory that defaults to Kafka_metrics. Then determine if the kafka.csv.metrics.reporter.enabled is set to True, if true, call the Startreporter method to open the report, otherwise it will end directly. Wu, Kafkametricsgroup.scalaThe Scala defines a trait and an object. As the kafkametricsgroup trait, as the name implies, this should be a metric group, defined a lot of methods, the main method is Newgauge, Newmeter, Newhistogram and Newtimer Call the Yammer framework's API to create different metric objects. The Scala object:kafkametricsgroup, respectively, consumer, server, and producer define their own metric lists. Of course, the Remove method is also provided to delete the metric of the given ClientID

"Original" KAKFA metrics package source code Analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.