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.
--Dinesh
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 -lncursesHow to Run ??
./pgbar_pgg
--Dinesh

Comments
Post a Comment