You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sirona.apache.org by rm...@apache.org on 2013/11/13 09:55:56 UTC
svn commit: r1541429 - in /incubator/sirona/trunk:
agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/repository/
core/src/main/java/org/apache/sirona/gauges/jmx/
Author: rmannibucau
Date: Wed Nov 13 08:55:56 2013
New Revision: 1541429
URL: http://svn.apache.org/r1541429
Log:
adding JMXAttributeGaugeBase to ease the addition of custom JMX based gauges
Added:
incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jmx/
incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jmx/JMXAttributeGaugeBase.java
Modified:
incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/repository/PullRepository.java
Modified: incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/repository/PullRepository.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/repository/PullRepository.java?rev=1541429&r1=1541428&r2=1541429&view=diff
==============================================================================
--- incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/repository/PullRepository.java (original)
+++ incubator/sirona/trunk/agent/pull/src/main/java/org/apache/sirona/agent/webapp/pull/repository/PullRepository.java Wed Nov 13 08:55:56 2013
@@ -66,7 +66,11 @@ public class PullRepository extends Defa
// gauges
for (final Gauge g : getGauges()) {
- answer.append(cube.gaugeSnapshot(time, g.role(), g.value()));
+ try {
+ answer.append(cube.gaugeSnapshot(time, g.role(), g.value()));
+ } catch (final Exception e) {
+ // no-op: ignore
+ }
}
// status
Added: incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jmx/JMXAttributeGaugeBase.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jmx/JMXAttributeGaugeBase.java?rev=1541429&view=auto
==============================================================================
--- incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jmx/JMXAttributeGaugeBase.java (added)
+++ incubator/sirona/trunk/core/src/main/java/org/apache/sirona/gauges/jmx/JMXAttributeGaugeBase.java Wed Nov 13 08:55:56 2013
@@ -0,0 +1,64 @@
+/*
+ * 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.sirona.gauges.jmx;
+
+import org.apache.sirona.Role;
+import org.apache.sirona.SironaException;
+import org.apache.sirona.configuration.Configuration;
+import org.apache.sirona.counters.Unit;
+import org.apache.sirona.gauges.Gauge;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import java.lang.management.ManagementFactory;
+
+public abstract class JMXAttributeGaugeBase implements Gauge {
+ private static final MBeanServer SERVER = ManagementFactory.getPlatformMBeanServer();
+
+ private final ObjectName name;
+ private final String attribute;
+ private final Role role;
+
+ public JMXAttributeGaugeBase(final ObjectName name, final String attribute, final String role, final Unit unit) {
+ this.name = name;
+ this.attribute = attribute;
+ this.role = new Role(role, unit);
+ }
+
+ public JMXAttributeGaugeBase(final ObjectName name, final String attribute) {
+ this(name, attribute, name.getCanonicalName() + "#" + attribute, Unit.UNARY);
+ }
+
+ @Override
+ public Role role() {
+ return role;
+ }
+
+ @Override
+ public double value() {
+ try {
+ return Number.class.cast(SERVER.getAttribute(name, attribute)).doubleValue();
+ } catch (final Exception e) {
+ throw new SironaException(e);
+ }
+ }
+
+ @Override
+ public long period() {
+ return Configuration.getInteger(Configuration.CONFIG_PROPERTY_PREFIX + "gauge.jmx.period", 4000);
+ }
+}