(Practice) Observe updates to the system information dashboard in Liferay System Management

Source: Internet
Author: User
Tags server memory

Introduction:

Sometimes we often encounter the server paralysis after Liferay runs for a period of time. In this case, we hope to log on to the Liferay Control Panel as an administrator (Dockbar-> Control Panel-> Server-> Service AdministrationAnd then call some operations in real time, such as garbage collection. Then, we can see the updated server memory or other situations from the dashboard. What kind of secrets are hidden? For example, how to recycle garbage? How is the dashboard updated?


Debugging analysis:

We started from the front end. When we first looked at the Liferay server system information, we saw the following memory overhead:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GG247-0.png "title =" 31.png"/>


When we click the action below: for example, gc:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GH0b-1.png "title =" 32.png"/>


It will trigger the struts action/Admin_server/edit_server,And commandCmdIsGc

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GM501-2.png "title =" 33.png"/>


We can easilyStruts-config.xmlFind the corresponding Action classEditServerAction:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GK964-3.png "title =" 34.png"/>


Because our cmd isGc, So the following branches are used:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GJ255-4.png "title =" 35.png"/>

And callGc ()Method:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GI139-5.png "title =" 36.png"/>

It can be seen that it calls the current applicationGc ()Method to force the garbage collection. I don't want to talk about the difference between Runtime. getRuntime. gc () and System. gc (). There are a lot of related articles.


Now let's look at more interesting topics, how to update the system information dashboard after gc () garbage collection is completed. It is easy to find. In fact, the code corresponding to this dashboard isServer. jspfIn this page frame, because our tab selects"Server"):

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GMS1-6.png "title =" 37.png"/>


We skipped a lot Of unimportant rows and we can find that, until 656th rows, we began to prepare data for the following dashboard:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GL0Z-7.png "title =" 42.png"/>

First, lines 656th to 660th need the total memory from the runtime to the runtime environment of the current application.(TotalMemory)And unused memory(FreeMemory)To calculate the memory used(UsedMemory).


650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GK2b-8.png "title =" 43.png"/>

Then, it calculates the percentage of memory occupied by the total memory (% * 100), And save the value to dataset,

Then initialize row 668MeterPlotObject, which represents a dial with a pointer and encapsulates the corresponding data. It is used by JFreechart and displays the color, ruler, and other information of the Scale Panel.

Then, Row 3 will createJFreeChartObject. The icon name isUsed-memory/total-memoryInternational text:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GG015-9.png "title =" 44.png"/>

All the information about the image in MeterPlotPlotInputJFreeChartObject.


Finally, a row 673rd creates an image object and inserts it into the current page:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GLV2-10.png "title =" 45.png"/>


Now we are more interested in how this image is created and where is its name? Where is the location?


In a macro view, it will callServletUtilities. saveChartASPNG ()The jfreechart object and the width and height of the image are all passed to this method for generating the image. Let's take a look at the implementation:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GL557-11.png "title =" 46.png"/>


First, it will create a temporary directory in row 180. Where is this temporary directory? Let's take a look.CreateTempDir ():

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GIP2-12.png "title =" 47.png"/>

Now I understand that the original temporary directory is inJava. io. tmpdirAnd this is on our server

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GKa9-13.png "title =" 48.png"/>

SeeJava. io. tmpdirDynamic Parameters, so we know that this temporary directory is created in/App/Liferay/RI/liferay-portal-6.1.0-ce-ga1/tomcat-7.0.23/temp, That is$ CATALINA_TMP_DIRBelow:


Then we get the prefix of the image file used at a time in row 183rd:Jfreechart-onetime-

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GG295-14.png "title =" 49.png"/>


Then, based on the file extension (Png), Prefix (Prefix) To create a File object for the corresponding image File:

We verify our$ CATALINA_TMP_DIRAnd found that an image file was created:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GK310-15.png "title =" 50.png"/>

But its size is 0, which is normal, because we only created the File object and didn't ask it to add the image content.

The code for adding content is reloaded by calling the Code in line 187th.ChartUtilitiesOfSaveChartAsPNGMethod implementation:

It can be found that it first createsFileOutputStreamPoint to the target image file, and then write the output stream of the file. It is called to createBufferedImageAnd then useEncoderUtilThis image is encoded in png format and eventually written to the File output stream corresponding to the File object.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GK5B-16.png "title =" 51.png"/>

Now we can compare the image file and find that the size is no longer 0, but now it is 9253 bytes ):

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GK007-17.png "title =" 52.png"/>


Because it is a one-time file, it is called in line 1RegistryChartForDeletionMethod registration to delete the image file.


We can see from the Web debugger of the browser that the resource file was loaded in:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/111GL4S-18.png "title =" 53.png"/>

It is displayed on the page.



Summary:

(1) When garbage collector is called in the control panel to recycle the memory, the essence is to call the gc () method of Runtime corresponding to the current Liferay application, it is used to forcibly perform a garbage collection.

(2) The recovery results are reflected in the upper dashboard and data zone in real time. This dashboard is drawn by JFreechart, which extracts necessary information from the Runtime and then constructs the graph. Then, JFreechart will create a temporary png file in the temporary directory of tomcat, open the file output stream to execute the file, and use JFreechart to create BufferedImage and finally output it to the output stream, then, the newly generated image file is loaded as src and displayed on the page.

(3) once the temporary image file PNG is executed, it will be removed from the temporary tomcat directory by the framework.

This article from "parallel line cohesion" blog, please be sure to keep this source http://supercharles888.blog.51cto.com/609344/1293853

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.