-
-
Save kenstir/89a5d499987bc7764465e7b0511d84b2 to your computer and use it in GitHub Desktop.
Wireshark dissector to decode statsd protocol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Usage: tshark -X lua_script:statsd_dissector.lua -r capture.pcap | |
-- Usage: tshark -X lua_script:statsd_dissector.lua -T fields -e statsd.metric_name -e statsd.value -e statsd.metric_type -r capture.pcap | |
local statsd = Proto("statsd","Statsd Protocol") | |
local pf_metric_name = ProtoField.new("Metric Name", "statsd.metric_name", ftypes.STRING) | |
local pf_value = ProtoField.new("Value", "statsd.value", ftypes.STRING) | |
local pf_metric_type = ProtoField.new("Metric Type", "statsd.metric_type", ftypes.STRING) | |
statsd.fields = { pf_metric_name, pf_value, pf_metric_type } | |
function statsd.dissector(tvbuf,pktinfo,root) | |
local pktlen = tvbuf:reported_length_remaining() | |
local tvbr = tvbuf:range(0,pktlen) | |
-- <metric name>:<value>|<metric type>[|@<sample rate>] | |
local payload = tvbr:string() | |
local a, b, metric_name, value, metric_type = string.find(payload, "^([^:]+):([^|]+)|([^|]+)") | |
if a then | |
pktinfo.cols.protocol:set("Statsd") | |
pktinfo.cols.info:set(payload) | |
local pos = 0 | |
local tree = root:add(statsd, tvbr) | |
tree:add(pf_metric_name, tvbuf:range(pos, metric_name:len()), metric_name) | |
pos = pos + metric_name:len() + 1 | |
tree:add(pf_value, tvbuf:range(pos, value:len()), value) | |
pos = pos + value:len() + 1 | |
tree:add(pf_metric_type, tvbuf:range(pos, metric_type:len()), metric_type) | |
pos = pos + metric_type:len() | |
end | |
end | |
DissectorTable.get("udp.port"):add(8125, statsd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment