1 8 package org.mmbase.applications.crontab; 9 10 import org.mmbase.util.ThreadPools; 11 import org.mmbase.cache.Cache; 12 import org.mmbase.util.logging.*; 13 14 43 44 public class MMBaseStatsJob extends AbstractCronJob { 45 private static final Logger log = Logging.getLoggerInstance(MMBaseStatsJob.class); 46 47 private Runnable job; 48 49 private Logger statsLogger; 50 51 protected void init() { 52 String what = cronEntry.getConfiguration(); 54 statsLogger = Logging.getLoggerInstance("org.mmbase.STATS." + what); 55 String w = what.toUpperCase(); 56 if (w.equals("MEMORY")) { 57 job = new Runnable () { 58 public void run() { 59 Runtime runtime = Runtime.getRuntime(); 60 statsLogger.service("" + runtime.freeMemory() + "\t" + runtime.totalMemory()); 61 } 62 }; 63 } else if (w.equals("QUERIES")) { 64 job = new Runnable () { 65 public void run() { 66 statsLogger.service("" + org.mmbase.module.database.MultiConnection.queries); 67 } 68 }; 69 } else if (w.equals("JOBSPOOL")) { 70 job = new Runnable () { 71 public void run() { 72 edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor j = 73 (edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor) ThreadPools.jobsExecutor; 74 statsLogger.service("" + j.getCompletedTaskCount() + '\t' + j.getActiveCount() + '\t'+ j.getQueue().size() + '\t' + 75 j.getPoolSize() + '\t' + j.getLargestPoolSize() + '\t' + j.getCorePoolSize() + '\t' + j.getMaximumPoolSize()); 76 } 77 }; 78 } else if (w.startsWith("CACHE.")) { 79 job = new Runnable () { 80 private Cache cache = getCache(); 81 { 82 if (cache == null) { 83 log.info("No cache with name " + cronEntry.getConfiguration().substring(6) + " found (yet)."); 84 } 85 } 86 public void run() { 87 if (cache == null) cache = getCache(); 88 if (cache != null) { 89 int h = cache.getHits(); 90 statsLogger.service("" + h + "\t" + (h + cache.getMisses())); 91 } 92 } 93 }; 94 } else { 95 job = new Runnable () { 96 public void run() { 97 } 98 }; 99 } 100 101 } 102 106 private Cache getCache() { 107 String cacheName = cronEntry.getConfiguration().substring(6); 108 return Cache.getCache(cacheName); 109 } 110 111 public final void run() { 112 job.run(); 113 } 114 } 115 | Popular Tags |