Source Code Cross Referenced for Stats.java in  » Testing » jakarta-jmeter » org » apache » jmeter » monitor » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » jakarta jmeter » org.apache.jmeter.monitor.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *   http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.jmeter.monitor.util;
018:
019:        import org.apache.jmeter.monitor.model.Connector;
020:        import org.apache.jmeter.monitor.model.Status;
021:
022:        /**
023:         * 
024:         * Description:
025:         * <p>
026:         * Stats is responsible for calculating the load and health of a given server.
027:         * It uses tomcat's status servlet results. A schema was generated for the XML
028:         * output and JAXB was used to generate classes.
029:         * <p>
030:         * The equations are:
031:         * <p>
032:         * memory weight = (int)(50 * (free/max))<br>
033:         * thread weight = (int)(50 * (current/max))
034:         * <p>
035:         * The load factors are stored in the properties files. Simply change the values
036:         * in the properties to change how load is calculated. The defaults values are
037:         * memory (50) and threads (50). The sum of the factors must equal 100.
038:         */
039:        public class Stats {
040:
041:            public static final int DEAD = 0;
042:
043:            public static final int ACTIVE = 2;
044:
045:            public static final int WARNING = 1;
046:
047:            public static final int HEALTHY = 3;
048:
049:            public static final int DEFAULT_MEMORY_FACTOR = 50;
050:
051:            public static final int DEFAULT_THREAD_FACTOR = 50;
052:
053:            public static final double HEALTHY_PER = 0.00;
054:
055:            public static final double ACTIVE_PER = 0.25;
056:
057:            public static final double WARNING_PER = 0.67;
058:
059:            /**
060:             * The method is responsible for taking a status object and calculating an
061:             * int value from 1 to 100. We use a combination of free memory and free
062:             * threads. The current factor is 50/50.
063:             * <p>
064:             * 
065:             * @param stat
066:             * @return calculated load value
067:             */
068:            public static int calculateLoad(Status stat) {
069:                if (stat != null) {
070:                    // equation for calculating the weight
071:                    // w = (int)(33 * (used/max))
072:                    long totMem = stat.getJvm().getMemory().getTotal();
073:                    long freeMem = stat.getJvm().getMemory().getFree();
074:                    long usedMem = totMem - freeMem;
075:                    double memdiv = (double) usedMem / (double) totMem;
076:                    double memWeight = DEFAULT_MEMORY_FACTOR * memdiv;
077:
078:                    // changed the logic for BEA Weblogic in the case a
079:                    // user uses Tomcat's status servlet without any
080:                    // modifications. Weblogic will return nothing for
081:                    // the connector, therefore we need to check the size
082:                    // of the list. Peter 12.22.04
083:                    double threadWeight = 0;
084:                    if (stat.getConnector().size() > 0) {
085:                        Connector cntr = (Connector) stat.getConnector().get(0);
086:                        int maxThread = cntr.getThreadInfo().getMaxThreads();
087:                        int curThread = cntr.getThreadInfo()
088:                                .getCurrentThreadsBusy();
089:                        double thdiv = (double) curThread / (double) maxThread;
090:                        threadWeight = DEFAULT_THREAD_FACTOR * thdiv;
091:                    }
092:                    return (int) (memWeight + threadWeight);
093:                } else {
094:                    return 0;
095:                }
096:            }
097:
098:            /**
099:             * Method should calculate if the server is: dead, active, warning or
100:             * healthy. We do this by looking at the current busy threads.
101:             * <ol>
102:             * <li> free &gt; spare is healthy
103:             * <li> free &lt; spare is active
104:             * <li> busy threads &gt; 75% is warning
105:             * <li> none of the above is dead
106:             * </ol>
107:             * 
108:             * @param stat
109:             * @return integer representing the status
110:             */
111:            public static int calculateStatus(Status stat) {
112:                if (stat != null && stat.getConnector().size() > 0) {
113:                    Connector cntr = (Connector) stat.getConnector().get(0);
114:                    int max = cntr.getThreadInfo().getMaxThreads();
115:                    int current = cntr.getThreadInfo().getCurrentThreadsBusy();
116:                    // int spare = cntr.getThreadInfo().getMaxSpareThreads();
117:                    double per = (double) current / (double) max;
118:                    if (per > WARNING_PER) {
119:                        return WARNING;
120:                    } else if (per >= ACTIVE_PER && per <= WARNING_PER) {
121:                        return ACTIVE;
122:                    } else if (per < ACTIVE_PER && per > HEALTHY_PER) {
123:                        return HEALTHY;
124:                    } else {
125:                        return DEAD;
126:                    }
127:                } else {
128:                    return DEAD;
129:                }
130:            }
131:
132:            /**
133:             * Method will calculate the memory load: used / max = load. The load value
134:             * is an integer between 1 and 100. It is the percent memory used. Changed
135:             * this to be more like other system monitors. Peter Lin 2-11-05
136:             * 
137:             * @param stat
138:             * @return memory load
139:             */
140:            public static int calculateMemoryLoad(Status stat) {
141:                double load = 0;
142:                if (stat != null) {
143:                    double total = stat.getJvm().getMemory().getTotal();
144:                    double free = stat.getJvm().getMemory().getFree();
145:                    double used = total - free;
146:                    load = (used / total);
147:                }
148:                return (int) (load * 100);
149:            }
150:
151:            /**
152:             * Method will calculate the thread load: busy / max = load. The value is an
153:             * integer between 1 and 100. It is the percent busy.
154:             * 
155:             * @param stat
156:             * @return thread load
157:             */
158:            public static int calculateThreadLoad(Status stat) {
159:                int load = 0;
160:                if (stat != null && stat.getConnector().size() > 0) {
161:                    Connector cntr = (Connector) stat.getConnector().get(0);
162:                    double max = cntr.getThreadInfo().getMaxThreads();
163:                    double current = cntr.getThreadInfo()
164:                            .getCurrentThreadsBusy();
165:                    load = (int) ((current / max) * 100);
166:                }
167:                return load;
168:            }
169:
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.