|
| 1 | +// Copyright (c) 2018 Pivotal Software, Inc. All rights reserved. |
| 2 | +// |
| 3 | +// This software, the RabbitMQ Java client library, is triple-licensed under the |
| 4 | +// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2 |
| 5 | +// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see |
| 6 | +// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL, |
| 7 | +// please see LICENSE-APACHE2. |
| 8 | +// |
| 9 | +// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, |
| 10 | +// either express or implied. See the LICENSE file for specific language governing |
| 11 | +// rights and limitations of this software. |
| 12 | +// |
| 13 | +// If you have any questions regarding licensing, please contact us at |
| 14 | + |
| 15 | + |
| 16 | +package com.rabbitmq.perf; |
| 17 | + |
| 18 | +import com.rabbitmq.client.ConnectionFactory; |
| 19 | +import com.rabbitmq.client.impl.MicrometerMetricsCollector; |
| 20 | +import io.micrometer.core.instrument.Tag; |
| 21 | +import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics; |
| 22 | +import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics; |
| 23 | +import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics; |
| 24 | +import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics; |
| 25 | +import io.micrometer.core.instrument.binder.system.ProcessorMetrics; |
| 26 | +import io.micrometer.core.instrument.composite.CompositeMeterRegistry; |
| 27 | +import org.apache.commons.cli.Option; |
| 28 | +import org.apache.commons.cli.Options; |
| 29 | + |
| 30 | +import java.util.ArrayList; |
| 31 | +import java.util.Collection; |
| 32 | + |
| 33 | +import static com.rabbitmq.perf.PerfTest.strArg; |
| 34 | + |
| 35 | +/** |
| 36 | + * |
| 37 | + */ |
| 38 | +public class BaseMetrics implements Metrics { |
| 39 | + |
| 40 | + @Override |
| 41 | + public Options options() { |
| 42 | + Options options = new Options(); |
| 43 | + options.addOption(new Option("mt", "metrics-tags", true, "metrics tags as key-value pairs separated by commas")); |
| 44 | + options.addOption(new Option("mpx", "metrics-prefix", true, "prefix for PerfTest metrics, default is perftest_")); |
| 45 | + options.addOption(new Option("mc", "metrics-client", false, "enable client metrics")); |
| 46 | + options.addOption(new Option("mcl", "metrics-class-loader", false, "enable JVM class loader metrics")); |
| 47 | + options.addOption(new Option("mjm", "metrics-jvm-memory", false, "enable JVM memory metrics")); |
| 48 | + options.addOption(new Option("mjgc", "metrics-jvm-gc", false, "enable JVM GC metrics")); |
| 49 | + options.addOption(new Option("mjp", "metrics-processor", false, "enable processor metrics (gathered by JVM)")); |
| 50 | + options.addOption(new Option("mjt", "metrics-jvm-thread", false, "enable JVM thread metrics")); |
| 51 | + |
| 52 | + return options; |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public void configure(CommandLineProxy cmd, CompositeMeterRegistry meterRegistry, ConnectionFactory factory) { |
| 57 | + String argumentTags = strArg(cmd, "mt", null); |
| 58 | + Collection<Tag> tags = new ArrayList<>(); |
| 59 | + if (argumentTags != null) { |
| 60 | + for (String tag : argumentTags.split(",")) { |
| 61 | + String[] keyValue = tag.split("="); |
| 62 | + tags.add(Tag.of(keyValue[0], keyValue[1])); |
| 63 | + } |
| 64 | + } |
| 65 | + meterRegistry.config().commonTags(tags); |
| 66 | + if (cmd.hasOption("mc")) { |
| 67 | + factory.setMetricsCollector(new MicrometerMetricsCollector(meterRegistry, "client")); |
| 68 | + } |
| 69 | + |
| 70 | + if (cmd.hasOption("mcl")) { |
| 71 | + new ClassLoaderMetrics().bindTo(meterRegistry); |
| 72 | + } |
| 73 | + if (cmd.hasOption("mjm")) { |
| 74 | + new JvmMemoryMetrics().bindTo(meterRegistry); |
| 75 | + } |
| 76 | + if (cmd.hasOption("mjgc")) { |
| 77 | + new JvmGcMetrics().bindTo(meterRegistry); |
| 78 | + } |
| 79 | + if (cmd.hasOption("mjp")) { |
| 80 | + new ProcessorMetrics().bindTo(meterRegistry); |
| 81 | + } |
| 82 | + if (cmd.hasOption("mjt")) { |
| 83 | + new JvmThreadMetrics().bindTo(meterRegistry); |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public String toString() { |
| 89 | + return "Base Metrics"; |
| 90 | + } |
| 91 | +} |
0 commit comments