Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions cloud-init.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,33 @@ tx_delta=\$((tx_now - tx_start))
function send_metrics() {
metrics="github.actions.\$1:\$${2:-1}|\$${3:-c}|#runner_group:${RUNNERGROUP}"
metrics=\$metrics,#repo:\$GITHUB_REPOSITORY,#workflow:\$GITHUB_WORKFLOW,#job:\$GITHUB_JOB,#arch:$ARCH
[[ -n "\$4" ]] && metrics="\$metrics,\$4"
echo "Send metrics \$metrics to $dd_host"
echo -n "\$metrics" > /dev/udp/$dd_host/8125
}
send_metrics jobs.repo
send_metrics jobs.duration \$job_duration_ms "ms|@1"
send_metrics jobs.network.rx_bytes \$rx_delta
send_metrics jobs.network.tx_bytes \$tx_delta

if systemctl is-active --quiet zeek-capture 2>/dev/null; then
sudo systemctl stop zeek-capture
sleep 1
fi

if [[ -f /tmp/zeek/conn.log ]]; then
jq -s -r '
(.[0] // []) as \$conns |
(.[1] // []) as \$ssls |
(\$ssls | map({(.uid): .server_name}) | add // {}) as \$sni |
\$conns
# ssl.log / dns.log may be absent if no TLS/DNS was seen; tolerate that.
[[ -f /tmp/zeek/ssl.log ]] || : > /tmp/zeek/ssl.log
[[ -f /tmp/zeek/dns.log ]] || : > /tmp/zeek/dns.log
jq -s -r \
--slurpfile ssls /tmp/zeek/ssl.log \
--slurpfile dns /tmp/zeek/dns.log '
# uid -> SNI (from the TLS ClientHello)
(\$ssls | map(select(.server_name != null) | {(.uid): .server_name}) | add // {}) as \$sni
# answer IP -> queried domain (protocol-independent fallback for non-TLS)
| (\$dns
| map(select(.answers != null) | .query as \$q | .answers[] | {(tostring): \$q})
| add // {}) as \$ip2name
| map({
domain: (\$sni[.uid] // .["id.resp_h"]),
domain: (\$sni[.uid] // \$ip2name[.["id.resp_h"]] // .["id.resp_h"]),
tx_bytes: (.orig_ip_bytes // 0),
rx_bytes: (.resp_ip_bytes // 0)
})
Expand All @@ -204,11 +210,11 @@ if [[ -f /tmp/zeek/conn.log ]]; then
})
| .[]
| "\(.domain) \(.tx_bytes) \(.rx_bytes)"
' /tmp/zeek/conn.log /tmp/zeek/ssl.log 2>/dev/null | while read -r domain tx rx; do
' /tmp/zeek/conn.log 2>/dev/null | while read -r domain tx rx; do
[[ -z "\$domain" ]] && continue
echo "Send bandwidth counter domain=\$domain tx=\$tx rx=\$rx"
echo -n "github.actions.bandwidth.tx_bytes:\$tx|c|#domain:\$domain" > /dev/udp/$dd_host/8125
echo -n "github.actions.bandwidth.rx_bytes:\$rx|c|#domain:\$domain" > /dev/udp/$dd_host/8125
send_metrics bandwidth.tx_bytes "\$tx" c "#domain:\$domain"
send_metrics bandwidth.rx_bytes "\$rx" c "#domain:\$domain"
done
fi
EOF
Expand Down