From e809f41d74e11f4f73b4c7b0191bacd5b1899fda Mon Sep 17 00:00:00 2001 From: andsel Date: Wed, 18 Dec 2024 17:54:18 +0100 Subject: [PATCH] Removed Librato and Dropwizard dependencies --- broker/pom.xml | 14 --- .../java/io/moquette/BrokerConstants.java | 5 - .../io/moquette/broker/NewNettyAcceptor.java | 13 --- .../metrics/DropWizardMetricsHandler.java | 95 ------------------- distribution/src/main/resources/moquette.conf | 14 --- 5 files changed, 141 deletions(-) delete mode 100644 broker/src/main/java/io/moquette/broker/metrics/DropWizardMetricsHandler.java diff --git a/broker/pom.xml b/broker/pom.xml index bdc2c3b2a..cb21135e4 100644 --- a/broker/pom.xml +++ b/broker/pom.xml @@ -81,7 +81,6 @@ ${netty.version} - io.netty netty-transport-native-epoll @@ -107,7 +106,6 @@ osx-x86_64 - io.netty netty-tcnative-boringssl-static @@ -140,7 +138,6 @@ runtime - com.h2database h2-mvstore @@ -153,17 +150,6 @@ 2.4.7 - - io.dropwizard.metrics - metrics-core - 3.2.2 - - - io.dropwizard.metrics - metrics-jvm - 3.2.2 - - commons-codec commons-codec diff --git a/broker/src/main/java/io/moquette/BrokerConstants.java b/broker/src/main/java/io/moquette/BrokerConstants.java index fc725655c..6e905c391 100644 --- a/broker/src/main/java/io/moquette/BrokerConstants.java +++ b/broker/src/main/java/io/moquette/BrokerConstants.java @@ -113,11 +113,6 @@ public final class BrokerConstants { public static final int NO_BUFFER_FLUSH = -1; public static final int IMMEDIATE_BUFFER_FLUSH = 0; - public static final String METRICS_ENABLE_PROPERTY_NAME = "use_metrics"; - public static final String METRICS_LIBRATO_EMAIL_PROPERTY_NAME = "metrics.librato.email"; - public static final String METRICS_LIBRATO_TOKEN_PROPERTY_NAME = "metrics.librato.token"; - public static final String METRICS_LIBRATO_SOURCE_PROPERTY_NAME = "metrics.librato.source"; - @Deprecated public static final String ENABLE_TELEMETRY_NAME = IConfig.ENABLE_TELEMETRY_NAME; diff --git a/broker/src/main/java/io/moquette/broker/NewNettyAcceptor.java b/broker/src/main/java/io/moquette/broker/NewNettyAcceptor.java index d5fbfaa1a..f80976931 100644 --- a/broker/src/main/java/io/moquette/broker/NewNettyAcceptor.java +++ b/broker/src/main/java/io/moquette/broker/NewNettyAcceptor.java @@ -132,7 +132,6 @@ public void operationComplete(ChannelFuture future) throws Exception { private final Map ports = new HashMap<>(); private BytesMetricsCollector bytesMetricsCollector = new BytesMetricsCollector(); private MessageMetricsCollector metricsCollector = new MessageMetricsCollector(); - private Optional metrics; private int nettySoBacklog; private boolean nettySoReuseaddr; @@ -172,15 +171,6 @@ public void initialize(NewNettyMQTTHandler mqttHandler, IConfig props, ISslConte channelClass = NioServerSocketChannel.class; } - final boolean useFineMetrics = props.boolProp(METRICS_ENABLE_PROPERTY_NAME, false); - if (useFineMetrics) { - DropWizardMetricsHandler metricsHandler = new DropWizardMetricsHandler(); - metricsHandler.init(props); - this.metrics = Optional.of(metricsHandler); - } else { - this.metrics = Optional.empty(); - } - initializePlainTCPTransport(mqttHandler, props, brokerConfiguration); initializeWebSocketTransport(mqttHandler, props, brokerConfiguration); if (securityPortsConfigured(props)) { @@ -286,9 +276,6 @@ private void configureMQTTPipeline(ChannelPipeline pipeline, MoquetteIdleTimeout pipeline.addLast("encoder", MqttEncoder.INSTANCE); pipeline.addLast("metrics", new MessageMetricsHandler(metricsCollector)); pipeline.addLast("messageLogger", new MQTTMessageLogger()); - if (metrics.isPresent()) { - pipeline.addLast("wizardMetrics", metrics.get()); - } pipeline.addLast("handler", handler); } diff --git a/broker/src/main/java/io/moquette/broker/metrics/DropWizardMetricsHandler.java b/broker/src/main/java/io/moquette/broker/metrics/DropWizardMetricsHandler.java deleted file mode 100644 index 83ae6f8e6..000000000 --- a/broker/src/main/java/io/moquette/broker/metrics/DropWizardMetricsHandler.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2012-2018 The original author or authors - * ------------------------------------------------------ - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * The Apache License v2.0 is available at - * http://www.opensource.org/licenses/apache2.0.php - * - * You may elect to redistribute this code under either of these licenses. - */ -package io.moquette.broker.metrics; - -import com.codahale.metrics.Counter; -import com.codahale.metrics.Meter; -import com.codahale.metrics.MetricRegistry; -import com.librato.metrics.reporter.Librato; -import io.moquette.broker.config.IConfig; -import io.moquette.broker.NettyUtils; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; -import io.netty.handler.codec.mqtt.MqttMessage; -import io.netty.handler.codec.mqtt.MqttMessageType; - -import java.util.concurrent.TimeUnit; - -import static io.moquette.BrokerConstants.*; -import static io.netty.channel.ChannelHandler.Sharable; - -/** - * Pipeline handler use to track some MQTT metrics. - */ -@Sharable -public final class DropWizardMetricsHandler extends ChannelInboundHandlerAdapter { - private MetricRegistry metrics; - private Meter publishesMetrics; - private Meter subscribeMetrics; - private Counter connectedClientsMetrics; - - public void init(IConfig props) { - this.metrics = new MetricRegistry(); - this.publishesMetrics = metrics.meter("publish.requests"); - this.subscribeMetrics = metrics.meter("subscribe.requests"); - this.connectedClientsMetrics = metrics.counter("connect.num_clients"); -// ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics) -// .convertRatesTo(TimeUnit.SECONDS) -// .convertDurationsTo(TimeUnit.MILLISECONDS) -// .build(); -// reporter.start(1, TimeUnit.MINUTES); - final String email = props.getProperty(METRICS_LIBRATO_EMAIL_PROPERTY_NAME); - final String token = props.getProperty(METRICS_LIBRATO_TOKEN_PROPERTY_NAME); - final String source = props.getProperty(METRICS_LIBRATO_SOURCE_PROPERTY_NAME); - - Librato.reporter(this.metrics, email, token) - .setSource(source) - .start(10, TimeUnit.SECONDS); - } - - @Override - public void channelRead(ChannelHandlerContext ctx, Object message) { - MqttMessage msg = (MqttMessage) message; - MqttMessageType messageType = msg.fixedHeader().messageType(); - switch (messageType) { - case PUBLISH: - this.publishesMetrics.mark(); - break; - case SUBSCRIBE: - this.subscribeMetrics.mark(); - break; - case CONNECT: - this.connectedClientsMetrics.inc(); - break; - case DISCONNECT: - this.connectedClientsMetrics.dec(); - break; - default: - break; - } - ctx.fireChannelRead(message); - } - - @Override - public void channelInactive(ChannelHandlerContext ctx) throws Exception { - String clientID = NettyUtils.clientID(ctx.channel()); - if (clientID != null && !clientID.isEmpty()) { - this.connectedClientsMetrics.dec(); - } - ctx.fireChannelInactive(); - } - -} diff --git a/distribution/src/main/resources/moquette.conf b/distribution/src/main/resources/moquette.conf index 916d53b00..63731edad 100644 --- a/distribution/src/main/resources/moquette.conf +++ b/distribution/src/main/resources/moquette.conf @@ -153,20 +153,6 @@ password_file config/password_file.conf #********************************************************************* # session_queue_size 1024 -#********************************************************************* -# Metrics Configuration -# -# use_metrics: used to enable Dropwizard Metrics sampling metrics. -# metrics.librato.email: Librato account's email -# metrics.librato.token: Librato account's security token -# metrics.librato.source: your application as source in Librato -# definitions -#********************************************************************* -# use_metrics true -# metrics.librato.email john@doe.com -# metrics.librato.token sdfergheghliuhyr2283ehd9827398h -# metrics.librato.source My Fantastic Service - #********************************************************************* # Telemetry information sending #