Friday, August 6, 2010
A UNIX survival guide for students
1. Basic UNIX commands
> ls
List the contents in current directory.
> ls -alF
List the contents in long format in the current directory.
> cd directoryname
Change current directory to another directory.
> mkdir directoryname
Create a directory.
> cp file1.txt file2.txt
Make a copy of file1.txt.
> mv /home/harpreet/file1.txt /tmp/file2.txt
Move the file to different location or can be used for renaming a file.
> rm filename.txt
Delete a file.
> rm -R directoryname
Delete the contents of a directory.
> head -20 filename.txt
Get 20 lines from the top of the file.
> tail -30 filename.txt
Get 30 lines from the bottom of the file.
2. vi filename.txt
Edit a file.
a. Esc dd
Deletes the current line
b. Esc u
Undo the last action
c. Esc :0 (zero)
Move cursor to first line of file
d. Esc $
Move to end of current line
e. Esc Shift+g
Move to end of file
f. Esc yy
Copy the current line
Esc y3y
Copy the next three lines
g. Esc p
Paste the copied line(s)
h. Esc :35
Moves the cursor to line number 35
i. Esc /wordtofind
Find the word within the file. Press 'n' to move to the next occurrence.
3. > grep 'wordtofind' filename.txt
Finds the line containing a string from the file
grep -i 'wordtofind' filename.txt
Case-insensitive find.
4. > find /tmp/directoryname -name test.txt
Find a file with name 'test.txt' in the given path.
5. > find . -type f -exec grep -i Row2 {} \; -print
Find the word 'row2' from all the files in current path.
Also, shows the line containing an occurrence of the word.
6. > scp harpreet@hostname.edu:/tmp/file.txt .
Copy a file located on another server to the current directory on the present server.
> scp file.txt harpreet@hostname.edu:.
Copy a file from current server to another server into your home directory.
> scp file.txt harpreet@hostname.edu:/home/directory/file.txt
Copy a file from one machine to another.
7. > tar cvzf new_tar_file.tar.gz file1.txt file2.txt
Create a tar file new_tar_file.tar.gz containing file1.txt and file2.txt
> tar xvzf abc.tar.gz
Untar the contents of a file abc.tar.gz to the current directory
8. awk - Let us create a file 'test.txt' with these contents
Row1-column1 Row1-column2 Row1-column3 Row1-column4
Row2-column1 Row2-column2-HARPREET Row2-column3 Row2-column4
Row3-column1 Row3-column2 Row3-column3 Row3-column4-SINGH
Observe the output for various commands
> awk '{print $2}' test.txt
Row1-column2
Row2-column2-HARPREET
Row3-column2
The above command prints the second column
String matching using awk :
> awk '{if ( $4 ~ /SINGH/ ) { print $2 $3}}' test.txt
Row3-column2Row3-column3
The above command matches the string 'SINGH' and prints column 2 and 3.
Corrections/improvements/questions are welcome :)
Location:
Mountain View, CA, USA
Friday, July 30, 2010
Compiling Ganglia - Errors and problems
Some errors and problems:
My install directory was /opt/ganglia.
Error -
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
Solution -
Add gcc bin path to PATH environment variable
Error -
checking for pcre.h... no
checking for pcre_compile in -lpcre... no
libpcre not found, specify --with-libpcre=no to build without PCRE support
Solution -
PCRE is not installed.
# wget ftp://ftp.sunfreeware.com/pub/freeware/SOURCES/pcre-8.10.tar.gz
# /usr/local/bin/tar -xzf pcre-8.10.tar.gz
# cd pcre-8.10
# ./configure --prefix=/opt/ganglia
# make && make install
Make sure you add, -I/opt/ganglia/include to CFLAGS environment variable
and -L/opt/ganglia/lib to LDFLAGS after this.
Problem -
Graphs not shown in ganglia or images not shown on ganglia front end.
Reason -
php-gd may not have been installed.
You can do so by ( as root) -
Error -
Reason -
APR is not installed or path of apr-1-config is not available through the PATH environment variable.
Error -
libgcc_s.so.1: open failed: No such file or directory
Solution-
Execute the following:
# ldd gmond
...
libgcc_s.so.1 => (file not found)
...
So gmond can link to libgcc
Add the following to you LDFLAGS
# setenv LDFLAGS $LDFLAGS:-R/yourgccpath/gcc-4.0.3/lib
-R records the runtime search path.
Install again
# ./configure --prefix=/opt/ganglia --sysconfdir=/opt/ganglia/etc
# make && make install
Error -
After installation, while executing gmond
apr_pollset_create failed: Invalid argument
Solution -
In your config file gmond.conf, if there is no udp_recv_channel or tcp_accept_channel
defined, gmond fails to run with this error.
Set "deaf = yes " under "globals"
Error -
/usr/bin/ld: cannot find -lpython2.3
collect2: ld returned 1 exit status
make[4]: *** [modpython.la] Error 1
Solution -
I dont remember exactly how i resolved it.
Most likely it was the linker not being able to find python.
Probably by setting library flags this error was resolved.
Error -
false cru libgetopthelper.a getopt1.o getopt.o getopt_init.o
make[2]: *** [libgetopthelper.a] Error 1
Solution -
Add /usr/ccs/bin to PATH environment variable.
In case of dependency not found errors, you could configure options, like --with-libapr, --with-libconfuse to point to dependency paths.
Error -
Some gm_protocol_xdr.c related warnings and finally build fails with this error
ld: fatal: relocations remain against allocatable but non-writable sections
collect2: ld returned 1 exit status
Solution -
Uninstall the dependency 'confuse' and install it by setting CFLAGS="-O3 -fPIC"
> cd ../confuse-2.7/
> make uninstall
> make clean
> env CFLAGS="-O3 -fPIC" ./configure --prefix=/opt/ganglia
> make && make install
Do a configure, make and make install and you should be good.
My install directory was /opt/ganglia.
Error -
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
Solution -
Add gcc bin path to PATH environment variable
Error -
checking for pcre.h... no
checking for pcre_compile in -lpcre... no
libpcre not found, specify --with-libpcre=no to build without PCRE support
Solution -
PCRE is not installed.
# wget ftp://ftp.sunfreeware.com/pub/freeware/SOURCES/pcre-8.10.tar.gz
# /usr/local/bin/tar -xzf pcre-8.10.tar.gz
# cd pcre-8.10
# ./configure --prefix=/opt/ganglia
# make && make install
Make sure you add, -I/opt/ganglia/include to CFLAGS environment variable
and -L/opt/ganglia/lib to LDFLAGS after this.
Problem -
Graphs not shown in ganglia or images not shown on ganglia front end.
Reason -
php-gd may not have been installed.
You can do so by ( as root) -
# yum install php-gd
Another reason could be front-end can't find RRD path. Make sure it is set in conf.phpError -
checking for apr-1-config... no
configure: error: apr-1-config binary not found in path
configure: error: apr-1-config binary not found in path
Reason -
APR is not installed or path of apr-1-config is not available through the PATH environment variable.
Error -
libgcc_s.so.1: open failed: No such file or directory
Solution-
Execute the following:
# ldd gmond
...
libgcc_s.so.1 => (file not found)
...
So gmond can link to libgcc
Add the following to you LDFLAGS
# setenv LDFLAGS $LDFLAGS:-R/yourgccpath/gcc-4.0.3/lib
-R records the runtime search path.
Install again
# ./configure --prefix=/opt/ganglia --sysconfdir=/opt/ganglia/etc
# make && make install
Error -
After installation, while executing gmond
apr_pollset_create failed: Invalid argument
Solution -
In your config file gmond.conf, if there is no udp_recv_channel or tcp_accept_channel
defined, gmond fails to run with this error.
Set "deaf = yes " under "globals"
Error -
/usr/bin/ld: cannot find -lpython2.3
collect2: ld returned 1 exit status
make[4]: *** [modpython.la] Error 1
Solution -
I dont remember exactly how i resolved it.
Most likely it was the linker not being able to find python.
Probably by setting library flags this error was resolved.
Error -
false cru libgetopthelper.a getopt1.o getopt.o getopt_init.o
make[2]: *** [libgetopthelper.a] Error 1
Solution -
Add /usr/ccs/bin to PATH environment variable.
In case of dependency not found errors, you could configure options, like --with-libapr, --with-libconfuse to point to dependency paths.
Error -
Some gm_protocol_xdr.c related warnings and finally build fails with this error
ld: fatal: relocations remain against allocatable but non-writable sections
collect2: ld returned 1 exit status
Solution -
Uninstall the dependency 'confuse' and install it by setting CFLAGS="-O3 -fPIC"
> cd ../confuse-2.7/
> make uninstall
> make clean
> env CFLAGS="-O3 -fPIC" ./configure --prefix=/opt/ganglia
> make && make install
Do a configure, make and make install and you should be good.
Location:
Mountain View, CA, USA
jQuery - Start date/end date datepicker calendar and datatable
This post is basically a snippet of code to address the following -
1. Attach jQuery (datepicker) calendar to start date and end date inputs.
2. Create a jQuery datatable
3. On page submit, hide submit button and show a loading image instead.
After you have downloaded jQuery and extracted it to appropriate folders,
create a php file with these contents -
<?php
class InitPage {
public $jscript = "
<script type=\"text/javascript\" src=\"js/jquery-1.4.2.min.js\"></script>
<script type=\"text/javascript\" src=\"ui/jquery.ui.core.js\"></script>
<script type=\"text/javascript\" src=\"ui/jquery.ui.widget.js\"></script>
<script type=\"text/javascript\" src=\"ui/jquery.ui.datepicker.js\"></script>
<script type=\"text/javascript\" src=\"js/jquery.dataTables.js\"></script>
<script type=\"text/javascript\" src=\"js/myjscript.js\"></script>";
public $css =
" <link type=\"text/css\" href=\"themes/redmond/jquery.ui.all.css\" rel=\"stylesheet\" />";
public $header = "<html><head><title>Random Information</title>";
public $body = "</head><body ><h1 >Random Information</h1>";
public $footer =
"<div id=\"footer\"><p><a href=\"http://rowsandcolumns.blogspot.com\">
http://rowsandcolumns.blogspot.com</a></div></body> </html>";
public function print_page($v_header,$v_jscript,$contents,$v_footer="") {
if(!$v_header) {
$v_header = $this->header.$this->jscript.$this->css.$this->body;
}
if(!$v_footer) {
$v_footer = $this->footer;
}
echo $v_header.$contents.$v_footer;
}
function is_date( $str )
{
$stamp = strtotime( $str );
if (!is_numeric($stamp)) {
return FALSE;
}
$month = date( 'm', $stamp );
$day = date( 'd', $stamp );
$year = date( 'Y', $stamp );
if (checkdate($month, $day, $year)) {
return TRUE;
}
return FALSE;
}
}
$table_contents = "";
if(isset($_POST) && !empty($_POST)) { //On submit enter here
$bp = new InitPage();
// Get dates and validate if
//start date and end date are in proper format
if (isset($_POST["start-date"]) &&
$bp->is_date($_POST["start-date"]) &&
isset($_POST["end-date"]) &&
$bp->is_date($_POST["end-date"])
){
list($start_date_m, $start_date_d, $start_date_Y)= explode("/",$_POST["start-date"]);
list($end_date_m, $end_date_d, $end_date_Y)= explode("/",$_POST["end-date"]);
$start_date = date("Y-m-d H:i:s", mktime(8, 0, 0, $start_date_m, $start_date_d, $start_date_Y));
$end_date = date("Y-m-d H:i:s", mktime(8, 0, 0, $end_date_m, $end_date_d, $end_date_Y));
if($end_date <= $start_date) {
$table_contents.= "<font size=\"2\" color=\"red\">Start date should be
less than end date!</font>";
$bp->print_page("","",$table_contents,"");
die;
}
//Time to hide submit button and show loading image
sleep(3);
$table_contents = "<br/><br/><div style=\"width:500;\" >
<table border=\"1\" width=\"500\" id=\"reading\">
<thead>
<tr>
<th>Serial #</th>
<th>Name</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<tr><td> 1 </td> <td> Managers </td> <td> 10 </td></tr>
<tr><td> 2 </td> <td> Engineers </td> <td> 50 </td></tr>
<tr><td> 3 </td> <td> Interns </td> <td> 5 </td></tr>
<tr><td> 4 </td> <td> Executives </td> <td> 3 </td></tr>
<tr><td> 5 </td> <td> Facilities </td> <td> 2 </td></tr>
</tbody>
<tfoot>
<tr>
<th>Serial #</th>
<th>Name</th>
<th>Count</th>
</tr>
</tfoot>
</table></div><br/> ";
}
else {
$table_contents.= "<font size=\"2\" color=\"red\">Start date/End date
is not valid!</font>";
}
$bp->print_page("","",$table_contents,"");
die;
}
else { // On first page load
$bp = new InitPage();
$select_cb = "<form action=\"index.php\" method=\"post\">Please select start and
end date...<br/>
<br/><label for=\"start-date\">Start date:</label>
<input type=\"text\" name=\"start-date\" id=\"start-date\"/><br/><br/>
<label for=\"end-date\">End date: </label>
<input type=\"text\" name=\"end-date\" id=\"end-date\"/>
<p><input type=\"submit\" id=\"submit_button\" name=\"submit_button\"
value=\"Submit\"></p>
<span id=\"spanloader\" style=\"display: none;\"><img src=\"images/loading1.gif\"
alt=\"Please wait...\"> Please wait...</span>
</form> ";
$bp->print_page("","",$select_cb,"");
}
?>
Create javascript file (js/myscript.js) with these contents:
//attach datepicker to start date
$(function() {
$("#start-date").datepicker();
});
//attach datepicker to end date
$(function() {
$("#end-date").datepicker();
});
$().ready(function() {
$('#submit_button').show();
//hide the submit button after click and show loading image
$('[id$=submit_button]').click(function() {
$('#spanloader').show();
$('#submit_button').hide();
});
});
//set datatable
$(document).ready(function() {
$('#reading').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers"});
} );
This should get you started with a data table and start date end date datepicker using jquery.
1. Attach jQuery (datepicker) calendar to start date and end date inputs.
2. Create a jQuery datatable
3. On page submit, hide submit button and show a loading image instead.
After you have downloaded jQuery and extracted it to appropriate folders,
create a php file with these contents -
<?php
class InitPage {
public $jscript = "
<script type=\"text/javascript\" src=\"js/jquery-1.4.2.min.js\"></script>
<script type=\"text/javascript\" src=\"ui/jquery.ui.core.js\"></script>
<script type=\"text/javascript\" src=\"ui/jquery.ui.widget.js\"></script>
<script type=\"text/javascript\" src=\"ui/jquery.ui.datepicker.js\"></script>
<script type=\"text/javascript\" src=\"js/jquery.dataTables.js\"></script>
<script type=\"text/javascript\" src=\"js/myjscript.js\"></script>";
public $css =
" <link type=\"text/css\" href=\"themes/redmond/jquery.ui.all.css\" rel=\"stylesheet\" />";
public $header = "<html><head><title>Random Information</title>";
public $body = "</head><body ><h1 >Random Information</h1>";
public $footer =
"<div id=\"footer\"><p><a href=\"http://rowsandcolumns.blogspot.com\">
http://rowsandcolumns.blogspot.com</a></div></body> </html>";
public function print_page($v_header,$v_jscript,$contents,$v_footer="") {
if(!$v_header) {
$v_header = $this->header.$this->jscript.$this->css.$this->body;
}
if(!$v_footer) {
$v_footer = $this->footer;
}
echo $v_header.$contents.$v_footer;
}
function is_date( $str )
{
$stamp = strtotime( $str );
if (!is_numeric($stamp)) {
return FALSE;
}
$month = date( 'm', $stamp );
$day = date( 'd', $stamp );
$year = date( 'Y', $stamp );
if (checkdate($month, $day, $year)) {
return TRUE;
}
return FALSE;
}
}
$table_contents = "";
if(isset($_POST) && !empty($_POST)) { //On submit enter here
$bp = new InitPage();
// Get dates and validate if
//start date and end date are in proper format
if (isset($_POST["start-date"]) &&
$bp->is_date($_POST["start-date"]) &&
isset($_POST["end-date"]) &&
$bp->is_date($_POST["end-date"])
){
list($start_date_m, $start_date_d, $start_date_Y)= explode("/",$_POST["start-date"]);
list($end_date_m, $end_date_d, $end_date_Y)= explode("/",$_POST["end-date"]);
$start_date = date("Y-m-d H:i:s", mktime(8, 0, 0, $start_date_m, $start_date_d, $start_date_Y));
$end_date = date("Y-m-d H:i:s", mktime(8, 0, 0, $end_date_m, $end_date_d, $end_date_Y));
if($end_date <= $start_date) {
$table_contents.= "<font size=\"2\" color=\"red\">Start date should be
less than end date!</font>";
$bp->print_page("","",$table_contents,"");
die;
}
//Time to hide submit button and show loading image
sleep(3);
$table_contents = "<br/><br/><div style=\"width:500;\" >
<table border=\"1\" width=\"500\" id=\"reading\">
<thead>
<tr>
<th>Serial #</th>
<th>Name</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<tr><td> 1 </td> <td> Managers </td> <td> 10 </td></tr>
<tr><td> 2 </td> <td> Engineers </td> <td> 50 </td></tr>
<tr><td> 3 </td> <td> Interns </td> <td> 5 </td></tr>
<tr><td> 4 </td> <td> Executives </td> <td> 3 </td></tr>
<tr><td> 5 </td> <td> Facilities </td> <td> 2 </td></tr>
</tbody>
<tfoot>
<tr>
<th>Serial #</th>
<th>Name</th>
<th>Count</th>
</tr>
</tfoot>
</table></div><br/> ";
}
else {
$table_contents.= "<font size=\"2\" color=\"red\">Start date/End date
is not valid!</font>";
}
$bp->print_page("","",$table_contents,"");
die;
}
else { // On first page load
$bp = new InitPage();
$select_cb = "<form action=\"index.php\" method=\"post\">Please select start and
end date...<br/>
<br/><label for=\"start-date\">Start date:</label>
<input type=\"text\" name=\"start-date\" id=\"start-date\"/><br/><br/>
<label for=\"end-date\">End date: </label>
<input type=\"text\" name=\"end-date\" id=\"end-date\"/>
<p><input type=\"submit\" id=\"submit_button\" name=\"submit_button\"
value=\"Submit\"></p>
<span id=\"spanloader\" style=\"display: none;\"><img src=\"images/loading1.gif\"
alt=\"Please wait...\"> Please wait...</span>
</form> ";
$bp->print_page("","",$select_cb,"");
}
?>
Create javascript file (js/myscript.js) with these contents:
//attach datepicker to start date
$(function() {
$("#start-date").datepicker();
});
//attach datepicker to end date
$(function() {
$("#end-date").datepicker();
});
$().ready(function() {
$('#submit_button').show();
//hide the submit button after click and show loading image
$('[id$=submit_button]').click(function() {
$('#spanloader').show();
$('#submit_button').hide();
});
});
//set datatable
$(document).ready(function() {
$('#reading').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers"});
} );
This should get you started with a data table and start date end date datepicker using jquery.
Labels:
calendar,
datatable,
datepicker,
end date,
jquery,
loading image,
start date
Location:
Mountain View, CA, USA
Tuesday, July 27, 2010
Ganglia - Basic installation and configuration guide
After playing around, with both Zabbix and Ganglia, I decided to go ahead with Ganglia. The installation is tricky but once it is installed, configuring and adding hosts is easy. Here I will discuss, installation and configuration of Ganglia. Both the client and server daemon will be installed on the same machine.
Ganglia is a monitoring system for high-performance computing systems. Ganglia comprises of two daemons. The daemon gmond, acts like a client and sends machine information( as xml fomat), to daemon gmetad which stores these statistics in a round robin database.
A PHP-based web frontend is used to dispay the graphs in near real time.
Before starting Ganglia a few dependencies are required to be installed.
Another dependency required for Ganglia is libconfuse.
Now we download Ganglia source package and begin installation.
Setup config files for gmetad and gmond.conf
# vi gmond.conf
host = masterhostname
port = 8650
ttl = 1
}
# vi gmetad.conf
GMOND=/opt/ganglia/sbin/gmond
Optional (this would enable running the daemons as an automated service) :
Add the following lines if they are not a part of your config file.
Edit conf.php in web folder:
define("RRDTOOL", "/opt/rrdtool-1.4.4/bin/rrdtool");
RRDTOOL should point to rrdtool path
You can point your browser to the web front end location and it should display you the graphs.
Ganglia is a monitoring system for high-performance computing systems. Ganglia comprises of two daemons. The daemon gmond, acts like a client and sends machine information( as xml fomat), to daemon gmetad which stores these statistics in a round robin database.
A PHP-based web frontend is used to dispay the graphs in near real time.
Before starting Ganglia a few dependencies are required to be installed.
# tcsh
# setenv INSTALL_DIR /opt/rrdtool-1.4.4
# setenv BUILD_DIR /opt/build/rrdbuild
# cd $BUILD_DIR
# wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.4.tar.gz
# gunzip -c rrdtool-1.4.4.tar.gz | tar xf – # cd rrdtool-1.4.4
# ./configure --prefix=$INSTALL_DIR && make && make install
This would have installed round robin database. It is required only on the head node. The head node (server) would be the one where you want to install gmetad daemon.Another dependency required for Ganglia is libconfuse.
# cd /opt/build
# wget http://bzero.se/confuse/confuse-2.6.tar.gz
# /bin/tar -xzf confuse-2.6.tar.gz
# cd confuse-2.6
# ./configure --prefix=/opt/ganglia
# env CFLAGS="-O3 -fPIC" ./configure --prefix=/opt/ganglia
# make
# make install
# wget http://bzero.se/confuse/confuse-2.6.tar.gz
# /bin/tar -xzf confuse-2.6.tar.gz
# cd confuse-2.6
# ./configure --prefix=/opt/ganglia
# env CFLAGS="-O3 -fPIC" ./configure --prefix=/opt/ganglia
# make
# make install
Now we download Ganglia source package and begin installation.
# cd /opt/build/
# wget http://sourceforge.net/projects/ganglia/files/ganglia%20monitoring%20core/3.1.7/ganglia-3.1.7.tar.gz/download
# tar -xzf ganglia-3.1.7.tar.gz
# cd ganglia-3.1.7
# setenv CFLAGS "-I/opt/ganglia/include/ -I/opt/rrdtool-1.4.4/include"
# setenv LDFLAGS "-L/opt/ganglia/lib/ -L/opt/rrdtool-1.4.4/lib"
# ./configure --prefix=/opt/ganglia --with-gmetad --sysconfdir=/etc/ganglia
# make
# make install
Make sure the permissions are appropriate on path /opt/ganglia/rrds. This is the path where I have my round robin database.# cd /opt/ganglia/sbin/
# ./gmond --default-config > gmond.conf
# ./gmetad --default-config > gmetad.conf
Setup config files for gmetad and gmond.conf
# vi gmond.conf
Set up your udp_send_channel to look like this:
udp_send_channel {host = masterhostname
port = 8650
ttl = 1
}
# vi gmetad.conf
Modify directives as:
data_source "MyCluster" localhost rrd_rootdir "/opt/ganglia/rrds"
# cp gmond.conf /etc/ganglia/.
# cp gmetad.conf /etc/ganglia/.
# cd $BUILD_DIR
# cp gmond/gmond.init /etc/rc.d/init.d/gmond
# cp gmond/gmond.init /etc/rc.d/init.d/gmond
# vi /etc/rc.d/init.d/gmond
Set this variable asGMOND=/opt/ganglia/sbin/gmond
Optional (this would enable running the daemons as an automated service) :
# chkconfig --add gmond
# chkconfig --list gmond
gmond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
gmond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
# /etc/rc.d/init.d/gmond start
Starting GANGLIA gmond: [ OK ]
# cd /opt/build/ganglia-3.1.7/gmetad
# cp gmetad.init /etc/rc.d/init.d/gmetad
# vi /etc/rc.d/init.d/gmetad
GMETAD=/opt/ganglia/sbin/gmetad
# chkconfig --add gmetad
Starting GANGLIA gmond: [ OK ]
# cd /opt/build/ganglia-3.1.7/gmetad
# cp gmetad.init /etc/rc.d/init.d/gmetad
# vi /etc/rc.d/init.d/gmetad
GMETAD=/opt/ganglia/sbin/gmetad
# chkconfig --add gmetad
# chkconfig --list gmetad
gmetad 0:off 1:off 2:on 3:on 4:on 5:on 6:off
# /etc/rc.d/init.d/gmetad start
Starting GANGLIA gmetad: [ OK ]
Edit httpd.confgmetad 0:off 1:off 2:on 3:on 4:on 5:on 6:off
# /etc/rc.d/init.d/gmetad start
Starting GANGLIA gmetad: [ OK ]
Add the following lines if they are not a part of your config file.
LoadModule php5_module modules/libphp5.so
Edit DirectoryIndex like
DirectoryIndex index.html index.html.var index.php
Addtype application/x-httpd-php .php
Addtype application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Copy “web” folder to httpd document root locationEdit conf.php in web folder:
define("RRDTOOL", "/opt/rrdtool-1.4.4/bin/rrdtool");
RRDTOOL should point to rrdtool path
# /sbin/service httpd restart
You can point your browser to the web front end location and it should display you the graphs.
Location:
Fremont, CA, USA
Sunday, July 25, 2010
Extjs + PHP - How to embed Treepanel, Gridpanel and Formpanel in a page?
Here is a step by step procedure to get started with a basic extjs application. It covers handling data rendering in gridpanel as well.
1. Download ExtJS and unzip it to your web path.
2. Create an html file (say test_page.html) with these contents. This will be used to render the page.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> Main Page </title>
<link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css" />
<script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext/ext-all.js"> </script>
<script type="text/javascript" src="javascripts/test_ext_widget.js"> </script>
</head>
<body>
<div id="header">
</div>
</body>
</html>
3. Create php file (extjs.php) with the following contents. This file return a JSON object which will be rendered by extjs.
<?php
$start = @$_REQUEST["start"];
$limit = @$_REQUEST["limit"];
$start = $start ? $start : 0;
$limit = $limit ? $limit : 5;
$data = array(
array("first"=>'Jack', "last"=>'Shephard',"bpay"=>7.75,"cpay"=>8.75,"email"=>'jackx@clemsonx.edu',"uid"=>'jackx', "hiredate"=>'8/1 12:00am'),
array("first"=>'James', "last"=>'Ford',"bpay"=>7.75,"cpay"=>8.75, "email"=>'jamesx@clemson.edu',"uid"=>'jamesx', "hiredate"=>'9/1 12:00am'),
array("first"=>'Kate',"last"=>'Austen', "bpay"=>7.75,"cpay"=>8.75, "email"=>'katex@clemson.edu',"uid"=>'katex', "hiredate"=>'10/1 12:00am'),
array("first"=>'Juliet',"last"=>'Burke',"bpay"=>7.75,"cpay"=>8.75, "email"=>'julietx@clemson.edu',"uid"=>'julietx', "hiredate"=>'9/1 10:00am'),
array("first"=>'Sayid',"last"=>'Jarrah',"bpay"=>7.75,"cpay"=>8.75, "email"=>'sayidx@clemson.edu',"uid"=>'sayidx', "hiredate"=>'9/1 11:00am'),
);
$a = array();
for($i = $start; $i < 5; $i++) {
$a[] = $data[$i];
}
$o = array(
"success"=>true
,"totalCount"=>sizeof($data)
,"rows"=>$a
);
echo json_encode($o);
?>
4. Finally a js file (say test_ext_widget.js) which will contain the javascript to render the page. This would render a page with three panel objects (gridpanel, formpanel, treepanel).
Ext.ns('app_harpreet');
Ext.BLANK_IMAGE_URL = 'ext/resources/images/default/s.gif';
var item_list = [ {xtype : 'textfield', fieldLabel : 'First name'},
{xtype : 'textfield', fieldLabel : 'Last name'},
{xtype : 'textfield', fieldLabel : 'Email'},
{xtype : 'textfield', fieldLabel : 'Student ID'},
{xtype : 'textfield', fieldLabel : 'Current Pay'},
{xtype : 'textfield', fieldLabel : 'Base Pay'},
{xtype : 'datefield', fieldLabel : 'Hire Date'}
];
var final_cbox = new Ext.form.Checkbox( {
name : 'final_question',
id : 'final_question',
inputValue : 1,
fieldLabel : 'Suspended',
checked : true
});
item_list.push(final_cbox);
var btns = [];
btns.push( {text : 'Save', scope : this});
btns.push( {text : 'Cancel', scope : this});
// now the actual form
var uForm = new Ext.form.FormPanel( {
id:'u_form', region:'center', bodyStyle:'padding:30px', items:item_list, buttons:btns});
var window1 = new Ext.Window( {
id : 'user_edit_win',
title : 'Edit',
width : 900,
height : 650,
minWidth : 500,
minHeight : 600,
layout : 'border',
plain : true,
modal : true,
bodyStyle : 'padding:55px;',
items : [ uForm ]
});
// Custom grid pre-configured class
app_harpreet.Grid = Ext.extend(Ext.grid.GridPanel, {
//double click on user row opens a pop up window which can be used for updating record
_user_row_click : function() {window1.show();},
initComponent : function() {
var config = {
store : new Ext.data.JsonStore( {
id : 'members',
totalProperty : 'totalCount',
root : 'rows',
url : 'extjs.php',
fields : [ {name : 'first'},
{name : 'last'},
{name : 'email'},
{name : 'uid'},
{name : 'cpay', type : 'float'},
{name : 'bpay', type : 'float'},
{name : 'hiredate', type : 'date', dateFormat : 'n/j h:ia'}
]
}),
listeners : {
rowdblclick : this._user_row_click,
scope : this
},
columns : [ {
id : 'uid',
header : "UID",
width : 40,
sortable : true,
dataIndex : 'uid'
},{
id : 'first',
header : "First",
width : 40,
sortable : true,
dataIndex : 'first'
},{
id : 'last',
header : "Last",
width : 40,
sortable : true,
dataIndex : 'last'
}, {
id : 'base',
header : "Base Pay",
width : 40,
sortable : true,
renderer: Ext.util.Format.usMoney,
dataIndex : 'bpay'
}, {
id : 'pay',
header : "Current Pay",
width : 40,
sortable : true,
renderer: Ext.util.Format.usMoney,
dataIndex : 'cpay'
},{
id : 'email',
header : "Email",
width : 40,
sortable : true,
dataIndex : 'email'
}, {
header : "Hire Date",
width : 20,
sortable : true,
renderer : Ext.util.Format.dateRenderer('m/d/Y'),
dataIndex : 'hiredate'
},{
id : 'suspend',
header : "Suspend Until",
width : 40,
sortable : true,
dataIndex : 'suspend'
}],
viewConfig : {forceFit : true}
};
// apply config
Ext.apply(this, Ext.apply(this.initialConfig, config));
this.bbar = new Ext.PagingToolbar( {
store : this.store,
displayInfo : true,
pageSize : 10,
items : [ { xtype : 'textfield' } ]
});
// call parent
app_harpreet.Grid.superclass.initComponent.apply(this, arguments);
}
,
onRender : function() {
// call parent
app_harpreet.Grid.superclass.onRender.apply(this, arguments);
// load the store
this.store.load( {params : {start : 0,limit : 10}});
}});
Ext.reg('membergrid', app_harpreet.Grid);
var item_list1 = [ {xtype : 'textfield',fieldLabel : 'First name'},
{xtype : 'textfield',fieldLabel : 'Last name'},
{xtype : 'textfield', fieldLabel : 'Email'},
{xtype : 'textfield', fieldLabel : 'Student ID'} ];
var btns1 = [];
btns1.push( { text : 'Edit' });
Ext.onReady(function() {
var viewport = new Ext.Viewport( {
layout : 'border',
items : [ { //left tree panel
xtype : 'treepanel',
region : 'west',
collapsible : true,
title : 'Navigation',
id : 'tpNavigation',
root : new Ext.tree.AsyncTreeNode( {
expanded : true,
text : 'Home',
children : [ {text : 'User',leaf : true},
{text : 'Manage users',leaf : true},
{text : 'Clients',leaf : true}]
}),
rootVisible : false,
width : 200
// the west region uses a TreePanel with Accordion layout
}, { //bottom panel
region : 'south',
title : 'Search',
collapsible : true,
height : 200,
minHeight : 200,
items : [ {
xtype : 'form',
items : item_list1,
buttons : btns1
} ]
}, { // main panel to dispay records
region : 'center',
layout : 'fit',
title : 'Center',
xtype : 'membergrid'
} ]
});
});
Now you can point your browser to your html page to render the treepanel, formpanel and gridpanel. The page would make a call to extjs.php, to retrieve the data, as a Json object.
You can double click on the rows to open a pop up window, which can be used to update the data in the row.(row update is not accomplished in the above code)
Please let me know of any improvements/corrections.
1. Download ExtJS and unzip it to your web path.
2. Create an html file (say test_page.html) with these contents. This will be used to render the page.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> Main Page </title>
<link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css" />
<script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext/ext-all.js"> </script>
<script type="text/javascript" src="javascripts/test_ext_widget.js"> </script>
</head>
<body>
<div id="header">
</div>
</body>
</html>
3. Create php file (extjs.php) with the following contents. This file return a JSON object which will be rendered by extjs.
<?php
$start = @$_REQUEST["start"];
$limit = @$_REQUEST["limit"];
$start = $start ? $start : 0;
$limit = $limit ? $limit : 5;
$data = array(
array("first"=>'Jack', "last"=>'Shephard',"bpay"=>7.75,"cpay"=>8.75,"email"=>'jackx@clemsonx.edu',"uid"=>'jackx', "hiredate"=>'8/1 12:00am'),
array("first"=>'James', "last"=>'Ford',"bpay"=>7.75,"cpay"=>8.75, "email"=>'jamesx@clemson.edu',"uid"=>'jamesx', "hiredate"=>'9/1 12:00am'),
array("first"=>'Kate',"last"=>'Austen', "bpay"=>7.75,"cpay"=>8.75, "email"=>'katex@clemson.edu',"uid"=>'katex', "hiredate"=>'10/1 12:00am'),
array("first"=>'Juliet',"last"=>'Burke',"bpay"=>7.75,"cpay"=>8.75, "email"=>'julietx@clemson.edu',"uid"=>'julietx', "hiredate"=>'9/1 10:00am'),
array("first"=>'Sayid',"last"=>'Jarrah',"bpay"=>7.75,"cpay"=>8.75, "email"=>'sayidx@clemson.edu',"uid"=>'sayidx', "hiredate"=>'9/1 11:00am'),
);
$a = array();
for($i = $start; $i < 5; $i++) {
$a[] = $data[$i];
}
$o = array(
"success"=>true
,"totalCount"=>sizeof($data)
,"rows"=>$a
);
echo json_encode($o);
?>
4. Finally a js file (say test_ext_widget.js) which will contain the javascript to render the page. This would render a page with three panel objects (gridpanel, formpanel, treepanel).
Ext.ns('app_harpreet');
Ext.BLANK_IMAGE_URL = 'ext/resources/images/default/s.gif';
var item_list = [ {xtype : 'textfield', fieldLabel : 'First name'},
{xtype : 'textfield', fieldLabel : 'Last name'},
{xtype : 'textfield', fieldLabel : 'Email'},
{xtype : 'textfield', fieldLabel : 'Student ID'},
{xtype : 'textfield', fieldLabel : 'Current Pay'},
{xtype : 'textfield', fieldLabel : 'Base Pay'},
{xtype : 'datefield', fieldLabel : 'Hire Date'}
];
var final_cbox = new Ext.form.Checkbox( {
name : 'final_question',
id : 'final_question',
inputValue : 1,
fieldLabel : 'Suspended',
checked : true
});
item_list.push(final_cbox);
var btns = [];
btns.push( {text : 'Save', scope : this});
btns.push( {text : 'Cancel', scope : this});
// now the actual form
var uForm = new Ext.form.FormPanel( {
id:'u_form', region:'center', bodyStyle:'padding:30px', items:item_list, buttons:btns});
var window1 = new Ext.Window( {
id : 'user_edit_win',
title : 'Edit',
width : 900,
height : 650,
minWidth : 500,
minHeight : 600,
layout : 'border',
plain : true,
modal : true,
bodyStyle : 'padding:55px;',
items : [ uForm ]
});
// Custom grid pre-configured class
app_harpreet.Grid = Ext.extend(Ext.grid.GridPanel, {
//double click on user row opens a pop up window which can be used for updating record
_user_row_click : function() {window1.show();},
initComponent : function() {
var config = {
store : new Ext.data.JsonStore( {
id : 'members',
totalProperty : 'totalCount',
root : 'rows',
url : 'extjs.php',
fields : [ {name : 'first'},
{name : 'last'},
{name : 'email'},
{name : 'uid'},
{name : 'cpay', type : 'float'},
{name : 'bpay', type : 'float'},
{name : 'hiredate', type : 'date', dateFormat : 'n/j h:ia'}
]
}),
listeners : {
rowdblclick : this._user_row_click,
scope : this
},
columns : [ {
id : 'uid',
header : "UID",
width : 40,
sortable : true,
dataIndex : 'uid'
},{
id : 'first',
header : "First",
width : 40,
sortable : true,
dataIndex : 'first'
},{
id : 'last',
header : "Last",
width : 40,
sortable : true,
dataIndex : 'last'
}, {
id : 'base',
header : "Base Pay",
width : 40,
sortable : true,
renderer: Ext.util.Format.usMoney,
dataIndex : 'bpay'
}, {
id : 'pay',
header : "Current Pay",
width : 40,
sortable : true,
renderer: Ext.util.Format.usMoney,
dataIndex : 'cpay'
},{
id : 'email',
header : "Email",
width : 40,
sortable : true,
dataIndex : 'email'
}, {
header : "Hire Date",
width : 20,
sortable : true,
renderer : Ext.util.Format.dateRenderer('m/d/Y'),
dataIndex : 'hiredate'
},{
id : 'suspend',
header : "Suspend Until",
width : 40,
sortable : true,
dataIndex : 'suspend'
}],
viewConfig : {forceFit : true}
};
// apply config
Ext.apply(this, Ext.apply(this.initialConfig, config));
this.bbar = new Ext.PagingToolbar( {
store : this.store,
displayInfo : true,
pageSize : 10,
items : [ { xtype : 'textfield' } ]
});
// call parent
app_harpreet.Grid.superclass.initComponent.apply(this, arguments);
}
,
onRender : function() {
// call parent
app_harpreet.Grid.superclass.onRender.apply(this, arguments);
// load the store
this.store.load( {params : {start : 0,limit : 10}});
}});
Ext.reg('membergrid', app_harpreet.Grid);
var item_list1 = [ {xtype : 'textfield',fieldLabel : 'First name'},
{xtype : 'textfield',fieldLabel : 'Last name'},
{xtype : 'textfield', fieldLabel : 'Email'},
{xtype : 'textfield', fieldLabel : 'Student ID'} ];
var btns1 = [];
btns1.push( { text : 'Edit' });
Ext.onReady(function() {
var viewport = new Ext.Viewport( {
layout : 'border',
items : [ { //left tree panel
xtype : 'treepanel',
region : 'west',
collapsible : true,
title : 'Navigation',
id : 'tpNavigation',
root : new Ext.tree.AsyncTreeNode( {
expanded : true,
text : 'Home',
children : [ {text : 'User',leaf : true},
{text : 'Manage users',leaf : true},
{text : 'Clients',leaf : true}]
}),
rootVisible : false,
width : 200
// the west region uses a TreePanel with Accordion layout
}, { //bottom panel
region : 'south',
title : 'Search',
collapsible : true,
height : 200,
minHeight : 200,
items : [ {
xtype : 'form',
items : item_list1,
buttons : btns1
} ]
}, { // main panel to dispay records
region : 'center',
layout : 'fit',
title : 'Center',
xtype : 'membergrid'
} ]
});
});
Now you can point your browser to your html page to render the treepanel, formpanel and gridpanel. The page would make a call to extjs.php, to retrieve the data, as a Json object.
You can double click on the rows to open a pop up window, which can be used to update the data in the row.(row update is not accomplished in the above code)
Please let me know of any improvements/corrections.
Labels:
extjs,
gridpanel,
numberfield,
PagingToolbar,
php,
treepanel,
viewport
Location:
Fremont, CA, USA
Perl - How to create a tcp socket?
The following program can be used to create a tcp connection to a host on a specified port.
The program attempts connection at a periodic interval, which is passed as 'execution_interval'.
#!/usr/bin/perl
use IO::Socket;
use POSIX qw/strftime/;
if (@ARGV != 4)
{
usage();
exit;
}
my $hostname = $ARGV[0];
my $port = $ARGV[1];
my $timeout = $ARGV[2];
my $interval = $ARGV[3];
my $logdir = "/tmp/";
my $datestamp = strftime('%m-%d-%y_%H:%M:%S',localtime);
$mday = (localtime(time))[3];
my $logfile = $logdir."$hostname\_$port\_tcp_socket\_$datestamp.log";
open LOG, ">>","$logfile" or die $!;
LOG->autoflush(1);
while(1) {
my $sock = new IO::Socket::INET (PeerAddr => $hostname,
PeerPort => $port,
Proto => 'tcp',
Timeout => $timeout);
$cur_datestamp = strftime('%m-%d-%y_%H:%M:%S',localtime);
$cur_mday = (localtime(time))[3];
if(!$sock) {
print LOG "\n$cur_datestamp : Error - Could not create socket to $hostname on $port: $!";
sleep $interval;
next;
}
if($cur_mday != $mday) {
close(LOG);
$logfile = $logdir."$hostname\_$port\_tcp_socket\_$datestamp.log";
open LOG, ">>","$logfile" or die $!;
LOG->autoflush(1);
$mday = $cur_mday;
}
print LOG "\n$cur_datestamp : Socket created to $hostname on $port";
close($sock);
sleep $interval;
}
close(LOG);
sub usage
{
print "Invalid parameters \nUsage: ./tcp_socket.pl \n";
}
Please let me know, of any corrections/improvements.
The program attempts connection at a periodic interval, which is passed as 'execution_interval'.
#!/usr/bin/perl
use IO::Socket;
use POSIX qw/strftime/;
if (@ARGV != 4)
{
usage();
exit;
}
my $hostname = $ARGV[0];
my $port = $ARGV[1];
my $timeout = $ARGV[2];
my $interval = $ARGV[3];
my $logdir = "/tmp/";
my $datestamp = strftime('%m-%d-%y_%H:%M:%S',localtime);
$mday = (localtime(time))[3];
my $logfile = $logdir."$hostname\_$port\_tcp_socket\_$datestamp.log";
open LOG, ">>","$logfile" or die $!;
LOG->autoflush(1);
while(1) {
my $sock = new IO::Socket::INET (PeerAddr => $hostname,
PeerPort => $port,
Proto => 'tcp',
Timeout => $timeout);
$cur_datestamp = strftime('%m-%d-%y_%H:%M:%S',localtime);
$cur_mday = (localtime(time))[3];
if(!$sock) {
print LOG "\n$cur_datestamp : Error - Could not create socket to $hostname on $port: $!";
sleep $interval;
next;
}
if($cur_mday != $mday) {
close(LOG);
$logfile = $logdir."$hostname\_$port\_tcp_socket\_$datestamp.log";
open LOG, ">>","$logfile" or die $!;
LOG->autoflush(1);
$mday = $cur_mday;
}
print LOG "\n$cur_datestamp : Socket created to $hostname on $port";
close($sock);
sleep $interval;
}
close(LOG);
sub usage
{
print "Invalid parameters \nUsage: ./tcp_socket.pl
}
Please let me know, of any corrections/improvements.
Perl - send email without using sendmail
In a recent exercise, I was required to write a script which would attempt sending email through an smtp server instead of sendmail. At a periodic interval, the script would check if the smtp server is able to send emails or not. Basically, this script ran as a background process.
#!/usr/bin/perl
use Net::SMTP;
use POSIX qw/strftime/;
if (@ARGV != 5)
{
usage();
exit;
}
my $smtpmailhost = $ARGV[0];
my $from_address = $ARGV[1];
my $to_address = $ARGV[2];
my $timeout = $ARGV[3];
my $interval = $ARGV[4];
my $logdir = "/tmp/email_logs/";
my $datestamp = strftime('%m-%d-%y_%H:%M:%S',localtime);
$mday = (localtime(time))[3];
my $logfile = $logdir."$smtpmailhost\_email_log\_$datestamp.log";
open LOG, ">>","$logfile" or die $!;
LOG->autoflush(1);
while(1) {
$smtp = Net::SMTP->new($smtpmailhost,
Timeout => $timeout);
$cur_datestamp = strftime('%m-%d-%y_%H:%M:%S',localtime);
$cur_mday = (localtime(time))[3];
if(!$smtp) {
print LOG "\n$cur_datestamp : Error creating smtp object for $smtpmailhost: $!";
sleep $interval;
next;
}
if($cur_mday != $mday) {
close(LOG);
$logfile = $logdir."$smtpmailhost\_email_log\_$cur_datestamp.log";
open LOG, ">>","$logfile" or die $!;
LOG->autoflush(1);
$mday = $cur_mday;
}
$smtp->mail($from_address);
$smtp->to($to_address);
$smtp->data();
$smtp->datasend("Subject: $smtpmailhost - Test email message\n");
$smtp->datasend("\n");
$smtp->datasend("Test email has been sent successfully at $cur_datestamp!");
$smtp->dataend();
$smtp->quit;
print LOG "\n$cur_datestamp : Test Email sent via $smtpmailhost!";
sleep $interval;
}
close(LOG);
sub usage
{
print "Invalid parameters \nUsage: ./smtpemail_send.pl \n";
}
Please let me know, of any corrections/improvements.
#!/usr/bin/perl
use Net::SMTP;
use POSIX qw/strftime/;
if (@ARGV != 5)
{
usage();
exit;
}
my $smtpmailhost = $ARGV[0];
my $from_address = $ARGV[1];
my $to_address = $ARGV[2];
my $timeout = $ARGV[3];
my $interval = $ARGV[4];
my $logdir = "/tmp/email_logs/";
my $datestamp = strftime('%m-%d-%y_%H:%M:%S',localtime);
$mday = (localtime(time))[3];
my $logfile = $logdir."$smtpmailhost\_email_log\_$datestamp.log";
open LOG, ">>","$logfile" or die $!;
LOG->autoflush(1);
while(1) {
$smtp = Net::SMTP->new($smtpmailhost,
Timeout => $timeout);
$cur_datestamp = strftime('%m-%d-%y_%H:%M:%S',localtime);
$cur_mday = (localtime(time))[3];
if(!$smtp) {
print LOG "\n$cur_datestamp : Error creating smtp object for $smtpmailhost: $!";
sleep $interval;
next;
}
if($cur_mday != $mday) {
close(LOG);
$logfile = $logdir."$smtpmailhost\_email_log\_$cur_datestamp.log";
open LOG, ">>","$logfile" or die $!;
LOG->autoflush(1);
$mday = $cur_mday;
}
$smtp->mail($from_address);
$smtp->to($to_address);
$smtp->data();
$smtp->datasend("Subject: $smtpmailhost - Test email message\n");
$smtp->datasend("\n");
$smtp->datasend("Test email has been sent successfully at $cur_datestamp!");
$smtp->dataend();
$smtp->quit;
print LOG "\n$cur_datestamp : Test Email sent via $smtpmailhost!";
sleep $interval;
}
close(LOG);
sub usage
{
print "Invalid parameters \nUsage: ./smtpemail_send.pl
}
Please let me know, of any corrections/improvements.
Subscribe to:
Posts (Atom)