|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package io.opentelemetry.contrib.jmxscraper.target_systems; |
| 7 | + |
| 8 | +import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertGaugeWithAttributes; |
| 9 | +import static io.opentelemetry.contrib.jmxscraper.target_systems.MetricAssertions.assertSumWithAttributes; |
| 10 | +import static org.assertj.core.api.Assertions.entry; |
| 11 | + |
| 12 | +import io.opentelemetry.contrib.jmxscraper.JmxScraperContainer; |
| 13 | +import java.time.Duration; |
| 14 | +import org.testcontainers.containers.GenericContainer; |
| 15 | +import org.testcontainers.containers.wait.strategy.Wait; |
| 16 | +import org.testcontainers.images.builder.ImageFromDockerfile; |
| 17 | + |
| 18 | +public class ActiveMqIntegrationTest extends TargetSystemIntegrationTest { |
| 19 | + |
| 20 | + @Override |
| 21 | + protected GenericContainer<?> createTargetContainer(int jmxPort) { |
| 22 | + return new GenericContainer<>( |
| 23 | + new ImageFromDockerfile() |
| 24 | + .withDockerfileFromBuilder( |
| 25 | + builder -> builder.from("apache/activemq-classic:5.18.6").build())) |
| 26 | + .withEnv( |
| 27 | + "JAVA_TOOL_OPTIONS", |
| 28 | + "-Dcom.sun.management.jmxremote.port=" |
| 29 | + + jmxPort |
| 30 | + + " -Dcom.sun.management.jmxremote.rmi.port=" |
| 31 | + + jmxPort |
| 32 | + + " -Dcom.sun.management.jmxremote.ssl=false" |
| 33 | + + " -Dcom.sun.management.jmxremote.authenticate=false") |
| 34 | + .withStartupTimeout(Duration.ofMinutes(2)) |
| 35 | + .waitingFor(Wait.forListeningPort()); |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + protected JmxScraperContainer customizeScraperContainer(JmxScraperContainer scraper) { |
| 40 | + return scraper.withTargetSystem("activemq"); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + protected void verifyMetrics() { |
| 45 | + waitAndAssertMetrics( |
| 46 | + metric -> |
| 47 | + assertSumWithAttributes( |
| 48 | + metric, |
| 49 | + "activemq.consumer.count", |
| 50 | + "The number of consumers currently reading from the broker.", |
| 51 | + "consumers", |
| 52 | + /* isMonotonic= */ false, |
| 53 | + attrs -> |
| 54 | + attrs.containsOnly( |
| 55 | + entry("destination", "ActiveMQ.Advisory.MasterBroker"), |
| 56 | + entry("broker", "localhost"))), |
| 57 | + metric -> |
| 58 | + assertSumWithAttributes( |
| 59 | + metric, |
| 60 | + "activemq.producer.count", |
| 61 | + "The number of producers currently attached to the broker.", |
| 62 | + "producers", |
| 63 | + /* isMonotonic= */ false, |
| 64 | + attrs -> |
| 65 | + attrs.containsOnly( |
| 66 | + entry("destination", "ActiveMQ.Advisory.MasterBroker"), |
| 67 | + entry("broker", "localhost"))), |
| 68 | + metric -> |
| 69 | + assertSumWithAttributes( |
| 70 | + metric, |
| 71 | + "activemq.connection.count", |
| 72 | + "The total number of current connections.", |
| 73 | + "connections", |
| 74 | + /* isMonotonic= */ false, |
| 75 | + attrs -> attrs.containsOnly(entry("broker", "localhost"))), |
| 76 | + metric -> |
| 77 | + assertGaugeWithAttributes( |
| 78 | + metric, |
| 79 | + "activemq.memory.usage", |
| 80 | + "The percentage of configured memory used.", |
| 81 | + "%", |
| 82 | + attrs -> |
| 83 | + attrs.containsOnly( |
| 84 | + entry("destination", "ActiveMQ.Advisory.MasterBroker"), |
| 85 | + entry("broker", "localhost"))), |
| 86 | + metric -> |
| 87 | + assertGaugeWithAttributes( |
| 88 | + metric, |
| 89 | + "activemq.disk.store_usage", |
| 90 | + "The percentage of configured disk used for persistent messages.", |
| 91 | + "%", |
| 92 | + attrs -> attrs.containsOnly(entry("broker", "localhost"))), |
| 93 | + metric -> |
| 94 | + assertGaugeWithAttributes( |
| 95 | + metric, |
| 96 | + "activemq.disk.temp_usage", |
| 97 | + "The percentage of configured disk used for non-persistent messages.", |
| 98 | + "%", |
| 99 | + attrs -> attrs.containsOnly(entry("broker", "localhost"))), |
| 100 | + metric -> |
| 101 | + assertSumWithAttributes( |
| 102 | + metric, |
| 103 | + "activemq.message.current", |
| 104 | + "The current number of messages waiting to be consumed.", |
| 105 | + "messages", |
| 106 | + /* isMonotonic= */ false, |
| 107 | + attrs -> |
| 108 | + attrs.containsOnly( |
| 109 | + entry("destination", "ActiveMQ.Advisory.MasterBroker"), |
| 110 | + entry("broker", "localhost"))), |
| 111 | + metric -> |
| 112 | + assertSumWithAttributes( |
| 113 | + metric, |
| 114 | + "activemq.message.expired", |
| 115 | + "The total number of messages not delivered because they expired.", |
| 116 | + "messages", |
| 117 | + attrs -> |
| 118 | + attrs.containsOnly( |
| 119 | + entry("destination", "ActiveMQ.Advisory.MasterBroker"), |
| 120 | + entry("broker", "localhost"))), |
| 121 | + metric -> |
| 122 | + assertSumWithAttributes( |
| 123 | + metric, |
| 124 | + "activemq.message.enqueued", |
| 125 | + "The total number of messages received by the broker.", |
| 126 | + "messages", |
| 127 | + attrs -> |
| 128 | + attrs.containsOnly( |
| 129 | + entry("destination", "ActiveMQ.Advisory.MasterBroker"), |
| 130 | + entry("broker", "localhost"))), |
| 131 | + metric -> |
| 132 | + assertSumWithAttributes( |
| 133 | + metric, |
| 134 | + "activemq.message.dequeued", |
| 135 | + "The total number of messages delivered to consumers.", |
| 136 | + "messages", |
| 137 | + attrs -> |
| 138 | + attrs.containsOnly( |
| 139 | + entry("destination", "ActiveMQ.Advisory.MasterBroker"), |
| 140 | + entry("broker", "localhost"))), |
| 141 | + metric -> |
| 142 | + assertGaugeWithAttributes( |
| 143 | + metric, |
| 144 | + "activemq.message.wait_time.avg", |
| 145 | + "The average time a message was held on a destination.", |
| 146 | + "ms", |
| 147 | + attrs -> |
| 148 | + attrs.containsOnly( |
| 149 | + entry("destination", "ActiveMQ.Advisory.MasterBroker"), |
| 150 | + entry("broker", "localhost")))); |
| 151 | + } |
| 152 | +} |
0 commit comments