1
0
mirror of https://github.com/tmate-io/tmate-ssh-server.git synced 2020-11-18 19:53:51 -08:00
2013-06-18 05:53:37 -04:00

41 lines
879 B
Ruby
Executable File

#!/usr/bin/env ruby
# It's a bit hard to have the jailed process communicate with the parent.
# This is a workaround and is really gross. Please forgive me.
require 'rubygems'
require 'bundler'
Bundler.require
require 'logger'
StatsD.server = 'monitor:8125'
StatsD.logger = Logger.new(STDERR)
StatsD.mode = 'production'
hostname = Socket.gethostname
loop do
server_count = 0
client_count = 0
ips = []
Dir['/proc/*/cmdline'].map do |f|
if File.open(f).read =~ /^tmate-slave \[(.+)\] \((.+)\) (.+)$/
token = $1
role = $2
ip = $3
server_count += 1 if role == 'server'
client_count += 1 if role == 'client'
ips << ip
end
end
StatsD.gauge("tmate.#{hostname}.servers", server_count)
StatsD.gauge("tmate.#{hostname}.clients", client_count)
StatsD.gauge("tmate.#{hostname}.unique_ips", ips.uniq.count)
sleep 10
end