You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2011/10/09 17:50:19 UTC
svn commit: r1180634 - in
/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx:
TimeSeriesMBean.java TimeSeriesRecorder.java
Author: jukka
Date: Sun Oct 9 15:50:19 2011
New Revision: 1180634
URL: http://svn.apache.org/viewvc?rev=1180634&view=rev
Log:
JCR-3040: JMX Stats for the Session
Add a mechanism for recording time series of various events
Added:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesMBean.java (with props)
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesRecorder.java (with props)
Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesMBean.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesMBean.java?rev=1180634&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesMBean.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesMBean.java Sun Oct 9 15:50:19 2011
@@ -0,0 +1,57 @@
+/*
+ * 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.jackrabbit.core.jmx;
+
+/**
+ * Interface for a time series of the number of events per
+ * second, minute, hour and day. The type of the events is arbitrary; it
+ * could be cache hits or misses, disk reads or writes, created sessions,
+ * completed transactions, or pretty much anything of interest.
+ *
+ * @since Apache Jackrabbit 2.3.1
+ */
+public interface TimeSeriesMBean {
+
+ /**
+ * Returns the number of events per second over the last minute.
+ *
+ * @return number of events per second, in chronological order
+ */
+ long[] getEventsPerSecond();
+
+ /**
+ * Returns the number of events per minute over the last hour.
+ *
+ * @return number of events per minute, in chronological order
+ */
+ long[] getEventsPerMinute();
+
+ /**
+ * Returns the number of events per hour over the last week.
+ *
+ * @return number of events per hour, in chronological order
+ */
+ long[] getEventsPerHour();
+
+ /**
+ * Returns the number of events per week over the last three years.
+ *
+ * @return number of events per week, in chronological order
+ */
+ long[] getEventsPerWeek();
+
+}
Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesMBean.java
------------------------------------------------------------------------------
svn:executable = *
Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesRecorder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesRecorder.java?rev=1180634&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesRecorder.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesRecorder.java Sun Oct 9 15:50:19 2011
@@ -0,0 +1,129 @@
+/*
+ * 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.jackrabbit.core.jmx;
+
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * Recorder of a time series. An instance of this class records (and clears)
+ * the state of a given {@link AtomicLong} counter once every second and
+ * exposes the collected time series through the {@link TimeSeriesMBean}
+ * interface.
+ */
+public class TimeSeriesRecorder implements TimeSeriesMBean {
+
+ /** Number of events per second over the last minute. */
+ private final long[] eventsPerSecond = new long[60];
+
+ /** Number of events per minute over the last hour. */
+ private final long[] eventsPerMinute = new long[60];
+
+ /** Number of events per hour over the last week. */
+ private final long[] eventsPerHour = new long[7 * 24];
+
+ /** Number of events per week over the last three years. */
+ private final long[] eventsPerWeek = new long[3 * 52];
+
+ /** Current second (index in {@link #eventsPerSecond}) */
+ private int seconds = 0;
+
+ /** Current minute (index in {@link #eventsPerMinute}) */
+ private int minutes = 0;
+
+ /** Current hour (index in {@link #eventsPerHour}) */
+ private int hours = 0;
+
+ /** Current week (index in {@link #eventsPerWeek}) */
+ private int weeks = 0;
+
+ public TimeSeriesRecorder(
+ final AtomicLong counter, ScheduledExecutorService executor) {
+ executor.scheduleAtFixedRate(new Runnable() {
+ public void run() {
+ eventsPerSecond[seconds++] = counter.getAndSet(0);
+ if (seconds == eventsPerSecond.length) {
+ seconds = 0;
+ eventsPerMinute[minutes++] = sum(eventsPerSecond);
+ }
+ if (minutes == eventsPerMinute.length) {
+ minutes = 0;
+ eventsPerHour[hours++] = sum(eventsPerMinute);
+ }
+ if (hours == eventsPerHour.length) {
+ hours = 0;
+ eventsPerWeek[weeks++] = sum(eventsPerHour);
+ }
+ if (weeks == eventsPerWeek.length) {
+ weeks = 0;
+ }
+ }
+ }, 1, 1, TimeUnit.SECONDS);
+ }
+
+ //----------------------------------------------------------< TimeSeries >
+
+ public synchronized long[] getEventsPerSecond() {
+ return cyclicCopyFrom(eventsPerSecond, seconds);
+ }
+
+ public synchronized long[] getEventsPerMinute() {
+ return cyclicCopyFrom(eventsPerMinute, minutes);
+ }
+
+ public synchronized long[] getEventsPerHour() {
+ return cyclicCopyFrom(eventsPerHour, hours);
+ }
+
+ public synchronized long[] getEventsPerWeek() {
+ return cyclicCopyFrom(eventsPerWeek, weeks);
+ }
+
+ //-------------------------------------------------------------< private >
+
+ /**
+ * Returns the sum of all entries in the given array.
+ *
+ * @param array array to be summed
+ * @return sum of entries
+ */
+ private static long sum(long[] array) {
+ long sum = 0;
+ for (int i = 0; i < array.length; i++) {
+ sum += array[i];
+ }
+ return sum;
+ }
+
+ /**
+ * Returns a copy of the given cyclical array, with the element at
+ * the given position as the first element of the returned array.
+ *
+ * @param array cyclical array
+ * @param pos position of the first element
+ * @return copy of the array
+ */
+ private static long[] cyclicCopyFrom(long[] array, int pos) {
+ long[] reverse = new long[array.length];
+ for (int i = 0; i < array.length; i++) {
+ reverse[i] = array[(pos + i) % array.length];
+ }
+ return reverse;
+ }
+
+}
Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/jmx/TimeSeriesRecorder.java
------------------------------------------------------------------------------
svn:executable = *