summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/zabbix_agent/cpustat.c224
1 files changed, 89 insertions, 135 deletions
diff --git a/src/zabbix_agent/cpustat.c b/src/zabbix_agent/cpustat.c
index 8f409b2e..b8b3857f 100644
--- a/src/zabbix_agent/cpustat.c
+++ b/src/zabbix_agent/cpustat.c
@@ -58,39 +58,6 @@
CPUSTAT cpustat;
-int get_device_name(char *device,int mjr,int diskno)
-{
- DIR *dir;
- struct dirent *entries;
- struct stat buf;
- char filename[1204];
-
- dir=opendir("/dev");
- while((entries=readdir(dir))!=NULL)
- {
- strncpy(filename,"/dev/",1024);
- strncat(filename,entries->d_name,1024);
-
- if(stat(filename,&buf)==0)
- {
-/* printf("%s %d %d\n",filename,major(buf.st_rdev),minor(buf.st_rdev));*/
- if(S_ISBLK(buf.st_mode)&&(mjr==major(buf.st_rdev))&&(0 == minor(buf.st_rdev)))
- {
- /* We've gor /dev/hda here */
- strcpy(device,entries->d_name);
- /* diskno specifies a,b,c,d,e,f,g,h etc */
- device[strlen(device)-1] = (char)((int)'a' + (int)diskno);
-
-/* printf("%s [%d %d] %d %d\n",filename,mjr, diskno, major(buf.st_rdev),minor(buf.st_rdev));*/
- closedir(dir);
- return 0;
- }
- }
- }
- closedir(dir);
- return 1;
-}
-
void init_stats_cpustat()
{
int i;
@@ -108,128 +75,115 @@ void report_stats_cpustat(FILE *file, int now)
time5=0,
time15=0;
float
- sent=0,
- sent1=0,
- sent5=0,
- sent15=0,
- received=0,
- received1=0,
- received5=0,
- received15=0;
-
- int i,j;
-
- for(i=0;i<MAX_INTERFACE;i++)
+ cpu_idle=0,
+ cpu_idle1=0,
+ cpu_idle5=0,
+ cpu_idle15=0,
+ cpu_user=0,
+ cpu_user1=0,
+ cpu_user5=0,
+ cpu_user15=0;
+
+ int i;
+
+ time=now+1;
+ time1=now+1;
+ time5=now+1;
+ time15=now+1;
+ for(i=0;i<60*15;i++)
{
- if(interfaces[i].interface==0)
- {
- break;
- }
-/* printf("IF [%s]\n",interfaces[i].interface);*/
- sent=0;sent1=0;received1=0;
- received=0;sent5=0;received5=0;
- sent15=0;received15=0;
-
- time=now+1;
- time1=now+1;
- time5=now+1;
- time15=now+1;
- for(j=0;j<60*15;j++)
- {
- if(interfaces[i].clock[j]==0)
- {
- continue;
- }
- if(interfaces[i].clock[j]==now)
- {
- continue;
- }
- if((interfaces[i].clock[j] >= now-60) && (time1 > interfaces[i].clock[j]))
- {
- time1=interfaces[i].clock[j];
- }
- if((interfaces[i].clock[j] >= now-5*60) && (time5 > interfaces[i].clock[j]))
- {
- time5=interfaces[i].clock[j];
- }
- if((interfaces[i].clock[j] >= now-15*60) && (time15 > interfaces[i].clock[j]))
- {
- time15=interfaces[i].clock[j];
- }
- }
- for(j=0;j<60*15;j++)
- {
- if(interfaces[i].clock[j]==now)
- {
- sent=interfaces[i].sent[j];
- received=interfaces[i].received[j];
- }
- if(interfaces[i].clock[j]==time1)
- {
- sent1=interfaces[i].sent[j];
- received1=interfaces[i].received[j];
- }
- if(interfaces[i].clock[j]==time5)
- {
- sent5=interfaces[i].sent[j];
- received5=interfaces[i].received[j];
- }
- if(interfaces[i].clock[j]==time15)
- {
- sent15=interfaces[i].sent[j];
- received15=interfaces[i].received[j];
- }
- }
- if((sent!=0)&&(sent1!=0))
- {
- fprintf(file,"netloadout1[%s] %f\n", interfaces[i].interface, (float)((sent-sent1)/(now-time1)));
- }
- else
- {
- fprintf(file,"netloadout1[%s] 0\n", interfaces[i].interface);
- }
- if((sent!=0)&&(sent5!=0))
+ if(cpustat.clock[i]==0)
{
- fprintf(file,"netloadout5[%s] %f\n", interfaces[i].interface, (float)((sent-sent5)/(now-time5)));
- }
- else
- {
- fprintf(file,"netloadout5[%s] 0\n", interfaces[i].interface);
+ continue;
}
- if((sent!=0)&&(sent15!=0))
+ if(cpustat.clock[i]==now)
{
- fprintf(file,"netloadout15[%s] %f\n", interfaces[i].interface, (float)((sent-sent15)/(now-time15)));
+ continue;
}
- else
+ if((cpustat.clock[i] >= now-60) && (time1 > cpustat.clock[i]))
{
- fprintf(file,"netloadout15[%s] 0\n", interfaces[i].interface);
+ time1=cpustat.clock[i];
}
- if((received!=0)&&(received1!=0))
+ if((cpustat.clock[i] >= now-5*60) && (time5 > cpustat.clock[i]))
{
- fprintf(file,"netloadin1[%s] %f\n", interfaces[i].interface, (float)((received-received1)/(now-time1)));
+ time5=cpustat.clock[i];
}
- else
+ if((cpustat.clock[i] >= now-15*60) && (time15 > cpustat.clock[i]))
{
- fprintf(file,"netloadin1[%s] 0\n", interfaces[i].interface);
+ time15=cpustat.clock[i];
}
- if((received!=0)&&(received5!=0))
+ }
+ for(i=0;i<60*15;i++)
+ {
+ if(cpustat.clock[i]==now)
{
- fprintf(file,"netloadin5[%s] %f\n", interfaces[i].interface, (float)((received-received5)/(now-time5)));
+ cpu_idle=cpustat.cpu_idle[i];
+ cpu_user=cpustat.cpu_user[i];
}
- else
+ if(cpustat.clock[i]==time1)
{
- fprintf(file,"netloadin5[%s] 0\n", interfaces[i].interface);
+ cpu_idle1=cpustat.cpu_idle[i];
+ cpu_user1=cpustat.cpu_user[i];
}
- if((received!=0)&&(received15!=0))
+ if(cpustat.clock[i]==time5)
{
- fprintf(file,"netloadin15[%s] %f\n", interfaces[i].interface, (float)((received-received15)/(now-time15)));
+ cpu_idle5=cpustat.cpu_idle[i];
+ cpu_user5=cpustat.cpu_user[i];
}
- else
+ if(cpustat.clock[i]==time15)
{
- fprintf(file,"netloadin15[%s] 0\n", interfaces[i].interface);
+ cpu_idle15=cpustat.cpu_idle[i];
+ cpu_user15=cpustat.cpu_user[i];
}
}
-
+ if((sent!=0)&&(sent1!=0))
+ {
+ fprintf(file,"netloadout1[%s] %f\n", cpustat[i].interface, (float)((sent-sent1)/(now-time1)));
+ }
+ else
+ {
+ fprintf(file,"netloadout1[%s] 0\n", cpustat[i].interface);
+ }
+ if((sent!=0)&&(sent5!=0))
+ {
+ fprintf(file,"netloadout5[%s] %f\n", cpustat[i].interface, (float)((sent-sent5)/(now-time5)));
+ }
+ else
+ {
+ fprintf(file,"netloadout5[%s] 0\n", cpustat[i].interface);
+ }
+ if((sent!=0)&&(sent15!=0))
+ {
+ fprintf(file,"netloadout15[%s] %f\n", cpustat[i].interface, (float)((sent-sent15)/(now-time15)));
+ }
+ else
+ {
+ fprintf(file,"netloadout15[%s] 0\n", cpustat[i].interface);
+ }
+ if((received!=0)&&(received1!=0))
+ {
+ fprintf(file,"netloadin1[%s] %f\n", cpustat[i].interface, (float)((received-received1)/(now-time1)));
+ }
+ else
+ {
+ fprintf(file,"netloadin1[%s] 0\n", cpustat[i].interface);
+ }
+ if((received!=0)&&(received5!=0))
+ {
+ fprintf(file,"netloadin5[%s] %f\n", cpustat[i].interface, (float)((received-received5)/(now-time5)));
+ }
+ else
+ {
+ fprintf(file,"netloadin5[%s] 0\n", cpustat[i].interface);
+ }
+ if((received!=0)&&(received15!=0))
+ {
+ fprintf(file,"netloadin15[%s] %f\n", cpustat[i].interface, (float)((received-received15)/(now-time15)));
+ }
+ else
+ {
+ fprintf(file,"netloadin15[%s] 0\n", cpustat[i].interface);
+ }
}