Source Code Cross Referenced for AgentLoadTracePlugin.java in  » Science » Cougaar12_4 » org » cougaar » core » qos » metrics » 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 » Science » Cougaar12_4 » org.cougaar.core.qos.metrics 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 1997-2004 BBNT Solutions, LLC
005:         *  under sponsorship of the Defense Advanced Research Projects
006:         *  Agency (DARPA).
007:         * 
008:         *  You can redistribute this software and/or modify it under the
009:         *  terms of the Cougaar Open Source License as published on the
010:         *  Cougaar Open Source Website (www.cougaar.org).
011:         * 
012:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015:         *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023:         *  
024:         * </copyright>
025:         */
026:
027:        package org.cougaar.core.qos.metrics;
028:
029:        import java.text.DecimalFormat;
030:        import java.util.ArrayList;
031:        import java.util.Iterator;
032:        import java.util.Set;
033:        import java.text.DecimalFormat;
034:
035:        import org.cougaar.core.service.LoggingService;
036:        import org.cougaar.core.component.ServiceBroker;
037:        import org.cougaar.core.mts.MessageAddress;
038:        import org.cougaar.core.plugin.ComponentPlugin;
039:        import org.cougaar.core.service.ThreadService;
040:        import org.cougaar.core.thread.Schedulable;
041:        import org.cougaar.core.mts.AgentStatusService;
042:
043:        /**
044:         * The test Plugin will dump the time history of an Agent's resource
045:         * load into the logging system.  
046:         */
047:        public class AgentLoadTracePlugin extends ComponentPlugin implements 
048:                Constants {
049:            private LoggingService loggingService = null;
050:            private MetricsService metricsService;
051:            private DecimalFormat formatter = new DecimalFormat("###,#00.0#");
052:            private boolean first_time = true;
053:            private ArrayList agents;
054:            private long start;
055:            private static final int BASE_PERIOD = 10; //10SecAVG
056:            private AgentStatusService agentStatusService = null;
057:
058:            private class Poller implements  Runnable {
059:                public void run() {
060:                    if (first_time) {
061:
062:                        collectNames();
063:                        // log data key
064:                        if (loggingService.isInfoEnabled()) {
065:                            loggingService.info("--- Data Key ---\n"
066:                                    + "Timestamp, " + "AgentName, "
067:                                    + "CPULoad, " + "CPULoadJips, " + "MsgIn, "
068:                                    + "MsgOut, " + "bytesIn, " + "BytesOut, "
069:                                    + "PersistSize");
070:                        }
071:                    } else
072:                        dump();
073:                    first_time = false;
074:                }
075:            }
076:
077:            public AgentLoadTracePlugin() {
078:                super ();
079:            }
080:
081:            private void collectNames() {
082:                start = System.currentTimeMillis();
083:                Set localAgents = getLocalAgents();
084:                if (localAgents == null) {
085:                    return;
086:                }
087:                agents = new ArrayList();
088:                for (Iterator itr = localAgents.iterator(); itr.hasNext();) {
089:                    MessageAddress addr = (MessageAddress) itr.next();
090:                    String name = addr.getAddress();
091:                    agents.add(name);
092:                }
093:            }
094:
095:            private void logAgentMetrics(String name) {
096:                if (name == null) {
097:                    loggingService
098:                            .debug("Agent is null, cannot retrieve any metrics!");
099:                }
100:                String agentPath = "Agent(" + name + ")" + PATH_SEPR;
101:
102:                Metric cpuLoad = metricsService.getValue(agentPath
103:                        + CPU_LOAD_AVG + "(" + _10_SEC_AVG + ")");
104:                double cpuLoadV = cpuLoad.doubleValue();
105:
106:                Metric cpuLoadJips = metricsService.getValue(agentPath
107:                        + CPU_LOAD_MJIPS + "(" + _10_SEC_AVG + ")");
108:                double cpuLoadJipsV = cpuLoadJips.doubleValue();
109:
110:                Metric msgIn = metricsService.getValue(agentPath + MSG_IN + "("
111:                        + _10_SEC_AVG + ")");
112:                double msgInV = msgIn.doubleValue();
113:
114:                Metric msgOut = metricsService.getValue(agentPath + MSG_OUT
115:                        + "(" + _10_SEC_AVG + ")");
116:                double msgOutV = msgOut.doubleValue();
117:
118:                Metric bytesIn = metricsService.getValue(agentPath + BYTES_IN
119:                        + "(" + _10_SEC_AVG + ")");
120:                double bytesInV = bytesIn.doubleValue();
121:
122:                Metric bytesOut = metricsService.getValue(agentPath + BYTES_OUT
123:                        + "(" + _10_SEC_AVG + ")");
124:                double bytesOutV = bytesOut.doubleValue();
125:
126:                Metric persistSize = metricsService.getValue(agentPath
127:                        + PERSIST_SIZE_LAST);
128:                double persistSizeV = persistSize.doubleValue();
129:
130:                long now = System.currentTimeMillis();
131:
132:                if (loggingService.isInfoEnabled()) {
133:                    loggingService.info(now + ", " + name + ","
134:                            + formatter.format(cpuLoadV) + ","
135:                            + formatter.format(cpuLoadJipsV) + ","
136:                            + formatter.format(msgInV) + ","
137:                            + formatter.format(msgOutV) + ","
138:                            + formatter.format(bytesInV) + ","
139:                            + formatter.format(bytesOutV) + ","
140:                            + formatter.format(persistSizeV));
141:                }
142:            }
143:
144:            private long relativeTimeMillis() {
145:                return System.currentTimeMillis() - start;
146:            }
147:
148:            private void dump() {
149:                Iterator itr = agents.iterator();
150:                while (itr.hasNext()) {
151:                    String name = (String) itr.next();
152:                    logAgentMetrics(name);
153:                }
154:            }
155:
156:            public void load() {
157:                super .load();
158:
159:                ServiceBroker sb = getServiceBroker();
160:
161:                metricsService = (MetricsService) sb.getService(this ,
162:                        MetricsService.class, null);
163:
164:                loggingService = (LoggingService) sb.getService(this ,
165:                        LoggingService.class, null);
166:
167:                agentStatusService = (AgentStatusService) sb.getService(this ,
168:                        AgentStatusService.class, null);
169:
170:                ThreadService tsvc = (ThreadService) sb.getService(this ,
171:                        ThreadService.class, null);
172:
173:                Poller poller = new Poller();
174:                Schedulable sched = tsvc.getThread(this , poller, "LoadPoller");
175:                //sched.schedule(60000, 500);
176:                sched.schedule(5000, BASE_PERIOD * 1000);
177:                sb.releaseService(this , ThreadService.class, tsvc);
178:
179:            }
180:
181:            /**
182:             * @return the message addresses of the agents on this
183:             * node, or null if that information is not available.
184:             */
185:            protected final Set getLocalAgents() {
186:                // instead of asking the NodeControlService's AgentContainer for:
187:                //   agentContainer.getAgentAddresses()
188:                // we try getting agents from agentstatus service
189:                if (agentStatusService == null) {
190:                    if (loggingService.isDebugEnabled())
191:                        loggingService
192:                                .debug("No LocalAgents from AgentStatusService");
193:                    return null;
194:                } else {
195:                    return agentStatusService.getLocalAgents();
196:                }
197:            }
198:
199:            protected void setupSubscriptions() {
200:            }
201:
202:            protected void execute() {
203:            }
204:
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.