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

StatsD Monitoring

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.
This commit is contained in:
Nicolas Viennot 2013-06-14 15:54:34 -04:00
parent 12d02afd1b
commit 7f2759484a
6 changed files with 52 additions and 2 deletions

1
monitor/.ruby-gemset Normal file
View File

@ -0,0 +1 @@
tmate

1
monitor/.ruby-version Normal file
View File

@ -0,0 +1 @@
ruby-1.9.3-p327

3
monitor/Gemfile Normal file
View File

@ -0,0 +1,3 @@
source 'https://rubygems.org/'
gem 'statsd-instrument'

10
monitor/Gemfile.lock Normal file
View File

@ -0,0 +1,10 @@
GEM
remote: https://rubygems.org/
specs:
statsd-instrument (1.5.0)
PLATFORMS
ruby
DEPENDENCIES
statsd-instrument

35
monitor/monitor.rb Executable file
View File

@ -0,0 +1,35 @@
#!/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'
loop do
server_count = 0
client_count = 0
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'
end
end
StatsD.gauge('tmate.server_count', server_count)
StatsD.gauge('tmate.client_count', client_count)
sleep 10
end

View File

@ -83,8 +83,8 @@ static void set_session_token(struct tmate_ssh_client *client,
memset(cmdline, 0, cmdline_end - cmdline);
sprintf(cmdline, "tmate-slave [%s] %s %s",
tmate_session_token,
client->ip_address,
client->role == TMATE_ROLE_SERVER ? "(server)" : "");
client->role == TMATE_ROLE_SERVER ? "(server)" : "(client)",
client->ip_address);
}
static char tmate_token_digits[] = "abcdefghijklmnopqrstuvwxyz"