Commit b0c28a5c authored by ncampbell's avatar ncampbell

removing current version of meter...I'll add the new version later

git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/branches@2942 b35dd754-fafc-0310-a699-88a17e54d16e
parent f4400d3f
/**
*
*/
package org.jivesoftware.messenger.plugin.meter;
import java.util.ArrayList;
import java.util.Set;
import javax.management.openmbean.CompositeData;
import org.apache.commons.jxpath.DynamicPropertyHandler;
/**
* @author Noah Campbell
* @version 1.0
*/
public class CompositeDataPropertyHandler implements DynamicPropertyHandler {
/**
* @see org.apache.commons.jxpath.DynamicPropertyHandler#getPropertyNames(java.lang.Object)
*/
public String[] getPropertyNames(Object object) {
ArrayList<String> names = new ArrayList<String>(20);
if(object instanceof CompositeData) {
CompositeData cd = (CompositeData)object;
Set keys = cd.getCompositeType().keySet();
for(Object key : keys) {
names.add((String) key);
}
}
return names.toArray(new String[names.size()]);
}
/**
* @see org.apache.commons.jxpath.DynamicPropertyHandler#getProperty(java.lang.Object, java.lang.String)
*/
public Object getProperty(Object object, String propertyName) {
if(object instanceof CompositeData) {
CompositeData cd = (CompositeData)object;
return cd.get(propertyName);
}
return null;
}
/**
* @see org.apache.commons.jxpath.DynamicPropertyHandler#setProperty(java.lang.Object, java.lang.String, java.lang.Object)
*/
public void setProperty(@SuppressWarnings("unused") Object object,
@SuppressWarnings("unused") String propertyName,
@SuppressWarnings("unused") Object value) {
throw new UnsupportedOperationException("read-only");
}
}
/**
*
*/
package org.jivesoftware.messenger.plugin.meter;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.management.MBeanInfo;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.jrobin.annotations.Rrd;
/**
* @author Noah Campbell
* @version 1.0
*/
public class GraphBuilderBean {
/**
* Return all the ObjectNames
*
* @return objectnames
* @throws Exception
*/
public List<String> getChartableMBeans() throws Exception {
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Set mbeans = server.queryNames(null, null);
List<String> results = new ArrayList<String>(mbeans.size());
for(Object mbean : mbeans) {
ObjectName objectName = ((ObjectName)mbean);
MBeanInfo info = server.getMBeanInfo(objectName);
Rrd rrd = info.getClass().getAnnotation(Rrd.class);
if(rrd != null)
results.add(objectName.getCanonicalName());
}
return results;
}
public List<String> getStores() {
return new ArrayList<String>(RrdManager.listStores().keySet());
}
}
/**
*
*/
package org.jivesoftware.messenger.plugin.meter;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.imageio.ImageIO;
import javax.management.ObjectName;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.Converter;
import org.jrobin.core.RrdDb;
import org.jrobin.core.RrdDbPool;
import org.jrobin.graph.RrdGraph;
import org.jrobin.graph.RrdGraphDef;
/**
* @author Noah Campbell
* @version 1.0
*/
public class GraphServlet extends HttpServlet {
/** The serialVersionUID. */
private static final long serialVersionUID = 1L;
/**
* @param request The Request.
* @param response The Response.
* @throws ServletException Throw if unable to process the request due to a Servlet related problem.
* @throws IOException Thrown if unable to process the request due to an IO related problem.
* @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@SuppressWarnings("unused")
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("image/png");
ServletOutputStream out = response.getOutputStream();
response.addHeader("Cache-Control", "no-cache");
createPNGGraph(request, out);
}
/** The colors. */
private static final Color[] colors = new Color[]{new Color(102, 204, 204),
new Color(102,153,204),
new Color(102,102,204),
new Color(153,102,204),
new Color(102,204,153),
new Color( 61,184,184),
new Color( 46,138,138),
new Color(204,102,204),
new Color(102,204,102),
new Color(138, 46, 46),
new Color(184, 61, 61),
new Color(204,102,153),
new Color(153,204,102),
new Color(204,204,102),
new Color(204,153,102),
new Color(204,102,102)};
/** The converter. */
private static final Converter converter = new ColorConverter();
/**
* @param request The servlet request.
* @param out The output stream.
* @throws IOException Thrown if an IO exception occurs.
*/
private void createPNGGraph(HttpServletRequest request, OutputStream out) throws IOException {
int width;
int height;
try {
int w = Integer.parseInt(request.getParameter("width"));
width = w <= 800 ? w : 800;
} catch (NumberFormatException e) {
width = 400;
}
try {
int h = Integer.parseInt(request.getParameter("height"));
height = h <= 600 ? h : 600;
} catch (NumberFormatException e) {
height = 300;
}
String error = "An error has occured.";
try {
ConvertUtils.register(converter, Color.class);
String store = request.getParameter("store");
String objectName = request.getParameter("oname");
RrdGraphDef def = new RrdGraphDef();
BeanUtilsBean.getInstance().populate(def, request.getParameterMap());
String[] lines = request.getParameterValues("lines");
for(String line : lines) {
String[] field = line.split("::");
def.line(field[0], parseColor(field[1]), field[2]);
}
RrdDbPool pool = RrdDbPool.getInstance();
RrdManager manager = RrdManager.listStores().get(store);
String filename = manager.getFileName(new ObjectName(objectName));
RrdDb db = pool.requestRrdDb(filename);
String ref = "input";
int count = 0;
for(String ds : db.getDsNames()) {
String id = ref + count++;
def.datasource(id, filename, ds, "AVERAGE");
def.line(id, colors[count], ds);
}
RrdGraph graph = new RrdGraph(def);
byte[] output;
if(request.getParameter("width") == null) {
output = graph.getPNGBytes();
} else {
output = graph.getPNGBytes(width, height);
}
/**
* write out the byte array to the client.
*/
ByteArrayInputStream bis = new ByteArrayInputStream(output);
while(bis.available() > 0) {
out.write(bis.read());
}
} catch (Exception e) {
error += " " + e.getLocalizedMessage();
} finally {
ConvertUtils.deregister(Color.class);
}
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics();
g2d.setBackground(Color.white);
// g2d.setBackground(new Color(0,0,0,255));
// GradientPaint gpaint = new GradientPaint(0, height / 2, Color.white, width, height / 2, Color.gray);
// Paint originalPaint = g2d.getPaint();
// g2d.setPaint(gpaint);
g2d.fillRect(0,0,width,height);
int errorWidth = g2d.getFontMetrics().stringWidth(error);
// g2d.setPaint(originalPaint);
g2d.setColor(Color.black);
g2d.drawString(error, width / 2 - errorWidth / 2, height / 2);
g2d.dispose();
ImageIO.write(bufferedImage, "png", out);
}
/**
* @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
*/
@Override
public void init(ServletConfig arg0) throws ServletException {
// TODO Auto-generated method stub
super.init(arg0);
}
/**
* @author Noah Campbell
* @version 1.0
*/
private static class ColorConverter implements Converter {
/**
* @see org.apache.commons.beanutils.Converter#convert(java.lang.Class, java.lang.Object)
*/
public Object convert(@SuppressWarnings("unused") Class cls, Object input) {
if(input instanceof String) {
String s = (String)input;
return parseColor(s);
}
return colors[0];
}
}
/**
* Parse a string of format #RRBBGGAA where RR, BB, GG, AA are hex values
* ranging between 0 (00) and 255 (FF). AA is optional and can be excluded
* from the #RRBBGG string.
*
* @param s
* @return color
*/
private static Color parseColor(String s) {
try {
if( s.startsWith("#") ) {
int r = Integer.valueOf(s.substring(1, 3), 16);
int g = Integer.valueOf(s.substring(3, 5), 16);
int b = Integer.valueOf(s.substring(5, 7), 16);
int a = 255;
if(s.length() > 7) {
a = Integer.valueOf(s.substring(7, 9), 16);
}
return new Color(r, g, b, a);
}
} catch (RuntimeException e) {
}
return colors[0];
}
}
/**
*
*/
package org.jivesoftware.messenger.plugin.meter;
import org.jrobin.annotations.Ds;
import org.jrobin.annotations.Rrd;
import org.jrobin.annotations.SourceType;
/**
* @author Noah Campbell
* @version 1.0
*/
@Rrd
public interface MemoryMXBeanSupportInfo {
/**
* @return max The max heap memory usage.
*/
@Ds(name="max", expr="/HeapMemoryUsage/max", type=SourceType.COUNTER)
long getMaxHeapMemoryUsage();
/**
* @return initial The initial heap memory usage.
*/
@Ds(name="init", expr="/HeapMemoryUsage/init")
long getInitHeapMemoryUsage();
/**
* @return used The heap memory usage.
*/
@Ds(name="used", expr="/HeapMemoryUsage/used")
long getUsedHeapMemoryUsage();
/**
* @return commited The commited heap memory usage.
*/
@Ds(name="commited", expr="/HeapMemoryUsage/committed")
long getCommittedHeapMemoryUsage();
}
/**
*
*/
package org.jivesoftware.messenger.plugin.meter;
import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.Preferences;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import org.jivesoftware.messenger.container.Plugin;
import org.jivesoftware.messenger.container.PluginManager;
import org.jivesoftware.messenger.plugin.meter.accumulator.Accumulator;
import org.jrobin.core.RrdDbPool;
import org.jrobin.core.RrdException;
/**
* @author Noah Campbell
* @version 1.0
*/
public class MeterPlugin implements Plugin {
/** The pluginDirectory. */
@SuppressWarnings("unused")
private File pluginDirectory;
/** The manager. */
@SuppressWarnings("unused")
private PluginManager manager;
/** The logger. */
final static private Logger logger = Logger.getLogger("monitorplugin", "resources");
/** The server. */
private MBeanServer server = ManagementFactory.getPlatformMBeanServer();
/** The preferences. */
private Preferences preferences;
/** The rrdManager. */
private RrdManager rrdManager;
/** The executors. */
ScheduledExecutorService executors = Executors.newScheduledThreadPool(10);
/** The pool. */
RrdDbPool pool = RrdDbPool.getInstance();
/**
* @see org.jivesoftware.messenger.container.Plugin#initializePlugin(org.jivesoftware.messenger.container.PluginManager, java.io.File)
*/
public void initializePlugin(PluginManager manager, File pluginDirectory) {
this.manager = manager;
this.pluginDirectory = pluginDirectory;
File store = new File(pluginDirectory, "store");
if(!store.exists()) {
store.mkdirs();
}
try {
rrdManager = new RrdManager(store.getCanonicalFile(), pool);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
preferences = Preferences.systemNodeForPackage(MeterPlugin.class);
String monitoredObjectNames = preferences.get("monitoredObjectNames", "java.lang:type=Threading;java.lang:type=Memory");
for(String name : monitoredObjectNames.split("; ?")) {
logger.log(Level.FINER, "initialize.objectname", name);
try {
ObjectName objectName = new ObjectName(name);
Accumulator accum = rrdManager.create(objectName, server.getMBeanInfo(objectName));
/**
* Schedule the accumulator.
*/
executors.scheduleAtFixedRate(accum, 0, 300, TimeUnit.SECONDS);
} catch (MalformedObjectNameException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NullPointerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstanceNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RrdException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IntrospectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ReflectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
* @see org.jivesoftware.messenger.container.Plugin#destroyPlugin()
*/
public void destroyPlugin() {
}
}
/**
*
*/
package org.jivesoftware.messenger.plugin.meter;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.naming.OperationNotSupportedException;
import org.apache.commons.jxpath.DynamicPropertyHandler;
/**
* @author Noah Campbell
* @version 1.0
*/
public class ObjectNamePropertyHandler implements DynamicPropertyHandler {
/** The server. */
private static final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
/** The logger. */
final static private Logger logger = Logger.getLogger(
"objectnamepropertyhandler", "resources");
/**
* @see org.apache.commons.jxpath.DynamicPropertyHandler#getPropertyNames(java.lang.Object)
*/
public String[] getPropertyNames(Object object) {
ArrayList<String> list = new ArrayList<String>();
try {
ObjectName objectName = (ObjectName)object;
MBeanInfo info = server.getMBeanInfo(objectName);
MBeanAttributeInfo[] attrs = info.getAttributes();
for(MBeanAttributeInfo attr : attrs) {
list.add(attr.getName());
}
} catch (Exception e) {
logger.log(Level.WARNING, "unabletoevaluatepropertyname", e);
}
return list.toArray(new String[list.size()]);
}
/**
* @see org.apache.commons.jxpath.DynamicPropertyHandler#getProperty(java.lang.Object, java.lang.String)
*/
public Object getProperty(Object object, String propertyName) {
try {
return server.getAttribute((ObjectName) object, propertyName);
} catch (AttributeNotFoundException e) {
logger.log(Level.WARNING, "attributenotfound", e);
} catch (InstanceNotFoundException e) {
logger.log(Level.WARNING, "instancenotfound", e);
} catch (MBeanException e) {
logger.log(Level.WARNING, "mbeanexception", e);
} catch (ReflectionException e) {
logger.log(Level.WARNING, "reflectionexception", e);
}
return null;
}
/**
* @see org.apache.commons.jxpath.DynamicPropertyHandler#setProperty(java.lang.Object, java.lang.String, java.lang.Object)
*/
public void setProperty(@SuppressWarnings("unused") Object object,
@SuppressWarnings("unused") String propertyName,
@SuppressWarnings("unused") Object value) {
throw new RuntimeException(new OperationNotSupportedException("unable to perform this opertion."));
}
}
/**
*
*/
package org.jivesoftware.messenger.plugin.meter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Method;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanInfo;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MBeanServerInvocationHandler;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
import javax.management.relation.InvalidRelationTypeException;
import javax.management.relation.RelationService;
import javax.management.relation.RelationServiceMBean;
import javax.management.relation.RoleInfo;
import org.apache.commons.jxpath.JXPathIntrospector;
import org.jivesoftware.messenger.plugin.meter.accumulator.Accumulator;
import org.jivesoftware.messenger.plugin.meter.accumulator.AccumulatorManager;
import org.jrobin.annotations.Arc;
import org.jrobin.annotations.Ds;
import org.jrobin.annotations.Rrd;
import org.jrobin.core.RrdDb;
import org.jrobin.core.RrdDbPool;
import org.jrobin.core.RrdDef;
import org.jrobin.core.RrdException;
/**
* RrdManager is responsible for managing the RrdPools and the associated files
* associated with that pool.
*
* @author Noah Campbell
* @version 1.0
*/
public class RrdManager {
/** The JROBIN_TYPE_RELATION_SERVICE. */
private static final String JROBIN_TYPE_RELATION_SERVICE = "jrobin:type=RelationService";
/**
* @return storeList
*/
public static Map<String, RrdManager> listStores() {
return Collections.unmodifiableMap(stores);
}
/** The overrides. */
private final List<Accumulator> overrides = new ArrayList<Accumulator>();
/** The stores. */
private static Map<String, RrdManager> stores = new HashMap<String, RrdManager>();
/** The store. */
private final File store;
/** The pool. */
private final RrdDbPool pool;
/** The server. */
private static final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
/**
* Construct a new <code>RrdManager</code>.
*
* @param store
* @param pool
* @throws IOException
* @throws Exception
*/
public RrdManager(File store, RrdDbPool pool) throws IOException, Exception {
this.store = store;
this.pool = pool;
if(!stores.containsKey(store.getName())) {
stores.put(store.getName(), this);
} else {
logger.log(Level.WARNING, "rrdmanager.existingstore", store.getName());
}
startRelationshipService();
JXPathIntrospector.registerDynamicClass(ObjectName.class, ObjectNamePropertyHandler.class);
JXPathIntrospector.registerDynamicClass(CompositeData.class, CompositeDataPropertyHandler.class);
String systemOverride = System.getProperty("org.jivesoftware.messenger.plugin.monitor.overrides");
InputStream is = null;
if(systemOverride != null && systemOverride.length() > 0) {
is = new FileInputStream(systemOverride);
} else {
is = this.getClass().getClassLoader().getResourceAsStream("typeoverrides.config");
}
try {
Properties p = new Properties();
p.load(is);
Enumeration names = p.propertyNames();
for(; names.hasMoreElements(); ) {
String name = (String)names.nextElement();
try {
AccumulatorManager.registerOverride(new ObjectName(name), Class.forName(p.getProperty(name)));
} catch (Exception e) {
logger.log(Level.WARNING, "Unable to register override: {0}", e.getLocalizedMessage());
}
}
} catch (Exception e) {
logger.log(Level.WARNING, "rrdmanager.unabletoloadoverride");
}
}
/**
* @return overrides A list of overrides
*/
public List<Accumulator> getGraphableObjectNames() {
return this.overrides;
}
/**
* @throws MalformedObjectNameException
* @throws InstanceAlreadyExistsException
* @throws MBeanRegistrationException
* @throws NotCompliantMBeanException
* @throws IllegalArgumentException
* @throws ClassNotFoundException
* @throws InvalidRelationTypeException
*/
private void startRelationshipService() throws MalformedObjectNameException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, IllegalArgumentException, ClassNotFoundException, InvalidRelationTypeException {
// Create the Relation Service MBean
ObjectName relSvcName = new ObjectName(JROBIN_TYPE_RELATION_SERVICE);
RelationService relSvcObject = new RelationService(true);
server.registerMBean(relSvcObject, relSvcName);
// Create an MBean proxy for easier access to the Relation Service
RelationServiceMBean relSvc = (RelationServiceMBean)
MBeanServerInvocationHandler.newProxyInstance(server, relSvcName,
RelationServiceMBean.class,
false);
RoleInfo[] roles = new RoleInfo[] {
new RoleInfo("override", Object.class.getName()),
new RoleInfo("target", Object.class.getName()),
new RoleInfo("archive", String.class.getName())
};
relSvc.createRelationType("graph", roles);
}
/** The logger. */
final static private Logger logger = Logger.getLogger("rrdmanager", "resources");
/**
* Returns a file name that is unique for the ObjectName.
*
* @param name
* @return fileName
* @throws IOException
*/
public String getFileName(ObjectName name) throws IOException {
return new File(store, "x" + digest(name.getCanonicalName()) + ".rrd").getCanonicalPath();
}
/** The key. */
private static byte[] key = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x04, 0x03, 0x02, 0x01 };
/**
* @param buffer
* @return digest A Base64 encoded MD5 digest.
*/
private static String digest(String buffer) {
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(buffer.getBytes());
return new String(encodeHex(md5.digest(key)));
} catch (NoSuchAlgorithmException e) {
}
return null;
}
/**
* Used to build output as Hex
*/
private static final char[] DIGITS = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
/**
* @param data
* @return hexValue A char[].
*/
public static char[] encodeHex(byte[] data) {
int l = data.length;
char[] out = new char[l << 1];
// two characters form the hex value.
for (int i = 0, j = 0; i < l; i++) {
out[j++] = DIGITS[(0xF0 & data[i]) >>> 4 ];
out[j++] = DIGITS[ 0x0F & data[i] ];
}
return out;
}
/** The accumulators. */
public Map<ObjectName, Accumulator> accumulators =
new HashMap<ObjectName, Accumulator>();
/**
* Create an accumulator for the Rrd annotation and the ObjectName.
*
* @param objectName
* @param info
* @return accumulator
* @throws Exception
*/
public Accumulator create(ObjectName objectName, MBeanInfo info) throws Exception {
if (accumulators.containsKey(objectName)) {
return accumulators.get(objectName);
} else {
if (exists(objectName)) {
Accumulator acc = new Accumulator(objectName, getFileName(objectName));
accumulators.put(objectName, acc);
return acc;
} else {
Accumulator acc = internalCreate(objectName);
accumulators.put(objectName, acc);
return acc;
}
}
}
/**
* @param objectName
* @return accumulator
* @throws Exception
* @throws ClassNotFoundException
*/
private Accumulator internalCreate(ObjectName objectName) throws ClassNotFoundException, Exception {
Class<?> forName = findClass(objectName);
Rrd rrd = forName.getAnnotation(Rrd.class);
RrdDef def = new RrdDef(getFileName(objectName));
def.setStep(rrd.step());
for(Arc arc : rrd.archives()) {
def.addArchive(arc.consolidationFunction().toString(), arc.xff(), arc.steps(), arc.rows());
logger.log(Level.FINE, "rrdmanager.archiveadded", arc.consolidationFunction());
}
List<Ds> anonDs = findDs(forName);
for(Ds ds : anonDs) {
def.addDatasource(ds.name(), ds.type().toString(), ds.heartbeat(), ds.minValue(), ds.maxValue());
logger.log(Level.FINE, "rrdmanager.datasourceadded", new Object[]{ds.expr(), ds.name()});
}
/**
* Store
*/
RrdDb db = pool.requestRrdDb(def);
pool.release(db);
return new Accumulator(objectName, db.getPath());
}
/**
* @param objectName The objectName to build the accumulator against.
* @param info MBeanInfo to initialize the accumulator.
* @return accumulator The accumulator.
* @throws ClassNotFoundException
* @throws RrdException
* @throws IOException
* @throws Exception
*/
private Accumulator internalCreate(ObjectName objectName, String archive) throws ClassNotFoundException, RrdException, IOException, Exception {
return new Accumulator(objectName, archive);
}
/**
* @param objectName
* @param info
* @return cls A Class for the objectName that contains a the graphing information.
* @throws ClassNotFoundException
* @throws Exception
*/
private Class<?> findClass(ObjectName objectName) throws ClassNotFoundException, Exception {
Class<?> forName = Class.forName(server.getMBeanInfo(objectName).getClassName());
if(!forName.isAnnotationPresent(Rrd.class)) {
forName = AccumulatorManager.getOverride(objectName);
logger.log(Level.INFO, "rrdmanager.createoverride", forName.getName());
}
return forName;
}
/**
* @param forName
* @return dss A list of Ds attributes.
*/
private List<Ds> findDs(Class<?> forName) {
List<Ds> anonDs = new ArrayList<Ds>();
Method[] methods = forName.getMethods();
for(Method m : methods) {
Ds ds = m.getAnnotation(Ds.class);
if(ds != null) {
anonDs.add(ds);
}
}
return anonDs;
}
/**
* @param objectName
* @return boolean Does the rrd exist or not.
*/
public boolean exists(ObjectName objectName) {
try {
return new File(getFileName(objectName)).exists();
} catch (IOException e) {
logger.log(Level.SEVERE, "rrdmanager.existsfailed");
return false;
}
}
}
/**
*
*/
package org.jivesoftware.messenger.plugin.meter;
import org.jrobin.annotations.Ds;
import org.jrobin.annotations.Rrd;
/**
* @author Noah Campbell
* @version 1.0
*/
@Rrd
public interface ThreadMXBeanSupportInfo {
/**
* @return time The current thread cpu time.
*/
@Ds(name="cputime", expr="/CurrentThreadCpuTime" )
long getCurrentThreadCpuTime();
/**
* @return count The current thread count.
*/
@Ds(name="threadCount", expr="/ThreadCount")
long getThreadCount();
}
/**
*
*/
package org.jivesoftware.messenger.plugin.meter;
/**
* @author Noah Campbell
* @version 1.0
*/
public class UnableToAllocateAccumulator extends Exception {
/** The serialVersionUID. */
private static final long serialVersionUID = 1L;
/**
* Construct a new <code>UnableToAllocateAccumulator</code>.
*
*/
public UnableToAllocateAccumulator() {
super();
// TODO Auto-generated constructor stub
}
/**
* Construct a new <code>UnableToAllocateAccumulator</code>.
*
* @param message
* @param cause
*/
public UnableToAllocateAccumulator(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
}
/**
* Construct a new <code>UnableToAllocateAccumulator</code>.
*
* @param message
*/
public UnableToAllocateAccumulator(String message) {
super(message);
// TODO Auto-generated constructor stub
}
/**
* Construct a new <code>UnableToAllocateAccumulator</code>.
*
* @param cause
*/
public UnableToAllocateAccumulator(Throwable cause) {
super(cause);
// TODO Auto-generated constructor stub
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment