Created
July 28, 2017 18:33
-
-
Save alisdair/ebccae88ae0eccd957c0c321639f2e2b to your computer and use it in GitHub Desktop.
It's a statsd! Kind of!
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
#!/usr/bin/env ruby | |
require 'socket' | |
require 'optparse' | |
port = 8125 | |
pattern = /./ | |
OptionParser.new do |opts| | |
opts.banner = "Usage: #{File.basename(__FILE__)} [options]" | |
opts.on("-p", "--port=PORT", Integer) { |val| port = val } | |
opts.on("-m", "--match=REGEX", String) { |val| pattern = /#{val}/ } | |
opts.parse! | |
end | |
u = UDPSocket.new | |
u.bind(nil, port) | |
puts "Listening on #{port} for datagrams matching #{pattern.inspect}…" | |
while true | |
text, sender = u.recvfrom(65535) | |
puts "#{Time.now}: #{text}" if text =~ pattern | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment