Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/detstats.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
src/log.c | 130 +-----------------------------------------------------
src/log.h | 3 +
3 files changed, 132 insertions(+), 135 deletions(-)
diff --git a/src/detstats.c b/src/detstats.c
index 63f869b..f7ddb8d 100644
--- a/src/detstats.c
+++ b/src/detstats.c
@@ -39,12 +39,6 @@ details.
extern int exitloop;
extern int daemonized;
-/* from log.c, applicable only to this module */
-void writedstatlog(char *ifname, int unit,
- float peakactivity, float peakpps, float peakactivity_in,
- float peakpps_in, float peakactivity_out, float peakpps_out,
- struct ifcounts *ts, unsigned long nsecs, FILE * logfile);
-
/* USR1 log-rotation signal handlers */
static void rotate_dstat_log(int s __unused)
{
@@ -53,6 +47,134 @@ static void rotate_dstat_log(int s __unused)
signal(SIGUSR1, rotate_dstat_log);
}
+static void writedstatlog(char *ifname, int unit,
+ float peakactivity, float peakpps, float peakactivity_in,
+ float peakpps_in, float peakactivity_out, float peakpps_out,
+ struct ifcounts *ts, unsigned long nsecs, FILE *fd)
+{
+ char atime[TIME_TARGET_MAX];
+
+ genatime(time(NULL), atime);
+
+ fprintf(fd,
+ "\n*** Detailed statistics for interface %s, generated %s\n\n",
+ ifname, atime);
+
+ fprintf(fd, "Total: \t%llu packets, %llu bytes\n",
+ ts->total.proto_total.pc_packets,
+ ts->total.proto_total.pc_bytes);
+ fprintf(fd,
+ "\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
+ ts->total.proto_in.pc_packets,
+ ts->total.proto_in.pc_bytes,
+ ts->total.proto_out.pc_packets,
+ ts->total.proto_out.pc_bytes);
+ fprintf(fd, "IP: \t%llu packets, %llu bytes\n",
+ ts->ipv4.proto_total.pc_packets,
+ ts->ipv4.proto_total.pc_bytes);
+ fprintf(fd,
+ "\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
+ ts->ipv4.proto_in.pc_packets,
+ ts->ipv4.proto_in.pc_bytes,
+ ts->ipv4.proto_out.pc_packets,
+ ts->ipv4.proto_out.pc_bytes);
+ fprintf(fd, "TCP: %llu packets, %llu bytes\n",
+ ts->tcp.proto_total.pc_packets,
+ ts->tcp.proto_total.pc_bytes);
+ fprintf(fd,
+ "\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
+ ts->tcp.proto_in.pc_packets,
+ ts->tcp.proto_in.pc_bytes,
+ ts->tcp.proto_out.pc_packets,
+ ts->tcp.proto_out.pc_bytes);
+ fprintf(fd, "UDP: %llu packets, %llu bytes\n",
+ ts->udp.proto_total.pc_packets,
+ ts->udp.proto_total.pc_bytes);
+ fprintf(fd,
+ "\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
+ ts->udp.proto_in.pc_packets,
+ ts->udp.proto_in.pc_bytes,
+ ts->udp.proto_out.pc_packets,
+ ts->udp.proto_out.pc_bytes);
+ fprintf(fd, "ICMP: %llu packets, %llu bytes\n",
+ ts->icmp.proto_total.pc_packets,
+ ts->icmp.proto_total.pc_bytes);
+ fprintf(fd,
+ "\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
+ ts->icmp.proto_in.pc_packets,
+ ts->icmp.proto_in.pc_bytes,
+ ts->icmp.proto_out.pc_packets,
+ ts->icmp.proto_out.pc_bytes);
+ fprintf(fd, "Other IP: %llu packets, %llu bytes\n",
+ ts->other.proto_total.pc_packets,
+ ts->other.proto_total.pc_bytes);
+ fprintf(fd,
+ "\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
+ ts->other.proto_in.pc_packets,
+ ts->other.proto_in.pc_bytes,
+ ts->other.proto_out.pc_packets,
+ ts->other.proto_out.pc_bytes);
+ fprintf(fd, "Non-IP: %llu packets, %llu bytes\n",
+ ts->nonip.proto_total.pc_packets,
+ ts->nonip.proto_total.pc_bytes);
+ fprintf(fd,
+ "\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
+ ts->nonip.proto_in.pc_packets,
+ ts->nonip.proto_in.pc_bytes,
+ ts->nonip.proto_out.pc_packets,
+ ts->nonip.proto_out.pc_bytes);
+ fprintf(fd, "Broadcast: %llu packets, %llu bytes\n",
+ ts->bcast.pc_packets,
+ ts->bcast.pc_bytes);
+
+ if (nsecs > 5) {
+ fprintf(fd, "\nAverage rates:\n");
+
+ if (unit == KBITS) {
+ fprintf(fd, " Total:\t%.2f kbits/s, %.2f packets/s\n",
+ ((float) (ts->total.proto_total.pc_bytes * 8 / 1000) /
+ (float) nsecs),
+ ((float) (ts->total.proto_total.pc_packets) / (float) nsecs));
+ fprintf(fd,
+ " Incoming:\t%.2f kbits/s, %.2f packets/s\n",
+ (float) (ts->total.proto_in.pc_bytes * 8 / 1000) /
+ (float) (nsecs),
+ (float) (ts->total.proto_in.pc_packets) / (float) (nsecs));
+ fprintf(fd,
+ " Outgoing:\t%.2f kbits/s, %.2f packets/s\n",
+ (float) (ts->total.proto_out.pc_bytes * 8 / 1000) /
+ (float) (nsecs),
+ (float) (ts->total.proto_out.pc_packets) / (float) (nsecs));
+ } else {
+ fprintf(fd, "%.2f kbytes/s, %.2f packets/s\n",
+ ((float) (ts->total.proto_total.pc_bytes / 1024) /
+ (float) nsecs),
+ ((float) (ts->total.proto_total.pc_packets) / (float) nsecs));
+ fprintf(fd,
+ "Incoming:\t%.2f kbytes/s, %.2f packets/s\n",
+ (float) (ts->total.proto_in.pc_bytes / 1024) /
+ (float) (nsecs),
+ (float) (ts->total.proto_in.pc_packets) / (float) (nsecs));
+ fprintf(fd,
+ "Outgoing:\t%.2f kbytes/s, %.2f packets/s\n",
+ (float) (ts->total.proto_out.pc_bytes / 1024) /
+ (float) (nsecs),
+ (float) (ts->total.proto_out.pc_packets) / (float) (nsecs));
+
+ }
+ fprintf(fd,
+ "\nPeak total activity: %.2f %s, %.2f packets/s\n",
+ peakactivity, dispmode(unit), peakpps);
+ fprintf(fd, "Peak incoming rate: %.2f %s, %.2f packets/s\n",
+ peakactivity_in, dispmode(unit), peakpps_in);
+ fprintf(fd, "Peak outgoing rate: %.2f %s, %.2f packets/s\n\n",
+ peakactivity_out, dispmode(unit), peakpps_out);
+ }
+ fprintf(fd, "IP checksum errors: %llu\n\n", ts->bad.pc_packets);
+ fprintf(fd, "Running time: %lu seconds\n", nsecs);
+ fflush(fd);
+}
+
static void printdetlabels(WINDOW * win)
{
wattrset(win, BOXATTR);
diff --git a/src/log.c b/src/log.c
index 3a2061e..7b87501 100644
--- a/src/log.c
+++ b/src/log.c
@@ -30,10 +30,10 @@ details.
#include "serv.h"
#include "pktsize.h"
#include "hostmon.h"
+#include "log.h"
#define MSGSTRING_MAX 240
#define TARGET_LOGNAME_MAX 160
-#define TIME_TARGET_MAX 30
int rotate_flag;
char target_logname[TARGET_LOGNAME_MAX];
@@ -279,134 +279,6 @@ void writegstatlog(struct iftab *table, int unit, unsigned long
nsecs,
fflush(fd);
}
-void writedstatlog(char *ifname, int unit,
- float peakactivity, float peakpps, float peakactivity_in,
- float peakpps_in, float peakactivity_out, float peakpps_out,
- struct ifcounts *ts, unsigned long nsecs, FILE * fd)
-{
- char atime[TIME_TARGET_MAX];
-
- genatime(time((time_t *) NULL), atime);
-
- fprintf(fd,
- "\n*** Detailed statistics for interface %s, generated %s\n\n",
- ifname, atime);
-
- fprintf(fd, "Total: \t%llu packets, %llu bytes\n",
- ts->total.proto_total.pc_packets,
- ts->total.proto_total.pc_bytes);
- fprintf(fd,
- "\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
- ts->total.proto_in.pc_packets,
- ts->total.proto_in.pc_bytes,
- ts->total.proto_out.pc_packets,
- ts->total.proto_out.pc_bytes);
- fprintf(fd, "IP: \t%llu packets, %llu bytes\n",
- ts->ipv4.proto_total.pc_packets,
- ts->ipv4.proto_total.pc_bytes);
- fprintf(fd,
- "\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
- ts->ipv4.proto_in.pc_packets,
- ts->ipv4.proto_in.pc_bytes,
- ts->ipv4.proto_out.pc_packets,
- ts->ipv4.proto_out.pc_bytes);
- fprintf(fd, "TCP: %llu packets, %llu bytes\n",
- ts->tcp.proto_total.pc_packets,
- ts->tcp.proto_total.pc_bytes);
- fprintf(fd,
- "\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
- ts->tcp.proto_in.pc_packets,
- ts->tcp.proto_in.pc_bytes,
- ts->tcp.proto_out.pc_packets,
- ts->tcp.proto_out.pc_bytes);
- fprintf(fd, "UDP: %llu packets, %llu bytes\n",
- ts->udp.proto_total.pc_packets,
- ts->udp.proto_total.pc_bytes);
- fprintf(fd,
- "\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
- ts->udp.proto_in.pc_packets,
- ts->udp.proto_in.pc_bytes,
- ts->udp.proto_out.pc_packets,
- ts->udp.proto_out.pc_bytes);
- fprintf(fd, "ICMP: %llu packets, %llu bytes\n",
- ts->icmp.proto_total.pc_packets,
- ts->icmp.proto_total.pc_bytes);
- fprintf(fd,
- "\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
- ts->icmp.proto_in.pc_packets,
- ts->icmp.proto_in.pc_bytes,
- ts->icmp.proto_out.pc_packets,
- ts->icmp.proto_out.pc_bytes);
- fprintf(fd, "Other IP: %llu packets, %llu bytes\n",
- ts->other.proto_total.pc_packets,
- ts->other.proto_total.pc_bytes);
- fprintf(fd,
- "\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
- ts->other.proto_in.pc_packets,
- ts->other.proto_in.pc_bytes,
- ts->other.proto_out.pc_packets,
- ts->other.proto_out.pc_bytes);
- fprintf(fd, "Non-IP: %llu packets, %llu bytes\n",
- ts->nonip.proto_total.pc_packets,
- ts->nonip.proto_total.pc_bytes);
- fprintf(fd,
- "\t(incoming: %llu packets, %llu bytes; outgoing: %llu packets, %llu
bytes)\n",
- ts->nonip.proto_in.pc_packets,
- ts->nonip.proto_in.pc_bytes,
- ts->nonip.proto_out.pc_packets,
- ts->nonip.proto_out.pc_bytes);
- fprintf(fd, "Broadcast: %llu packets, %llu bytes\n",
- ts->bcast.pc_packets,
- ts->bcast.pc_bytes);
-
- if (nsecs > 5) {
- fprintf(fd, "\nAverage rates:\n");
-
- if (unit == KBITS) {
- fprintf(fd, " Total:\t%.2f kbits/s, %.2f packets/s\n",
- ((float) (ts->total.proto_total.pc_bytes * 8 / 1000) /
- (float) nsecs),
- ((float) (ts->total.proto_total.pc_packets) / (float) nsecs));
- fprintf(fd,
- " Incoming:\t%.2f kbits/s, %.2f packets/s\n",
- (float) (ts->total.proto_in.pc_bytes * 8 / 1000) /
- (float) (nsecs),
- (float) (ts->total.proto_in.pc_packets) / (float) (nsecs));
- fprintf(fd,
- " Outgoing:\t%.2f kbits/s, %.2f packets/s\n",
- (float) (ts->total.proto_out.pc_bytes * 8 / 1000) /
- (float) (nsecs),
- (float) (ts->total.proto_out.pc_packets) / (float) (nsecs));
- } else {
- fprintf(fd, "%.2f kbytes/s, %.2f packets/s\n",
- ((float) (ts->total.proto_total.pc_bytes / 1024) /
- (float) nsecs),
- ((float) (ts->total.proto_total.pc_packets) / (float) nsecs));
- fprintf(fd,
- "Incoming:\t%.2f kbytes/s, %.2f packets/s\n",
- (float) (ts->total.proto_in.pc_bytes / 1024) /
- (float) (nsecs),
- (float) (ts->total.proto_in.pc_packets) / (float) (nsecs));
- fprintf(fd,
- "Outgoing:\t%.2f kbytes/s, %.2f packets/s\n",
- (float) (ts->total.proto_out.pc_bytes / 1024) /
- (float) (nsecs),
- (float) (ts->total.proto_out.pc_packets) / (float) (nsecs));
-
- }
- fprintf(fd,
- "\nPeak total activity: %.2f %s, %.2f packets/s\n",
- peakactivity, dispmode(unit), peakpps);
- fprintf(fd, "Peak incoming rate: %.2f %s, %.2f packets/s\n",
- peakactivity_in, dispmode(unit), peakpps_in);
- fprintf(fd, "Peak outgoing rate: %.2f %s, %.2f packets/s\n\n",
- peakactivity_out, dispmode(unit), peakpps_out);
- }
- fprintf(fd, "IP checksum errors: %llu\n\n", ts->bad.pc_packets);
- fprintf(fd, "Running time: %lu seconds\n", nsecs);
- fflush(fd);
-}
-
void writeutslog(struct portlistent *list, unsigned long nsecs, int units,
FILE * fd)
{
diff --git a/src/log.h b/src/log.h
index 222d892..a899f76 100644
--- a/src/log.h
+++ b/src/log.h
@@ -9,10 +9,13 @@ Copyright (c) Gerard Paul Java 1997
***/
+#define TIME_TARGET_MAX 30
+
char *gen_instance_logname(char *template, int instance_id);
void input_logfile(char *target, int *aborted);
void opentlog(FILE ** fd, char *logfilename);
void writelog(int logging, FILE * fd, char *msg);
+void genatime(time_t now, char *atime);
void write_daemon_err(char *msg, va_list vararg);
void rotate_logfile(FILE ** fd, char *name);
void check_rotate_flag(FILE ** fd, int logging);
--
1.7.8.4