1*22714Sdist /* 2*22714Sdist ** Sendmail 3*22714Sdist ** Copyright (c) 1983 Eric P. Allman 4*22714Sdist ** Berkeley, California 5*22714Sdist ** 6*22714Sdist ** Copyright (c) 1983 Regents of the University of California. 7*22714Sdist ** All rights reserved. The Berkeley software License Agreement 8*22714Sdist ** specifies the terms and conditions for redistribution. 9*22714Sdist */ 10*22714Sdist 11*22714Sdist #ifndef lint 12*22714Sdist static char SccsId[] = "@(#)stats.c 5.1 (Berkeley) 06/07/85"; 13*22714Sdist #endif not lint 14*22714Sdist 154286Seric # include "sendmail.h" 164286Seric 17*22714Sdist SCCSID(@(#)stats.c 5.1 06/07/85); 184286Seric 194286Seric /* 209383Seric ** Statistics structure. 219383Seric */ 229383Seric 239383Seric struct statistics 249383Seric { 259383Seric time_t stat_itime; /* file initialization time */ 269383Seric short stat_size; /* size of this structure */ 279383Seric long stat_nf[MAXMAILERS]; /* # msgs from each mailer */ 289383Seric long stat_bf[MAXMAILERS]; /* kbytes from each mailer */ 299383Seric long stat_nt[MAXMAILERS]; /* # msgs to each mailer */ 309383Seric long stat_bt[MAXMAILERS]; /* kbytes to each mailer */ 319383Seric }; 329383Seric 339383Seric struct statistics Stat; 349383Seric extern long kbytes(); /* for _bf, _bt */ 359383Seric /* 369383Seric ** MARKSTATS -- mark statistics 379383Seric */ 389383Seric 399383Seric markstats(e, to) 409383Seric register ENVELOPE *e; 419383Seric register ADDRESS *to; 429383Seric { 439383Seric if (to == NULL) 449383Seric { 459383Seric Stat.stat_nf[e->e_from.q_mailer->m_mno]++; 469383Seric Stat.stat_bf[e->e_from.q_mailer->m_mno] += kbytes(CurEnv->e_msgsize); 479383Seric } 489383Seric else 499383Seric { 509383Seric Stat.stat_nt[to->q_mailer->m_mno]++; 519383Seric Stat.stat_bt[to->q_mailer->m_mno] += kbytes(CurEnv->e_msgsize); 529383Seric } 539383Seric } 549383Seric /* 554286Seric ** POSTSTATS -- post statistics in the statistics file 564286Seric ** 574286Seric ** Parameters: 584286Seric ** sfile -- the name of the statistics file. 594286Seric ** 604286Seric ** Returns: 614286Seric ** none. 624286Seric ** 634286Seric ** Side Effects: 644286Seric ** merges the Stat structure with the sfile file. 654286Seric */ 664286Seric 674286Seric poststats(sfile) 684286Seric char *sfile; 694286Seric { 704286Seric register int fd; 714286Seric struct statistics stat; 724319Seric extern long lseek(); 734286Seric 744319Seric (void) time(&Stat.stat_itime); 754286Seric Stat.stat_size = sizeof Stat; 764286Seric 774286Seric fd = open(sfile, 2); 784286Seric if (fd < 0) 7911937Seric { 8011937Seric errno = 0; 814286Seric return; 8211937Seric } 834319Seric if (read(fd, (char *) &stat, sizeof stat) == sizeof stat && 844286Seric stat.stat_size == sizeof stat) 854286Seric { 864286Seric /* merge current statistics into statfile */ 874286Seric register int i; 884286Seric 894286Seric for (i = 0; i < MAXMAILERS; i++) 904286Seric { 914286Seric stat.stat_nf[i] += Stat.stat_nf[i]; 924286Seric stat.stat_bf[i] += Stat.stat_bf[i]; 934286Seric stat.stat_nt[i] += Stat.stat_nt[i]; 944286Seric stat.stat_bt[i] += Stat.stat_bt[i]; 954286Seric } 964286Seric } 974286Seric else 9816887Seric bcopy((char *) &Stat, (char *) &stat, sizeof stat); 994286Seric 1004286Seric /* write out results */ 1014319Seric (void) lseek(fd, 0L, 0); 1024319Seric (void) write(fd, (char *) &stat, sizeof stat); 1034319Seric (void) close(fd); 1044286Seric } 1054286Seric /* 1064286Seric ** KBYTES -- given a number, returns the number of Kbytes. 1074286Seric ** 1084286Seric ** Used in statistics gathering of message sizes to try to avoid 1094286Seric ** wraparound (at least for a while.....) 1104286Seric ** 1114286Seric ** Parameters: 1124286Seric ** bytes -- actual number of bytes. 1134286Seric ** 1144286Seric ** Returns: 1154286Seric ** number of kbytes. 1164286Seric ** 1174286Seric ** Side Effects: 1184286Seric ** none. 1194286Seric ** 1204286Seric ** Notes: 1214286Seric ** This function is actually a ceiling function to 1224286Seric ** the nearest K. 1234286Seric ** Honestly folks, floating point might be better. 1244286Seric ** Or perhaps a "statistical" log method. 1254286Seric */ 1264286Seric 1274286Seric long 1284286Seric kbytes(bytes) 1294286Seric long bytes; 1304286Seric { 1314286Seric return ((bytes + 999) / 1000); 1324286Seric } 133