From 097670caef07dcb11c8c59839fa56dbb65b335f8 Mon Sep 17 00:00:00 2001 From: Tim Middleton Date: Tue, 5 Mar 2024 13:07:40 +0800 Subject: [PATCH] Initial version of tracer support --- .github/workflows/test-against-released.yml | 11 ++ .../workflows/test-against-snapshot-1440.yml | 9 +- .github/workflows/test-against-snapshot.yml | 13 +- coherence-visualvm-plugin/pom.xml | 17 ++ .../plugin/visualvm/VisualVMInstaller.java | 46 ++++- .../plugin/visualvm/VisualVMView.java | 37 ++++ .../plugin/visualvm/helper/GraphHelper.java | 10 +- .../panel/AbstractCoherencePanel.java | 114 +++++++++++- .../panel/CoherenceClusterOverviewPanel.java | 58 ++----- .../visualvm/panel/CoherenceMemberPanel.java | 2 +- .../tracer/AbstractCoherenceMonitorProbe.java | 138 +++++++++++++++ .../visualvm/tracer/CustomFormatter.java | 69 ++++++++ .../tracer/cluster/ClusterMonitorPackage.java | 163 ++++++++++++++++++ .../tracer/cluster/ClusterSizeProbe.java | 76 ++++++++ .../tracer/cluster/DepartureCountProbe.java | 75 ++++++++ .../tracer/cluster/LoadAverageProbe.java | 99 +++++++++++ .../tracer/cluster/PacketPublisherProbe.java | 101 +++++++++++ .../tracer/cluster/PacketReceiverProbe.java | 88 ++++++++++ .../cluster/StorageMembersHeapProbe.java | 100 +++++++++++ .../plugin/visualvm/Bundle.properties | 15 +- pom.xml | 15 +- scripts/install-tracer-library.sh | 64 +++++++ 22 files changed, 1261 insertions(+), 59 deletions(-) create mode 100644 coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/AbstractCoherenceMonitorProbe.java create mode 100644 coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/CustomFormatter.java create mode 100644 coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/ClusterMonitorPackage.java create mode 100644 coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/ClusterSizeProbe.java create mode 100644 coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/DepartureCountProbe.java create mode 100644 coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/LoadAverageProbe.java create mode 100644 coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/PacketPublisherProbe.java create mode 100644 coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/PacketReceiverProbe.java create mode 100644 coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/StorageMembersHeapProbe.java create mode 100755 scripts/install-tracer-library.sh diff --git a/.github/workflows/test-against-released.yml b/.github/workflows/test-against-released.yml index 5fc06dc..aeda9b5 100644 --- a/.github/workflows/test-against-released.yml +++ b/.github/workflows/test-against-released.yml @@ -60,6 +60,17 @@ jobs: key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2 + - name: Set up JDK 8 for Tracer Build + uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'zulu' + + - name: Build Tracer + shell: bash + run: | + ./scripts/install-tracer-library.sh + - name: Set up JDK 11 for Build uses: actions/setup-java@v3 with: diff --git a/.github/workflows/test-against-snapshot-1440.yml b/.github/workflows/test-against-snapshot-1440.yml index d563060..103fb04 100644 --- a/.github/workflows/test-against-snapshot-1440.yml +++ b/.github/workflows/test-against-snapshot-1440.yml @@ -57,12 +57,17 @@ jobs: key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2-snapshots - - name: Set up JDK 8 for Build + - name: Set up JDK 8 for Tracer Build uses: actions/setup-java@v3 with: - java-version: 8 + java-version: '8' distribution: 'zulu' + - name: Build Tracer + shell: bash + run: | + ./scripts/install-tracer-library.sh + - name: Print Versions run: mvn -version && ant -version diff --git a/.github/workflows/test-against-snapshot.yml b/.github/workflows/test-against-snapshot.yml index 231c977..1e57985 100644 --- a/.github/workflows/test-against-snapshot.yml +++ b/.github/workflows/test-against-snapshot.yml @@ -1,5 +1,5 @@ # -# Copyright (c) 2020, 2023 Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2020, 2024 Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -58,6 +58,17 @@ jobs: key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2-snapshots + - name: Set up JDK 8 for Tracer Build + uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'zulu' + + - name: Build Tracer + shell: bash + run: | + ./scripts/install-tracer-library.sh + - name: Set up JDK 17 for Build uses: actions/setup-java@v3 with: diff --git a/coherence-visualvm-plugin/pom.xml b/coherence-visualvm-plugin/pom.xml index f37a5f3..ebcdee5 100644 --- a/coherence-visualvm-plugin/pom.xml +++ b/coherence-visualvm-plugin/pom.xml @@ -107,6 +107,11 @@ org-graalvm-visualvm-lib-ui + + org.graalvm.visualvm.modules + org-graalvm-visualvm-modules-tracer + + com.fasterxml.jackson.core jackson-annotations @@ -125,6 +130,14 @@ coherence-discovery + + + com.oracle.coherence.plugin.visualvm + coherence-visualvm-tracer + 1.7.0-SNAPSHOT + provided + + org.hamcrest hamcrest @@ -164,6 +177,10 @@ ${java.version} ${java.version} ${java.version.release} + + --add-opens + jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED + diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/VisualVMInstaller.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/VisualVMInstaller.java index d862d3b..a571063 100644 --- a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/VisualVMInstaller.java +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/VisualVMInstaller.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2024 Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,6 +30,13 @@ import com.oracle.coherence.plugin.visualvm.impl.CoherenceClusterProvider; +import com.oracle.coherence.plugin.visualvm.tracer.cluster.ClusterMonitorPackage; + +import org.graalvm.visualvm.application.Application; +import org.graalvm.visualvm.modules.tracer.TracerPackage; +import org.graalvm.visualvm.modules.tracer.TracerPackageProvider; +import org.graalvm.visualvm.modules.tracer.TracerSupport; + import org.openide.modules.ModuleInstall; /** @@ -56,6 +63,14 @@ public void restored() CoherenceClusterDataSourceViewProvider.register(); CoherenceClusterProvider.initCoherenceClustersDataSource(); CoherenceApplicationTypeFactory.initialize(); + + // register the tracer probes + if (provider == null) + { + provider = new TracerPackageProviderImpl(); + } + + TracerSupport.getInstance().registerPackageProvider(provider); } /** @@ -69,5 +84,34 @@ public void uninstalled() CoherenceClusterDataSourceDescriptorProvider.unregister(); CoherenceClusterDataSourceViewProvider.unregister(); CoherenceApplicationTypeFactory.shutdown(); + + // un-register the tracer probes + if (provider == null) + { + provider = new TracerPackageProviderImpl(); + } + + TracerSupport.getInstance().unregisterPackageProvider(provider); } + + + /** + * Provider of Coherence tracer probes. + */ + private static class TracerPackageProviderImpl + extends TracerPackageProvider + { + + TracerPackageProviderImpl() + { + super(Application.class); + } + + public TracerPackage[] getPackages(Application application) + { + return new ClusterMonitorPackage[] {new ClusterMonitorPackage(application)}; + } } + + private TracerPackageProviderImpl provider; + } diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/VisualVMView.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/VisualVMView.java index 05b49db..dd28840 100644 --- a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/VisualVMView.java +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/VisualVMView.java @@ -62,6 +62,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; import java.util.logging.Logger; @@ -157,6 +158,14 @@ protected DataViewComponent createComponent() { final VisualVMModel model = VisualVMModel.getInstance(); + m_model = model; + + // only add the tracer if we are connecting via JMX + if (m_application != null) + { + addModelForApplication(m_application, model); + } + boolean fClusterSnapshotEnabled = com.oracle.coherence.plugin.visualvm.GlobalPreferences .sharedInstance().isClusterSnapshotEnabled(); @@ -418,6 +427,9 @@ public void run() protected void removed() { m_timer.stop(); + + // remove this application and the mapped VisualVmModel + f_visualVmModels.remove(m_application); } /** @@ -430,6 +442,28 @@ public void dataRemoved(Application app) m_timer.stop(); } + /** + * Returns the model that is being used for the application. + * + * @param application {@link Application} to associate with {@link VisualVMModel} + * @return the {@link VisualVMModel} + */ + public static VisualVMModel getModelForApplication(Application application) + { + return f_visualVmModels.get(application); + } + + /** + * Add the model that is being used for the application. + * + * @param application {@link Application} to associate with {@link VisualVMModel} + * @param model {@link VisualVMModel} + */ + public static void addModelForApplication(Application application, VisualVMModel model) + { + f_visualVmModels.put(application, model); + } + // ----- constants ------------------------------------------------------ /** @@ -447,8 +481,11 @@ public void dataRemoved(Application app) */ private static final Logger LOGGER = Logger.getLogger(VisualVMView.class.getName()); + private static final ConcurrentHashMap f_visualVmModels = new ConcurrentHashMap<>(); + // ----- data members --------------------------------------------------- + private VisualVMModel m_model; /** * Component used to display the tabs. */ diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/helper/GraphHelper.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/helper/GraphHelper.java index 30eaea6..49dcf14 100755 --- a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/helper/GraphHelper.java +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/helper/GraphHelper.java @@ -1229,9 +1229,9 @@ private static SimpleXYChartSupport createChart(SimpleXYChartDescriptor sxycd) */ public static final int VALUES_LIMIT = Integer.getInteger("coherence.plugin.visualvm.values.limit", 50000); - private static final String GRPH_CURRENT_AVERAGE = "GRPH_current_average"; - private static final String GRPH_MINIMUM = "GRPH_minimum"; - private static final String GRPH_MAXIMUM = "GRPH_maximum"; - private static final String GRPH_AVERAGE = "GRPH_average"; - private static final String GRPH_CURRENT_MAXIMUM = "GRPH_current_maximum"; + public static final String GRPH_CURRENT_AVERAGE = "GRPH_current_average"; + public static final String GRPH_MINIMUM = "GRPH_minimum"; + public static final String GRPH_MAXIMUM = "GRPH_maximum"; + public static final String GRPH_AVERAGE = "GRPH_average"; + public static final String GRPH_CURRENT_MAXIMUM = "GRPH_current_maximum"; } \ No newline at end of file diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/AbstractCoherencePanel.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/AbstractCoherencePanel.java index 97f60a2..7b436da 100755 --- a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/AbstractCoherencePanel.java +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/AbstractCoherencePanel.java @@ -36,6 +36,7 @@ import com.oracle.coherence.plugin.visualvm.helper.RequestSender; import com.oracle.coherence.plugin.visualvm.tablemodel.model.Data; import com.oracle.coherence.plugin.visualvm.tablemodel.model.FederationData; +import com.oracle.coherence.plugin.visualvm.tablemodel.model.MachineData; import com.oracle.coherence.plugin.visualvm.tablemodel.model.MemberData; import com.oracle.coherence.plugin.visualvm.tablemodel.model.NodeStorageData; import com.oracle.coherence.plugin.visualvm.VisualVMModel; @@ -88,6 +89,8 @@ import javax.swing.table.DefaultTableModel; import javax.swing.table.TableModel; +import static com.oracle.coherence.plugin.visualvm.helper.GraphHelper.MB; + /** * An abstract implementation of a {@link JPanel} which provides basic support @@ -296,9 +299,9 @@ protected String getFullyQualifiedName(RequestSender requestSender, String sQuer * @param nodeId the node id to check * @return true if the node is storage-enabled */ - protected boolean isNodeStorageEnabled(int nodeId) + public static boolean isNodeStorageEnabled(VisualVMModel model, int nodeId) { - List> nodeStorageData = f_model.getData(VisualVMModel.DataType.NODE_STORAGE); + List> nodeStorageData = model.getData(VisualVMModel.DataType.NODE_STORAGE); if (nodeStorageData != null) { @@ -773,8 +776,111 @@ protected static String getServiceName(String sSelectedServiceName) { String[] asParts = AbstractData.getDomainAndService(sSelectedServiceName); return asParts[1]; + } + + /** + * Return the machineData data for overview and tracers. + * + * @param machineData member data to introspect + * @return the data, 0 = Integer, count + * 1 = Double, cTotalLoadAverage + * 2 = Double, cMax + */ + public static Object[] getClusterLoadAverage(List> machineData) + { + int cCount = 0; + double cLoadAverage = 0; + double cMax = -1; + double cTotalLoadAverage = 0; + + // work out the max and average load averages for the graph + if (machineData != null) + { + for (Map.Entry entry : machineData) + { + cCount++; + cLoadAverage = (Double) entry.getValue().getColumn(MachineData.SYSTEM_LOAD_AVERAGE); + cTotalLoadAverage += cLoadAverage; + + if (cMax == -1 || cLoadAverage > cMax) + { + cMax = cLoadAverage; + } + } } + return new Object[] { + cCount, + cTotalLoadAverage, + cMax + }; + } + + /** + * Return the member data for overview and tracers. + * + * @param memberData member data to introspect + * @return the data, 0 = Integer, count + * 1 = Integer, totalMemory + * 2 = Integer, usedMemory + * 3 = Float, totalPublisherRate + * 4 = Float = totalReceiverRate + * 5 = Float = minPublisherRate + * 6 = Float = minReceiverRate + */ + public static Object[] getMemberMemoryRateData(VisualVMModel model, List> memberData) + { + int cTotalMemory = 0; + int cTotalMemoryUsed = 0; + float cTotalPublisherRate = 0.0f; + float cTotalReceiverRate = 0.0f; + float cMinPublisherRate = -1; + float cMinReceiverRate = -1; + int cCount = 0; + + // get the min /max values for publisher and receiver success rates + if (memberData != null) + { + float cRate = 0; + + for (Map.Entry entry : memberData) + { + // only include memory is the node is storage enabled + if (isNodeStorageEnabled(model, (Integer) entry.getValue().getColumn(MemberData.NODE_ID))) + { + cTotalMemory += (Integer) entry.getValue().getColumn(MemberData.MAX_MEMORY); + cTotalMemoryUsed += (Integer) entry.getValue().getColumn(MemberData.USED_MEMORY); + } + + cCount++; + cRate = (Float) entry.getValue().getColumn(MemberData.PUBLISHER_SUCCESS); + cTotalPublisherRate += cRate; + + if (cMinPublisherRate == -1 || cRate < cMinPublisherRate) + { + cMinPublisherRate = cRate; + } + + cRate = (Float) entry.getValue().getColumn(MemberData.RECEIVER_SUCCESS); + cTotalReceiverRate += cRate; + + if (cMinReceiverRate == -1 || cRate < cMinReceiverRate) + { + cMinReceiverRate = cRate; + } + } + } + + return new Object[] { + cCount, + cTotalMemory, + cTotalMemoryUsed, + cTotalPublisherRate, + cTotalReceiverRate, + cMinPublisherRate, + cMinReceiverRate + }; + } /** * Return the storage details. @@ -800,7 +906,7 @@ protected Object[] getStorageDetails(List> memberData) for (Map.Entry entry : memberData) { // only include memory if node is storage enabled - if (isNodeStorageEnabled((Integer) entry.getValue().getColumn(MemberData.NODE_ID))) + if (isNodeStorageEnabled(f_model, (Integer) entry.getValue().getColumn(MemberData.NODE_ID))) { cStorageCount++; cTotalMemory += (Integer) entry.getValue().getColumn(MemberData.MAX_MEMORY); @@ -871,7 +977,7 @@ protected Object[] getPersistenceData(List> persistenceD long cTotalBackup = (Long) entry.getValue().getColumn(PersistenceData.TOTAL_BACKUP_SPACE_USED_MB); cTotalActiveSpace += cTotalActive == -1 ? 0 : cTotalActive; - cTotalBackupSpace += cTotalBackup == -1 ? 0 : cTotalBackup * GraphHelper.MB; + cTotalBackupSpace += cTotalBackup == -1 ? 0 : cTotalBackup * MB; cLatencyTotal += (Float) entry.getValue().getColumn(PersistenceData.AVERAGE_LATENCY); diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/CoherenceClusterOverviewPanel.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/CoherenceClusterOverviewPanel.java index 9367ae1..c5d0e42 100755 --- a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/CoherenceClusterOverviewPanel.java +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/CoherenceClusterOverviewPanel.java @@ -185,46 +185,27 @@ public void updateGUI() float cTotalReceiverRate = 0.0f; float cMinPublisherRate = -1; float cMinReceiverRate = -1; + int cCount = 0; // get the min /max values for publisher and receiver success rates if (m_memberData != null) { - int count = 0; - float cRate = 0; + Object[] aoValues = getMemberMemoryRateData(f_model, m_memberData); - for (Entry entry : m_memberData) - { - // only include memory is the node is storage enabled - if (isNodeStorageEnabled((Integer) entry.getValue().getColumn(MemberData.NODE_ID))) - { - cTotalMemory += (Integer) entry.getValue().getColumn(MemberData.MAX_MEMORY); - cTotalMemoryUsed += (Integer) entry.getValue().getColumn(MemberData.USED_MEMORY); - } - - count++; - cRate = (Float) entry.getValue().getColumn(MemberData.PUBLISHER_SUCCESS); - cTotalPublisherRate += cRate; - - if (cMinPublisherRate == -1 || cRate < cMinPublisherRate) - { - cMinPublisherRate = cRate; - } - - cRate = (Float) entry.getValue().getColumn(MemberData.RECEIVER_SUCCESS); - cTotalReceiverRate += cRate; - - if (cMinReceiverRate == -1 || cRate < cMinReceiverRate) - { - cMinReceiverRate = cRate; - } - } + cCount = (Integer) aoValues[0]; + cTotalMemory = (Integer) aoValues[1]; + cTotalMemoryUsed = (Integer) aoValues[2]; + cTotalPublisherRate = (Float) aoValues[3]; + cTotalReceiverRate = (Float) aoValues[4]; + cMinPublisherRate = (Float) aoValues[5]; + cMinReceiverRate = (Float) aoValues[6]; // update the publisher graph GraphHelper.addValuesToPublisherGraph(f_publisherGraph, cMinPublisherRate, - count == 0 ? 0 : cTotalPublisherRate / count); + cCount == 0 ? 0 : cTotalPublisherRate / cCount); GraphHelper.addValuesToReceiverGraph(f_receiverGraph, cMinReceiverRate, - count == 0 ? 0 : cTotalReceiverRate / count); + cCount == 0 ? 0 : cTotalReceiverRate / cCount); } // update the memory graph @@ -282,24 +263,17 @@ else if (bestStatusHA == 1) } int count = 0; - double cLoadAverage = 0; double cMax = -1; double cTotalLoadAverage = 0; // work out the max and average load averages for the graph if (m_machineData != null) { - for (Entry entry : m_machineData) - { - count++; - cLoadAverage = (Double) entry.getValue().getColumn(MachineData.SYSTEM_LOAD_AVERAGE); - cTotalLoadAverage += cLoadAverage; - - if (cMax == -1 || cLoadAverage > cMax) - { - cMax = cLoadAverage; - } - } + Object[] aoValues = getClusterLoadAverage(m_machineData); + + count = (Integer) aoValues[0]; + cTotalLoadAverage = (Double) aoValues[1]; + cMax = (Double) aoValues[2]; // update graph GraphHelper.addValuesToLoadAverageGraph(f_loadAverageGraph, (float) cMax, diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/CoherenceMemberPanel.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/CoherenceMemberPanel.java index 3f54f92..0c4527e 100755 --- a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/CoherenceMemberPanel.java +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/panel/CoherenceMemberPanel.java @@ -284,7 +284,7 @@ public void updateData() { Data data = entry.getValue(); int nodeId = (Integer) entry.getKey(); - if (!isNodeStorageEnabled(nodeId)) + if (!isNodeStorageEnabled(f_model, nodeId)) { data.setColumn(MemberData.STORAGE_ENABLED, "false"); } diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/AbstractCoherenceMonitorProbe.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/AbstractCoherenceMonitorProbe.java new file mode 100644 index 0000000..3547ce3 --- /dev/null +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/AbstractCoherenceMonitorProbe.java @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2020, 2024 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.coherence.plugin.visualvm.tracer; + +import com.oracle.coherence.plugin.visualvm.Localization; +import com.oracle.coherence.plugin.visualvm.VisualVMModel; +import com.oracle.coherence.plugin.visualvm.tablemodel.model.Data; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import org.graalvm.visualvm.application.Application; +import org.graalvm.visualvm.modules.tracer.ItemValueFormatter; +import org.graalvm.visualvm.modules.tracer.ProbeItemDescriptor; +import org.graalvm.visualvm.modules.tracer.TracerProbe; +import org.openide.util.ImageUtilities; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import static com.oracle.coherence.plugin.visualvm.VisualVMView.IMAGE_PATH; + +/** + * Abstract implementations of a Coherence {@link TracerProbe}. + * @author tam 2024.03.03 + */ +public abstract class AbstractCoherenceMonitorProbe + extends TracerProbe + { + + // ----- constructors --------------------------------------------------- + + public AbstractCoherenceMonitorProbe(int valuesCount, ProbeItemDescriptor[] itemDescriptors, + MonitoredDataResolver resolver) + { + super(itemDescriptors); + this.f_nValuesCount = valuesCount; + this.f_resolver = resolver; + } + + public synchronized final long[] getItemValues(long timestamp) + { + VisualVMModel model = f_resolver.getMonitoredData(); + if (model != null) + { + return getValues(model); + } + + long[] noData = new long[f_nValuesCount]; + Arrays.fill(noData, ProbeItemDescriptor.VALUE_UNDEFINED); + return noData; + } + + protected static String getMonitorsString(String sKey) + { + return Localization.getLocalText("LBL_monitors") + " " + Localization.getLocalText(sKey); + } + + protected abstract long[] getValues(VisualVMModel model); + + public interface MonitoredDataResolver + { + VisualVMModel getMonitoredData(); + } + + protected long getValueAsLong(Object oValue) + { + if (oValue instanceof Long) + { + return (Long)oValue; + } + if (oValue instanceof Integer) + { + return (long)((Integer)oValue); + } + if (oValue instanceof String) + { + return Long.parseLong((String) oValue); + } + return 0L; + } + + /** + * Returns a single value from a data type. + * @param model the {@link VisualVMModel} to use + * @param dataType the {@link VisualVMModel.DataType} to query + * @param nColumn the column to extract + * @param aDefault default value + * + * @return the tracer result + */ + protected long[] getSingValue(VisualVMModel model, VisualVMModel.DataType dataType, int nColumn, long[] aDefault) + { + List> data = model.getData(dataType); + if (data == null || data.isEmpty()) + { + return aDefault; + } + + return new long[] {getValueAsLong(data.get(0).getValue().getColumn(nColumn))}; + } + + // ----- data members --------------------------------------------------- + + private final MonitoredDataResolver f_resolver; + + private final int f_nValuesCount; + + protected final long[] ZERO_VALUES2 = new long[]{0L,0L}; + protected final long[] ZERO_VALUES1 = new long[]{0L}; + + // ----- constants ------------------------------------------------------ + + public static final Icon ICON = new ImageIcon(ImageUtilities.loadImage(IMAGE_PATH, true)); // NOI18N + + public static final ItemValueFormatter CUSTOM_FORMATTER = new CustomFormatter(1000, ""); + + } diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/CustomFormatter.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/CustomFormatter.java new file mode 100644 index 0000000..f987bd9 --- /dev/null +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/CustomFormatter.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.coherence.plugin.visualvm.tracer; + +import org.graalvm.visualvm.modules.tracer.ItemValueFormatter; +import java.text.NumberFormat; + +/** + * A customer formatter. + * + * @author tam 2024.03.04 + */ +public class CustomFormatter + extends ItemValueFormatter { + + // ----- constructors --------------------------------------------------- + + public CustomFormatter(int factor, String units) + { + this.factor = factor; + this.units = units; + } + + @Override + public String formatValue(long value, int format) + { + return FORMAT.format(value / (double) this.factor); + } + + @Override + public String getUnits(int format) + { + return this.units; + } + + // ----- constants ------------------------------------------------------ + + private static final NumberFormat FORMAT = NumberFormat.getInstance(); + + + // ----- data members --------------------------------------------------- + + private final int factor; + private final String units; + + } diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/ClusterMonitorPackage.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/ClusterMonitorPackage.java new file mode 100644 index 0000000..73aa69d --- /dev/null +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/ClusterMonitorPackage.java @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.coherence.plugin.visualvm.tracer.cluster; + +import com.oracle.coherence.plugin.visualvm.Localization; +import com.oracle.coherence.plugin.visualvm.VisualVMModel; +import com.oracle.coherence.plugin.visualvm.VisualVMView; +import com.oracle.coherence.plugin.visualvm.tracer.AbstractCoherenceMonitorProbe; + +import org.graalvm.visualvm.application.Application; + +import org.graalvm.visualvm.modules.tracer.TracerPackage; +import org.graalvm.visualvm.modules.tracer.TracerProbe; +import org.graalvm.visualvm.modules.tracer.TracerProbeDescriptor; + +import static com.oracle.coherence.plugin.visualvm.tracer.AbstractCoherenceMonitorProbe.ICON; + + +/** + * A {@link TracerPackage} to show cluster related probes. + * + * @author tam 2024.03.04 + */ +public class ClusterMonitorPackage + extends TracerPackage implements AbstractCoherenceMonitorProbe.MonitoredDataResolver { + + public ClusterMonitorPackage(Application application) + { + super(NAME, DESCR, ICON, POSITION); + this.f_model = VisualVMView.getModelForApplication(application); + } + + // ---- TracerPackage methods ------------------------------------------- + + @Override + public TracerProbeDescriptor[] getProbeDescriptors() { + m_heapProbeDescriptor = StorageMembersHeapProbe.createDescriptor(f_model != null); + m_clusterSizeProbeDescriptor = ClusterSizeProbe.createDescriptor(f_model != null); + m_departureCountProbeDescriptor = DepartureCountProbe.createDescriptor(f_model != null); + m_packetPublisherProbeDescriptor = PacketPublisherProbe.createDescriptor(f_model != null); + m_packetReceiverProbeDescriptor = PacketReceiverProbe.createDescriptor(f_model != null); + m_loadAverageProbeDescriptor = LoadAverageProbe.createDescriptor(f_model != null); + + return new TracerProbeDescriptor[] { + m_heapProbeDescriptor, + m_clusterSizeProbeDescriptor, + m_departureCountProbeDescriptor, + m_packetPublisherProbeDescriptor, + m_packetReceiverProbeDescriptor, + m_loadAverageProbeDescriptor, + }; + } + + @Override + public TracerProbe getProbe(TracerProbeDescriptor descriptor) + { + if (descriptor == m_heapProbeDescriptor) + { + if (m_heapProbe == null) + { + m_heapProbe = new StorageMembersHeapProbe(this); + } + return m_heapProbe; + } + else if (descriptor == m_clusterSizeProbeDescriptor) + { + if (m_clusterSizeProbe == null) + { + m_clusterSizeProbe = new ClusterSizeProbe(this); + } + return m_clusterSizeProbe; + } + else if (descriptor == m_departureCountProbeDescriptor) + { + if (m_departureCountProbe == null) + { + m_departureCountProbe = new DepartureCountProbe(this); + } + return m_departureCountProbe; + } + else if (descriptor == m_packetPublisherProbeDescriptor) + { + if (m_packetPublisherProbe == null) + { + m_packetPublisherProbe = new PacketPublisherProbe(this); + } + return m_packetPublisherProbe; + } + else if (descriptor == m_packetReceiverProbeDescriptor) + { + if (m_packetReceiverProbe == null) + { + m_packetReceiverProbe = new PacketReceiverProbe(this); + } + return m_packetReceiverProbe; + } + else if (descriptor == m_loadAverageProbeDescriptor) + { + if (m_loadAverageProbe == null) + { + m_loadAverageProbe = new LoadAverageProbe(this); + } + return m_loadAverageProbe; + } + else + { + return null; + } + } + + // ---- AbstractCoherenceMonitorProbe.MonitoredDataResolver interface --- + + @Override + public VisualVMModel getMonitoredData() + { + return f_model; + } + + // ----- constants ------------------------------------------------------ + + private static final String NAME = Localization.getLocalText("LBL_cluster_probe"); + private static final String DESCR = Localization.getLocalText("LBL_cluster_probe_description"); + private static final int POSITION = 500; + + private TracerProbeDescriptor m_heapProbeDescriptor; + private TracerProbeDescriptor m_clusterSizeProbeDescriptor; + private TracerProbeDescriptor m_departureCountProbeDescriptor; + private TracerProbeDescriptor m_packetPublisherProbeDescriptor; + private TracerProbeDescriptor m_packetReceiverProbeDescriptor; + private TracerProbeDescriptor m_loadAverageProbeDescriptor; + + private AbstractCoherenceMonitorProbe m_heapProbe; + private AbstractCoherenceMonitorProbe m_clusterSizeProbe; + private AbstractCoherenceMonitorProbe m_departureCountProbe; + private AbstractCoherenceMonitorProbe m_packetPublisherProbe; + private AbstractCoherenceMonitorProbe m_packetReceiverProbe; + private AbstractCoherenceMonitorProbe m_loadAverageProbe; + + private final VisualVMModel f_model; + } diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/ClusterSizeProbe.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/ClusterSizeProbe.java new file mode 100644 index 0000000..68db5a0 --- /dev/null +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/ClusterSizeProbe.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.coherence.plugin.visualvm.tracer.cluster; + +import com.oracle.coherence.plugin.visualvm.Localization; +import com.oracle.coherence.plugin.visualvm.VisualVMModel; +import com.oracle.coherence.plugin.visualvm.tablemodel.model.ClusterData; + +import com.oracle.coherence.plugin.visualvm.tracer.AbstractCoherenceMonitorProbe; + +import org.graalvm.visualvm.modules.tracer.ItemValueFormatter; +import org.graalvm.visualvm.modules.tracer.ProbeItemDescriptor; +import org.graalvm.visualvm.modules.tracer.TracerProbeDescriptor; + +/** + * Tracer probe to return the cluster size. + * + * @author tam 2024.03.03 + */ +public class ClusterSizeProbe + extends AbstractCoherenceMonitorProbe + { + // ----- constructors --------------------------------------------------- + + public ClusterSizeProbe(MonitoredDataResolver resolver) + { + super(1, createItemDescriptors(), resolver); + } + + // ---- TracerProbe methods --------------------------------------------- + + @Override + public long[] getValues(VisualVMModel model) + { + return getSingValue(model, VisualVMModel.DataType.CLUSTER, ClusterData.CLUSTER_SIZE, ZERO_VALUES1); + } + + public static TracerProbeDescriptor createDescriptor(boolean available) + { + return new TracerProbeDescriptor(Localization.getLocalText("LBL_total_members"), + Localization.getLocalText("LBL_members_desc"), ICON, 5, available); + } + + private static ProbeItemDescriptor[] createItemDescriptors() + { + return new ProbeItemDescriptor[] + { + ProbeItemDescriptor.continuousLineFillItem(Localization.getLocalText("LBL_total_members"), + getMonitorsString("LBL_total_members"), ItemValueFormatter.DEFAULT_DECIMAL, + 1d, 0, 1), + }; + } + } diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/DepartureCountProbe.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/DepartureCountProbe.java new file mode 100644 index 0000000..4a2ad36 --- /dev/null +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/DepartureCountProbe.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.coherence.plugin.visualvm.tracer.cluster; + +import com.oracle.coherence.plugin.visualvm.Localization; +import com.oracle.coherence.plugin.visualvm.VisualVMModel; +import com.oracle.coherence.plugin.visualvm.tablemodel.model.ClusterData; + +import com.oracle.coherence.plugin.visualvm.tracer.AbstractCoherenceMonitorProbe; + +import org.graalvm.visualvm.modules.tracer.ItemValueFormatter; +import org.graalvm.visualvm.modules.tracer.ProbeItemDescriptor; +import org.graalvm.visualvm.modules.tracer.TracerProbeDescriptor; + +/** + * Tracer probe to return the members left. + * + * @author tam 2024.03.03 + */ +public class DepartureCountProbe + extends AbstractCoherenceMonitorProbe + { + + public DepartureCountProbe(MonitoredDataResolver resolver) + { + super(1, createItemDescriptors(), resolver); + } + + // ---- TracerProbe methods --------------------------------------------- + + @Override + public long[] getValues(VisualVMModel model) + { + return getSingValue(model, VisualVMModel.DataType.CLUSTER, ClusterData.DEPARTURE_COUNT, ZERO_VALUES1); + } + + public static TracerProbeDescriptor createDescriptor(boolean available) + { + return new TracerProbeDescriptor(Localization.getLocalText("LBL_member_departure_count"), + Localization.getLocalText("LBL_departure_count"), ICON, 10, available); + } + + private static ProbeItemDescriptor[] createItemDescriptors() + { + return new ProbeItemDescriptor[] + { + ProbeItemDescriptor.continuousLineFillItem(Localization.getLocalText("LBL_member_departure_count"), + getMonitorsString("LBL_member_departure_count"), ItemValueFormatter.DEFAULT_DECIMAL, + 1d, 0, 1), + }; + } + } diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/LoadAverageProbe.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/LoadAverageProbe.java new file mode 100644 index 0000000..accd272 --- /dev/null +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/LoadAverageProbe.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.coherence.plugin.visualvm.tracer.cluster; + +import java.util.List; +import java.util.Map; + +import static com.oracle.coherence.plugin.visualvm.helper.GraphHelper.GRPH_CURRENT_AVERAGE; +import static com.oracle.coherence.plugin.visualvm.helper.GraphHelper.GRPH_MAXIMUM; +import static com.oracle.coherence.plugin.visualvm.panel.AbstractCoherencePanel.getClusterLoadAverage; + +import com.oracle.coherence.plugin.visualvm.Localization; +import com.oracle.coherence.plugin.visualvm.VisualVMModel; +import com.oracle.coherence.plugin.visualvm.tablemodel.model.Data; +import com.oracle.coherence.plugin.visualvm.tracer.AbstractCoherenceMonitorProbe; +import org.graalvm.visualvm.modules.tracer.ProbeItemDescriptor; +import org.graalvm.visualvm.modules.tracer.TracerProbeDescriptor; + +/** + * Tracer probe to return average and max load average. + * + * @author tam 2024.03.03 + */ +public class LoadAverageProbe + extends AbstractCoherenceMonitorProbe + { + // ----- constructors --------------------------------------------------- + + public LoadAverageProbe(MonitoredDataResolver resolver) + { + super(2, LoadAverageProbe.createItemDescriptors(), resolver); + } + + // ---- TracerProbe methods --------------------------------------------- + + @Override + public long[] getValues(VisualVMModel model) + { + List> data = model.getData(VisualVMModel.DataType.MACHINE); + if (data == null || data.isEmpty()) + { + return ZERO_VALUES2; + } + + Object[] aoValues = getClusterLoadAverage(data); + + int cCount = (Integer) aoValues[0]; + double cTotalLoadAverage = (Double) aoValues[1]; + double cMax = (Double) aoValues[2]; + + return new long[] + { + (long) ((cTotalLoadAverage / (cCount * 1.0f)) * 1000), + (long) (cMax * 1000) + }; + } + + public static TracerProbeDescriptor createDescriptor(boolean available) + { + return new TracerProbeDescriptor(Localization.getLocalText("GRPH_load_average"), + Localization.getLocalText("LBL_load_average_desc"), ICON, 15, available); + } + + private static ProbeItemDescriptor[] createItemDescriptors() + { + return new ProbeItemDescriptor[] + { + ProbeItemDescriptor.continuousLineFillItem(Localization.getLocalText(GRPH_CURRENT_AVERAGE), + getMonitorsString(GRPH_CURRENT_AVERAGE), CUSTOM_FORMATTER, + 1000, 0, 1), + ProbeItemDescriptor.continuousLineFillItem(Localization.getLocalText(GRPH_MAXIMUM), + getMonitorsString(GRPH_MAXIMUM), CUSTOM_FORMATTER, + 1000, 0, 1) + }; + } + } diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/PacketPublisherProbe.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/PacketPublisherProbe.java new file mode 100644 index 0000000..1342c37 --- /dev/null +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/PacketPublisherProbe.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.coherence.plugin.visualvm.tracer.cluster; + +import java.util.List; +import java.util.Map; + +import static com.oracle.coherence.plugin.visualvm.helper.GraphHelper.GRPH_CURRENT_AVERAGE; +import static com.oracle.coherence.plugin.visualvm.helper.GraphHelper.GRPH_MINIMUM; +import static com.oracle.coherence.plugin.visualvm.panel.AbstractCoherencePanel.getMemberMemoryRateData; + +import com.oracle.coherence.plugin.visualvm.Localization; +import com.oracle.coherence.plugin.visualvm.VisualVMModel; +import com.oracle.coherence.plugin.visualvm.tablemodel.model.Data; +import com.oracle.coherence.plugin.visualvm.tracer.AbstractCoherenceMonitorProbe; + +import org.graalvm.visualvm.modules.tracer.ProbeItemDescriptor; +import org.graalvm.visualvm.modules.tracer.TracerProbeDescriptor; + +/** + * Tracer probe to return average and minimum package publisher. + * + * @author tam 2024.03.03 + */ +public class PacketPublisherProbe + extends AbstractCoherenceMonitorProbe + { + // ----- constructors --------------------------------------------------- + + public PacketPublisherProbe(MonitoredDataResolver resolver) + { + super(2, createItemDescriptors(), resolver); + } + + // ---- TracerProbe methods --------------------------------------------- + + @Override + public long[] getValues(VisualVMModel model) + { + List> data = model.getData(VisualVMModel.DataType.MEMBER); + if (data == null || data.isEmpty()) + { + return ZERO_VALUES2; + } + + Object[] aoValues = getMemberMemoryRateData(model, data); + + int cCount = (Integer) aoValues[0]; + float cTotalPublisherRate = (Float) aoValues[3]; + float cMinPublisherRate = (Float) aoValues[5]; + + return new long[] + { + (long) ((cTotalPublisherRate / (cCount * 1.0f)) * 1000), + (long) (cMinPublisherRate * 1000) + }; + + } + + public static TracerProbeDescriptor createDescriptor(boolean available) + { + return new TracerProbeDescriptor(Localization.getLocalText("GRPH_packet_publisher"), + Localization.getLocalText("LBL_packet_publisher_desc"), ICON, 15, available); + } + + protected static ProbeItemDescriptor[] createItemDescriptors() + { + return new ProbeItemDescriptor[] + { + ProbeItemDescriptor.continuousLineFillItem(Localization.getLocalText(GRPH_CURRENT_AVERAGE), + getMonitorsString(GRPH_CURRENT_AVERAGE), CUSTOM_FORMATTER, + 1, 0, 1000), + ProbeItemDescriptor.continuousLineFillItem(Localization.getLocalText(GRPH_MINIMUM), + getMonitorsString(GRPH_MINIMUM), CUSTOM_FORMATTER, + 1, 0, 1000) + }; + } + } diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/PacketReceiverProbe.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/PacketReceiverProbe.java new file mode 100644 index 0000000..bd80d8f --- /dev/null +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/PacketReceiverProbe.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.coherence.plugin.visualvm.tracer.cluster; + +import java.util.List; +import java.util.Map; + +import static com.oracle.coherence.plugin.visualvm.helper.GraphHelper.GRPH_CURRENT_AVERAGE; +import static com.oracle.coherence.plugin.visualvm.helper.GraphHelper.GRPH_MINIMUM; +import static com.oracle.coherence.plugin.visualvm.panel.AbstractCoherencePanel.getMemberMemoryRateData; + +import com.oracle.coherence.plugin.visualvm.Localization; +import com.oracle.coherence.plugin.visualvm.VisualVMModel; +import com.oracle.coherence.plugin.visualvm.tablemodel.model.Data; +import com.oracle.coherence.plugin.visualvm.tracer.AbstractCoherenceMonitorProbe; +import org.graalvm.visualvm.modules.tracer.ItemValueFormatter; +import org.graalvm.visualvm.modules.tracer.ProbeItemDescriptor; +import org.graalvm.visualvm.modules.tracer.TracerProbeDescriptor; + +/** + * Tracer probe to return average and minimum package receiver. + * + * @author tam 2024.03.03 + */ +public class PacketReceiverProbe + extends AbstractCoherenceMonitorProbe + { + // ----- constructors --------------------------------------------------- + + public PacketReceiverProbe(MonitoredDataResolver resolver) + { + super(2, PacketPublisherProbe.createItemDescriptors(), resolver); + } + + // ---- TracerProbe methods --------------------------------------------- + + @Override + public long[] getValues(VisualVMModel model) + { + List> data = model.getData(VisualVMModel.DataType.MEMBER); + if (data == null || data.isEmpty()) + { + return ZERO_VALUES2; + } + + Object[] aoValues = getMemberMemoryRateData(model, data); + + int cCount = (Integer) aoValues[0]; + float cTotalReceiverRate = (Float) aoValues[4]; + float cMinReceiverRate = (Float) aoValues[6]; + + return new long[] + { + (long) ((cTotalReceiverRate / (cCount * 1.0f)) * 1000), + (long) (cMinReceiverRate * 1000) + }; + + } + + public static TracerProbeDescriptor createDescriptor(boolean available) + { + return new TracerProbeDescriptor(Localization.getLocalText("GRPH_packet_receiver"), + Localization.getLocalText("LBL_packet_receiver_desc"), ICON, 15, available); + } + } diff --git a/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/StorageMembersHeapProbe.java b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/StorageMembersHeapProbe.java new file mode 100644 index 0000000..8310b21 --- /dev/null +++ b/coherence-visualvm-plugin/src/main/java/com/oracle/coherence/plugin/visualvm/tracer/cluster/StorageMembersHeapProbe.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.oracle.coherence.plugin.visualvm.tracer.cluster; + +import com.oracle.coherence.plugin.visualvm.Localization; +import com.oracle.coherence.plugin.visualvm.VisualVMModel; +import com.oracle.coherence.plugin.visualvm.tablemodel.model.Data; +import com.oracle.coherence.plugin.visualvm.tablemodel.model.MemberData; +import com.oracle.coherence.plugin.visualvm.tracer.AbstractCoherenceMonitorProbe; + +import org.graalvm.visualvm.modules.tracer.ItemValueFormatter; +import org.graalvm.visualvm.modules.tracer.ProbeItemDescriptor; +import org.graalvm.visualvm.modules.tracer.TracerProbeDescriptor; + +import java.util.List; +import java.util.Map; + +import static com.oracle.coherence.plugin.visualvm.helper.GraphHelper.GB; +import static com.oracle.coherence.plugin.visualvm.helper.GraphHelper.MB; +import static com.oracle.coherence.plugin.visualvm.panel.AbstractCoherencePanel.getMemberMemoryRateData; + +/** + * Tracer probe to return maximum and used storage heap for a cluster. + * + * @author tam 2024.03.03 + */ +public class StorageMembersHeapProbe + extends AbstractCoherenceMonitorProbe + { + // ----- constructors --------------------------------------------------- + + public StorageMembersHeapProbe(MonitoredDataResolver resolver) + { + super(2, createItemDescriptors(), resolver); + } + + // ---- TracerProbe methods --------------------------------------------- + + @Override + public long[] getValues(VisualVMModel model) + { + List> data = model.getData(VisualVMModel.DataType.MEMBER); + if (data == null || data.isEmpty()) + { + return ZERO_VALUES2; + } + Object[] aoValues = getMemberMemoryRateData(model, model.getData(VisualVMModel.DataType.MEMBER)); + + int cTotalMemory = (Integer) aoValues[1]; + int cTotalMemoryUsed = (Integer) aoValues[2]; + + return new long[] + { + (long) cTotalMemory * MB, + (long) cTotalMemoryUsed * MB, + }; + } + + public static TracerProbeDescriptor createDescriptor(boolean available) + { + return new TracerProbeDescriptor(Localization.getLocalText("GRPH_cluster_memory_details"), + Localization.getLocalText("LBL_storage_members_heap_desc"), ICON, 15, available); + } + + private static ProbeItemDescriptor[] createItemDescriptors() + { + return new ProbeItemDescriptor[] + { + ProbeItemDescriptor.continuousLineFillItem(Localization.getLocalText("GRPH_total_cluster_memory"), + getMonitorsString("GRPH_total_cluster_memory"), ItemValueFormatter.DEFAULT_BYTES, + 1d, 0, GB), + ProbeItemDescriptor.continuousLineFillItem(Localization.getLocalText("GRPH_used_cluster_memory"), + getMonitorsString("GRPH_used_cluster_memory"), ItemValueFormatter.DEFAULT_BYTES, + 1d, 0, GB) + }; + } + } diff --git a/coherence-visualvm-plugin/src/main/resources/com/oracle/coherence/plugin/visualvm/Bundle.properties b/coherence-visualvm-plugin/src/main/resources/com/oracle/coherence/plugin/visualvm/Bundle.properties index ec54de6..a0623f7 100644 --- a/coherence-visualvm-plugin/src/main/resources/com/oracle/coherence/plugin/visualvm/Bundle.properties +++ b/coherence-visualvm-plugin/src/main/resources/com/oracle/coherence/plugin/visualvm/Bundle.properties @@ -29,6 +29,8 @@ OpenIDE-Module-Long-Description=\ This plug-in provides a GUI to allow developers to view information about a running Coherence Cluster.
\ Once installed, when you connect to a local or remote process running a Coherence MBean server you will see a "Coherence Tab" \ which allows you to view Coherence related information for that cluster.

\ + Version 1.7.0 includes support for the VisualVM Tracer framework and includes various Coherence probes, which gather metrics from Coherence and display the data in a timeline.
\ + See the documentation on GitHub for more information.

\ The following tabs are displayed: \
    \
  • Cluster Overview - Displays high-level information about the Coherence cluster including cluster name, version, member count and 'Cluster StatusHA'. Summary graphs show total cluster memory available and used, packet publisher and receiver success rates and load averages for machines running Coherence.
  • \ @@ -705,4 +707,15 @@ LBL_error_discovering=Error discovering clusters on host {0}:{1}, {2}. LBL_confirm_add_clusters=Are you sure you want to add the following clusters discovered on this host?\n LBL_discovering_clusters=Discovering clusters on host {0}, port {1}... LBL_enter_cluster_port=Enter cluster port -LBL_invalid_cluster_port=Invalid cluster port {0}. \ No newline at end of file +LBL_invalid_cluster_port=Invalid cluster port {0}. + +# Monitor Probes +LBL_cluster_probe=Coherence - Cluster Overview +LBL_cluster_probe_description=Provides cluster based metrics as per Cluster Overview tab. +LBL_storage_members_heap_desc=Monitors allocated and used Heap size for storage members. +LBL_packet_publisher_desc=Monitors average and minimum packet publisher rates across all members. +LBL_packet_receiver_desc=Monitors average and minimum packet receiver rates across all members. +LBL_load_average_desc=Monitors average and maximum load average across all machines. +LBL_members_desc=Monitors the number of cluster members. +LBL_departure_count=Monitors the number of cluster members that have left. +LBL_monitors=Monitors \ No newline at end of file diff --git a/pom.xml b/pom.xml index dc8d164..ccf0ba6 100644 --- a/pom.xml +++ b/pom.xml @@ -65,9 +65,9 @@ 3.0.12 2.13.5 ${jackson.version} - 1.8 + 11 1.8 - 8 + 11 1.2.0 4.13.1 2.1 @@ -136,6 +136,13 @@ org-graalvm-visualvm-host ${visualvm.version} + + + org.graalvm.visualvm.modules + org-graalvm-visualvm-modules-tracer + ${visualvm.version} + + org.netbeans.api org-openide-modules @@ -259,6 +266,10 @@ ${java.version} ${java.version} ${java.version.release} + + --add-opens + jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED + diff --git a/scripts/install-tracer-library.sh b/scripts/install-tracer-library.sh new file mode 100755 index 0000000..f4e51dc --- /dev/null +++ b/scripts/install-tracer-library.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# +# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the LICENSE file that accompanied this code. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# +# +# Purpose: Build and install the org-graalvm-visualvm-modules-tracer plugin as it is not available in Maven. +set -e +echo "Installing required tracer VisualVM dependencies" +TEMP_DIR=`mktemp -d` +echo "Temp dir = ${TEMP_DIR}" + +trap "rm -rf $TEMP_DIR 2>&1 > /dev/null" 0 1 2 3 + +cd $TEMP_DIR +echo "Cloning VisualVM..." +git clone https://github.com/oracle/visualvm.git +cd visualvm +git checkout 2.1.7 + +curl -Lo /tmp/nb140_platform_20230511.zip https://github.com/oracle/visualvm/releases/download/2.1.7/nb140_platform_20230511.zip +cd visualvm +unzip /tmp/nb140_platform_20230511.zip + +echo "Building VisualVM..." +ant build-zip + +cd ../plugins +ant build + +MODULE_NAME=org-graalvm-visualvm-modules-tracer + +TRACER=`find . -name ${MODULE_NAME}.jar | sed 1q` +FULL_PATH=`pwd`/${TRACER} + +echo "Installing ${FULL_PATH}" + +set -x +mvn install:install-file -Dfile=${FULL_PATH} -DgroupId=org.graalvm.visualvm.modules -DartifactId=org-graalvm-visualvm-modules-tracer -Dversion=2.1 -Dpackaging=jar + +ls -l ~/.m2/repository/org/graalvm/visualvm/modules/org-graalvm-visualvm-modules-tracer/2.1 + + +