mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 22:58:20 +00:00
add bytes recvd to Stats and stats.bro
use libpcap packet hdr.len to count bytes
This commit is contained in:
parent
4c2e5fc8b2
commit
3877b3e34b
5 changed files with 20 additions and 4 deletions
|
@ -440,6 +440,7 @@ type NetStats: record {
|
||||||
## packet capture system, this value may not be available and will then
|
## packet capture system, this value may not be available and will then
|
||||||
## be always set to zero.
|
## be always set to zero.
|
||||||
pkts_link: count &default=0;
|
pkts_link: count &default=0;
|
||||||
|
bytes_recvd: count &default=0; ##< Bytes received by Bro.
|
||||||
};
|
};
|
||||||
|
|
||||||
## Statistics about Bro's resource consumption.
|
## Statistics about Bro's resource consumption.
|
||||||
|
|
|
@ -39,6 +39,9 @@ export {
|
||||||
## Number of packets seen on the link since the last stats
|
## Number of packets seen on the link since the last stats
|
||||||
## interval if reading live traffic.
|
## interval if reading live traffic.
|
||||||
pkts_link: count &log &optional;
|
pkts_link: count &log &optional;
|
||||||
|
## Number of bytes received since the last stats interval if
|
||||||
|
## reading live traffic.
|
||||||
|
bytes_recv: count &log &optional;
|
||||||
};
|
};
|
||||||
|
|
||||||
## Event to catch stats as they are written to the logging stream.
|
## Event to catch stats as they are written to the logging stream.
|
||||||
|
@ -74,6 +77,7 @@ event check_stats(last_ts: time, last_ns: NetStats, last_res: bro_resources)
|
||||||
info$pkts_recv = ns$pkts_recvd - last_ns$pkts_recvd;
|
info$pkts_recv = ns$pkts_recvd - last_ns$pkts_recvd;
|
||||||
info$pkts_dropped = ns$pkts_dropped - last_ns$pkts_dropped;
|
info$pkts_dropped = ns$pkts_dropped - last_ns$pkts_dropped;
|
||||||
info$pkts_link = ns$pkts_link - last_ns$pkts_link;
|
info$pkts_link = ns$pkts_link - last_ns$pkts_link;
|
||||||
|
info$bytes_recv = ns$bytes_recvd - last_ns$bytes_recvd;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::write(Stats::LOG, info);
|
Log::write(Stats::LOG, info);
|
||||||
|
|
|
@ -1675,6 +1675,7 @@ function net_stats%(%): NetStats
|
||||||
unsigned int recv = 0;
|
unsigned int recv = 0;
|
||||||
unsigned int drop = 0;
|
unsigned int drop = 0;
|
||||||
unsigned int link = 0;
|
unsigned int link = 0;
|
||||||
|
uint64 bytes = 0;
|
||||||
|
|
||||||
const iosource::Manager::PktSrcList& pkt_srcs(iosource_mgr->GetPktSrcs());
|
const iosource::Manager::PktSrcList& pkt_srcs(iosource_mgr->GetPktSrcs());
|
||||||
|
|
||||||
|
@ -1688,12 +1689,14 @@ function net_stats%(%): NetStats
|
||||||
recv += stat.received;
|
recv += stat.received;
|
||||||
drop += stat.dropped;
|
drop += stat.dropped;
|
||||||
link += stat.link;
|
link += stat.link;
|
||||||
|
bytes += stat.bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
RecordVal* ns = new RecordVal(net_stats);
|
RecordVal* ns = new RecordVal(net_stats);
|
||||||
ns->Assign(0, new Val(recv, TYPE_COUNT));
|
ns->Assign(0, new Val(recv, TYPE_COUNT));
|
||||||
ns->Assign(1, new Val(drop, TYPE_COUNT));
|
ns->Assign(1, new Val(drop, TYPE_COUNT));
|
||||||
ns->Assign(2, new Val(link, TYPE_COUNT));
|
ns->Assign(2, new Val(link, TYPE_COUNT));
|
||||||
|
ns->Assign(3, new Val(bytes, TYPE_COUNT));
|
||||||
|
|
||||||
return ns;
|
return ns;
|
||||||
%}
|
%}
|
||||||
|
|
|
@ -38,7 +38,12 @@ public:
|
||||||
*/
|
*/
|
||||||
unsigned int link;
|
unsigned int link;
|
||||||
|
|
||||||
Stats() { received = dropped = link = 0; }
|
/**
|
||||||
|
* Bytes received by source after filtering (w/o drops).
|
||||||
|
*/
|
||||||
|
uint64 bytes;
|
||||||
|
|
||||||
|
Stats() { received = dropped = link = bytes = 0; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -180,6 +180,7 @@ bool PcapSource::ExtractNextPacket(Packet* pkt)
|
||||||
last_hdr = current_hdr;
|
last_hdr = current_hdr;
|
||||||
last_data = data;
|
last_data = data;
|
||||||
++stats.received;
|
++stats.received;
|
||||||
|
stats.bytes += current_hdr.len;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +220,7 @@ bool PcapSource::SetFilter(int index)
|
||||||
|
|
||||||
#ifndef HAVE_LINUX
|
#ifndef HAVE_LINUX
|
||||||
// Linux doesn't clear counters when resetting filter.
|
// Linux doesn't clear counters when resetting filter.
|
||||||
stats.received = stats.dropped = stats.link = 0;
|
stats.received = stats.dropped = stats.link = stats.bytes = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -230,7 +231,7 @@ void PcapSource::Statistics(Stats* s)
|
||||||
char errbuf[PCAP_ERRBUF_SIZE];
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
|
||||||
if ( ! (props.is_live && pd) )
|
if ( ! (props.is_live && pd) )
|
||||||
s->received = s->dropped = s->link = 0;
|
s->received = s->dropped = s->link = s->bytes = 0;
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -238,7 +239,7 @@ void PcapSource::Statistics(Stats* s)
|
||||||
if ( pcap_stats(pd, &pstat) < 0 )
|
if ( pcap_stats(pd, &pstat) < 0 )
|
||||||
{
|
{
|
||||||
PcapError();
|
PcapError();
|
||||||
s->received = s->dropped = s->link = 0;
|
s->received = s->dropped = s->link = s->bytes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
|
@ -250,6 +251,8 @@ void PcapSource::Statistics(Stats* s)
|
||||||
|
|
||||||
s->received = stats.received;
|
s->received = stats.received;
|
||||||
|
|
||||||
|
s->bytes = stats.bytes;
|
||||||
|
|
||||||
if ( ! props.is_live )
|
if ( ! props.is_live )
|
||||||
s->dropped = 0;
|
s->dropped = 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue