Skip to main content

Simple Monitoring Console

Hi All,

Find the below simple user console program what i have written in "C" @Linux. It might be helpful to you in monitoring.

Here is the snippet of code, for your reference.

#include"stdio.h"
#include"stdlib.h"
#include"ncurses.h"
#include"string.h"
#include "sys/types.h"
#include "unistd.h"
#include "sys/wait.h"
void init()
{
int i,j;
for(i=1;i<=25;i++)
{
printw("\n%3d-|",50-i*2);
}
printw("\n%3s"," ");
for(j=1;j<=32;j++)
{
printw("%3s","-");
}
printw("  ");
printw("\n\n\n");
printw("%5s"," ");
for(j=1;j<=94;j++)
{
printw("=");
}
printw("\n");
printw("%60s","TOP 10 CPU PROCESSES");
printw("\n");
printw("%5s"," ");
for(j=1;j<=94;j++)
printw("-");
mvprintw(1,110,"");
for(j=1;j<=40;j++)
printw("=");
printw("\n");
mvprintw(2,123,"PRIMARY MEMORY");
mvprintw(3,110,"");
for(j=1;j<=40;j++)
printw("-");
refresh();
}

main()
{
FILE *fp;
FILE *log;
char info[50],n,c;
int i,j=0,k,x,y,status;
float f1,f2,f3;
initscr();
i=1,j=6;
init();
while(1)
{
fp=popen("uptime|awk -F 'load average:' '{print $2}'","r");
fgets(info,50,fp);
sscanf(info,"%f, %f, %f",&f1,&f2,&f3);
mvprintw((50-(int)f1)/2,j,"%3s","*");
if((int)f1>=10)

{

system("touch /tmp/.hi_cpu_usage.txt;mail -s \"Alert for High Cpu Usage >=10 \" dineshkumar02@gmail.com
/dev/null");
}
for(k=(50-(int)f1)/2+1;k<=25;k++) { mvprintw(k,j+2,"|"); } fgets(info,10,fp); info[strlen(info)-1]='\0'; fgets(info,50,fp); info[strlen(info)-1]='\0'; mvprintw(1,30,"Load=%f",f1); pclose(fp); mvprintw(32,4," "); fp=popen("ps -eo pcpu,pid,pmem,user,args|sort -k1 -r|head -11","r"); while((c=fgetc(fp))!=EOF) { if(c==(char)10) { printw("%c",c); printw("%5s"," "); } else printw("%c",c); } fclose(fp); fp=popen("vmstat|awk -F ' ' '{print \"Swap :- \\t\"$3\"\\nFree :- \\t\"$4\"\\nBuffer :- \\t\"$5\"\\ncache :- \\t\"$6}'|tail -4","r"); x=117,y=4; while((c=fgetc(fp))!=EOF) { if(c==(char)10) { mvprintw(y++,x,"%c",c); x=117; continue; } else { mvprintw(y,x++,"%c",c); } } j+=3; refresh(); while ( waitpid(-1, &status, WNOHANG) > 0 );
sleep(3);
if(j>=100)
{
clear();
init();
j=6;
}
}
refresh();
getch();
endwin();
fclose(fp);
return 0;
}
How to Compile ??

gcc -o pgbar_pgg pgbar_pgg.c -lncurses

How to Run ??

./pgbar_pgg



--Dinesh

Comments

Popular posts from this blog

Pgpool Configuration & Failback

I would like to share the pgpool configuration, and it's failback mechanism in this post.

Hope it will be helpful to you in creating pgpool and it's failback setup.

Pgpool Installation & Configuration

1. Download the pgpool from below link(Latest version is 3.2.1).
    http://www.pgpool.net/mediawiki/index.php/Downloads


2. Untart the pgpool-II-3.2.1.tar.gz and goto pgpool-II-3.2.1 directory.

3. Install the pgpool by executing the below commands:

./configure ­­prefix=/opt/PostgreSQL92/ ­­--with­-pgsql­-includedir=/opt/PostgreSQL92/include/ --with­-pgsql­-libdir=/opt/PostgreSQL92/lib/ make make install 4. You can see the pgpool files in /opt/PostgreSQL92/bin location.
/opt/PostgreSQL92/bin $ ls clusterdb   droplang  pcp_attach_node  pcp_proc_count pcp_systemdb_info  pg_controldata  pgpool pg_test_fsync pltcl_loadmod  reindexdb createdb    dropuser  pcp_detach_node  pcp_proc_info createlang  ecpg      pcp_node_count   pcp_promote_node oid2name  pcp_pool_status  pcp_stop_pgpool  …

pgBucket - A new concurrent job scheduler

Hi All,

I'm so excited to announce about my first contribution tool for postgresql. I have been working with PostgreSQL from 2011 and I'm really impressed with such a nice database.

I started few projects in last 2 years like pgHawk[A beautiful report generator for Openwatch] , pgOwlt [CUI monitoring. It is still under development, incase you are interested to see what it is, attaching the image here for you ],


pgBucket [Which I'm gonna talk about] and learned a lot and lot about PostgreSQL/Linux internals.

Using pgBucket we can schedule jobs easily and we can also maintain them using it's CLI options. We can update/insert/delete jobs at online. And here is its architecture which gives you a basic idea about how it works.


Yeah, I know there are other good job schedulers available for PostgreSQL. I haven't tested them and not comparing them with this, as I implemented it in my way.
Features are: OS/DB jobsCron style sytaxOnline job modificationsRequired cli options

N-Node Mutlimaster Replication With Bucardo...!

Our team recently got  a problem, which is to solve the N-Node multi master replication in PostgreSQL.

We all know that, there are some other db engines like Postgres-XC which works in this way. But, we don't have any tool available in PostgreSQL, except Bucardo.

Bucardo is the nice solution for 2-Nodes. Is there a way we can exceed this limitation from 2 to N..?

As an initial step on this, I have done with 3 Nodes, which I believe, we can extend this upto N. { I might be wrong here.}

Please follow the below steps to set up the 1 - 1 multi master replication.

1. Follow the below steps to get all the pre-requisites for the Bucardo.

yum install perl-DBIx-Safe or apt-get install libdbix-safe-perl Install the below components from CPAN. DBI DBD::Pg Test::Simple boolean (Bucardo 5.0 and higher) Download the latest tarball from here. tar xvfz Bucardo-4.4.8.tar.gz cd Bucardo-4.4.8 perl Makefile.PL make sudo make install 2. We need to create plperl extension in db. For this, download…