Project

General

Profile

« Previous | Next » 

Revision aa4c257a

Added by Andreas Kohlbecker about 13 years ago

showing memory usage

View differences:

src/main/java/eu/etaxonomy/cdm/server/Bootloader.java
177 177
		return configAndStatusSet;
178 178
	}
179 179

  
180
	private File webappFile = null;
180
	private File cdmRemoteWebAppFile = null;
181 181
    private File defaultWebAppFile = null;
182 182
    
183 183
    private Server server = null;
......
276 276
		 // print the help message
277 277
		 if(cmdLine.hasOption(HELP.getOpt())){
278 278
			 HelpFormatter formatter = new HelpFormatter();
279
			 formatter.setWidth(200);
279 280
			 formatter.printHelp( "java .. ", CommandOptions.getOptions() );
280 281
			 System.exit(0);
281 282
		 }
......
367 368
    	
368 369
    	 // WARFILE
369 370
    	 if(cmdLine.hasOption(WEBAPP.getOpt())){
370
    		 webappFile = new File(cmdLine.getOptionValue(WEBAPP.getOpt()));
371
    		 if(webappFile.isDirectory()){
372
    			 logger.info("using user defined web application folder: " + webappFile.getAbsolutePath());    			     			 
371
    		 cdmRemoteWebAppFile = new File(cmdLine.getOptionValue(WEBAPP.getOpt()));
372
    		 if(cdmRemoteWebAppFile.isDirectory()){
373
    			 logger.info("using user defined web application folder: " + cdmRemoteWebAppFile.getAbsolutePath());    			     			 
373 374
    		 } else {
374
    			 logger.info("using user defined warfile: " + webappFile.getAbsolutePath());
375
    			 logger.info("using user defined warfile: " + cdmRemoteWebAppFile.getAbsolutePath());
375 376
    		 }
376
    		 if(isRunningFromSource()){
377
    			 //FIXME check if all local paths are valid !!!!
377
    		 if(isRunningFromCdmRemoteWebAppSource()){
378
    			 //TODO check if all local paths are valid !!!!
378 379
    	    	defaultWebAppFile = new File("./src/main/webapp");	
379 380
    	    	
380 381
    	     } else {
381 382
    	    	defaultWebAppFile = extractWar(DEFAULT_WEBAPP_WAR_NAME);
382 383
    	     }
383 384
    	 } else {    	 
384
    		 webappFile = extractWar(CDM_WEBAPP_WAR_NAME);
385
    		 cdmRemoteWebAppFile = extractWar(CDM_WEBAPP_WAR_NAME);
385 386
    		 defaultWebAppFile = extractWar(DEFAULT_WEBAPP_WAR_NAME);
386 387
    	 }
387 388
    	 
......
600 601
            
601 602
            cdmWebappContext.setAttribute(ATTRIBUTE_DATASOURCE_NAME, conf.getDataSourceName());
602 603
            cdmWebappContext.setAttribute(ATTRIBUTE_JDBC_JNDI_NAME, conf.getJdbcJndiName());
603
	        setWebApp(cdmWebappContext, webappFile);
604
	        setWebApp(cdmWebappContext, cdmRemoteWebAppFile);
604 605
	        
605 606
			cdmWebappContext.setAttribute(ATTRIBUTE_CDM_LOGFILE,
606 607
					LOG_PATH + File.separator + "cdm-"
607 608
							+ conf.getDataSourceName() + ".log");
608 609
   
609
	        if(webappFile.isDirectory() && isRunningFromSource()){
610
	        if(cdmRemoteWebAppFile.isDirectory() && isRunningFromCdmRemoteWebAppSource()){
610 611
        		
611 612
				/*
612 613
				 * when running the webapp from {projectpath} src/main/webapp we
......
660 661
	/**
661 662
	 * @return
662 663
	 */
663
	private boolean isRunningFromSource() {
664
		String webappPathNormalized = webappFile.getAbsolutePath().replace('\\', '/');
665
		return webappPathNormalized.endsWith("src/main/webapp") || webappPathNormalized.endsWith("cdmlib-remote/target/cdmserver");
664
	private boolean isRunningFromCdmRemoteWebAppSource() {
665
		String webappPathNormalized = cdmRemoteWebAppFile.getAbsolutePath().replace('\\', '/');
666
		return webappPathNormalized.endsWith("src/main/webapp") || webappPathNormalized.endsWith("cdmlib-remote-webapp/target/cdmserver");
666 667
	}
667 668
	
668 669
	/**
src/main/java/eu/etaxonomy/cdm/server/CommandOptions.java
30 30
	public static final Option WEBAPP = OptionBuilder
31 31
			.withArgName("file")
32 32
			.hasArg()
33
			.withDescription( "use the specified webapplication this either can be a compressed war or extracted file. " +
34
					"If this option is used extraction of the war from the cdmserver jar file is omitted." +
35
					"Using the following paths developers can run the server completely from the target folder or completely from source:\n" +
36
					"'{cdmlib-project-root}/cdmlib-remote/target/cdmserver'\n " +
37
					"'{cdmlib-project-root}/cdmlib-remote/src/main/webapp'" )
33
			.withDescription( "Defines the webapplication to run from, this either can be a compressed war or extracted file.\n" +
34
					"Defaults to the cdm-remote-webapp.war which is found in cdm-server/traget\n" +
35
					"If this option is used extraction of the war from the cdmserver jar file is omitted.\n \n" +
36
					"Using the following paths developers can run the cdmlib-remote-webapp instaces completely from the target folder or from source:\n" +
37
					" - '{cdmlib-project-root}/cdmlib-remote-webapp/target/cdmserver'\n " +
38
					" - '{cdmlib-project-root}/cdmlib-remote-webapp/src/main/webapp'\n" +
39
					"This will also affect the cdm-server project, if any of both paths is set cdm-server will be run using the cdm-server/src/main/webapp folder!" )
38 40
			.create("webapp");
39 41

  
40 42
	@SuppressWarnings("static-access")
src/main/webapp/manage/index.jsp
5 5
<%@page import="java.net.URL" %>
6 6
<%@page import="eu.etaxonomy.cdm.server.CdmInstanceProperties"%>
7 7
<%@page import="eu.etaxonomy.cdm.server.JvmManager" %>
8
<%@page import="java.io.IOException"%>
9
<%!
10
public void printMemoryUsage(java.lang.management.MemoryUsage memoryUsage, String label, String barWidth, String cssColorUsed, String cssColorMax, JspWriter writer) throws IOException{
11
	float mb = 1024 * 1024;
12
	float gb = mb * 1024;
13
    float max = memoryUsage.getMax() / mb;
14
    float used = memoryUsage.getUsed() / mb;
15
    float percent = used * 100 / max;
16
	writer.append("<span class=\"memory-usage\">").append(label + "(" + used + " of "  + max+ " MB)&nbsp;")
17
	.append("<div style=\"height: 100%; width:")
18
	.append(barWidth).append(";background-color:").append(cssColorMax).append("\">")
19
	.append("<div style=\"background-color:" + cssColorUsed + "; width:" + percent + "%\">&nbsp;</div></div></span>");
20
}
21
%>
22

  
8 23
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
9 24

  
10 25
<head>
......
43 58
								<!-- ============================= -->
44 59
								<div class="block-wrapper">
45 60
								  <h2 class="title block-title pngfix">Server Status</h2>
46
									<div class="block" id="status">JVM memory configuration: 
61
									<div class="block" id="status">
47 62
									   <% 
48
									   double mb = 1024 * 1024;
49
									   out.append("HeapMemory=").append(String.valueOf((JvmManager.getHeapMemoryUsage().getMax() / mb))).append("MB ;");
50
									   out.append("PermGenSpace=").append(String.valueOf((JvmManager.getPermGenSpaceUsage().getMax() / mb))).append("MB"); 
63
									   printMemoryUsage(JvmManager.getHeapMemoryUsage(), "HeapUsage", "100%", "#F48B65", "#65B1F4", out);
64
									   printMemoryUsage(JvmManager.getPermGenSpaceUsage(), "PermGenSpaceUsage", "100%","#F48B65", "#65B1F4", out);
51 65
									   %> 
52 66
									</div>
53 67
								</div>

Also available in: Unified diff