1 /**
2 * @file mediator_stat.c
3 *
4 * Handles mediator/yaf stats
5 *
6 ** ------------------------------------------------------------------------
7 ** Copyright (C) 2012-2017 Carnegie Mellon University. All Rights Reserved.
8 ** ------------------------------------------------------------------------
9 * Authors: Emily Sarneso <netsa-help@cert.org>
10 * ------------------------------------------------------------------------
11 * @OPENSOURCE_HEADER_START@
12 * Use of this (and related) source code is subject to the terms
13 * of the following licenses:
14 *
15 * GNU Public License (GPL) Rights pursuant to Version 2, June 1991
16 * Government Purpose License Rights (GPLR) pursuant to DFARS 252.227.7013
17 *
18 * This material is based upon work funded and supported by
19 * the Department of Defense under Contract FA8721-05-C-0003 with
20 * Carnegie Mellon University for the operation of the Software Engineering
21 * Institue, a federally funded research and development center. Any opinions,
22 * findings and conclusions or recommendations expressed in this
23 * material are those of the author(s) and do not
24 * necessarily reflect the views of the United States
25 * Department of Defense.
26 *
27 * NO WARRANTY
28 *
29 * THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE
30 * MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY
31 * MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED
32 * AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF
33 * FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS
34 * OBTAINED FROM THE USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY
35 * DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM
36 * PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
37 *
38 * This material has been approved for public release and unlimited
39 * distribution.
40 *
41 * Carnegie Mellon®, CERT® and CERT Coordination Center® are
42 * registered marks of Carnegie Mellon University.
43 *
44 * DM-0001877
45 *
46 * Carnegie Mellon University retains
47 * copyrights in all material produced under this contract. The U.S.
48 * Government retains a non-exclusive, royalty-free license to publish or
49 * reproduce these documents, or allow others to do so, for U.S.
50 * Government purposes only pursuant to the copyright license under the
51 * contract clause at 252.227.7013.
52 *
53 * Licensee hereby agrees to defend, indemnify, and hold harmless Carnegie
54 * Mellon University, its trustees, officers, employees, and agents from
55 * all claims or demands made against them (and any related losses,
56 * expenses, or attorney's fees) arising out of, or relating to Licensee's
57 * and/or its sub licensees' negligent use or willful misuse of or
58 * negligent conduct or willful misconduct regarding the Software,
59 * facilities, or other rights or assistance granted by Carnegie Mellon
60 * University under this License, including, but not limited to, any
61 * claims of product liability, personal injury, death, damage to
62 * property, or violation of any laws or regulations.
63 *
64 * @OPENSOURCE_HEADER_END@
65 * -----------------------------------------------------------
66 */
67
68 #include <mediator/mediator_inf.h>
69 #include <mediator/mediator_core.h>
70 #include <mediator/mediator_util.h>
71 #include "mediator_stat.h"
72
73 static GTimer *md_start = NULL;
74
75 /**
76 * mdStatInit
77 *
78 *
79 *
80 */
mdStatInit()81 void mdStatInit(
82 )
83 {
84 md_start = g_timer_new();
85 g_timer_start(md_start);
86 }
87
88
89 /**
90 * mdStatGetTimer
91 *
92 *
93 */
mdStatGetTimer()94 GTimer *mdStatGetTimer()
95 {
96 return md_start;
97 }
98
99
100 /**
101 * mdLogStats
102 *
103 * Log YAF process statistics
104 *
105 */
mdLogStats(yaf_stats_option_t * stats,char * colname)106 void mdLogStats(
107 yaf_stats_option_t *stats,
108 char *colname)
109 {
110
111 char ipaddr[20];
112 time_t cur_time = time(NULL);
113 uint64_t ms = cur_time * 1000;
114 uint64_t uptime = 0;
115 uint64_t days = 0;
116 uint64_t hours = 0;
117 uint64_t mins = 0;
118
119 if (ms > stats->systemInitTimeMilliseconds) {
120 uptime = (ms - stats->systemInitTimeMilliseconds)/1000;
121 days = uptime/86400;
122 uptime -= (days * 86400);
123 hours = (uptime/3600);
124 uptime -= (hours * 3600);
125 mins = (uptime/60);
126 uptime -= (mins * 60);
127 }
128
129 md_util_print_ip4_addr(ipaddr, stats->exporterIPv4Address);
130 g_message("%s: YAF ID: %d IP: %s Uptime: %"PRIu64"d:%"PRIu64"h:%"PRIu64"m:"
131 "%"PRIu64"s", colname, stats->exportingProcessId, ipaddr,
132 days, hours, mins, uptime);
133 /*if (stats->sysInitTime) {
134 g_message("%s: YAF Uptime: %llu Days, %llu Hours, %llu Minutes, "
135 "%llu Seconds", colname, days, hours, mins, uptime);
136 }*/
137 g_message("%s: YAF Flows: %"PRIu64" Packets: %"PRIu64" Dropped: %"PRIu64
138 " Ignored: %"PRIu64" Out of Sequence: %"PRIu64" Expired Frags:"
139 " %u Assembled Frags: %u", colname,
140 stats->exportedFlowRecordTotalCount,
141 stats->packetTotalCount, stats->droppedPacketTotalCount,
142 stats->ignoredPacketTotalCount, stats->notSentPacketTotalCount,
143 stats->expiredFragmentCount, stats->assembledFragmentCount);
144
145 /*g_message("Exported Flows: %llu", stats->exportedFlowTotalCount);
146 g_message("Packets Processed: %llu", stats->packetTotalCount);
147 g_message("Dropped Packets: %llu", stats->droppedPacketTotalCount);
148 g_message("Ignored Packets: %llu", stats->ignoredPacketTotalCount);
149 g_message("Rejected Out of Sequence Packets: %llu",
150 stats->rejectedPacketTotalCount);
151 g_message("Expired Fragments: %u", stats->expiredFragmentCount);
152 g_message("Assembled Fragments: %u", stats->assembledFragmentCount);*/
153 }
154
155
156 /**
157 * mdStatUpdate
158 *
159 * Log Mediator process statistics
160 *
161 */
mdStatUpdate(md_stats_t * stats)162 void mdStatUpdate(
163 md_stats_t *stats)
164 {
165
166 uint64_t seconds = g_timer_elapsed(md_start, NULL);
167 uint64_t uptime = seconds;
168 uint64_t days, hours, mins;
169
170 days = uptime/86400;
171 uptime -= (days * 86400);
172 hours = uptime/3600;
173 uptime -= (hours * 3600);
174 mins = uptime/60;
175 uptime -= (mins * 60);
176
177 g_message("SM: Uptime: %"PRIu64"d:%"PRIu64"h:%"PRIu64"m:"
178 "%"PRIu64"s, Total Flows: %"PRIu64", Filtered: %"PRIu64", "
179 "Stats: %"PRIu64", DNS: %"PRIu64", Other: %"PRIu64", UDP-uniflows: %"PRIu64,
180 days, hours, mins, uptime, stats->recvd_flows,
181 stats->recvd_filtered, stats->recvd_stats, stats->dns,
182 stats->nonstd_flows, stats->uniflows);
183 }
184
185
mdStatDump(mdConfig_t * cfg,md_stats_t * stats)186 void mdStatDump(
187 mdConfig_t *cfg,
188 md_stats_t *stats)
189 {
190
191 mdStatUpdate(stats);
192 mdExporterUpdateStats(cfg, TRUE);
193 mdCollectorUpdateStats(cfg);
194
195 }
196