Monday, June 30, 2014

Non-Access Modifiers in Java

No comments:

We know what are the list of access modifiers in Java, but what are the list of non-access modifiers ? Here is the list in tabular format !

clip_image002[4]

Just listed out the list of Non-Access modifier in detail for better understanding !

image

Happy learning !

Courtesy: http://www.tutorialspoint.com/java/java_nonaccess_modifiers.htm

Read More

Sunday, June 29, 2014

How to host website using node Js ?

No comments:

Is it possible to develop a web server functionality using Java Scripting language? Do you believe this, because I didn’t believe in it when I heard about it first.

clip_image001

But the author of node.js Ryan Lienhart Dahl believed and delivered ! Node.js simple yet amazing, give a try!

What Wikipedia says about node Js ?

Node.js is a software platform for scalable server-side and networking applications. Node.js applications are written in JavaScript, and can be run within the Node.js runtime on Mac OS X, Windows and Linux with no changes.

Things that you can do using node.js ?

The HTTP and socket support allows Node.js to act as a web server without additional web server software such as Apache HTTP server.

My Experiment with node.js:

1] Prerequisites :-

clip_image001 Node.js

clip_image001[1] Connect package

2] Server.js content:-

var connect = require('connect');

connect().use(connect.static(__dirname + '/sociogram')).listen(80);

console.log('Server started on port 80');

3] Application folder structure:-

clip_image002

4] Start the server process:-

As mentioned in the js code a server process initiated and it will be keep on listening on port 80.

clip_image004

5] Hosting:-

Snapshot of sociogram application that hosted using node.js server side functionality.

clip_image005

Happy hosting !

Read More

Automation – Take Snapshot of live webpage periodically using PhantomJS

No comments:

Requirement:-

PhantomJS

I have developed a monitoring dashboard application which displays backlog trends of various application components, something like below. I want take snapshot of this live monitoring dashboard webpage every 30 minutes and send it as inline attachment to specific set of Email Ids.

Observare

Please visit the following link for the live demo.

http://anjuwedssrini.com/Demos/HighCharts-Demo/

Steps Involved:-

1] First download the phantomJS plugin from the following link, and extract it inside the desired folder.

https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2

2] Put the code inside the a Js file.

[thiru@localhost bin]$ cat observare.js
var page = require('webpage').create();
page.open('http://anjuwedssrini.com/Demos/HighCharts-Demo/’, function() {
         page.viewportSize = { width:1200, height:768 };
         window.setTimeout(function () {
         page.render('/optionalphantom/bin/observare.jpg');
         phantom.exit();
}, 1000);
});

3] Execute the JS  code using phanomJS executable available inside extracted binary.

[thiru@localhost bin]$ /optional/phantom/bin/phantomjs observare.js

Now we done with the image generation, but how to attach the generated image as inline attachment ? Is it easy ?

How to send image as an inline attachment using sendmail?

Linux send mail command have some exceptional features to do all these stuff.

/usr/sbin/sendmail -t <<EOT
TO: industryvertical@gmal.com
FROM: Thirunavukkarasu.Muthusamy@gmail.com
SUBJECT:  Observer – Dashboard Report
MIME-Version: 1.0
Content-Type: multipart/related;boundary="XYZ"

--XYZ
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
</head>
<body bgcolor="#ffffff" text="#000000">
<img src="cid:part1.0609040" alt="">
</body>
</html>

--XYZ
Content-Type: image/jpeg;name="observare.jpg"
Content-Transfer-Encoding: base64
Content-ID: <part1.0609040>
Content-Disposition: inline; filename="observare.jpg"

$(base64 /optional/images/observare.jpg)

--XYZ--
EOT

Now we done with the image generation using phantomJs and image encoding, inline attachment using sendemail utility. By putting it all together we got the following script.

Full script:-

#!/bin/bash
#Program Name: Report_generation.sh
#Purpose: Report Generation

export hour=`date -u +%H`

function takesnap()
{
echo "Inside Take Snap fucntion!!"
/optional/phantom/bin/phantomjs observare.js
}

function sendmail()
{
/usr/sbin/sendmail -t <<EOT
TO: industryvertical@gmal.com
FROM: Thirunavukkarasu.Muthusamy@gmail.com
SUBJECT:  Observer – Dashboard Report
MIME-Version: 1.0
Content-Type: multipart/related;boundary="XYZ"

--XYZ
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
</head>
<body bgcolor="#ffffff" text="#000000">
<img src="cid:part1.0609040" alt="">
</body>
</html>

--XYZ
Content-Type: image/jpeg;name="observare.jpg"
Content-Transfer-Encoding: base64
Content-ID: <part1.0609040>
Content-Disposition: inline; filename="observare.jpg"

$(base64 /optional/images/observare.jpg)

--XYZ--
EOT

}

#Main function starts here
takesnap
sendmail

Schedule as Cron:-

Make it as a cron, to send the report periodically to the distribution list something like below.

#Dashboard report generation
*/30 * * * *  sh /optional/phantom/bin/Report_generation.sh > /dev/null 2>&1

Read More

Automation – Monthly SAR report using KSAR

No comments:

If you are an System/Database administrator, and just like me you also want to generate the monthly SAR report in graphical form for analyze the trend. Then this article is definitely for you, please follow the steps mentioned below.

image

Step 1: -

Merge all the SAR output available in the /var/log/sa*.

#!/bin/bash

#Program Name:gather_sar.sh

merge_sar()

{

#loop through 31 possible days, merge all files into one

for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31; do

LC_ALL=C sar -A -f /var/log/sa/sa$i >> sarmonthly.txt

done

}

#Main function starts here

merge_sar

Step 2:-

Pass the merged text filed as an input to this kSar.jar, like below:

[thiru@localhost kSar-5.0.6]$ java -jar kSar.jar  -input sarmonthly.txt -outputPDF sarmonthly.pdf

time to parse: 1022ms number of line: 4357 line/msec: 4.0

Step 3:- Memory utilization of this machine for the last one week.

image

Read More

Automation - KSAR report generation

No comments:

Currently in most organizations people use Oracle Enterprise Manager(OEM) to analyze/monitor the CPU,Memory,IO utilization of Linux machines in pictorial representation. But think of a situation where you have no such tools to analyze the trends of Memory/CPU/IO. And that is moment KSAR is going to very handy.

Do you know that interesting trick? Now with the graphical SAR tool called KSAR, it’s easy to automate the report generation by just following the below steps.

Step 1:-

At the end of 23:59 minute generate the system activity report and redirect it to text file.

[thiru@localhost kSar-5.0.6]$ LC_ALL=C sar -A -f /var/log/sa/sa13 > sar13.txt

Step 2:-

Just download the KSAR from the following site http://sourceforge.net/projects/ksar/. And unzip it to some directory, now you can go ahead and execute this following command to generate SAR report in PDF format.

[thiru@localhost kSar-5.0.6]$ java -jar kSar.jar  -input sar13.txt -outputPDF sar13.pdf

time to parse: 1022ms number of line: 4357 line/msec: 4.0

And I do believe it helps you at some point, where you don’t have tools like Oracle Enterprise Manager(OEM) to monitor all this stuff!

Read More

Little background about SAR

1 comment:

By default Linux and Unix machines stores the SAR (System Activity Report) output for 9 days. And it will be stored inside the /var/log/sa/ directory.

image

[thiru@localhost~]$ ls -ltr /var/log/sa/sa*|grep -v sar
-rw-r--r-- 1 root root 338928 Jan 13 23:50 /var/log/sa/sa13
-rw-r--r-- 1 root root 338928 Jan 14 23:50 /var/log/sa/sa14
-rw-r--r-- 1 root root 338928 Jan 15 23:50 /var/log/sa/sa15
-rw-r--r-- 1 root root 338928 Jan 16 23:50 /var/log/sa/sa16
-rw-r--r-- 1 root root 338928 Jan 17 23:50 /var/log/sa/sa17
-rw-r--r-- 1 root root 338928 Jan 18 23:50 /var/log/sa/sa18
-rw-r--r-- 1 root root 338928 Jan 19 23:50 /var/log/sa/sa19
-rw-r--r-- 1 root root 338928 Jan 20 23:50 /var/log/sa/sa20
-rw-r--r-- 1 root root  82560 Jan 21 05:40 /var/log/sa/sa21

We can extract the memory utilization, CPU, Swap, IO from the stored SAR report by providing the specified SAR report file.

Example:

I - RAM Memory utilization

[thiru@localhost~]$ sar -r -f /var/log/sa/sa20

10:40:01 PM kbmemfree kbmemused  %memused kbbuffers  kbcached kbswpfree kbswpused  %swpused  kbswpcad
10:50:01 PM  28089004   6510764     18.82    468820    386136  32505732       108      0.00         0
11:00:01 PM  28087392   6512376     18.82    470460    386144  32505732       108      0.00         0
11:10:01 PM  28081460   6518308     18.84    472020    390504  32505732       108      0.00         0
11:20:01 PM  28079972   6519796     18.84    473672    390504  32505732       108      0.00         0
11:30:02 PM  28078236   6521532     18.85    475384    390512  32505732       108      0.00         0
11:40:01 PM  28076872   6522896     18.85    477040    390508  32505732       108      0.00         0
11:50:01 PM  28073836   6525932     18.86    478784    390560  32505732       108      0.00         0
Average:     13386344  21213424     61.31    227578  15170261  32505732       108      0.00 

II - CPU Utilization

“[thiru@localhost~]$ sar -u -f /var/log/sa/sa20

05:40:01 AM       CPU     %user     %nice   %system   %iowait    %steal     %idle
05:50:02 AM       all     80.62      0.00      1.67      0.12      0.00     17.59
06:00:02 AM       all     81.22      0.00      1.70      0.09      0.00     17.00
06:10:01 AM       all     81.39      0.00      1.69      0.10      0.00     16.82
06:20:02 AM       all     81.59      0.00      1.72      0.12      0.00     16.58
06:30:01 AM       all     80.31      0.00      1.71      0.09      0.00     17.90
06:40:01 AM       all     80.88      0.00      1.82      0.11      0.00     17.19
06:50:01 AM       all     81.05      0.00      1.87      0.05      0.00     17.04
07:00:01 AM       all     80.31      0.00      2.07      0.03      0.00     17.58
07:10:01 AM       all     80.80      0.00      2.30      0.11      0.00     16.79
07:20:01 AM       all     79.90      0.00      2.27      0.08      0.00     17.74
07:30:01 AM       all     79.97      0.00      2.33      0.06      0.00     17.64
07:40:02 AM       all     80.84      0.00      2.59      0.06      0.00     16.52
07:50:01 AM       all     79.75      0.00      2.42      0.05      0.00     17.79
08:00:01 AM       all     81.13      0.00      2.21      0.10      0.00     16.56
08:10:02 AM       all     81.71      0.00      1.74      0.08      0.00     16.46

Read More