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:
parent
12d02afd1b
commit
7f2759484a
1
monitor/.ruby-gemset
Normal file
1
monitor/.ruby-gemset
Normal file
@ -0,0 +1 @@
|
||||
tmate
|
1
monitor/.ruby-version
Normal file
1
monitor/.ruby-version
Normal file
@ -0,0 +1 @@
|
||||
ruby-1.9.3-p327
|
3
monitor/Gemfile
Normal file
3
monitor/Gemfile
Normal file
@ -0,0 +1,3 @@
|
||||
source 'https://rubygems.org/'
|
||||
|
||||
gem 'statsd-instrument'
|
10
monitor/Gemfile.lock
Normal file
10
monitor/Gemfile.lock
Normal 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
35
monitor/monitor.rb
Executable 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
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user