Package org.apache.kafka.common.metrics

Examples of org.apache.kafka.common.metrics.Sensor


        public void maybeRegisterTopicMetrics(String topic) {
            // if one sensor of the metrics has been registered for the topic,
            // then all other sensors should have been registered; and vice versa
            String topicRecordsCountName = "topic." + topic + ".records-per-batch";
            Sensor topicRecordCount = this.metrics.getSensor(topicRecordsCountName);
            if (topicRecordCount == null) {
                topicRecordCount = this.metrics.sensor(topicRecordsCountName);
                topicRecordCount.add("topic." + topic + ".record-send-rate", new Rate());

                String topicByteRateName = "topic." + topic + ".bytes";
                Sensor topicByteRate = this.metrics.sensor(topicByteRateName);
                topicByteRate.add("topic." + topic + ".byte-rate", new Rate());

                String topicCompressionRateName = "topic." + topic + ".compression-rate";
                Sensor topicCompressionRate = this.metrics.sensor(topicCompressionRateName);
                topicCompressionRate.add("topic." + topic + ".compression-rate", new Avg());

                String topicRetryName = "topic." + topic + ".record-retries";
                Sensor topicRetrySensor = this.metrics.sensor(topicRetryName);
                topicRetrySensor.add("topic." + topic + ".record-retry-rate", new Rate());

                String topicErrorName = "topic." + topic + ".record-errors";
                Sensor topicErrorSensor = this.metrics.sensor(topicErrorName);
                topicErrorSensor.add("topic." + topic + ".record-error-rate", new Rate());
            }
        }
View Full Code Here


                        String topic = batch.topicPartition.topic();
                        maybeRegisterTopicMetrics(topic);

                        // per-topic record send rate
                        String topicRecordsCountName = "topic." + topic + ".records-per-batch";
                        Sensor topicRecordCount = Utils.notNull(this.metrics.getSensor(topicRecordsCountName));
                        topicRecordCount.record(batch.recordCount);

                        // per-topic bytes send rate
                        String topicByteRateName = "topic." + topic + ".bytes";
                        Sensor topicByteRate = Utils.notNull(this.metrics.getSensor(topicByteRateName));
                        topicByteRate.record(batch.records.sizeInBytes());

                        // per-topic compression rate
                        String topicCompressionRateName = "topic." + topic + ".compression-rate";
                        Sensor topicCompressionRate = Utils.notNull(this.metrics.getSensor(topicCompressionRateName));
                        topicCompressionRate.record(batch.records.compressionRate());

                        // global metrics
                        this.batchSizeSensor.record(batch.records.sizeInBytes(), now);
                        this.queueTimeSensor.record(batch.drainedMs - batch.createdMs, now);
                        this.compressionRateSensor.record(batch.records.compressionRate());
View Full Code Here

        public void recordRetries(String topic, int count) {
            long now = time.milliseconds();
            this.retrySensor.record(count, now);
            String topicRetryName = "topic." + topic + ".record-retries";
            Sensor topicRetrySensor = this.metrics.getSensor(topicRetryName);
            if (topicRetrySensor != null)
                topicRetrySensor.record(count, now);
        }
View Full Code Here

        public void recordErrors(String topic, int count) {
            long now = time.milliseconds();
            this.errorSensor.record(count, now);
            String topicErrorName = "topic." + topic + ".record-errors";
            Sensor topicErrorSensor = this.metrics.getSensor(topicErrorName);
            if (topicErrorSensor != null)
                topicErrorSensor.record(count, now);
        }
View Full Code Here

        public void recordLatency(int node, long latency) {
            long now = time.milliseconds();
            this.requestTimeSensor.record(latency, now);
            if (node >= 0) {
                String nodeTimeName = "node-" + node + ".latency";
                Sensor nodeRequestTime = this.metrics.getSensor(nodeTimeName);
                if (nodeRequestTime != null)
                    nodeRequestTime.record(latency, now);
            }
        }
View Full Code Here

public class MetricsBench {

    public static void main(String[] args) {
        long iters = Long.parseLong(args[0]);
        Metrics metrics = new Metrics();
        Sensor parent = metrics.sensor("parent");
        Sensor child = metrics.sensor("child", parent);
        for (Sensor sensor : Arrays.asList(parent, child)) {
            sensor.add(sensor.name() + ".avg", new Avg());
            sensor.add(sensor.name() + ".count", new Count());
            sensor.add(sensor.name() + ".max", new Max());
            sensor.add(new Percentiles(1024,
View Full Code Here

        public void maybeRegisterNodeMetrics(int node) {
            if (node >= 0) {
                // if one sensor of the metrics has been registered for the node,
                // then all other sensors should have been registered; and vice versa
                String nodeRequestName = "node-" + node + ".bytes-sent";
                Sensor nodeRequest = this.metrics.getSensor(nodeRequestName);
                if (nodeRequest == null) {
                    nodeRequest = this.metrics.sensor(nodeRequestName);
                    nodeRequest.add("node-" + node + ".outgoing-byte-rate", new Rate());
                    nodeRequest.add("node-" + node + ".request-rate",
                                    "The average number of requests sent per second.",
                                    new Rate(new Count()));
                    nodeRequest.add("node-" + node + ".request-size-avg", "The average size of all requests in the window..", new Avg());
                    nodeRequest.add("node-" + node + ".request-size-max", "The maximum size of any request sent in the window.", new Max());

                    String nodeResponseName = "node-" + node + ".bytes-received";
                    Sensor nodeResponse = this.metrics.sensor(nodeResponseName);
                    nodeResponse.add("node-" + node + ".incoming-byte-rate", new Rate());
                    nodeResponse.add("node-" + node + ".response-rate",
                                     "The average number of responses received per second.",
                                     new Rate(new Count()));

                    String nodeTimeName = "node-" + node + ".latency";
                    Sensor nodeRequestTime = this.metrics.sensor(nodeTimeName);
                    nodeRequestTime.add("node-" + node + ".request-latency-avg", new Avg());
                    nodeRequestTime.add("node-" + node + ".request-latency-max", new Max());
                }
            }
        }
View Full Code Here

        public void recordBytesSent(int node, int bytes) {
            long now = time.milliseconds();
            this.bytesSent.record(bytes, now);
            if (node >= 0) {
                String nodeRequestName = "node-" + node + ".bytes-sent";
                Sensor nodeRequest = this.metrics.getSensor(nodeRequestName);
                if (nodeRequest != null)
                    nodeRequest.record(bytes, now);
            }
        }
View Full Code Here

        public void recordBytesReceived(int node, int bytes) {
            long now = time.milliseconds();
            this.bytesReceived.record(bytes, now);
            if (node >= 0) {
                String nodeRequestName = "node-" + node + ".bytes-received";
                Sensor nodeRequest = this.metrics.getSensor(nodeRequestName);
                if (nodeRequest != null)
                    nodeRequest.record(bytes, now);
            }
        }
View Full Code Here

    @Test
    public void testJmxRegistration() throws Exception {
        Metrics metrics = new Metrics();
        metrics.addReporter(new JmxReporter());
        Sensor sensor = metrics.sensor("kafka.requests");
        sensor.add("pack.bean1.avg", new Avg());
        sensor.add("pack.bean2.total", new Total());
        Sensor sensor2 = metrics.sensor("kafka.blah");
        sensor2.add("pack.bean1.some", new Total());
        sensor2.add("pack.bean2.some", new Total());
    }
View Full Code Here

TOP

Related Classes of org.apache.kafka.common.metrics.Sensor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.