From b7cfea7711aef732299233188dc094037b7c72eb Mon Sep 17 00:00:00 2001 From: LOOHP Date: Sat, 15 Aug 2020 23:22:43 +0800 Subject: [PATCH] Updated Metrics --- src/com/loohp/interactivechat/InteractiveChat.java | 3 +++ src/com/loohp/interactivechat/Listeners/ChatPackets.java | 1 + src/com/loohp/interactivechat/Metrics/Charts.java | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/src/com/loohp/interactivechat/InteractiveChat.java b/src/com/loohp/interactivechat/InteractiveChat.java index 458de5a6..ccdd4378 100644 --- a/src/com/loohp/interactivechat/InteractiveChat.java +++ b/src/com/loohp/interactivechat/InteractiveChat.java @@ -10,6 +10,7 @@ import java.util.Optional; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicLong; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -142,6 +143,8 @@ public class InteractiveChat extends JavaPlugin { public static boolean useCustomPlaceholderPermissions = false; public static Optional chatAltColorCode = Optional.empty(); + + public static AtomicLong messagesCounter = new AtomicLong(0); @Override public void onEnable() { diff --git a/src/com/loohp/interactivechat/Listeners/ChatPackets.java b/src/com/loohp/interactivechat/Listeners/ChatPackets.java index 2ebf8a75..76f9b175 100644 --- a/src/com/loohp/interactivechat/Listeners/ChatPackets.java +++ b/src/com/loohp/interactivechat/Listeners/ChatPackets.java @@ -41,6 +41,7 @@ public static void chatMessageListener() { InteractiveChat.protocolManager.addPacketListener(new PacketAdapter(InteractiveChat.plugin, ListenerPriority.MONITOR, PacketType.Play.Server.CHAT) { @Override public void onPacketSending(PacketEvent event) { + InteractiveChat.messagesCounter.getAndIncrement(); int debug = 0; try { if (!event.getPacketType().equals(PacketType.Play.Server.CHAT)) { diff --git a/src/com/loohp/interactivechat/Metrics/Charts.java b/src/com/loohp/interactivechat/Metrics/Charts.java index 5b3a35f8..41ab12d2 100644 --- a/src/com/loohp/interactivechat/Metrics/Charts.java +++ b/src/com/loohp/interactivechat/Metrics/Charts.java @@ -15,6 +15,14 @@ public Integer call() throws Exception { } })); + metrics.addCustomChart(new Metrics.SingleLineChart("total_amount_of_chat_messages_processing_per_interval", new Callable() { + @Override + public Integer call() throws Exception { + long amount = InteractiveChat.messagesCounter.getAndSet(0); + return amount > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) amount; + } + })); + } }