001: /* Copyright 2005 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.jmx;
007:
008: import java.util.ArrayList;
009: import java.util.Date;
010: import java.util.Iterator;
011: import java.util.List;
012:
013: import org.jasig.portal.ChannelManager;
014: import org.jasig.portal.GuestUserInstance;
015: import org.jasig.portal.PortalException;
016: import org.jasig.portal.PortalSessionManager;
017: import org.jasig.portal.ProblemsTable;
018: import org.jasig.portal.RDBMServices;
019: import org.jasig.portal.UserInstance;
020: import org.jasig.portal.services.Authentication;
021: import org.jasig.portal.utils.MovingAverageSample;
022:
023: /**
024: * uPortal metrics to make available via JMX.
025: *
026: * @author George Lindholm <a href="mailto:George.Lindholm@ubc.ca">George.Lindholm@ubc.ca</a>
027: * @version $Revision: 36731 $ $Date: 2006-09-27 11:21:06 -0700 (Wed, 27 Sep 2006) $
028: * @since uPortal 2.5
029: */
030: public class FrameworkMBeanImpl implements FrameworkMBean {
031: public FrameworkMBeanImpl() {
032:
033: }
034:
035: /**
036: * Time/Data uPortal was started
037: * @return Date
038: */
039: public Date getStartedAt() {
040: return PortalSessionManager.STARTED_AT;
041: }
042:
043: /*
044: * Track framework rendering performance
045: */
046: public long getRenderAverage() {
047: return UserInstance.lastRender.average;
048: }
049:
050: public long getRenderHighMax() {
051: return UserInstance.lastRender.highMax;
052: }
053:
054: public long getRenderLast() {
055: return UserInstance.lastRender.lastSample;
056: }
057:
058: public long getRenderMin() {
059: return UserInstance.lastRender.min;
060: }
061:
062: public long getRenderMax() {
063: return UserInstance.lastRender.max;
064: }
065:
066: public long getRenderTotalRenders() {
067: return UserInstance.lastRender.totalSamples;
068: }
069:
070: public MovingAverageSample getLastRender() {
071: return UserInstance.lastRender;
072: }
073:
074: public String[] getRecentProblems() {
075: final List rpe = ProblemsTable.getRecentPortalExceptions();
076: final ArrayList al = new ArrayList(rpe.size());
077: for (Iterator it = rpe.iterator(); it.hasNext();) {
078: final PortalException pe = (PortalException) it.next();
079: al.add(pe.getMessage());
080: }
081: return (String[]) al.toArray(new String[0]);
082: }
083:
084: /*
085: * sessions
086: */
087: public long getUserSessionCount() {
088: return UserInstance.userSessions.longValue();
089: }
090:
091: public long getGuestSessionCount() {
092: return GuestUserInstance.guestSessions.longValue();
093: }
094:
095: /*
096: * Track framework database performance
097: */
098: public MovingAverageSample getLastDatabase() {
099: return RDBMServices.lastDatabase;
100: }
101:
102: public long getDatabaseAverage() {
103: return RDBMServices.lastDatabase.average;
104: }
105:
106: public long getDatabaseHighMax() {
107: return RDBMServices.lastDatabase.highMax;
108: }
109:
110: public long getDatabaseLast() {
111: return RDBMServices.lastDatabase.lastSample;
112: }
113:
114: public long getDatabaseMin() {
115: return RDBMServices.lastDatabase.min;
116: }
117:
118: public long getDatabaseMax() {
119: return RDBMServices.lastDatabase.max;
120: }
121:
122: public long getDatabaseTotalConnections() {
123: return RDBMServices.lastDatabase.totalSamples;
124: }
125:
126: public int getRDBMActiveConnectionCount() {
127: return RDBMServices.getActiveConnectionCount();
128: }
129:
130: public int getRDBMMaxConnectionCount() {
131: return RDBMServices.getMaxConnectionCount();
132: }
133:
134: /*
135: * Track framework Authentication performance
136: */
137: public MovingAverageSample getLastAuthentication() {
138: return Authentication.lastAuthentication;
139: }
140:
141: public long getAuthenticationAverage() {
142: return Authentication.lastAuthentication.average;
143: }
144:
145: public long getAuthenticationHighMax() {
146: return Authentication.lastAuthentication.highMax;
147: }
148:
149: public long getAuthenticationLast() {
150: return Authentication.lastAuthentication.lastSample;
151: }
152:
153: public long getAuthenticationMin() {
154: return Authentication.lastAuthentication.min;
155: }
156:
157: public long getAuthenticationMax() {
158: return Authentication.lastAuthentication.max;
159: }
160:
161: public long getAuthenticationTotalLogins() {
162: return Authentication.lastAuthentication.totalSamples;
163: }
164:
165: // Threads
166: public long getThreadCount() {
167: return PortalSessionManager.getThreadGroup().activeCount();
168: }
169:
170: public long getChannelRendererActiveThreads() {
171: return ChannelManager.activeRenderers.get();
172: }
173:
174: public long getChannelRendererMaxActiveThreads() {
175: return ChannelManager.maxRenderThreads.get();
176: }
177: }
|