1 17 package org.apache.jmeter.monitor.util; 18 19 import org.apache.jmeter.monitor.model.Connector; 20 import org.apache.jmeter.monitor.model.Status; 21 22 39 public class Stats 40 { 41 42 public static final int DEAD = 0; 43 public static final int ACTIVE = 2; 44 public static final int WARNING = 1; 45 public static final int HEALTHY = 3; 46 47 public static final int DEFAULT_MEMORY_FACTOR = 50; 48 public static final int DEFAULT_THREAD_FACTOR = 50; 49 public static final double HEALTHY_PER = 0.00; 50 public static final double ACTIVE_PER = 0.25; 51 public static final double WARNING_PER = 0.67; 52 53 62 public static int calculateLoad(Status stat){ 63 if (stat != null){ 64 long totMem = stat.getJvm().getMemory().getTotal(); 67 long usedMem = stat.getJvm().getMemory().getFree(); 68 double memdiv = (double)usedMem/(double)totMem; 69 double memWeight = DEFAULT_MEMORY_FACTOR * memdiv; 70 71 Connector cntr = (Connector)stat.getConnector().get(0); 72 int maxThread = cntr.getThreadInfo().getMaxThreads(); 73 int curThread = cntr.getThreadInfo().getCurrentThreadsBusy(); 74 double thdiv = (double)curThread/(double)maxThread; 75 double threadWeight = DEFAULT_THREAD_FACTOR * thdiv; 76 return (int)(memWeight + threadWeight); 77 } else { 78 return 0; 79 } 80 } 81 82 95 public static int calculateStatus(Status stat){ 96 if (stat != null){ 97 Connector cntr = (Connector)stat.getConnector().get(0); 98 int max = cntr.getThreadInfo().getMaxThreads(); 99 int current = cntr.getThreadInfo().getCurrentThreadsBusy(); 100 double per = (double)current/(double)max; 102 if (per > WARNING_PER){ 103 return WARNING; 104 } else if (per >= ACTIVE_PER && per <= WARNING_PER){ 105 return ACTIVE; 106 } else if (per < ACTIVE_PER && per > HEALTHY_PER){ 107 return HEALTHY; 108 } else { 109 return DEAD; 110 } 111 } else { 112 return DEAD; 113 } 114 } 115 116 124 public static int calculateMemoryLoad(Status stat){ 125 double load = 0; 126 if (stat != null){ 127 double total = (double)stat.getJvm().getMemory().getTotal(); 128 double used = (double)stat.getJvm().getMemory().getFree(); 129 load = (used/total); 130 } 131 return (int)(load * 100); 132 } 133 134 142 public static int calculateThreadLoad(Status stat){ 143 int load = 0; 144 if (stat != null){ 145 Connector cntr = (Connector)stat.getConnector().get(0); 146 double max = (double)cntr.getThreadInfo().getMaxThreads(); 147 double current = 148 (double)cntr.getThreadInfo().getCurrentThreadsBusy(); 149 load = (int)((current/max) * 100); 150 } 151 return load; 152 } 153 154 } 155 | Popular Tags |