Skip to content

Commit 881fc35

Browse files
committed
for cisagov#703, record stats for network interfaces periodically
1 parent f0335d2 commit 881fc35

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

config/pcap-capture.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ PCAP_ROTATE_MEGABYTES=4096
2020
# will be closed for processing and a new PCAP file created
2121
PCAP_ROTATE_MINUTES=10
2222
# Specifies a tcpdump-style filter expression for local packet capture ('' to capture all traffic)
23-
PCAP_FILTER=
23+
PCAP_FILTER=
24+
# Get OS-level stats for network interfaces periodically (leave blank to disable)
25+
PCAP_IFACE_STATS_CRON_EXPRESSION=

dashboards/dashboards/beats/Metricbeat-system-overview.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
"attributes": {
109109
"description": "",
110110
"kibanaSavedObjectMeta": {
111-
"searchSourceJSON": "{\"query\":{\"query\":\"miscbeat.mem:* OR miscbeat.cpu:*\",\"language\":\"kuery\"},\"filter\":[],\"indexRefName\":\"kibanaSavedObjectMeta.searchSourceJSON.index\"}"
111+
"searchSourceJSON": "{\"query\":{\"query\":\"miscbeat.mem:* OR miscbeat.cpu:* OR miscbeat.network:*\",\"language\":\"kuery\"},\"filter\":[],\"indexRefName\":\"kibanaSavedObjectMeta.searchSourceJSON.index\"}"
112112
},
113113
"title": "Number of hosts",
114114
"uiStateJSON": "{\"vis\":{\"defaultColors\":{\"0 - 100\":\"rgb(0,104,55)\"}}}",

docs/malcolm-config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Although the configuration script automates many of the following configuration
129129
- `PCAP_IFACE_TWEAK` - if set to `true`, Malcolm will [use `ethtool`]({{ site.github.repository_url }}/blob/{{ site.github.build_revision }}/shared/bin/nic-capture-setup.sh) to disable NIC hardware offloading features and adjust ring buffer sizes for capture interface(s); this should be `true` if the interface(s) are being used for capture only, `false` if they are being used for management/communication
130130
- `PCAP_ROTATE_MEGABYTES` – used to specify how large a locally captured PCAP file can become (in megabytes) before it is closed for processing and a new PCAP file created
131131
- `PCAP_ROTATE_MINUTES` – used to specify a time interval (in minutes) after which a locally-captured PCAP file will be closed for processing and a new PCAP file created
132+
- `PCAP_IFACE_STATS_CRON_EXPRESSION` - Specifies a [cron expression](https://en.wikipedia.org/wiki/Cron#CRON_expression) (using [`cronexpr`](https://github.com/aptible/supercronic/tree/master/cronexpr#implementation)-compatible syntax) indicating the refresh interval for collecting kernel-level statistics for network interfaces. An empty value for this variable means these statistics will not be generated.
132133
* **`postgres.env`** - Settings related to the PostgreSQL relational database
133134
* **`process.env`** - settings for how the processes running inside Malcolm containers are executed
134135
- `PUID` and `PGID` - Docker runs all its containers as the privileged `root` user by default. For better security, Malcolm immediately drops to non-privileged user accounts for executing internal processes wherever possible. The `PUID` (**p**rocess **u**ser **ID**) and `PGID` (**p**rocess **g**roup **ID**) environment variables allow Malcolm to map internal non-privileged user accounts to a corresponding [user account](https://en.wikipedia.org/wiki/User_identifier) on the host. Note a few (including the `logstash` and `netbox` containers) may take a few extra minutes during startup if `PUID` and `PGID` are set to values other than the default `1000`. This is expected and should not affect operation after the initial startup.

filebeat/filebeat-logs.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,38 @@ filebeat.inputs:
129129
close_eof: ${FILEBEAT_CLOSE_EOF:true}
130130
clean_removed: ${FILEBEAT_CLEAN_REMOVED:true}
131131

132+
#-------------------------- network interface stats (as JSON) ---------------
133+
# (see netdev-json.sh)
134+
- type: log
135+
paths:
136+
- ${FILEBEAT_ZEEK_LOG_LIVE_PATH:/zeek/live}/netdev-stats*.json
137+
symlinks: true
138+
json:
139+
expand_keys: false
140+
add_error_key: false
141+
ignore_decoding_error: true
142+
keys_under_root: false
143+
target: miscbeat.network
144+
fields:
145+
miscbeat.module: network
146+
processors:
147+
- rename:
148+
fields:
149+
- from: "fields.miscbeat.module"
150+
to: "miscbeat.module"
151+
- from: "json"
152+
to: "miscbeat.network"
153+
tags: ["_malcolm_beats", "_malcolm_miscbeat"]
154+
compression_level: 0
155+
scan_frequency: ${FILEBEAT_SCAN_FREQUENCY:10s}
156+
clean_inactive: ${FILEBEAT_CLEAN_INACTIVE:180m}
157+
ignore_older: ${FILEBEAT_IGNORE_OLDER:120m}
158+
close_inactive: ${FILEBEAT_CLOSE_INACTIVE_LIVE:90m}
159+
close_renamed: true
160+
close_removed: true
161+
close_eof: true
162+
clean_removed: true
163+
132164
#================================ Outputs ======================================
133165

134166
#-------------------------- Logstash Output ------------------------------------

zeek/scripts/docker_entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,16 @@ ZEEK_DIR=${ZEEK_DIR:-"/opt/zeek"}
66
setcap 'CAP_NET_RAW+eip CAP_NET_ADMIN+eip' "${ZEEK_DIR}"/bin/zeek 2>/dev/null || true
77
setcap 'CAP_NET_RAW+eip CAP_NET_ADMIN+eip' "${ZEEK_DIR}"/bin/capstats 2>/dev/null || true
88

9+
# generate packet statistics for network interfaces periodically
10+
if [[ -d "${ZEEK_LOG_PATH}" ]] && [[ -n "${SUPERCRONIC_CRONTAB}" ]]; then
11+
12+
touch "${SUPERCRONIC_CRONTAB}" 2>/dev/null || true
13+
sed -i -e "/netdev-json\.sh/d" "${SUPERCRONIC_CRONTAB}"
14+
15+
[[ -n "${PCAP_IFACE_STATS_CRON_EXPRESSION}" ]] && \
16+
echo "${PCAP_IFACE_STATS_CRON_EXPRESSION} /usr/local/bin/netdev-json.sh >\"${ZEEK_LOG_PATH}\"/netdev-stats.json.tmp 2>/dev/null && mv -f \"${ZEEK_LOG_PATH}\"/netdev-stats.json.tmp \"${ZEEK_LOG_PATH}\"/netdev-stats.json" \
17+
>> "${SUPERCRONIC_CRONTAB}"
18+
fi
19+
920
# start supervisor (which will spawn pcap-zeek, cron, etc.) or whatever the default command is
1021
exec "$@"

0 commit comments

Comments
 (0)