Skip to content
This repository
Browse code

Misc. JMX improvements

  • Loading branch information...
commit 7033e0fb1753b4f25093d2bd1a0d90a255624258 1 parent bc91ded
jkreps jkreps authored
8 src/java/voldemort/server/VoldemortServer.java
@@ -114,14 +114,16 @@ public VoldemortServer(VoldemortConfig config, Cluster cluster) {
114 114 voldemortConfig.getCoreThreads(),
115 115 voldemortConfig.getMaxThreads(),
116 116 voldemortConfig.getSocketBufferSize(),
117   - "client-request-service"));
  117 + "client-request-server",
  118 + voldemortConfig.isJmxEnabled()));
118 119 if(voldemortConfig.isAdminServerEnabled())
119 120 services.add(new SocketService(requestHandlerFactory.getRequestHandler(RequestFormatType.ADMIN_HANDLER),
120 121 identityNode.getAdminPort(),
121 122 voldemortConfig.getAdminCoreThreads(),
122 123 voldemortConfig.getAdminMaxThreads(),
123 124 voldemortConfig.getAdminSocketBufferSize(),
124   - "admin-service"));
  125 + "admin-server",
  126 + voldemortConfig.isJmxEnabled()));
125 127
126 128 if(voldemortConfig.isJmxEnabled())
127 129 services.add(new JmxService(this,
@@ -134,7 +136,7 @@ public VoldemortServer(VoldemortConfig config, Cluster cluster) {
134 136
135 137 @Override
136 138 protected void startInner() throws VoldemortException {
137   - logger.info("Starting all services: " + services.size());
  139 + logger.info("Starting " + services.size() + " services.");
138 140 long start = System.currentTimeMillis();
139 141 for(VoldemortService service: services)
140 142 service.start();
10 src/java/voldemort/server/socket/SocketService.java
@@ -22,6 +22,7 @@
22 22 import voldemort.server.ServiceType;
23 23 import voldemort.server.VoldemortService;
24 24 import voldemort.server.protocol.RequestHandler;
  25 +import voldemort.utils.JmxUtils;
25 26
26 27 /**
27 28 * The VoldemortService that loads up the socket server
@@ -32,14 +33,17 @@
32 33 @JmxManaged(description = "A server that handles remote operations on stores via tcp/ip.")
33 34 public class SocketService extends AbstractService implements VoldemortService {
34 35
  36 + private final String serviceName;
35 37 private final SocketServer server;
  38 + private final boolean enableJmx;
36 39
37 40 public SocketService(RequestHandler requestHandler,
38 41 int port,
39 42 int coreConnections,
40 43 int maxConnections,
41 44 int socketBufferSize,
42   - String serviceName) {
  45 + String serviceName,
  46 + boolean enableJmx) {
43 47 super(ServiceType.SOCKET);
44 48 this.server = new SocketServer(serviceName,
45 49 port,
@@ -47,12 +51,16 @@ public SocketService(RequestHandler requestHandler,
47 51 maxConnections,
48 52 socketBufferSize,
49 53 requestHandler);
  54 + this.serviceName = serviceName;
  55 + this.enableJmx = enableJmx;
50 56 }
51 57
52 58 @Override
53 59 protected void startInner() {
54 60 this.server.start();
55 61 this.server.awaitStartupCompletion();
  62 + if(enableJmx)
  63 + JmxUtils.registerMbean(serviceName, server);
56 64 }
57 65
58 66 @Override
21 src/java/voldemort/server/storage/StorageService.java
@@ -17,7 +17,6 @@
17 17 package voldemort.server.storage;
18 18
19 19 import java.io.File;
20   -import java.lang.management.ManagementFactory;
21 20 import java.util.ArrayList;
22 21 import java.util.Calendar;
23 22 import java.util.Date;
@@ -29,9 +28,6 @@
29 28 import java.util.concurrent.ConcurrentMap;
30 29 import java.util.concurrent.Semaphore;
31 30
32   -import javax.management.MBeanServer;
33   -import javax.management.ObjectName;
34   -
35 31 import org.apache.log4j.Logger;
36 32
37 33 import voldemort.VoldemortException;
@@ -118,6 +114,10 @@ private void initStorageConfig(String configClassName) {
118 114 new Object[] { voldemortConfig });
119 115 logger.info("Initializing " + configuration.getType() + " storage engine.");
120 116 storageConfigs.put(configuration.getType(), configuration);
  117 +
  118 + if(voldemortConfig.isJmxEnabled())
  119 + JmxUtils.registerMbean(configuration.getType() + "StorageConfiguration",
  120 + configuration);
121 121 } catch(IllegalStateException e) {
122 122 logger.error("Error loading storage configuration '" + configClassName + "'.", e);
123 123 }
@@ -183,17 +183,8 @@ public void registerEngine(StorageEngine<ByteArray, byte[]> engine) {
183 183 SystemTime.INSTANCE);
184 184 if(voldemortConfig.isStatTrackingEnabled()) {
185 185 store = new StatTrackingStore<ByteArray, byte[]>(store);
186   -
187   - if(voldemortConfig.isJmxEnabled()) {
188   -
189   - MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
190   - ObjectName name = JmxUtils.createObjectName(JmxUtils.getPackageName(store.getClass()),
191   - store.getName());
192   -
193   - if(mbeanServer.isRegistered(name))
194   - JmxUtils.unregisterMbean(mbeanServer, name);
195   - JmxUtils.registerMbean(mbeanServer, JmxUtils.createModelMBean(store), name);
196   - }
  186 + if(voldemortConfig.isJmxEnabled())
  187 + JmxUtils.registerMbean(store.getName(), store);
197 188 }
198 189 storeRepository.addLocalStore(store);
199 190 }
18 src/java/voldemort/store/bdb/BdbStorageConfiguration.java
@@ -23,6 +23,7 @@
23 23 import org.apache.log4j.Logger;
24 24
25 25 import voldemort.VoldemortException;
  26 +import voldemort.annotations.jmx.JmxGetter;
26 27 import voldemort.server.VoldemortConfig;
27 28 import voldemort.store.StorageConfiguration;
28 29 import voldemort.store.StorageEngine;
@@ -35,6 +36,8 @@
35 36 import com.sleepycat.je.DatabaseException;
36 37 import com.sleepycat.je.Environment;
37 38 import com.sleepycat.je.EnvironmentConfig;
  39 +import com.sleepycat.je.EnvironmentStats;
  40 +import com.sleepycat.je.StatsConfig;
38 41
39 42 /**
40 43 * The configuration that is shared between berkeley db instances. This includes
@@ -115,6 +118,21 @@ public String getType() {
115 118 return TYPE_NAME;
116 119 }
117 120
  121 + public EnvironmentStats getEnvStats() {
  122 + try {
  123 + StatsConfig config = new StatsConfig();
  124 + config.setFast(true);
  125 + return environment.getStats(config);
  126 + } catch(DatabaseException e) {
  127 + throw new VoldemortException(e);
  128 + }
  129 + }
  130 +
  131 + @JmxGetter(name = "stats", description = "A variety of stats about this BDB environment.")
  132 + public String getEnvStatsAsString() {
  133 + return getEnvStats().toString();
  134 + }
  135 +
118 136 public void close() {
119 137 synchronized(lock) {
120 138 try {
41 src/java/voldemort/store/bdb/BdbStorageEngine.java
@@ -27,6 +27,7 @@
27 27 import org.apache.log4j.Logger;
28 28
29 29 import voldemort.VoldemortException;
  30 +import voldemort.annotations.jmx.JmxGetter;
30 31 import voldemort.serialization.IdentitySerializer;
31 32 import voldemort.serialization.VersionedSerializer;
32 33 import voldemort.store.NoSuchCapabilityException;
@@ -49,11 +50,13 @@
49 50 import com.sleepycat.je.Database;
50 51 import com.sleepycat.je.DatabaseEntry;
51 52 import com.sleepycat.je.DatabaseException;
  53 +import com.sleepycat.je.DatabaseStats;
52 54 import com.sleepycat.je.Environment;
  55 +import com.sleepycat.je.EnvironmentConfig;
53 56 import com.sleepycat.je.LockMode;
54 57 import com.sleepycat.je.OperationStatus;
  58 +import com.sleepycat.je.StatsConfig;
55 59 import com.sleepycat.je.Transaction;
56   -import com.sleepycat.je.EnvironmentConfig;
57 60
58 61 /**
59 62 * A store that uses BDB for persistence
@@ -83,14 +86,20 @@ public BdbStorageEngine(String name, Environment environment, Database database)
83 86 this.isOpen = new AtomicBoolean(true);
84 87
85 88 try {
86   - logger.info(" BDB[" + name + "] : cache size = " + environment.getConfig().getCacheSize());
  89 + logger.info(" BDB[" + name + "] : cache size = "
  90 + + environment.getConfig().getCacheSize());
87 91 logger.info(" BDB[" + name + "] : " + EnvironmentConfig.CLEANER_THREADS + " = "
88   - + environment.getConfig().getConfigParam(EnvironmentConfig.CLEANER_THREADS));
89   - logger.info(" BDB[" + name + "] : " + EnvironmentConfig.CLEANER_MIN_FILE_UTILIZATION + " = "
90   - + environment.getConfig().getConfigParam(EnvironmentConfig.CLEANER_MIN_FILE_UTILIZATION));
  92 + + environment.getConfig().getConfigParam(EnvironmentConfig.CLEANER_THREADS));
  93 + logger.info(" BDB["
  94 + + name
  95 + + "] : "
  96 + + EnvironmentConfig.CLEANER_MIN_FILE_UTILIZATION
  97 + + " = "
  98 + + environment.getConfig()
  99 + .getConfigParam(EnvironmentConfig.CLEANER_MIN_FILE_UTILIZATION));
91 100 logger.info(" BDB[" + name + "] : " + EnvironmentConfig.LOG_FILE_MAX + " = "
92   - + environment.getConfig().getConfigParam(EnvironmentConfig.LOG_FILE_MAX));
93   - } catch (DatabaseException e) {
  101 + + environment.getConfig().getConfigParam(EnvironmentConfig.LOG_FILE_MAX));
  102 + } catch(DatabaseException e) {
94 103 logger.error("Error getting config inforation for BDB at startup", e);
95 104 }
96 105 }
@@ -322,7 +331,8 @@ public void close() throws PersistenceFailureException {
322 331
323 332 private void attemptAbort(Transaction transaction) {
324 333 try {
325   - transaction.abort();
  334 + if(transaction != null)
  335 + transaction.abort();
326 336 } catch(Exception e) {
327 337 logger.error("Abort failed!", e);
328 338 }
@@ -338,6 +348,21 @@ private void attemptCommit(Transaction transaction) {
338 348 }
339 349 }
340 350
  351 + public DatabaseStats getStats() {
  352 + try {
  353 + StatsConfig config = new StatsConfig();
  354 + config.setFast(true);
  355 + return this.bdbDatabase.getStats(config);
  356 + } catch(DatabaseException e) {
  357 + throw new VoldemortException(e);
  358 + }
  359 + }
  360 +
  361 + @JmxGetter(name = "stats", description = "A variety of stats about the BDB for this store.")
  362 + public String getStatsAsString() {
  363 + return getStats().toString();
  364 + }
  365 +
341 366 private static class BdbStoreIterator implements
342 367 ClosableIterator<Pair<ByteArray, Versioned<byte[]>>> {
343 368
5 src/java/voldemort/store/socket/SocketPool.java
@@ -154,6 +154,11 @@ public int getNumberOfIdleConnections() {
154 154 return this.pool.getNumIdle();
155 155 }
156 156
  157 + @JmxGetter(name = "numberOfTotalConnections", description = "The total number of connections, whether active or idle.")
  158 + public int getTotalNumberOfConnections() {
  159 + return this.pool.getNumActive() + this.pool.getNumIdle();
  160 + }
  161 +
157 162 @JmxGetter(name = "avgWaitTimeMs", description = "The avg. ms of wait time to acquire a connection.")
158 163 public double getAvgWaitTimeMs() {
159 164 return this.avgWaitNs.doubleValue() / Time.NS_PER_MS;
20 src/java/voldemort/utils/JmxUtils.java
@@ -17,6 +17,7 @@
17 17 package voldemort.utils;
18 18
19 19 import java.lang.annotation.Annotation;
  20 +import java.lang.management.ManagementFactory;
20 21 import java.lang.reflect.Method;
21 22 import java.util.ArrayList;
22 23 import java.util.HashMap;
@@ -292,6 +293,25 @@ public static void registerMbean(MBeanServer server, ModelMBean mbean, ObjectNam
292 293 }
293 294
294 295 /**
  296 + * Register the given object under the package name of the object's class
  297 + * with the given type name.
  298 + *
  299 + * this method using the platform mbean server as returned by
  300 + * ManagementFactory.getPlatformMBeanServer()
  301 + *
  302 + * @param typeName The name of the type to register
  303 + * @param obj The object to register as an mbean
  304 + */
  305 + public static void registerMbean(String typeName, Object obj) {
  306 + MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
  307 + ObjectName name = JmxUtils.createObjectName(JmxUtils.getPackageName(obj.getClass()),
  308 + typeName);
  309 + if(mbeanServer.isRegistered(name))
  310 + JmxUtils.unregisterMbean(mbeanServer, name);
  311 + JmxUtils.registerMbean(mbeanServer, JmxUtils.createModelMBean(obj), name);
  312 + }
  313 +
  314 + /**
295 315 * Unregister the mbean with the given name
296 316 *
297 317 * @param server The server to unregister from

0 comments on commit 7033e0f

Please sign in to comment.
Something went wrong with that request. Please try again.