Skip to content

Instantly share code, notes, and snippets.

@tiagoamaro
Last active May 5, 2020 13:40
Show Gist options
  • Save tiagoamaro/5ef57d68c4b05050d915f28acecc1bc4 to your computer and use it in GitHub Desktop.
Save tiagoamaro/5ef57d68c4b05050d915f28acecc1bc4 to your computer and use it in GitHub Desktop.
Statsd to STDOUT (Ruby and Python)
# -*- coding: utf-8 -*-
# Source: https://gist.github.com/wilspi/f68545494eafd57b7a8229ba3359c389
# Script to run UDP Server on 127.0.0.1:8126
# This mocks statsd server for testing
import socket
UDP_IP_ADDRESS = "127.0.0.1"
UDP_PORT_NO = 8126
serverSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
serverSock.bind((UDP_IP_ADDRESS, UDP_PORT_NO))
while True:
data, addr = serverSock.recvfrom(1024)
print "Message: ", data
# Derived from https://github.com/yob/puma-plugin-statsd/blob/master/devtools/statsd-to-stdout.rb
require "socket"
$stdout.puts "Starting Statsd to STDOUT"
host = ENV["STATSD_HOST"] || "127.0.0.1"
port = ENV["STATSD_PORT"] || "8126"
server = UDPSocket.new
server.bind(host, port)
while true
text, sender = server.recvfrom(64)
remote_host = sender[3]
$stdout.puts "#{remote_host}:" + text
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment