jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1565273 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/ oak-core/src/main/java/org/apache/jackrabbit/oak/stats/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/ oak-jcr/src/main/java/org...
Date Thu, 06 Feb 2014 14:29:03 GMT
Author: mduerig
Date: Thu Feb  6 14:29:02 2014
New Revision: 1565273

URL: http://svn.apache.org/r1565273
Log:
OAK-1338: Implement QueryStat from Jackrabbit API
Implement repository statistics: session login count and session count

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/RepositoryStatsMBean.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/RepositoryStats.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/StatisticManager.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionImpl.java

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/RepositoryStatsMBean.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/RepositoryStatsMBean.java?rev=1565273&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/RepositoryStatsMBean.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/jmx/RepositoryStatsMBean.java
Thu Feb  6 14:29:02 2014
@@ -0,0 +1,42 @@
+/*
+ * 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.oak.api.jmx;
+
+import javax.management.openmbean.CompositeData;
+
+/**
+ * MBean for providing repository wide statistics.
+ * This MBean exposes the time series provided by
+ * {@link org.apache.jackrabbit.api.stats.RepositoryStatistics RepositoryStatistics}
+ * through JMX as {@code CompositeData} of arrays.
+ */
+public interface RepositoryStatsMBean {
+    String TYPE = "RepositoryStats";
+
+    /**
+     * @see org.apache.jackrabbit.api.stats.RepositoryStatistics.Type#SESSION_COUNT
+     */
+    CompositeData getSessionCount();
+
+    /**
+     * @see org.apache.jackrabbit.api.stats.RepositoryStatistics.Type#SESSION_LOGIN_COUNTER
+     */
+    CompositeData getSessionLogin();
+}

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/RepositoryStats.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/RepositoryStats.java?rev=1565273&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/RepositoryStats.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/RepositoryStats.java
Thu Feb  6 14:29:02 2014
@@ -0,0 +1,85 @@
+/*
+ * 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.oak.stats;
+
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_COUNT;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_LOGIN_COUNTER;
+
+import javax.management.openmbean.ArrayType;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenDataException;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
+
+import org.apache.jackrabbit.api.stats.RepositoryStatistics;
+import org.apache.jackrabbit.api.stats.TimeSeries;
+import org.apache.jackrabbit.oak.api.jmx.RepositoryStatsMBean;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RepositoryStats implements RepositoryStatsMBean {
+    private static final Logger LOG = LoggerFactory.getLogger(RepositoryStats.class);
+
+    private final RepositoryStatistics repoStats;
+
+    public RepositoryStats(RepositoryStatistics repoStats) {
+        this.repoStats = repoStats;
+    }
+
+    @Override
+    public CompositeData getSessionCount() {
+        return asCompositeData(SESSION_COUNT);
+    }
+
+    @Override
+    public CompositeData getSessionLogin() {
+        return asCompositeData(SESSION_LOGIN_COUNTER);
+    }
+
+    public static final String[] ITEM_NAMES = new String[] {
+            "per second", "per minute", "per hour", "per week"};
+
+    private CompositeData asCompositeData(Type type) {
+        try {
+            TimeSeries timeSeries = repoStats.getTimeSeries(type);
+            long[][] values = new long[][] {
+                timeSeries.getValuePerSecond(),
+                timeSeries.getValuePerMinute(),
+                timeSeries.getValuePerHour(),
+                timeSeries.getValuePerWeek()};
+            return new CompositeDataSupport(getCompositeType(type), ITEM_NAMES, values);
+        } catch (Exception e) {
+            LOG.error("Error creating CompositeData instance from TimeSeries", e);
+            return null;
+        }
+    }
+
+    private static CompositeType getCompositeType(Type type) throws OpenDataException {
+        ArrayType<int[]> longArrayType = new ArrayType<int[]>(SimpleType.LONG,
true);
+        OpenType<?>[] itemTypes = new OpenType[] {
+                longArrayType, longArrayType, longArrayType, longArrayType};
+        String name = type.toString();
+        return new CompositeType(name, name + " time series", ITEM_NAMES, ITEM_NAMES, itemTypes);
+    }
+
+}

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/StatisticManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/StatisticManager.java?rev=1565273&r1=1565272&r2=1565273&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/StatisticManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/stats/StatisticManager.java
Thu Feb  6 14:29:02 2014
@@ -21,10 +21,16 @@ package org.apache.jackrabbit.oak.stats;
 
 import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean;
 
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicLong;
+
 import org.apache.jackrabbit.api.jmx.QueryStatManagerMBean;
+import org.apache.jackrabbit.api.stats.RepositoryStatistics.Type;
+import org.apache.jackrabbit.oak.api.jmx.RepositoryStatsMBean;
 import org.apache.jackrabbit.oak.spi.whiteboard.CompositeRegistration;
 import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
 import org.apache.jackrabbit.stats.QueryStatImpl;
+import org.apache.jackrabbit.stats.RepositoryStatisticsImpl;
 import org.apache.jackrabbit.stats.jmx.QueryStatManager;
 
 /**
@@ -34,6 +40,7 @@ import org.apache.jackrabbit.stats.jmx.Q
  */
 public class StatisticManager {
     private final QueryStatImpl queryStat = new QueryStatImpl();
+    private final RepositoryStatisticsImpl repoStats;
     private final CompositeRegistration registration;
 
     /**
@@ -41,10 +48,13 @@ public class StatisticManager {
      * statistics with the passed {@code whiteboard}.
      * @param whiteboard   whiteboard for registering the individual statistics with
      */
-    public StatisticManager(Whiteboard whiteboard) {
+    public StatisticManager(Whiteboard whiteboard, ScheduledExecutorService executor) {
+        repoStats = new RepositoryStatisticsImpl(executor);
         registration = new CompositeRegistration(
-            registerMBean(whiteboard, QueryStatManagerMBean.class,
-                new QueryStatManager(queryStat), "QueryStats", QueryStatManagerMBean.NAME));
+            registerMBean(whiteboard, QueryStatManagerMBean.class, new QueryStatManager(queryStat),
+                    "QueryStats", "Oak Query Statistics"),
+            registerMBean(whiteboard, RepositoryStatsMBean.class, new RepositoryStats(repoStats),
+                    RepositoryStats.TYPE, "Oak Repository Statistics"));
     }
 
     /**
@@ -59,6 +69,16 @@ public class StatisticManager {
     }
 
     /**
+     * Get the counter of the specified {@code type}.
+     * @param type  type of the counter
+     * @return  counter for the given {@code type}
+     * @see org.apache.jackrabbit.stats.RepositoryStatisticsImpl#getCounter(org.apache.jackrabbit.api.stats.RepositoryStatistics.Type)
+     */
+    public AtomicLong getCounter(Type type) {
+        return repoStats.getCounter(type);
+    }
+
+    /**
      * Unregister all statistics previously registered with the whiteboard passed
      * to the constructor.
      */

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java?rev=1565273&r1=1565272&r2=1565273&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java
Thu Feb  6 14:29:02 2014
@@ -98,7 +98,7 @@ public class RepositoryImpl implements J
         this.securityProvider = checkNotNull(securityProvider);
         this.threadSaveCount = new ThreadLocal<Long>();
         this.descriptors = determineDescriptors();
-        this.statisticManager = new StatisticManager(whiteboard);
+        this.statisticManager = new StatisticManager(whiteboard, scheduledExecutor);
     }
 
     //---------------------------------------------------------< Repository >---

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java?rev=1565273&r1=1565272&r2=1565273&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
Thu Feb  6 14:29:02 2014
@@ -25,6 +25,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
@@ -42,7 +43,7 @@ import org.apache.jackrabbit.api.securit
 import org.apache.jackrabbit.api.security.authorization.PrivilegeManager;
 import org.apache.jackrabbit.api.security.principal.PrincipalManager;
 import org.apache.jackrabbit.api.security.user.UserManager;
-import org.apache.jackrabbit.oak.stats.StatisticManager;
+import org.apache.jackrabbit.api.stats.RepositoryStatistics.Type;
 import org.apache.jackrabbit.oak.jcr.delegate.AccessControlManagerDelegator;
 import org.apache.jackrabbit.oak.jcr.delegate.JackrabbitAccessControlManagerDelegator;
 import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
@@ -66,6 +67,7 @@ import org.apache.jackrabbit.oak.spi.sec
 import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
 import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
 import org.apache.jackrabbit.oak.spi.xml.ProtectedItemImporter;
+import org.apache.jackrabbit.oak.stats.StatisticManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -173,6 +175,11 @@ public class SessionContext implements N
     }
 
     @Nonnull
+    public AtomicLong getCounter(Type type) {
+        return statisticManager.getCounter(type);
+    }
+
+    @Nonnull
     public Repository getRepository() {
         return repository;
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionImpl.java?rev=1565273&r1=1565272&r2=1565273&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionImpl.java
Thu Feb  6 14:29:02 2014
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.oak.jcr.session;
 
 import static com.google.common.collect.Sets.newTreeSet;
+import static org.apache.jackrabbit.api.stats.RepositoryStatistics.Type.SESSION_COUNT;
 import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath;
 
 import java.io.IOException;
@@ -25,6 +26,7 @@ import java.io.OutputStream;
 import java.security.AccessControlException;
 import java.util.Collections;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
@@ -49,6 +51,7 @@ import javax.jcr.security.AccessControlM
 import org.apache.jackrabbit.api.JackrabbitSession;
 import org.apache.jackrabbit.api.security.principal.PrincipalManager;
 import org.apache.jackrabbit.api.security.user.UserManager;
+import org.apache.jackrabbit.api.stats.RepositoryStatistics.Type;
 import org.apache.jackrabbit.commons.xml.DocumentViewExporter;
 import org.apache.jackrabbit.commons.xml.Exporter;
 import org.apache.jackrabbit.commons.xml.ParsingContentHandler;
@@ -78,10 +81,14 @@ public class SessionImpl implements Jack
 
     private final SessionContext sessionContext;
     private final SessionDelegate sd;
+    private final AtomicLong sessionCounter;
 
     public SessionImpl(SessionContext sessionContext) {
         this.sessionContext = sessionContext;
         this.sd = sessionContext.getSessionDelegate();
+        this.sessionCounter = sessionContext.getCounter(SESSION_COUNT);
+        sessionCounter.incrementAndGet();
+        sessionContext.getCounter(Type.SESSION_LOGIN_COUNTER).incrementAndGet();
     }
 
     static void checkIndexOnName(SessionContext sessionContext, String path) throws RepositoryException
{
@@ -451,6 +458,7 @@ public class SessionImpl implements Jack
     @Override
     public void logout() {
         if (sd.isAlive()) {
+            sessionCounter.decrementAndGet();
             safePerform(new SessionOperation<Void>() {
                 @Override
                 public Void perform() {



Mime
View raw message