LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 01-08-2011, 01:18 AM   #1
tincy
LQ Newbie
 
Registered: Sep 2010
Posts: 6

Rep: Reputation: 0
how to calculate overall network load and cpu performance of a client?


hi all,
i wrote a script which sends the server,files from /proc/ like dev,netstat,loadavg etc of a client. i want to calculate the network load and the overall cpu performance of the client using the information from the files.I donot know how to calculate that as i have too many values in those. Can anyone please tell me which values will be useful and how to calculate??
 
Old 01-08-2011, 10:42 AM   #2
xandercage17
Member
 
Registered: Sep 2009
Posts: 125

Rep: Reputation: Disabled
Delete My account

Last edited by xandercage17; 04-22-2012 at 03:34 PM. Reason: Delete My account
 
Old 02-02-2011, 04:14 AM   #3
tincy
LQ Newbie
 
Registered: Sep 2010
Posts: 6

Original Poster
Rep: Reputation: 0
thanks for the links. i used Top for getting cpu info, memory , network load etc..but i need a formula to calculate the overall performance of a system considering all the above values.i dont know how to generate such a formula, as each of the above fields are different from each other. i have pasted my code below. pls help.

#include<stdio.h>
#include<ctype.h>
void main( void )
{
int i,j,flag=0;
float num1,num2,no1,no2;
char line[128]="/0",out[120]="/0",out1[120]="/0",out2[120]="/0",out3[120]="/0",out4[120]="/0",out5[120]="/0";
char s,avg1[10];
system("top -n 1 -b > output.txt"); //Execution of 'top' function to retreive the files.
static const char filename[] = "/home/teena/Main_project/output.txt";
FILE *file = fopen ( filename, "r" );
if ( file != NULL )
{
while(s!=EOF)
{
if(flag==0) //To retrieve the load average value.
{
line[0]=s;
i=1;
do
{
line[i]=fgetc(file);
i++;
}while( (line[i-1]!=' ')&&(line[i-1]!='\n'));
if((line[0]=='a')&&(line[1]=='v')&&(line[2]=='e')&&(line[3]=='r')&&(line[4]=='a')&&(line[5]=='g')&&(line[6]=='e')&&(line[7]==':'))
{
flag=1;
i=0;
while((s=fgetc(file))!=',')
{
out[i]=s;
i++;
}
}
no1 = (((out[0]-48)*1)+((out[2]-48)*0.1)+((out[3]-48)*0.01));
}
if(flag==1) //To retreive the total number of tasks.
{
line[0]=s;
i=1;
do
{
line[i]=fgetc(file);
i++;
}while( (line[i-1]!=' ')&&(line[i-1]!='\n'));
if((line[0]=='T')&&(line[1]=='a')&&(line[2]=='s')&&(line[3]=='k')&&(line[4]=='s')&&(line[5]==':'))
{
flag=2;
i=0;
while((s=fgetc(file))!='t')
{
out1[i]=s;
i++;
}
j=i-1;
}

}
if(flag==2) //To retrieve the total number of running tasks.
{
line[0]=s;
i=1;
j=0;
do
{
line[i]=fgetc(file);
if(isdigit(line[i]))
{
flag=3;
out2[j]=line[i];
j++;
}
i++;
}while((line[i-1])!='r');
out2[j]='\0';
}
if(flag==3) //To calculate the current total CPU Utilisation.
{
line[0]=s;
i=1;
j=0;
do
{
line[i]=fgetc(file);
i++;
}while((line[i-1])!='(');
do
{
line[i]=fgetc(file);
i++;
}while((line[i-1])!='n');
do
{
line[i]=fgetc(file);
if((isdigit(line[i]))||(line[i]=='.'))
{
flag=4;
out3[j]=line[i];
j++;
}
i++;
}while((line[i-1])!='%');
out3[j]='\0';
num1 = (((out3[0]-48)*10)+((out3[1]-48)*1)+((out3[3]-48)*0.1));
num2 =(100-num1);
}
if(flag==4) //To retrieve the total amount of RAM available.
{
line[0]=s;
i=1;
j=0;
do
{
line[i]=fgetc(file);
i++;
}while((line[i-1])!=':');
do
{
line[i]=fgetc(file);
if(isdigit(line[i]))
{
flag=5;
out4[j]=line[i];
j++;
}
i++;
}while((line[i-1])!='t');
out4[j]='\0';
}
if(flag==5) //To retrieve the amount of used RAM.
{
line[0]=s;
i=1;
j=0;
do
{
line[i]=fgetc(file);
if(isdigit(line[i]))
{
flag=6;
out5[j]=line[i];
j++;
}
i++;
}while((line[i-1])!='u');
out5[j]='\0';
}
s=fgetc(file);
}
//printf("%c",out);
printf("\n\nProcesses running averaged over the last 1 minute: %f\n\n",no1);
printf("Total no. of tasks given to the system: %s\n\n",out1);
printf("Total no. of currently running tasks: %s\n\n",out2);
printf("Current Total CPU Utilisation: %f %\n\n",num2);
printf("Total RAM memory: %sk\n\n",out4);
printf("Used RAM memory: %sk\n\n",out5);
fclose ( file );
}
return 0;
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
External CPU and/or network load monitor johnkeates Linux - Hardware 2 12-20-2009 06:38 AM
SLES9 snmp calculate CPU usage peter72 Linux - Software 0 11-04-2009 09:57 PM
how to calculate total cpu time of task in percentage using task_struct namit2010 Linux - Kernel 1 05-25-2009 12:43 AM
How to calculate a process %CPU from /proc kbarani Linux - Networking 2 01-23-2009 12:31 AM
How to calculate cpu and memory usage of a process narendra1310 Ubuntu 1 08-30-2008 03:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration