stats to syslog
This commit is contained in:
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
@ -66,21 +67,39 @@ void decStatCounter(int cnt_idx) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void outputStats(int nice) {
|
void outputStats(int stdout_nice, int syslog_nice) {
|
||||||
#if ENABLE_STATS==1
|
#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");
|
printf("---------------------------------------------------------\n");
|
||||||
|
|
||||||
for (i=1; i<STAT_CNT_MAXNUM; i++) {
|
for (i=1; i<STAT_CNT_MAXNUM; i++) {
|
||||||
if (nice)
|
v = getStatCounter(i);
|
||||||
printf("%44s = %5d\n", stat_cnt_names[i], getStatCounter(i));
|
if (2 == stdout_nice)
|
||||||
else
|
printf("%44s = %5d\n", stat_cnt_names[i], v);
|
||||||
printf("%d ", getStatCounter(i));
|
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");
|
printf("\n");
|
||||||
|
|
||||||
|
if (1 == stdout_nice)
|
||||||
|
printf("%s\n\n", buf);
|
||||||
|
if (1 == syslog_nice)
|
||||||
|
syslog(LOG_DEBUG, buf);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,5 +99,5 @@ void initStatCounter();
|
|||||||
unsigned int getStatCounter(int cnt_idx);
|
unsigned int getStatCounter(int cnt_idx);
|
||||||
void incStatCounter(int cnt_idx);
|
void incStatCounter(int cnt_idx);
|
||||||
void decStatCounter(int cnt_idx);
|
void decStatCounter(int cnt_idx);
|
||||||
|
void outputStats(int stdout_nice, int syslog_nice);
|
||||||
#endif /* _STATS_H_ */
|
#endif /* _STATS_H_ */
|
||||||
|
@ -110,11 +110,12 @@ cfg_t *cfg;
|
|||||||
|
|
||||||
#if ENABLE_STATS==1
|
#if ENABLE_STATS==1
|
||||||
void * statser(void * arg) {
|
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"));
|
int period = atoi(findcfgx(cfg, "stats", "period", "10"));
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
outputStats(nice);
|
outputStats(stdout_nice, syslog_nice);
|
||||||
sleep(period);
|
sleep(period);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,11 @@ enable_stats = 0
|
|||||||
enable_snmp = 1
|
enable_snmp = 1
|
||||||
|
|
||||||
[snmp]
|
[snmp]
|
||||||
|
agentx_socket = /var/agentx/master
|
||||||
|
|
||||||
[stats]
|
[stats]
|
||||||
nice = 1
|
stdout_nice = 2
|
||||||
|
syslog_nice = 1
|
||||||
period = 1
|
period = 1
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user