stats to syslog

This commit is contained in:
whottgen
2004-11-08 21:00:38 +00:00
parent 2e75bee478
commit ef7f203672
4 changed files with 33 additions and 11 deletions

View File

@ -20,6 +20,7 @@
#include <assert.h>
#include <syslog.h>
#include "config.h"
@ -66,21 +67,39 @@ void decStatCounter(int cnt_idx) {
#endif
}
void outputStats(int nice) {
void outputStats(int stdout_nice, int syslog_nice) {
#if ENABLE_STATS==1
int i;
char buf[1024];
char buf2[64];
int i, v;
if (nice)
*buf = '\0';
*buf2 = '\0';
strcat(buf, "Stats: ");
if (2 == stdout_nice)
printf("---------------------------------------------------------\n");
for (i=1; i<STAT_CNT_MAXNUM; i++) {
if (nice)
printf("%44s = %5d\n", stat_cnt_names[i], getStatCounter(i));
else
printf("%d ", getStatCounter(i));
v = getStatCounter(i);
if (2 == stdout_nice)
printf("%44s = %5d\n", stat_cnt_names[i], v);
if (2 == syslog_nice)
syslog(LOG_DEBUG, "%44s = %5d\n", stat_cnt_names[i], v);
if ((1 == stdout_nice) || (1 == syslog_nice)) {
sprintf(buf2, "%d ", v);
strcat(buf, buf2);
}
}
if (stdout_nice)
printf("\n");
if (1 == stdout_nice)
printf("%s\n\n", buf);
if (1 == syslog_nice)
syslog(LOG_DEBUG, buf);
#endif
}

View File

@ -99,5 +99,5 @@ void initStatCounter();
unsigned int getStatCounter(int cnt_idx);
void incStatCounter(int cnt_idx);
void decStatCounter(int cnt_idx);
void outputStats(int stdout_nice, int syslog_nice);
#endif /* _STATS_H_ */

View File

@ -110,11 +110,12 @@ cfg_t *cfg;
#if ENABLE_STATS==1
void * statser(void * arg) {
int nice = atoi(findcfgx(cfg, "stats", "nice", "0"));
int stdout_nice = atoi(findcfgx(cfg, "stats", "stdout_nice", "0"));
int syslog_nice = atoi(findcfgx(cfg, "stats", "syslog_nice", "0"));
int period = atoi(findcfgx(cfg, "stats", "period", "10"));
while(1) {
outputStats(nice);
outputStats(stdout_nice, syslog_nice);
sleep(period);
}
}

View File

@ -10,9 +10,11 @@ enable_stats = 0
enable_snmp = 1
[snmp]
agentx_socket = /var/agentx/master
[stats]
nice = 1
stdout_nice = 2
syslog_nice = 1
period = 1