Main Page | Class List | Directories | File List | Class Members | File Members

cfenvgraph.c File Reference

#include "../pub/getopt.h"
#include "cf.defs.h"
#include "cf.extern.h"
#include <math.h>
#include <db.h>

Go to the source code of this file.

Functions

int main ARGLIST ((int argc, char **argv))
int main (int argc, char **argv)
void ReadAverages ()
void SummarizeAverages ()
void WriteGraphFiles ()
void WriteHistograms ()
void CheckOpts (int argc, char **argv)
void Syntax ()
char * CanonifyName (char *str)

Variables

char * COPYRIGHT = "Free Software Foundation 2001-\nDonated by Mark Burgess, Faculty of Engineering,\nOslo University College, 0254 Oslo, Norway"
option GRAPHOPTIONS []
int TITLES = false
int TIMESTAMPS = false
int HIRES = false
int SEPARATE = false
int ERRORBARS = true
int NOSCALING = true
char FILENAME [bufsize]
unsigned int HISTOGRAM [ATTR *2+5+PH_LIMIT][7][GRAINS]
int SMOOTHHISTOGRAM [ATTR *2+5+PH_LIMIT][7][GRAINS]
char * ECGSOCKS [ATTR][2]
char * PH_BINARIES [PH_LIMIT]
int errno
int i
int j
int k
int count = 0
int its
time_t NOW
DBT key
DBT value
DB * DBP
static struct Averages ENTRY
MAX 
DET
char TIMEKEY [64]
char FLNAME [256]
char * sp
double AGE
FILE * FPAV = NULL
FILE * FPVAR = NULL
FILE * FPROOT = NULL
FILE * FPUSER = NULL
FILE * FPOTHER = NULL
FILE * FPDISK = NULL
FILE * FPLOAD = NULL
FILE * FPIN [ATTR]
FILE * FPOUT [ATTR]
FILE * FPPH [PH_LIMIT]
FILE * fp


Function Documentation

int main ARGLIST (int argc, char **argv)   ) 
 

char* CanonifyName char *  str  ) 
 

Definition at line 1036 of file cfenvgraph.c.

References bufsize, and bzero.

Referenced by AddMultipleClasses(), AddNetworkClass(), ArmClasses(), CheckFileWrapper(), CheckOptsAndInit(), CheckSystemVariables(), CopyReg(), DirectoriesWrapper(), DisableFiles(), DoEditFile(), DoTree(), EvalAvQ(), GetInterfaceInfo(), GetNameInfo(), HardLinkFiles(), Initialize(), InstallLocalInfo(), LinkFiles(), LocalExec(), MailCheck(), MakeChildLinks(), MakeImages(), MakeLinks(), RecHomeTidyWrapper(), SaveItemList(), Scripts(), SensibleFile(), SetDomainName(), TidyWrapper(), Unmount(), WriteGraphFiles(), and WriteHistograms().

01040 { static char buffer[bufsize];
01041   char *sp;
01042 
01043 bzero(buffer,bufsize);
01044 strcpy(buffer,str);
01045 
01046 for (sp = buffer; *sp != '\0'; sp++)
01047     {
01048     if (!isalnum((int)*sp) || *sp == '.')
01049        {
01050        *sp = '_';
01051        }
01052     }
01053 
01054 return buffer;
01055 }

void CheckOpts int  argc,
char **  argv
 

Definition at line 970 of file cfenvgraph.c.

References AVDB_FILE, bufsize, getopt_long(), optarg, snprintf(), and Syntax().

00975 { extern char *optarg;
00976   int optindex = 0;
00977   int c;
00978 
00979 snprintf(FILENAME,bufsize,"%s/%s",WORKDIR,AVDB_FILE);
00980 
00981 while ((c=getopt_long(argc,argv,"Thtf:rsen",GRAPHOPTIONS,&optindex)) != EOF)
00982   {
00983   switch ((char) c)
00984       {
00985       case 't': TITLES = true;
00986                 break;
00987 
00988       case 'f': strcpy(FILENAME,optarg);
00989                 break;
00990 
00991       case 'T': TIMESTAMPS = true;
00992                 break;
00993 
00994       case 'r': HIRES = true;
00995                 break;
00996 
00997       case 's': SEPARATE = true;
00998                 break;
00999 
01000       case 'e': ERRORBARS = false;
01001                 break;
01002 
01003       case 'n': NOSCALING = true;
01004                 break;
01005 
01006       default:  Syntax();
01007                 exit(1);
01008 
01009       }
01010    }
01011 }

int main int  argc,
char **  argv
 

Definition at line 119 of file cfenvgraph.c.

References CheckOpts(), ReadAverages(), SummarizeAverages(), WriteGraphFiles(), and WriteHistograms().

00124 {
00125 CheckOpts(argc,argv);
00126 ReadAverages(); 
00127 SummarizeAverages();
00128 WriteGraphFiles();
00129 WriteHistograms();
00130 return 0;
00131 }

void ReadAverages  ) 
 

Definition at line 137 of file cfenvgraph.c.

References ATTR, bcopy, bzero, cf_monday_morning, CFWEEK, Averages::expect_diskfree, Averages::expect_incoming, Averages::expect_loadavg, Averages::expect_number_of_users, Averages::expect_otherprocs, Averages::expect_outgoing, Averages::expect_pH, Averages::expect_rootprocs, GenTimeKey(), MEASURE_INTERVAL, NULL, PH_LIMIT, Averages::var_diskfree, Averages::var_incoming, Averages::var_loadavg, Averages::var_number_of_users, Averages::var_otherprocs, Averages::var_outgoing, Averages::var_pH, and Averages::var_rootprocs.

Referenced by main().

00139 {
00140 printf("\nLooking for database %s\n",FILENAME);
00141 printf("\nFinding MAXimum values...\n\n");
00142 printf("N.B. socket values are numbers in CLOSE_WAIT. See documentation.\n"); 
00143   
00144 if ((errno = db_create(&DBP,NULL,0)) != 0)
00145    {
00146    printf("Couldn't create average database %s\n",FILENAME);
00147    exit(1);
00148    }
00149 
00150 #ifdef CF_OLD_DB 
00151 if ((errno = DBP->open(DBP,FILENAME,NULL,DB_BTREE,DB_RDONLY,0644)) != 0)
00152 #else
00153 if ((errno = DBP->open(DBP,NULL,FILENAME,NULL,DB_BTREE,DB_RDONLY,0644)) != 0)    
00154 #endif
00155    {
00156    printf("Couldn't open average database %s\n",FILENAME);
00157    DBP->err(DBP,errno,NULL);
00158    exit(1);
00159    }
00160 
00161 bzero(&key,sizeof(key));       
00162 bzero(&value,sizeof(value));
00163 
00164 MAX.expect_number_of_users = 0.1;
00165 MAX.expect_rootprocs = 0.1;
00166 MAX.expect_otherprocs = 0.1;
00167 MAX.expect_diskfree = 0.1;
00168 MAX.expect_loadavg = 0.1; 
00169 
00170 MAX.var_number_of_users = 0.1;
00171 MAX.var_rootprocs = 0.1;
00172 MAX.var_otherprocs = 0.1;
00173 MAX.var_diskfree = 0.1;
00174 MAX.var_loadavg = 0.1; 
00175 
00176 for (i = 0; i < ATTR; i++)
00177    {
00178    MAX.var_incoming[i] = 0.1;
00179    MAX.var_outgoing[i] = 0.1;
00180    MAX.expect_incoming[i] = 0.1;
00181    MAX.expect_outgoing[i] = 0.1;
00182    }
00183 
00184 for (NOW = cf_monday_morning; NOW < cf_monday_morning+CFWEEK; NOW += MEASURE_INTERVAL)
00185    {
00186    bzero(&key,sizeof(key));       
00187    bzero(&value,sizeof(value));
00188    bzero(&ENTRY,sizeof(ENTRY));
00189 
00190    strcpy(TIMEKEY,GenTimeKey(NOW));
00191 
00192    key.data = TIMEKEY;
00193    key.size = strlen(TIMEKEY)+1;
00194    
00195    if ((errno = DBP->get(DBP,NULL,&key,&value,0)) != 0)
00196       {
00197       if (errno != DB_NOTFOUND)
00198          {
00199          DBP->err(DBP,errno,NULL);
00200          exit(1);
00201          }
00202       }
00203    
00204    
00205    if (value.data != NULL)
00206       {
00207       bcopy(value.data,&ENTRY,sizeof(ENTRY));
00208       
00209       if (fabs(ENTRY.expect_number_of_users) > MAX.expect_number_of_users)
00210          {
00211          MAX.expect_number_of_users = fabs(ENTRY.expect_number_of_users);
00212          }
00213       if (fabs(ENTRY.expect_number_of_users) > MAX.expect_number_of_users)
00214          {
00215          MAX.expect_number_of_users = fabs(ENTRY.expect_number_of_users);
00216          }      
00217       if (fabs(ENTRY.expect_rootprocs) > MAX.expect_rootprocs)
00218          {
00219          MAX.expect_rootprocs = fabs(ENTRY.expect_rootprocs);
00220          }
00221       if (fabs(ENTRY.expect_otherprocs) >  MAX.expect_otherprocs)
00222          {
00223          MAX.expect_otherprocs = fabs(ENTRY.expect_otherprocs);
00224          }      
00225       if (fabs(ENTRY.expect_diskfree) > MAX.expect_diskfree)
00226          {
00227          MAX.expect_diskfree = fabs(ENTRY.expect_diskfree);
00228          }
00229       if (fabs(ENTRY.expect_loadavg) > MAX.expect_loadavg)
00230          {
00231          MAX.expect_diskfree = fabs(ENTRY.expect_loadavg);
00232          }
00233 
00234       for (i = 0; i < ATTR; i++)
00235          {
00236          if (fabs(ENTRY.expect_incoming[i]) > MAX.expect_incoming[i])
00237             {
00238             MAX.expect_incoming[i] = fabs(ENTRY.expect_incoming[i]);
00239             }
00240          if (fabs(ENTRY.expect_outgoing[i]) > MAX.expect_outgoing[i])
00241             {
00242             MAX.expect_outgoing[i] = fabs(ENTRY.expect_outgoing[i]);
00243             }
00244          }
00245 
00246       if (fabs(ENTRY.var_number_of_users) > MAX.var_number_of_users)
00247          {
00248          MAX.var_number_of_users = fabs(ENTRY.var_number_of_users);
00249          }
00250       if (fabs(ENTRY.var_number_of_users) > MAX.var_number_of_users)
00251          {
00252          MAX.var_number_of_users = fabs(ENTRY.var_number_of_users);
00253          }      
00254       if (fabs(ENTRY.var_rootprocs) > MAX.var_rootprocs)
00255          {
00256          MAX.var_rootprocs = fabs(ENTRY.var_rootprocs);
00257          }
00258       if (fabs(ENTRY.var_otherprocs) >  MAX.var_otherprocs)
00259          {
00260          MAX.var_otherprocs = fabs(ENTRY.var_otherprocs);
00261          }      
00262       if (fabs(ENTRY.var_diskfree) > MAX.var_diskfree)
00263          {
00264          MAX.var_diskfree = fabs(ENTRY.var_diskfree);
00265          }
00266       if (fabs(ENTRY.var_loadavg) > MAX.var_loadavg)
00267          {
00268          MAX.var_diskfree = fabs(ENTRY.var_loadavg);
00269          }
00270       
00271       for (i = 0; i < ATTR; i++)
00272          {
00273          if (fabs(ENTRY.var_incoming[i]) > MAX.var_incoming[i])
00274             {
00275             MAX.var_incoming[i] = fabs(ENTRY.var_incoming[i]);
00276             }
00277          if (fabs(ENTRY.var_outgoing[i]) > MAX.var_outgoing[i])
00278             {
00279             MAX.var_outgoing[i] = fabs(ENTRY.var_outgoing[i]);
00280             }
00281          }
00282 
00283       for (i = 0; i < PH_LIMIT; i++)
00284          {
00285          if (PH_BINARIES[i] == NULL)
00286             {
00287             continue;
00288             }
00289          
00290          if (fabs(ENTRY.expect_pH[i]) > MAX.expect_pH[i])
00291             {
00292             MAX.expect_pH[i] = fabs(ENTRY.expect_pH[i]);
00293             }
00294 
00295          if (fabs(ENTRY.var_pH[i]) > MAX.var_pH[i])
00296             {
00297             MAX.var_pH[i] = fabs(ENTRY.var_pH[i]);
00298             }
00299          }
00300 
00301       
00302       }
00303    }
00304 
00305 DBP->close(DBP,0);
00306 }

void SummarizeAverages  ) 
 

Definition at line 310 of file cfenvgraph.c.

References ATTR, bzero, CFWEEK, Averages::expect_diskfree, Averages::expect_incoming, Averages::expect_loadavg, Averages::expect_number_of_users, Averages::expect_otherprocs, Averages::expect_outgoing, Averages::expect_pH, Averages::expect_rootprocs, MEASURE_INTERVAL, NULL, PH_LIMIT, Averages::var_diskfree, Averages::var_incoming, Averages::var_loadavg, Averages::var_number_of_users, Averages::var_otherprocs, Averages::var_outgoing, Averages::var_pH, and Averages::var_rootprocs.

Referenced by main().

00312 {
00313  
00314 printf(" x  yN (Variable content)\n---------------------------------------------------------\n");
00315 printf(" 1. MAX <number of users> = %10f +/- %10f\n",MAX.expect_number_of_users,sqrt(MAX.var_number_of_users));
00316 printf(" 2. MAX <rootprocs>       = %10f +/- %10f\n",MAX.expect_rootprocs,sqrt(MAX.var_rootprocs));
00317 printf(" 3. MAX <otherprocs>      = %10f +/- %10f\n",MAX.expect_otherprocs,sqrt(MAX.var_otherprocs));
00318 printf(" 4. MAX <diskfree>        = %10f +/- %10f\n",MAX.expect_diskfree,sqrt(MAX.var_diskfree));
00319 printf(" 5. MAX <loadavg>         = %10f +/- %10f\n",MAX.expect_loadavg,sqrt(MAX.var_loadavg)); 
00320 
00321  for (i = 0; i < ATTR*2; i+=2)
00322    {
00323    printf("%2d. MAX <%-10s-in>   = %10f +/- %10f\n",6+i,ECGSOCKS[i/2][1],MAX.expect_incoming[i/2],sqrt(MAX.var_incoming[i/2]));
00324    printf("%2d. MAX <%-10s-out>  = %10f +/- %10f\n",7+i,ECGSOCKS[i/2][1],MAX.expect_outgoing[i/2],sqrt(MAX.var_outgoing[i/2]));
00325    }
00326 
00327  for (i = 0; i < PH_LIMIT; i++)
00328    {
00329    if (PH_BINARIES[i] == NULL)
00330       {
00331       continue;
00332       }
00333    printf("%2d. MAX <%-10s-in>   = %10f +/- %10f\n",i+5+ATTR,PH_BINARIES[i],MAX.expect_pH[i],sqrt(MAX.var_pH[i]));
00334    }
00335 
00336  
00337 if ((errno = db_create(&DBP,NULL,0)) != 0)
00338    {
00339    printf("Couldn't open average database %s\n",FILENAME);
00340    exit(1);
00341    }
00342 
00343 #ifdef CF_OLD_DB 
00344 if ((errno = DBP->open(DBP,FILENAME,NULL,DB_BTREE,DB_RDONLY,0644)) != 0)
00345 #else
00346 if ((errno = DBP->open(DBP,NULL,FILENAME,NULL,DB_BTREE,DB_RDONLY,0644)) != 0)
00347 #endif
00348    {
00349    printf("Couldn't open average database %s\n",FILENAME);
00350    exit(1);
00351    }
00352 
00353 bzero(&key,sizeof(key));       
00354 bzero(&value,sizeof(value));
00355       
00356 key.data = "DATABASE_AGE";
00357 key.size = strlen("DATABASE_AGE")+1;
00358 
00359 if ((errno = DBP->get(DBP,NULL,&key,&value,0)) != 0)
00360    {
00361    if (errno != DB_NOTFOUND)
00362       {
00363       DBP->err(DBP,errno,NULL);
00364       exit(1);
00365       }
00366    }
00367  
00368 if (value.data != NULL)
00369    {
00370    AGE = *(double *)(value.data);
00371    printf("\n\nDATABASE_AGE %.1f (weeks)\n\n",AGE/CFWEEK*MEASURE_INTERVAL);
00372    }
00373 
00374 }

void Syntax  ) 
 

Definition at line 1015 of file cfenvgraph.c.

References NULL.

01017 { int i;
01018 
01019 printf("Cfengine Environment Graph Generator\n%s\n%s\n",VERSION,COPYRIGHT);
01020 printf("\n");
01021 printf("Options:\n\n");
01022 
01023 for (i=0; GRAPHOPTIONS[i].name != NULL; i++)
01024    {
01025    printf("--%-20s    (-%c)\n",GRAPHOPTIONS[i].name,(char)GRAPHOPTIONS[i].val);
01026    }
01027 
01028 printf("\nBug reports to bug-cfengine@gnu.org (News: gnu.cfengine.bug)\n");
01029 printf("General help to help-cfengine@gnu.org (News: gnu.cfengine.help)\n");
01030 printf("Info & fixes at http://www.iu.hio.no/cfengine\n");
01031 }

void WriteGraphFiles  ) 
 

Definition at line 378 of file cfenvgraph.c.

References ATTR, bcopy, bzero, CanonifyName(), cf_monday_morning, CFWEEK, Averages::expect_diskfree, Averages::expect_incoming, Averages::expect_loadavg, Averages::expect_number_of_users, Averages::expect_otherprocs, Averages::expect_outgoing, Averages::expect_pH, Averages::expect_rootprocs, GenTimeKey(), its, MEASURE_INTERVAL, NULL, and PH_LIMIT.

Referenced by main().

00380 {
00381 if (TIMESTAMPS)
00382    {
00383    if ((NOW = time((time_t *)NULL)) == -1)
00384       {
00385       printf("Couldn't read system clock\n");
00386       }
00387      
00388    sprintf(FLNAME,"cfenvgraphs-%s",ctime(&NOW));
00389 
00390    for (sp = FLNAME; *sp != '\0'; sp++)
00391       {
00392       if (isspace((int)*sp))
00393          {
00394          *sp = '_';
00395          }
00396       }    
00397    }
00398  else
00399    {
00400    sprintf(FLNAME,"cfenvgraphs-snapshot");
00401    }
00402 
00403 printf("Creating sub-directory %s\n",FLNAME);
00404 
00405 if (mkdir(FLNAME,0755) == -1)
00406    {
00407    perror("mkdir");
00408    printf("Aborting\n");
00409    exit(0);
00410    }
00411  
00412 if (chdir(FLNAME))
00413    {
00414    perror("chdir");
00415    exit(0);
00416    }
00417 
00418 
00419 printf("Writing data to sub-directory %s: \n   x,y1,y2,y3...\n ",FLNAME);
00420 
00421 
00422 sprintf(FLNAME,"cfenv-average");
00423 
00424 if ((FPAV = fopen(FLNAME,"w")) == NULL)
00425    {
00426    perror("fopen");
00427    exit(1);
00428    }
00429 
00430 sprintf(FLNAME,"cfenv-stddev"); 
00431 
00432 if ((FPVAR = fopen(FLNAME,"w")) == NULL)
00433    {
00434    perror("fopen");
00435    exit(1);
00436    }
00437 
00438 
00439 /* Now if -s open a file foreach metric! */
00440 
00441 if (SEPARATE)
00442    {
00443    sprintf(FLNAME,"users.cfenv"); 
00444    if ((FPUSER = fopen(FLNAME,"w")) == NULL)
00445       {
00446       perror("fopen");
00447       exit(1);
00448       }
00449    sprintf(FLNAME,"rootprocs.cfenv"); 
00450    if ((FPROOT = fopen(FLNAME,"w")) == NULL)
00451       {
00452       perror("fopen");
00453       exit(1);
00454       }
00455    sprintf(FLNAME,"otherprocs.cfenv"); 
00456    if ((FPOTHER = fopen(FLNAME,"w")) == NULL)
00457       {
00458       perror("fopen");
00459       exit(1);
00460       }
00461    sprintf(FLNAME,"freedisk.cfenv"); 
00462    if ((FPDISK = fopen(FLNAME,"w")) == NULL)
00463       {
00464       perror("fopen");
00465       exit(1);
00466       }
00467    sprintf(FLNAME,"loadavg.cfenv"); 
00468    if ((FPLOAD = fopen(FLNAME,"w")) == NULL)
00469       {
00470       perror("fopen");
00471       exit(1);
00472       }
00473 
00474    for (i = 0; i < ATTR; i++)
00475       {
00476       sprintf(FLNAME,"%s-in.cfenv",ECGSOCKS[i][1]); 
00477       if ((FPIN[i] = fopen(FLNAME,"w")) == NULL)
00478          {
00479          perror("fopen");
00480          exit(1);
00481          }
00482 
00483       sprintf(FLNAME,"%s-out.cfenv",ECGSOCKS[i][1]); 
00484       if ((FPOUT[i] = fopen(FLNAME,"w")) == NULL)
00485          {
00486          perror("fopen");
00487          exit(1);
00488          }
00489       }
00490 
00491    for (i = 0; i < PH_LIMIT; i++)
00492       {
00493       if (PH_BINARIES[i] == NULL)
00494          {
00495          continue;
00496          }
00497       
00498       sprintf(FLNAME,"%s.cfenv",CanonifyName(PH_BINARIES[i])); 
00499       if ((FPPH[i] = fopen(FLNAME,"w")) == NULL)
00500          {
00501          perror("fopen");
00502          exit(1);
00503          }
00504       }
00505 
00506    }
00507 
00508 if (TITLES)
00509    {
00510    fprintf(FPAV,"# Column 1: Users\n");
00511    fprintf(FPAV,"# Column 2: Root Processes\n");
00512    fprintf(FPAV,"# Column 3: Non-root Processes 3\n");
00513    fprintf(FPAV,"# Column 4: Percent free disk\n");
00514    fprintf(FPAV,"# Column 5: Load average\n");
00515      
00516    for (i = 0; i < ATTR*2; i+=2)
00517       {
00518       fprintf(FPAV,"# Column %d: Incoming %s sockets\n",6+i,ECGSOCKS[i/2][1]);
00519       fprintf(FPAV,"# Column %d: Outgoing %s sockets\n",7+i,ECGSOCKS[i/2][1]);
00520       }
00521 
00522    for (i = 0; i < PH_LIMIT; i++)
00523       {
00524       if (PH_BINARIES[i] == NULL)
00525          {
00526          continue;
00527          }
00528       fprintf(FPAV,"# Column %d: pH %s \n",6+i,PH_BINARIES[i]);
00529       }
00530 
00531    fprintf(FPAV,"##############################################\n");
00532      
00533    fprintf(FPVAR,"# Column 1: Users\n");
00534    fprintf(FPVAR,"# Column 2: Root Processes\n");
00535    fprintf(FPVAR,"# Column 3: Non-root Processes 3\n");
00536    fprintf(FPVAR,"# Column 4: Percent free disk\n");
00537    fprintf(FPVAR,"# Column 5: Load Average\n");
00538      
00539    for (i = 0; i < ATTR*2; i+=2)
00540       {
00541       fprintf(FPVAR,"# Column %d: Incoming %s sockets\n",6+i,ECGSOCKS[i/2][1]);
00542       fprintf(FPVAR,"# Column %d: Outgoing %s sockets\n",7+i,ECGSOCKS[i/2][1]);
00543       }
00544 
00545    for (i = 0; i < PH_LIMIT; i++)
00546       {
00547       if (PH_BINARIES[i] == NULL)
00548          {
00549          continue;
00550          }
00551       fprintf(FPVAR,"# Column %d: pH %s \n",6+i,PH_BINARIES[i]);
00552       }
00553 
00554    fprintf(FPVAR,"##############################################\n");
00555    }
00556 
00557 if (HIRES)
00558    {
00559    its = 1;
00560    }
00561 else
00562    {
00563    its = 12;
00564    }
00565 
00566 NOW = cf_monday_morning;
00567 bzero(&ENTRY,sizeof(ENTRY)); 
00568  
00569 while (NOW < cf_monday_morning+CFWEEK)
00570    {
00571    for (j = 0; j < its; j++)
00572       {
00573       bzero(&key,sizeof(key));       
00574       bzero(&value,sizeof(value));
00575       
00576       strcpy(TIMEKEY,GenTimeKey(NOW));
00577       key.data = TIMEKEY;
00578       key.size = strlen(TIMEKEY)+1;
00579       
00580       if ((errno = DBP->get(DBP,NULL,&key,&value,0)) != 0)
00581          {
00582          if (errno != DB_NOTFOUND)
00583             {
00584             DBP->err(DBP,errno,NULL);
00585             exit(1);
00586             }
00587          }
00588       
00589       if (value.data != NULL)
00590          {
00591          bcopy(value.data,&DET,sizeof(DET));
00592          
00593          ENTRY.expect_number_of_users += DET.expect_number_of_users/(double)its;
00594          ENTRY.expect_rootprocs += DET.expect_rootprocs/(double)its;
00595          ENTRY.expect_otherprocs += DET.expect_otherprocs/(double)its;
00596          ENTRY.expect_diskfree += DET.expect_diskfree/(double)its;
00597          ENTRY.expect_loadavg += DET.expect_loadavg/(double)its;
00598          ENTRY.var_number_of_users += DET.var_number_of_users/(double)its;
00599          ENTRY.var_rootprocs += DET.var_rootprocs/(double)its;
00600          ENTRY.var_otherprocs += DET.var_otherprocs/(double)its;
00601          ENTRY.var_diskfree += DET.var_diskfree/(double)its;
00602          ENTRY.var_loadavg += DET.var_loadavg/(double)its;
00603 
00604          for (i = 0; i < ATTR; i++)
00605             {
00606             ENTRY.expect_incoming[i] += DET.expect_incoming[i]/(double)its;
00607             ENTRY.expect_outgoing[i] += DET.expect_outgoing[i]/(double)its;
00608             ENTRY.var_incoming[i] += DET.var_incoming[i]/(double)its;
00609             ENTRY.var_outgoing[i] += DET.var_outgoing[i]/(double)its;
00610             }
00611 
00612          for (i = 0; i< PH_LIMIT; i++)
00613             {
00614             if (PH_BINARIES[i] == NULL)
00615                {
00616                continue;
00617                }
00618 
00619             ENTRY.expect_pH[i] += DET.expect_pH[i]/(double)its;
00620             ENTRY.var_pH[i] += DET.var_pH[i]/(double)its;
00621             }
00622 
00623 
00624          if (NOSCALING)
00625             {
00626             MAX.expect_number_of_users = 1;
00627             MAX.expect_rootprocs = 1;
00628             MAX.expect_otherprocs = 1;
00629             MAX.expect_diskfree = 1;
00630             MAX.expect_loadavg = 1;
00631             
00632             for (i = 1; i < ATTR; i++)
00633                {
00634                MAX.expect_incoming[i] = 1;
00635                MAX.expect_outgoing[i] = 1;
00636                }
00637 
00638             for (i = 1; i < PH_LIMIT; i++)
00639                {
00640                if (PH_BINARIES[i] == NULL)
00641                   {
00642                   continue;
00643                   }
00644                MAX.expect_pH[i] = 1;
00645                }
00646             
00647             }
00648          
00649          if (j == its-1)
00650             {
00651             fprintf(FPAV,"%d %f %f %f %f %f",count++,
00652                  ENTRY.expect_number_of_users/MAX.expect_number_of_users,
00653                  ENTRY.expect_rootprocs/MAX.expect_rootprocs,
00654                  ENTRY.expect_otherprocs/MAX.expect_otherprocs,
00655                  ENTRY.expect_diskfree/MAX.expect_diskfree,
00656                  ENTRY.expect_loadavg/MAX.expect_loadavg);
00657          
00658             for (i = 0; i < ATTR; i++)
00659                {
00660                fprintf(FPAV,"%f %f "
00661                        ,ENTRY.expect_incoming[i]/MAX.expect_incoming[i]
00662                        ,ENTRY.expect_outgoing[i]/MAX.expect_outgoing[i]);
00663                }
00664 
00665             for (i = 0; i < PH_LIMIT; i++)
00666                {
00667                if (PH_BINARIES[i] == NULL)
00668                   {
00669                   continue;
00670                   }
00671                fprintf(FPAV,"%f ",ENTRY.expect_pH[i]/MAX.expect_pH[i]);
00672                }
00673 
00674             
00675             fprintf(FPAV,"\n");
00676             
00677             fprintf(FPVAR,"%d %f %f %f %f %f",count,
00678                     sqrt(ENTRY.var_number_of_users)/MAX.expect_number_of_users,
00679                     sqrt(ENTRY.var_rootprocs)/MAX.expect_rootprocs,
00680                     sqrt(ENTRY.var_otherprocs)/MAX.expect_otherprocs,
00681                     sqrt(ENTRY.var_diskfree)/MAX.expect_diskfree,
00682                     sqrt(ENTRY.var_loadavg)/MAX.expect_loadavg);
00683             
00684             for (i = 0; i < ATTR; i++)
00685                {
00686                fprintf(FPVAR,"%f %f ",
00687                        sqrt(ENTRY.var_incoming[i])/MAX.expect_incoming[i],
00688                        sqrt(ENTRY.var_outgoing[i])/MAX.expect_outgoing[i]);
00689                }
00690 
00691             for (i = 0; i < PH_LIMIT; i++)
00692                {
00693                if (PH_BINARIES[i] == NULL)
00694                   {
00695                   continue;
00696                   }
00697                fprintf(FPVAR,"%f ",sqrt(ENTRY.var_pH[i])/MAX.expect_pH[i]);
00698                }
00699 
00700 
00701             
00702             
00703             fprintf(FPVAR,"\n");
00704 
00705             if (SEPARATE)
00706                {
00707                fprintf(FPUSER,"%d %f %f\n",count,ENTRY.expect_number_of_users/MAX.expect_number_of_users,sqrt(ENTRY.var_number_of_users)/MAX.expect_number_of_users);
00708                fprintf(FPROOT,"%d %f %f\n",count,ENTRY.expect_rootprocs/MAX.expect_rootprocs,sqrt(ENTRY.var_rootprocs)/MAX.expect_rootprocs);
00709                fprintf(FPOTHER,"%d %f %f\n",count,ENTRY.expect_otherprocs/MAX.expect_otherprocs,sqrt(ENTRY.var_otherprocs)/MAX.expect_otherprocs);
00710                fprintf(FPDISK,"%d %f %f\n",count,ENTRY.expect_diskfree/MAX.expect_diskfree,sqrt(ENTRY.var_diskfree)/MAX.expect_diskfree);
00711                fprintf(FPLOAD,"%d %f %f\n",count,ENTRY.expect_loadavg/MAX.expect_loadavg,sqrt(ENTRY.var_loadavg)/MAX.expect_loadavg);
00712 
00713                for (i = 0; i < ATTR; i++)
00714                   {
00715                   fprintf(FPIN[i],"%d %f %f\n",count,ENTRY.expect_incoming[i]/MAX.expect_incoming[i],sqrt(ENTRY.var_incoming[i])/MAX.expect_incoming[i]);
00716                   fprintf(FPOUT[i],"%d %f %f\n",count,ENTRY.expect_outgoing[i]/MAX.expect_outgoing[i],sqrt(ENTRY.var_outgoing[i])/MAX.expect_outgoing[i]);
00717                   }
00718 
00719                for (i = 0; i < PH_LIMIT; i++)
00720                   {
00721                   if (PH_BINARIES[i] == NULL)
00722                      {
00723                      continue;
00724                      }
00725                   fprintf(FPPH[i],"%d %f %f\n",count,ENTRY.expect_pH[i]/MAX.expect_pH[i],sqrt(ENTRY.var_pH[i])/MAX.expect_pH[i]);
00726                   }            
00727                }
00728  
00729             bzero(&ENTRY,sizeof(ENTRY)); 
00730             }
00731          }
00732       
00733       NOW += MEASURE_INTERVAL;
00734       }
00735    }
00736  
00737 DBP->close(DBP,0);
00738 
00739 fclose(FPAV);
00740 fclose(FPVAR); 
00741 
00742 if (SEPARATE)
00743    {
00744    fclose(FPROOT);
00745    fclose(FPOTHER);
00746    fclose(FPUSER);
00747    fclose(FPDISK);
00748    fclose(FPLOAD);
00749    for (i = 0; i < ATTR; i++)
00750       {
00751       fclose(FPIN[i]);
00752       fclose(FPOUT[i]);
00753       }
00754    for (i = 0; i < PH_LIMIT; i++)
00755       {
00756       if (PH_BINARIES[i] == NULL)
00757          {
00758          continue;
00759          }
00760       fclose(FPPH[i]);
00761       }
00762    }
00763 
00764 }

void WriteHistograms  ) 
 

Definition at line 768 of file cfenvgraph.c.

References ATTR, bufsize, CanonifyName(), GRAINS, NULL, PH_LIMIT, and snprintf().

Referenced by main().

00770 {
00771 /* Finally, look at the histograms */
00772 
00773 for (i = 0; i < 7; i++)
00774    {
00775    for (j = 0; j < PH_LIMIT+ATTR*2+5; j++)
00776       {
00777       for (k = 0; k < GRAINS; k++)
00778           {
00779           HISTOGRAM[j][i][k] = 0;
00780           }
00781       }
00782    }
00783 
00784 if (SEPARATE)
00785    {
00786    int position,day;
00787    int weekly[ATTR*2+5][GRAINS];
00788    
00789    snprintf(FLNAME,bufsize,"%s/histograms",WORKDIR);
00790    
00791    if ((fp = fopen(FLNAME,"r")) == NULL)
00792       {
00793       printf("Unable to load histogram data\n");
00794       exit(1);
00795       }
00796    
00797    for (position = 0; position < GRAINS; position++)
00798       {
00799       fscanf(fp,"%d ",&position);
00800       
00801       for (i = 0; i < 5 + 2*ATTR+PH_LIMIT; i++)
00802          {
00803          for (day = 0; day < 7; day++)
00804             {
00805             fscanf(fp,"%d ",&(HISTOGRAM[i][day][position]));
00806             }
00807 
00808          weekly[i][position] = 0;
00809          }
00810       }
00811    
00812    fclose(fp);
00813 
00814    if (!HIRES)
00815       {
00816       /* Smooth daily and weekly histograms */
00817       for (k = 1; k < GRAINS-1; k++)
00818          {
00819          int a;
00820          
00821          for (j = 0; j < ATTR*2+5+PH_LIMIT; j++)
00822             {
00823             for (i = 0; i < 7; i++)      
00824                {
00825                SMOOTHHISTOGRAM[j][i][k] = ((double)(HISTOGRAM[j][i][k-1] + HISTOGRAM[j][i][k] + HISTOGRAM[j][i][k+1]))/3.0;
00826                }
00827             }
00828          }
00829       }
00830    else
00831       {
00832       for (k = 1; k < GRAINS-1; k++)
00833          {
00834          int a;
00835          
00836          for (j = 0; j < ATTR*2+5+PH_LIMIT; j++)
00837             {
00838             for (i = 0; i < 7; i++)      
00839                {
00840                SMOOTHHISTOGRAM[j][i][k] = (double) HISTOGRAM[j][i][k];
00841                }
00842             }
00843          }
00844       }
00845 
00846    sprintf(FLNAME,"users.distr"); 
00847    if ((FPUSER = fopen(FLNAME,"w")) == NULL)
00848       {
00849       perror("fopen");
00850       exit(1);
00851       }
00852    sprintf(FLNAME,"rootprocs.distr"); 
00853    if ((FPROOT = fopen(FLNAME,"w")) == NULL)
00854       {
00855       perror("fopen");
00856       exit(1);
00857       }
00858    sprintf(FLNAME,"otherprocs.distr"); 
00859    if ((FPOTHER = fopen(FLNAME,"w")) == NULL)
00860       {
00861       perror("fopen");
00862       exit(1);
00863       }
00864    sprintf(FLNAME,"freedisk.distr"); 
00865    if ((FPDISK = fopen(FLNAME,"w")) == NULL)
00866       {
00867       perror("fopen");
00868       exit(1);
00869       }
00870    sprintf(FLNAME,"loadavg.distr"); 
00871    if ((FPLOAD = fopen(FLNAME,"w")) == NULL)
00872       {
00873       perror("fopen");
00874       exit(1);
00875       }
00876 
00877    for (i = 0; i < ATTR; i++)
00878       {
00879       sprintf(FLNAME,"%s-in.distr",ECGSOCKS[i][1]); 
00880       if ((FPIN[i] = fopen(FLNAME,"w")) == NULL)
00881          {
00882          perror("fopen");
00883          exit(1);
00884          }
00885 
00886       sprintf(FLNAME,"%s-out.distr",ECGSOCKS[i][1]); 
00887       if ((FPOUT[i] = fopen(FLNAME,"w")) == NULL)
00888          {
00889          perror("fopen");
00890          exit(1);
00891          }
00892       }
00893 
00894    for (i = 0; i < PH_LIMIT; i++)
00895       {
00896       if (PH_BINARIES[i] == NULL)
00897          {
00898          continue;
00899          }
00900 
00901       sprintf(FLNAME,"%s.distr",CanonifyName(PH_BINARIES[i])); 
00902       if ((FPOUT[i] = fopen(FLNAME,"w")) == NULL)
00903          {
00904          perror("fopen");
00905          exit(1);
00906          }
00907       }
00908 
00909    /* Plot daily and weekly histograms */
00910    for (k = 0; k < GRAINS; k++)
00911       {
00912       int a;
00913       
00914       for (j = 0; j < ATTR*2+5+PH_LIMIT; j++)
00915          {
00916          for (i = 0; i < 7; i++)         
00917             {
00918             weekly[j][k] += (int) (SMOOTHHISTOGRAM[j][i][k]+0.5);
00919             }
00920          }
00921 
00922       fprintf(FPUSER,"%d %d\n",k,weekly[0][k]);
00923       fprintf(FPROOT,"%d %d\n",k,weekly[1][k]);
00924       fprintf(FPOTHER,"%d %d\n",k,weekly[2][k]);
00925       fprintf(FPDISK,"%d %d\n",k,weekly[3][k]);
00926       fprintf(FPLOAD,"%d %d\n",k,weekly[4][k]);
00927 
00928       for (a = 0; a < ATTR; a++)
00929          {
00930          fprintf(FPIN[a],"%d %d\n",k,weekly[5+a][k]);
00931          fprintf(FPOUT[a],"%d %d\n",k,weekly[5+ATTR+a][k]);
00932          }
00933 
00934       for (a = 0; a < PH_LIMIT; a++)
00935          {
00936          if (PH_BINARIES[a] == NULL)
00937             {
00938             continue;
00939             }
00940          fprintf(FPIN[a],"%d %d\n",k,weekly[5+ATTR+a][k]);
00941          }
00942       
00943       }