You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by rm...@apache.org on 2013/08/12 12:43:00 UTC
svn commit: r1513099 - in /commons/sandbox/monitoring/trunk: ./
core/src/main/java/org/apache/commons/monitoring/gauges/
core/src/main/java/org/apache/commons/monitoring/repositories/
core/src/main/java/org/apache/commons/monitoring/store/ jta/ jta/src...
Author: rmannibucau
Date: Mon Aug 12 10:42:58 2013
New Revision: 1513099
URL: http://svn.apache.org/r1513099
Log:
adding JTA plugin
Added:
commons/sandbox/monitoring/trunk/jta/
commons/sandbox/monitoring/trunk/jta/pom.xml
commons/sandbox/monitoring/trunk/jta/src/
commons/sandbox/monitoring/trunk/jta/src/main/
commons/sandbox/monitoring/trunk/jta/src/main/java/
commons/sandbox/monitoring/trunk/jta/src/main/java/org/
commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/
commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/commons/
commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/commons/monitoring/
commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/commons/monitoring/jta/
commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/commons/monitoring/jta/JTAGauges.java
commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/commons/monitoring/jta/JTAInterceptor.java
commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/commons/monitoring/jta/JTAMonitored.java
commons/sandbox/monitoring/trunk/jta/src/main/resources/
commons/sandbox/monitoring/trunk/jta/src/main/resources/META-INF/
commons/sandbox/monitoring/trunk/jta/src/main/resources/META-INF/beans.xml
commons/sandbox/monitoring/trunk/jta/src/main/resources/META-INF/services/
commons/sandbox/monitoring/trunk/jta/src/main/resources/META-INF/services/org.apache.commons.monitoring.gauges.GaugeFactory
commons/sandbox/monitoring/trunk/jta/src/test/
commons/sandbox/monitoring/trunk/jta/src/test/java/
commons/sandbox/monitoring/trunk/jta/src/test/java/org/
commons/sandbox/monitoring/trunk/jta/src/test/java/org/apache/
commons/sandbox/monitoring/trunk/jta/src/test/java/org/apache/commons/
commons/sandbox/monitoring/trunk/jta/src/test/java/org/apache/commons/monitoring/
commons/sandbox/monitoring/trunk/jta/src/test/java/org/apache/commons/monitoring/jta/
commons/sandbox/monitoring/trunk/jta/src/test/java/org/apache/commons/monitoring/jta/GaugesTest.java
commons/sandbox/monitoring/trunk/jta/src/test/resources/
commons/sandbox/monitoring/trunk/jta/src/test/resources/commons-monitoring.properties
commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/json/
commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/json/Jsons.java
commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/jta/
commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/jta/JTAEndpoints.java
commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/jta/JTAPlugin.java
commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/jta/
commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/jta/jta.vm
commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/macro.vm
commons/sandbox/monitoring/trunk/src/site/markdown/jta.md
- copied, changed from r1511211, commons/sandbox/monitoring/trunk/src/site/markdown/reporting.md
commons/sandbox/monitoring/trunk/web/src/main/java/org/apache/commons/monitoring/web/discovery/
commons/sandbox/monitoring/trunk/web/src/main/java/org/apache/commons/monitoring/web/discovery/GaugeDiscoveryListener.java
Removed:
commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/listener/
Modified:
commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/DefaultGaugeManager.java
commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/Gauge.java
commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/GaugeManager.java
commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/DefaultRepository.java
commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/Repository.java
commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DefaultDataStore.java
commons/sandbox/monitoring/trunk/pom.xml
commons/sandbox/monitoring/trunk/reporting/pom.xml
commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/jvm/JVMEndpoints.java
commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/template/Templates.java
commons/sandbox/monitoring/trunk/reporting/src/main/resources/META-INF/services/org.apache.commons.monitoring.reporting.web.plugin.Plugin
commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/jvm/jvm.vm
commons/sandbox/monitoring/trunk/reporting/src/main/webapp/WEB-INF/web.xml
commons/sandbox/monitoring/trunk/src/site/markdown/reporting.md
commons/sandbox/monitoring/trunk/src/site/site.xml
Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/DefaultGaugeManager.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/DefaultGaugeManager.java?rev=1513099&r1=1513098&r2=1513099&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/DefaultGaugeManager.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/DefaultGaugeManager.java Mon Aug 12 10:42:58 2013
@@ -19,11 +19,7 @@ package org.apache.commons.monitoring.ga
import org.apache.commons.monitoring.Role;
import org.apache.commons.monitoring.store.DataStore;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.LinkedList;
import java.util.Map;
-import java.util.ServiceLoader;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
@@ -37,11 +33,6 @@ public final class DefaultGaugeManager i
}
@Override
- public void start() {
- startFoundGaugeTimers();
- }
-
- @Override
public void stop() {
for (final Timer timer : timers.values()) {
timer.cancel();
@@ -49,39 +40,25 @@ public final class DefaultGaugeManager i
timers.clear();
}
- protected void startFoundGaugeTimers() {
- for (final Gauge gauge : findGauges()) {
- final Role role = gauge.role();
-
- this.store.createOrNoopGauge(role);
-
- final Timer timer = new Timer("gauge-" + role.getName() + "-timer", true);
- timers.put(role, timer);
- timer.scheduleAtFixedRate(new GaugeTask(store, gauge), 0, gauge.period());
- }
- }
-
- protected Collection<Gauge> findGauges() {
- // core (where gauge is) is often in an upper classloader so don't use Gauge classloader
- final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- final Collection<Gauge> gauges = new LinkedList<Gauge>();
- for (final Gauge g : ServiceLoader.load(Gauge.class, classLoader)) {
- gauges.add(g);
- }
- for (final GaugeFactory gf : ServiceLoader.load(GaugeFactory.class, classLoader)) {
- gauges.addAll(Arrays.asList(gf.gauges()));
- }
- return gauges;
- }
-
@Override
public void stopGauge(final Role role) {
- final Timer timer = timers.get(role);
+ final Timer timer = timers.remove(role);
if (timer != null) {
timer.cancel();
}
}
+ @Override
+ public void addGauge(final Gauge gauge) {
+ final Role role = gauge.role();
+
+ this.store.createOrNoopGauge(role);
+
+ final Timer timer = new Timer("gauge-" + role.getName() + "-timer", true);
+ timers.put(role, timer);
+ timer.scheduleAtFixedRate(new GaugeTask(store, gauge), 0, gauge.period());
+ }
+
private static class GaugeTask extends TimerTask {
private final Gauge gauge;
private final DataStore store;
Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/Gauge.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/Gauge.java?rev=1513099&r1=1513098&r2=1513099&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/Gauge.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/Gauge.java Mon Aug 12 10:42:58 2013
@@ -17,9 +17,51 @@
package org.apache.commons.monitoring.gauges;
import org.apache.commons.monitoring.Role;
+import org.apache.commons.monitoring.repositories.Repository;
+
+import java.util.LinkedList;
+import java.util.ServiceLoader;
public interface Gauge {
Role role();
double value();
long period();
+
+ public static class LoaderHelper {
+ private LinkedList<Gauge> gauges = new LinkedList<Gauge>();
+
+ public LoaderHelper(final boolean excludeParent, final String... includedPrefixes) {
+ final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+
+ for (final Gauge g : ServiceLoader.load(Gauge.class, classLoader)) {
+ addGaugeIfNecessary(classLoader, g, excludeParent, includedPrefixes);
+ }
+ for (final GaugeFactory gf : ServiceLoader.load(GaugeFactory.class, classLoader)) {
+ for (final Gauge g : gf.gauges()) {
+ addGaugeIfNecessary(classLoader, g, excludeParent, includedPrefixes);
+ }
+ }
+ }
+
+ private void addGaugeIfNecessary(final ClassLoader classLoader, final Gauge g, final boolean excludeParent, final String... prefixes) {
+ final Class<? extends Gauge> gaugeClass = g.getClass();
+ if (!excludeParent || gaugeClass.getClassLoader() == classLoader) {
+ if (prefixes != null) {
+ for (final String p : prefixes) {
+ if (!gaugeClass.getName().startsWith(p)) {
+ return;
+ }
+ }
+ }
+ Repository.INSTANCE.addGauge(g);
+ gauges.add(g);
+ }
+ }
+
+ public void destroy() {
+ for (final Gauge gauge : gauges) {
+ Repository.INSTANCE.stopGauge(gauge.role());
+ }
+ }
+ }
}
Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/GaugeManager.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/GaugeManager.java?rev=1513099&r1=1513098&r2=1513099&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/GaugeManager.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/gauges/GaugeManager.java Mon Aug 12 10:42:58 2013
@@ -19,9 +19,7 @@ package org.apache.commons.monitoring.ga
import org.apache.commons.monitoring.Role;
public interface GaugeManager {
- void start();
-
void stop();
-
+ void addGauge(Gauge gauge);
void stopGauge(Role role);
}
Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/DefaultRepository.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/DefaultRepository.java?rev=1513099&r1=1513098&r2=1513099&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/DefaultRepository.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/DefaultRepository.java Mon Aug 12 10:42:58 2013
@@ -20,6 +20,7 @@ import org.apache.commons.monitoring.Rol
import org.apache.commons.monitoring.configuration.Configuration;
import org.apache.commons.monitoring.counters.Counter;
import org.apache.commons.monitoring.gauges.DefaultGaugeManager;
+import org.apache.commons.monitoring.gauges.Gauge;
import org.apache.commons.monitoring.stopwatches.CounterStopWatch;
import org.apache.commons.monitoring.stopwatches.StopWatch;
import org.apache.commons.monitoring.store.DataStore;
@@ -36,11 +37,6 @@ public class DefaultRepository implement
this.gaugeManager = new DefaultGaugeManager(dataStore);
}
- @Configuration.Created
- public void startGaugeTimers() {
- gaugeManager.start(); // no persistence
- }
-
@Configuration.Destroying
public void stopGaugeTimers() {
gaugeManager.stop();
@@ -72,6 +68,11 @@ public class DefaultRepository implement
}
@Override
+ public void addGauge(final Gauge gauge) {
+ gaugeManager.addGauge(gauge);
+ }
+
+ @Override
public void stopGauge(final Role role) {
gaugeManager.stopGauge(role);
}
Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/Repository.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/Repository.java?rev=1513099&r1=1513098&r2=1513099&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/Repository.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/repositories/Repository.java Mon Aug 12 10:42:58 2013
@@ -20,6 +20,7 @@ package org.apache.commons.monitoring.re
import org.apache.commons.monitoring.Role;
import org.apache.commons.monitoring.configuration.Configuration;
import org.apache.commons.monitoring.counters.Counter;
+import org.apache.commons.monitoring.gauges.Gauge;
import org.apache.commons.monitoring.stopwatches.StopWatch;
import java.util.Map;
@@ -28,12 +29,10 @@ public interface Repository extends Iter
static final Repository INSTANCE = Configuration.newInstance(Repository.class);
Counter getCounter(Counter.Key key);
-
void clear();
-
StopWatch start(Counter counter);
- Map<Long, Double> getGaugeValues(long start, long end, Role role);
-
+ void addGauge(final Gauge gauge);
void stopGauge(Role role);
+ Map<Long, Double> getGaugeValues(long start, long end, Role role);
}
Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DefaultDataStore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DefaultDataStore.java?rev=1513099&r1=1513098&r2=1513099&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DefaultDataStore.java (original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/store/DefaultDataStore.java Mon Aug 12 10:42:58 2013
@@ -24,16 +24,16 @@ import org.apache.commons.monitoring.gau
import java.util.Collection;
import java.util.Collections;
-import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.locks.Lock;
public class DefaultDataStore implements DataStore {
private final ConcurrentMap<Counter.Key, Counter> counters = new ConcurrentHashMap<Counter.Key, Counter>(50);
- private final Map<Role, FixedSizedMap> gauges = new ConcurrentHashMap<Role, FixedSizedMap>();
+ private final Map<Role, Map<Long, Double>> gauges = new ConcurrentHashMap<Role, Map<Long, Double>>();
@Override
public Counter getOrCreateCounter(final Counter.Key key) {
@@ -81,8 +81,11 @@ public class DefaultDataStore implements
return Collections.emptyMap();
}
+ final Map<Long, Double> copy = new TreeMap<Long, Double>();
+ copy.putAll(map);
+
final Map<Long, Double> out = new TreeMap<Long, Double>();
- for (final Map.Entry<Long, Double> entry : map.entrySet()) {
+ for (final Map.Entry<Long, Double> entry : copy.entrySet()) {
final long time = entry.getKey();
if (time >= start && time <= end) {
out.put(time, entry.getValue());
@@ -102,11 +105,11 @@ public class DefaultDataStore implements
}
// no perf issues here normally since add is called not that often
- protected static class FixedSizedMap extends LinkedHashMap<Long, Double> {
+ protected static class FixedSizedMap extends ConcurrentSkipListMap<Long, Double> {
private static final int MAX_SIZE = Configuration.getInteger(Configuration.COMMONS_MONITORING_PREFIX + "gauge.max-size", 100);
protected FixedSizedMap() {
- super(MAX_SIZE);
+ // no-op
}
protected FixedSizedMap(final Map<Long, Double> value) {
@@ -114,12 +117,11 @@ public class DefaultDataStore implements
}
@Override
- protected boolean removeEldestEntry(final Map.Entry<Long, Double> eldest) {
- return size() > MAX_SIZE;
- }
-
- public synchronized Map<Long, Double> copy() {
- return Map.class.cast(super.clone());
+ public Double put(final Long key, final Double value) {
+ if (size() >= MAX_SIZE) {
+ remove(keySet().iterator().next());
+ }
+ return super.put(key, value);
}
}
}
Added: commons/sandbox/monitoring/trunk/jta/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/jta/pom.xml?rev=1513099&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/jta/pom.xml (added)
+++ commons/sandbox/monitoring/trunk/jta/pom.xml Mon Aug 12 10:42:58 2013
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>commons-monitoring-parent</artifactId>
+ <groupId>org.apache.commons.monitoring</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>commons-monitoring-jta</artifactId>
+ <name>Commons Monitoring (Sandbox) :: JTA</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jta_1.1_spec</artifactId>
+ <version>1.1.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jcdi_1.0_spec</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-interceptor_1.1_spec</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons.monitoring</groupId>
+ <artifactId>commons-monitoring-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-core</artifactId>
+ <version>4.5.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Added: commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/commons/monitoring/jta/JTAGauges.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/commons/monitoring/jta/JTAGauges.java?rev=1513099&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/commons/monitoring/jta/JTAGauges.java (added)
+++ commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/commons/monitoring/jta/JTAGauges.java Mon Aug 12 10:42:58 2013
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.monitoring.jta;
+
+import org.apache.commons.monitoring.Role;
+import org.apache.commons.monitoring.configuration.Configuration;
+import org.apache.commons.monitoring.counters.Unit;
+import org.apache.commons.monitoring.gauges.Gauge;
+import org.apache.commons.monitoring.gauges.GaugeFactory;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+public class JTAGauges implements GaugeFactory {
+ public static final Role JTA_COMMITED = new Role("jta-commited", Unit.UNARY);
+ public static final Role JTA_ROLLBACKED = new Role("jta-rollbacked", Unit.UNARY);
+ public static final Role JTA_ACTIVE = new Role("jta-active", Unit.UNARY);
+
+ static final AtomicLong ACTIVE = new AtomicLong(0);
+ static final AtomicLong COMMITTED = new AtomicLong(0);
+ static final AtomicLong ROLLBACKED = new AtomicLong(0);
+
+ @Override
+ public Gauge[] gauges() {
+ final long period = Configuration.getInteger(Configuration.COMMONS_MONITORING_PREFIX + "gauge.jta.period", 4000);
+ return new Gauge[] {
+ new JTAGauge(JTA_COMMITED, COMMITTED, period),
+ new JTAGauge(JTA_ROLLBACKED, ROLLBACKED, period),
+ new JTAActiveGauge(JTA_ACTIVE, ACTIVE, period)
+ };
+ }
+
+ protected static class JTAGauge implements Gauge {
+ private final Role role;
+ private final long period;
+ protected final AtomicLong counter;
+
+ protected JTAGauge(final Role role, final AtomicLong counter, final long period) {
+ this.role = role;
+ this.counter = counter;
+ this.period = period;
+ }
+
+ @Override
+ public Role role() {
+ return role;
+ }
+
+ @Override
+ public double value() {
+ return counter.getAndSet(0);
+ }
+
+ @Override
+ public long period() {
+ return period;
+ }
+ }
+
+ protected static class JTAActiveGauge extends JTAGauge {
+ protected JTAActiveGauge(final Role role, final AtomicLong counter, final long period) {
+ super(role, counter, period);
+ }
+
+ @Override
+ public double value() {
+ return counter.get();
+ }
+ }
+}
Added: commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/commons/monitoring/jta/JTAInterceptor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/commons/monitoring/jta/JTAInterceptor.java?rev=1513099&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/commons/monitoring/jta/JTAInterceptor.java (added)
+++ commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/commons/monitoring/jta/JTAInterceptor.java Mon Aug 12 10:42:58 2013
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.monitoring.jta;
+
+import javax.annotation.Resource;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.AroundTimeout;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.TransactionSynchronizationRegistry;
+
+@Interceptor
+@JTAMonitored
+public class JTAInterceptor {
+ private static final String RESOURCE_KEY = JTAInterceptor.class.getName();
+
+ @Resource
+ private TransactionSynchronizationRegistry transactionSynchronizationRegistry;
+
+ @AroundInvoke
+ @AroundTimeout
+ public Object jta(final InvocationContext invocationContext) throws Throwable {
+ if (transactionSynchronizationRegistry.getResource(RESOURCE_KEY) == null) {
+ JTAGauges.ACTIVE.incrementAndGet();
+ transactionSynchronizationRegistry.putResource(RESOURCE_KEY, Boolean.TRUE);
+ transactionSynchronizationRegistry.registerInterposedSynchronization(new JTACounterSynchronization());
+ }
+ return invocationContext.proceed();
+ }
+
+ private static class JTACounterSynchronization implements Synchronization {
+ @Override
+ public void beforeCompletion() {
+ // no-op
+ }
+
+ @Override
+ public void afterCompletion(final int status) {
+ if (status == Status.STATUS_COMMITTED) {
+ JTAGauges.COMMITTED.incrementAndGet();
+ } else if (status == Status.STATUS_ROLLEDBACK) {
+ JTAGauges.ROLLBACKED.incrementAndGet();
+ }
+ JTAGauges.ACTIVE.decrementAndGet();
+ }
+ }
+}
Added: commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/commons/monitoring/jta/JTAMonitored.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/commons/monitoring/jta/JTAMonitored.java?rev=1513099&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/commons/monitoring/jta/JTAMonitored.java (added)
+++ commons/sandbox/monitoring/trunk/jta/src/main/java/org/apache/commons/monitoring/jta/JTAMonitored.java Mon Aug 12 10:42:58 2013
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.monitoring.jta;
+
+import javax.interceptor.InterceptorBinding;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@InterceptorBinding
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface JTAMonitored {
+}
Added: commons/sandbox/monitoring/trunk/jta/src/main/resources/META-INF/beans.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/jta/src/main/resources/META-INF/beans.xml?rev=1513099&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/jta/src/main/resources/META-INF/beans.xml (added)
+++ commons/sandbox/monitoring/trunk/jta/src/main/resources/META-INF/beans.xml Mon Aug 12 10:42:58 2013
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+ <interceptors>
+ <class>org.apache.commons.monitoring.jta.JTAInterceptor</class>
+ </interceptors>
+</beans>
Added: commons/sandbox/monitoring/trunk/jta/src/main/resources/META-INF/services/org.apache.commons.monitoring.gauges.GaugeFactory
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/jta/src/main/resources/META-INF/services/org.apache.commons.monitoring.gauges.GaugeFactory?rev=1513099&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/jta/src/main/resources/META-INF/services/org.apache.commons.monitoring.gauges.GaugeFactory (added)
+++ commons/sandbox/monitoring/trunk/jta/src/main/resources/META-INF/services/org.apache.commons.monitoring.gauges.GaugeFactory Mon Aug 12 10:42:58 2013
@@ -0,0 +1 @@
+org.apache.commons.monitoring.jta.JTAGauges
Added: commons/sandbox/monitoring/trunk/jta/src/test/java/org/apache/commons/monitoring/jta/GaugesTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/jta/src/test/java/org/apache/commons/monitoring/jta/GaugesTest.java?rev=1513099&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/jta/src/test/java/org/apache/commons/monitoring/jta/GaugesTest.java (added)
+++ commons/sandbox/monitoring/trunk/jta/src/test/java/org/apache/commons/monitoring/jta/GaugesTest.java Mon Aug 12 10:42:58 2013
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.monitoring.jta;
+
+import org.apache.commons.monitoring.gauges.Gauge;
+import org.apache.commons.monitoring.repositories.Repository;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.ejb.EJB;
+import javax.ejb.Lock;
+import javax.ejb.LockType;
+import javax.ejb.Singleton;
+import javax.ejb.embeddable.EJBContainer;
+import java.util.Collection;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import static org.junit.Assert.assertEquals;
+
+public class GaugesTest {
+ private static final int ITERATIONS = 500;
+
+ private static Gauge.LoaderHelper gaugeLoader;
+
+ @BeforeClass
+ public static void init() {
+ Repository.INSTANCE.clear();
+ gaugeLoader = new Gauge.LoaderHelper(false);
+ }
+
+ @AfterClass
+ public static void reset() {
+ Repository.INSTANCE.clear();
+ gaugeLoader.destroy();
+ }
+
+ @EJB
+ private EjbWithJTASupport jtaSupport;
+
+ @Test
+ public void test() throws Exception {
+ final EJBContainer container = EJBContainer.createEJBContainer();
+ container.getContext().bind("inject", this);
+
+ final long start = System.currentTimeMillis();
+
+ final CountDownLatch latch = new CountDownLatch(ITERATIONS);
+ try {
+ final ExecutorService es = Executors.newFixedThreadPool(50);
+ for (int i = 0; i < ITERATIONS; i++) {
+ es.submit(new Runnable() {
+ @Override
+ public void run() {
+ jtaSupport.commit();
+ try {
+ jtaSupport.rollback();
+ } finally {
+ latch.countDown();
+ }
+ }
+ });
+ }
+ es.shutdown();
+ latch.await();
+
+ Thread.sleep(500); // wait last measure
+
+ final long end = System.currentTimeMillis();
+
+ assertEquals(ITERATIONS, sum(Repository.INSTANCE.getGaugeValues(start, end, JTAGauges.JTA_COMMITED).values()), 0);
+ assertEquals(ITERATIONS, sum(Repository.INSTANCE.getGaugeValues(start, end, JTAGauges.JTA_ROLLBACKED).values()), 0);
+
+ // due to the sleep we use in commit() we only see half of the tx when checking actives
+ assertEquals(ITERATIONS / 2, sum(Repository.INSTANCE.getGaugeValues(start, end, JTAGauges.JTA_ACTIVE).values()), ITERATIONS * .1);
+ } finally {
+ container.close();
+ }
+ }
+
+ private double sum(final Collection<Double> values) {
+ double sum = 0;
+ for (final Double d : values) {
+ sum += d;
+ }
+ return sum;
+ }
+
+ @Singleton
+ @Lock(LockType.READ)
+ @JTAMonitored
+ public static class EjbWithJTASupport {
+ public void commit() {
+ try {
+ Thread.sleep(50);
+ } catch (final InterruptedException e) {
+ // no-op
+ }
+ }
+
+ public void rollback() {
+ throw new NullPointerException();
+ }
+ }
+}
Added: commons/sandbox/monitoring/trunk/jta/src/test/resources/commons-monitoring.properties
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/jta/src/test/resources/commons-monitoring.properties?rev=1513099&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/jta/src/test/resources/commons-monitoring.properties (added)
+++ commons/sandbox/monitoring/trunk/jta/src/test/resources/commons-monitoring.properties Mon Aug 12 10:42:58 2013
@@ -0,0 +1,17 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+org.apache.commons.monitoring.gauge.jta.period = 100
Modified: commons/sandbox/monitoring/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/pom.xml?rev=1513099&r1=1513098&r2=1513099&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/pom.xml (original)
+++ commons/sandbox/monitoring/trunk/pom.xml Mon Aug 12 10:42:58 2013
@@ -42,9 +42,10 @@
<module>aop</module>
<module>cdi</module>
<module>spring</module>
+ <module>aspectj</module>
+ <module>jta</module>
<module>web</module>
<module>reporting</module>
- <module>aspectj</module>
</modules>
<developers>
@@ -168,6 +169,11 @@
<artifactId>commons-monitoring-instrumentation</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.commons.monitoring</groupId>
+ <artifactId>commons-monitoring-web</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</dependencyManagement>
Modified: commons/sandbox/monitoring/trunk/reporting/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/pom.xml?rev=1513099&r1=1513098&r2=1513099&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/pom.xml (original)
+++ commons/sandbox/monitoring/trunk/reporting/pom.xml Mon Aug 12 10:42:58 2013
@@ -39,6 +39,10 @@
<artifactId>commons-monitoring-core</artifactId>
<scope>provided</scope> <!-- using to put it in the container to get JDBC monitoring and deploy the webapp -->
</dependency>
+ <dependency>
+ <groupId>org.apache.commons.monitoring</groupId>
+ <artifactId>commons-monitoring-web</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Added: commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/json/Jsons.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/json/Jsons.java?rev=1513099&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/json/Jsons.java (added)
+++ commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/json/Jsons.java Mon Aug 12 10:42:58 2013
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.monitoring.reporting.web.plugin.json;
+
+import java.util.Iterator;
+import java.util.Map;
+
+public final class Jsons {
+ public static String toJson(final Map<Long, Double> data) { // helper for gauges
+ final StringBuilder builder = new StringBuilder().append("[");
+ final Iterator<Map.Entry<Long,Double>> iterator = data.entrySet().iterator();
+ while (iterator.hasNext()) {
+ final Map.Entry<Long, Double> entry = iterator.next();
+ builder.append("[").append(entry.getKey()).append(", ").append(entry.getValue()).append("]");
+ if (iterator.hasNext()) {
+ builder.append(", ");
+ }
+ }
+ return builder.append("]").toString();
+ }
+
+ private Jsons() {
+ // no-op
+ }
+}
Added: commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/jta/JTAEndpoints.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/jta/JTAEndpoints.java?rev=1513099&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/jta/JTAEndpoints.java (added)
+++ commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/jta/JTAEndpoints.java Mon Aug 12 10:42:58 2013
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.monitoring.reporting.web.plugin.jta;
+
+import org.apache.commons.monitoring.Role;
+import org.apache.commons.monitoring.counters.Unit;
+import org.apache.commons.monitoring.reporting.web.handler.api.Regex;
+import org.apache.commons.monitoring.reporting.web.handler.api.Template;
+import org.apache.commons.monitoring.reporting.web.plugin.json.Jsons;
+import org.apache.commons.monitoring.repositories.Repository;
+
+public class JTAEndpoints {
+ // copied to avoid classloading issue depending on the deployment, see org.apache.commons.monitoring.jta.JTAGauges
+ private static final Role COMMITED = new Role("jta-commited", Unit.UNARY);
+ private static final Role ROLLBACKED = new Role("jta-rollbacked", Unit.UNARY);
+ private static final Role ACTIVE = new Role("jta-active", Unit.UNARY);
+
+ @Regex
+ public Template home() {
+ return new Template("jta/jta.vm");
+ }
+
+ @Regex("/Commits/([0-9]*)/([0-9]*)")
+ public String commit(final long start, final long end) {
+ return "{ \"data\": " + Jsons.toJson(Repository.INSTANCE.getGaugeValues(start, end, COMMITED)) + ", \"label\": \"Commits\", \"color\": \"#317eac\" }";
+ }
+
+ @Regex("/Rollbacks/([0-9]*)/([0-9]*)")
+ public String rollback(final long start, final long end) {
+ return "{ \"data\": " + Jsons.toJson(Repository.INSTANCE.getGaugeValues(start, end, ROLLBACKED)) + ", \"label\": \"Rollback\", \"color\": \"#317eac\" }";
+ }
+
+ @Regex("/Actives/([0-9]*)/([0-9]*)")
+ public String active(final long start, final long end) {
+ return "{ \"data\": " + Jsons.toJson(Repository.INSTANCE.getGaugeValues(start, end, ACTIVE)) + ", \"label\": \"Active\", \"color\": \"#317eac\" }";
+ }
+}
Added: commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/jta/JTAPlugin.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/jta/JTAPlugin.java?rev=1513099&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/jta/JTAPlugin.java (added)
+++ commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/jta/JTAPlugin.java Mon Aug 12 10:42:58 2013
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.monitoring.reporting.web.plugin.jta;
+
+import org.apache.commons.monitoring.reporting.web.plugin.Plugin;
+
+public class JTAPlugin implements Plugin {
+ @Override
+ public String name() {
+ return "JTA";
+ }
+
+ @Override
+ public Class<?> endpoints() {
+ return JTAEndpoints.class;
+ }
+
+ @Override
+ public String mapping() {
+ return "/jta";
+ }
+}
Modified: commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/jvm/JVMEndpoints.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/jvm/JVMEndpoints.java?rev=1513099&r1=1513098&r2=1513099&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/jvm/JVMEndpoints.java (original)
+++ commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/plugin/jvm/JVMEndpoints.java Mon Aug 12 10:42:58 2013
@@ -18,6 +18,7 @@ package org.apache.commons.monitoring.re
import org.apache.commons.monitoring.reporting.web.handler.api.Regex;
import org.apache.commons.monitoring.reporting.web.handler.api.Template;
+import org.apache.commons.monitoring.reporting.web.plugin.json.Jsons;
import org.apache.commons.monitoring.reporting.web.plugin.jvm.gauges.CPUGauge;
import org.apache.commons.monitoring.reporting.web.plugin.jvm.gauges.UsedMemoryGauge;
import org.apache.commons.monitoring.reporting.web.template.MapBuilder;
@@ -47,24 +48,11 @@ public class JVMEndpoints {
@Regex("/cpu/([0-9]*)/([0-9]*)")
public String cpu(final long start, final long end) {
- return "{ \"data\": " + toJson(Repository.INSTANCE.getGaugeValues(start, end, CPUGauge.CPU)) + ", \"label\": \"CPU Usage\", \"color\": \"#317eac\" }";
+ return "{ \"data\": " + Jsons.toJson(Repository.INSTANCE.getGaugeValues(start, end, CPUGauge.CPU)) + ", \"label\": \"CPU Usage\", \"color\": \"#317eac\" }";
}
@Regex("/memory/([0-9]*)/([0-9]*)")
public String memory(final long start, final long end) {
- return "{ \"data\": " + toJson(Repository.INSTANCE.getGaugeValues(start, end, UsedMemoryGauge.USED_MEMORY)) + ", \"label\": \"Used Memory\", \"color\": \"#317eac\" }";
- }
-
- private String toJson(final Map<Long, Double> data) {
- final StringBuilder builder = new StringBuilder().append("[");
- final Iterator<Map.Entry<Long,Double>> iterator = data.entrySet().iterator();
- while (iterator.hasNext()) {
- final Map.Entry<Long, Double> entry = iterator.next();
- builder.append("[").append(entry.getKey()).append(", ").append(entry.getValue()).append("]");
- if (iterator.hasNext()) {
- builder.append(", ");
- }
- }
- return builder.append("]").toString();
+ return "{ \"data\": " + Jsons.toJson(Repository.INSTANCE.getGaugeValues(start, end, UsedMemoryGauge.USED_MEMORY)) + ", \"label\": \"Used Memory\", \"color\": \"#317eac\" }";
}
}
Modified: commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/template/Templates.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/template/Templates.java?rev=1513099&r1=1513098&r2=1513099&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/template/Templates.java (original)
+++ commons/sandbox/monitoring/trunk/reporting/src/main/java/org/apache/commons/monitoring/reporting/web/template/Templates.java Mon Aug 12 10:42:58 2013
@@ -40,6 +40,7 @@ public final class Templates {
velocityConfiguration.setProperty(RuntimeConstants.RUNTIME_REFERENCES_STRICT, Boolean.TRUE.toString());
velocityConfiguration.setProperty(RuntimeConstants.RUNTIME_REFERENCES_STRICT_ESCAPE, Boolean.TRUE.toString());
velocityConfiguration.setProperty(RuntimeConstants.RESOURCE_LOADER, "monitoring");
+ velocityConfiguration.setProperty(RuntimeConstants.VM_LIBRARY, "/templates/macro.vm");
velocityConfiguration.setProperty("monitoring." + RuntimeConstants.RESOURCE_LOADER + ".class", ClasspathResourceLoader.class.getName());
Velocity.init(velocityConfiguration);
Modified: commons/sandbox/monitoring/trunk/reporting/src/main/resources/META-INF/services/org.apache.commons.monitoring.reporting.web.plugin.Plugin
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/resources/META-INF/services/org.apache.commons.monitoring.reporting.web.plugin.Plugin?rev=1513099&r1=1513098&r2=1513099&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/main/resources/META-INF/services/org.apache.commons.monitoring.reporting.web.plugin.Plugin (original)
+++ commons/sandbox/monitoring/trunk/reporting/src/main/resources/META-INF/services/org.apache.commons.monitoring.reporting.web.plugin.Plugin Mon Aug 12 10:42:58 2013
@@ -1,3 +1,4 @@
org.apache.commons.monitoring.reporting.web.plugin.report.ReportPlugin
org.apache.commons.monitoring.reporting.web.plugin.jmx.JMXPlugin
org.apache.commons.monitoring.reporting.web.plugin.jvm.JVMPlugin
+org.apache.commons.monitoring.reporting.web.plugin.jta.JTAPlugin
Added: commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/jta/jta.vm
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/jta/jta.vm?rev=1513099&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/jta/jta.vm (added)
+++ commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/jta/jta.vm Mon Aug 12 10:42:58 2013
@@ -0,0 +1,92 @@
+#*
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*#
+#macro ( graph $name )
+<div class="span4">
+ <div class="page-header">
+ <h2>$name</h2>
+ </div>
+
+ <div id="${name}-graph" class="plot"></div>
+ #dateForm('$name')
+</div>
+#end
+
+#set ( $parts = ["Commits", "Rollbacks", "Actives"])
+
+<div class="container-fluid">
+ <div class="row-fluid">
+ #foreach ($item in $parts )
+ #graph($item)
+ #end
+ </div>
+</div>
+
+<script type="text/javascript" src="$mapping/resources/js/bootstrap-datetimepicker.min.js"></script>
+<script type="text/javascript" src="$mapping/resources/js/jquery.flot.min.js"></script>
+<script type="text/javascript" src="$mapping/resources/js/jquery.flot.time.min.js"></script>
+<script type="text/javascript">
+ $(function() {
+ #foreach ($item in $parts )
+ $('#${item}-datetimepicker-start').datetimepicker();
+ $('#${item}-datetimepicker-end').datetimepicker();
+ #end
+
+ var options = {
+ canvas: true,
+ series: { lines: { show: true }, points: { show: true } },
+ grid: { hoverable: true, clickable: true },
+ xaxes: [ { mode: "time", timezone: "browser" } ],
+ yaxes: [ { min: 0 } ]
+ };
+
+ var updateGraph = function (graph, start, end, options) {
+ $.ajax({
+ url: "$mapping/jta/" + graph + "/" + start + "/" + end,
+ type: "GET",
+ dataType: "json",
+ success: function (data) {
+ $.plot("#" + graph + "-graph", [ data ], options);
+ }
+ });
+ };
+
+ var extractTime = function (picker) {
+ return picker.data('datetimepicker').getLocalDate().getTime();
+ };
+
+ (function () { // init
+ var now = new Date();
+ var yesterday = new Date();
+ yesterday.setMinutes(now.getMinutes() - 10);
+
+ var start = yesterday.getTime();
+ var end = now.getTime();
+
+ #foreach ($item in $parts )
+ updateGraph("$item", start, end, options);
+ #end
+ })();
+
+ // update diagram when clicking on update buttons
+ #foreach ($item in $parts )
+ $('#update-$item').submit(function () {
+ updateGraph($item, extractTime($('#${item}-datetimepicker-start')), extractTime($('#${item}-datetimepicker-end')), options);
+ return false;
+ });
+ #end
+ });
+</script>
Modified: commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/jvm/jvm.vm
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/jvm/jvm.vm?rev=1513099&r1=1513098&r2=1513099&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/jvm/jvm.vm (original)
+++ commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/jvm/jvm.vm Mon Aug 12 10:42:58 2013
@@ -14,23 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
*#
-#macro ( datePicker $label $id )
- <div id="$id" class="input-append date">
- <label for="$id">$label</label>
- <input data-format="dd/MM/yyyy hh:mm:ss" type="text">
- <span class="add-on">
- <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
- </span>
- </div>
-#end
-#macro (dateForm $id)
- <form class="form-inline" id="update-$id">
- #datePicker("From", "${id}-datetimepicker-start")
- #datePicker("To", "${id}-datetimepicker-end")
- <button type="submit" class="btn btn-primary">Update</button>
- </form>
-#end
-
<div class="container-fluid">
<div class="row-fluid">
<div class="span6">
Added: commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/macro.vm
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/macro.vm?rev=1513099&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/macro.vm (added)
+++ commons/sandbox/monitoring/trunk/reporting/src/main/resources/templates/macro.vm Mon Aug 12 10:42:58 2013
@@ -0,0 +1,33 @@
+#*
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*#
+#macro ( datePicker $label $id )
+<div id="$id" class="input-append date">
+ <label for="$id">$label</label>
+ <input data-format="dd/MM/yyyy hh:mm:ss" type="text">
+ <span class="add-on">
+ <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
+ </span>
+</div>
+#end
+
+#macro (dateForm $id)
+<form class="form-inline" id="update-$id">
+ #datePicker("From", "${id}-datetimepicker-start")
+ #datePicker("To", "${id}-datetimepicker-end")
+ <button type="submit" class="btn btn-primary">Update</button>
+</form>
+#end
Modified: commons/sandbox/monitoring/trunk/reporting/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/reporting/src/main/webapp/WEB-INF/web.xml?rev=1513099&r1=1513098&r2=1513099&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/reporting/src/main/webapp/WEB-INF/web.xml (original)
+++ commons/sandbox/monitoring/trunk/reporting/src/main/webapp/WEB-INF/web.xml Mon Aug 12 10:42:58 2013
@@ -20,8 +20,13 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
+ <context-param> <!-- only register this webapp gauges -->
+ <param-name>monitoring.discovery.packages</param-name>
+ <param-value>org.apache.commons.monitoring.reporting.web.plugin</param-value>
+ </context-param>
+
<listener>
- <listener-class>org.apache.commons.monitoring.reporting.web.listener.CleanupListener</listener-class>
+ <listener-class>org.apache.commons.monitoring.web.discovery.GaugeDiscoveryListener</listener-class>
</listener>
<filter>
Copied: commons/sandbox/monitoring/trunk/src/site/markdown/jta.md (from r1511211, commons/sandbox/monitoring/trunk/src/site/markdown/reporting.md)
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/site/markdown/jta.md?p2=commons/sandbox/monitoring/trunk/src/site/markdown/jta.md&p1=commons/sandbox/monitoring/trunk/src/site/markdown/reporting.md&r1=1511211&r2=1513099&rev=1513099&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/site/markdown/reporting.md (original)
+++ commons/sandbox/monitoring/trunk/src/site/markdown/jta.md Mon Aug 12 10:42:58 2013
@@ -16,69 +16,28 @@ KIND, either express or implied. See th
specific language governing permissions and limitations
under the License.
-->
-## Reporting module
+## JTA module
-Reporting module provides a lightweight GUI to visualize monitoring information.
+This module aims to monitor commits/rollbacks and active transaction number.
## Installation
-### The webapp
-commons-monitoring-reporting is available as a webapp (.war) so you can just drop it in your servlet container.
-
-Note 1: commons-monitoring-core is not provided and should be in the container.
-Note 2: if you use commons-monitoring-jdbc put it in the container too.
-
-### Embeded in your web application
-
-Just adding commons-monitoring-reporting jar (classifier `classes` if you use maven) in your application
-you can embed it. You'll need to update your web.xml to declare the monitoring filter:
+`commons-monitoring-jta` should be added to your webapp. You need to register the jta gauges. To do it the easiest is
+to add `commons-monitoring-web` to your webapp and register the listener `org.apache.commons.monitoring.web.discovery.GaugeDiscoveryListener`:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
-
<listener>
- <listener-class>org.apache.commons.monitoring.reporting.web.listener.CleanupListener</listener-class>
+ <listener-class>org.apache.commons.monitoring.web.discovery.GaugeDiscoveryListener</listener-class>
</listener>
-
- <filter>
- <filter-name>Monitoring</filter-name>
- <filter-class>org.apache.commons.monitoring.reporting.web.MonitoringController</filter-class>
- <init-param> <!-- should match your filter mapping base -->
- <param-name>monitoring-mapping</param-name>
- <param-value>/monitoring/</param-value>
- </init-param>
- </filter>
-
- <filter-mapping>
- <filter-name>Monitoring</filter-name>
- <url-pattern>/monitoring/*</url-pattern>
- </filter-mapping>
-
</web-app>
-## Usage
-
-Once started you'll arrive on the home page which should look like:
-
-![Home](images/gui/home.png)
-
-By default you have three activated plugins:
-
-* Report: view to work with counter data
-* JMX: access to MBeans (read attribute, invoke operations)
-* JVM: basic measure of CPU and used heap memory
-
-### Report
-
-![Report](images/gui/report.png)
-
-### JMX
-
-![JMX](images/gui/mbean-attributes.png)
-![JMX](images/gui/mbean-operations.png)
+Note: you can register it manually using `org.apache.commons.monitoring.gauges.Gauge$LoaderHelper` or `org.apache.commons.monitoring.repositories.Repository#addGauge`.
-### JVM
+Then you need to add on the beans which can be enrolled in transactions you want to monitor the annotation
+`org.apache.commons.monitoring.jta.JTAMonitored` (CDI beans) or the interceptor `org.apache.commons.monitoring.jta.JTAInterceptor`
+(for EJB for instance it can be done through configuration, see ejb-jar.xml).
-![JVM](images/gui/jvm.png)
+Note: we are working to make it configurable - same note as for CDI module.
Modified: commons/sandbox/monitoring/trunk/src/site/markdown/reporting.md
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/site/markdown/reporting.md?rev=1513099&r1=1513098&r2=1513099&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/site/markdown/reporting.md (original)
+++ commons/sandbox/monitoring/trunk/src/site/markdown/reporting.md Mon Aug 12 10:42:58 2013
@@ -39,7 +39,7 @@ you can embed it. You'll need to update
version="2.5">
<listener>
- <listener-class>org.apache.commons.monitoring.reporting.web.listener.CleanupListener</listener-class>
+ <listener-class>org.apache.commons.monitoring.reporting.web.listener.MonitoringListener</listener-class>
</listener>
<filter>
Modified: commons/sandbox/monitoring/trunk/src/site/site.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/site/site.xml?rev=1513099&r1=1513098&r2=1513099&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/site/site.xml (original)
+++ commons/sandbox/monitoring/trunk/src/site/site.xml Mon Aug 12 10:42:58 2013
@@ -50,6 +50,7 @@
<item name="Instrumentation" href="/instrumentation.html"/>
<item name="Reporting" href="/reporting.html"/>
<item name="Plugins" href="/plugins.html"/>
+ <item name="JTA" href="/jta.html"/>
</menu>
</body>
</project>
Added: commons/sandbox/monitoring/trunk/web/src/main/java/org/apache/commons/monitoring/web/discovery/GaugeDiscoveryListener.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/web/src/main/java/org/apache/commons/monitoring/web/discovery/GaugeDiscoveryListener.java?rev=1513099&view=auto
==============================================================================
--- commons/sandbox/monitoring/trunk/web/src/main/java/org/apache/commons/monitoring/web/discovery/GaugeDiscoveryListener.java (added)
+++ commons/sandbox/monitoring/trunk/web/src/main/java/org/apache/commons/monitoring/web/discovery/GaugeDiscoveryListener.java Mon Aug 12 10:42:58 2013
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.monitoring.web.discovery;
+
+import org.apache.commons.monitoring.gauges.Gauge;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+public class GaugeDiscoveryListener implements ServletContextListener {
+ private Gauge.LoaderHelper helper;
+
+ @Override
+ public void contextInitialized(final ServletContextEvent sce) {
+ final String prefixesStr = sce.getServletContext().getInitParameter("monitoring.discovery.packages");
+ final String[] prefixes;
+ if (prefixesStr != null) {
+ prefixes = prefixesStr.split(",");
+ } else {
+ prefixes = new String[0];
+ }
+ helper = new Gauge.LoaderHelper("true".equals(sce.getServletContext().getInitParameter("monitoring.discovery.exclude-parent")), prefixes);
+ }
+
+ @Override
+ public void contextDestroyed(final ServletContextEvent sce) {
+ helper.destroy();
+ }
+}