From 5ce20c48bcab06509c06a5cb5f4aeddff45a9911 Mon Sep 17 00:00:00 2001 From: Nicolas Viennot Date: Tue, 18 Jun 2013 05:52:00 -0400 Subject: [PATCH] Dynamic hostname support --- monitor/monitor.rb | 8 +++++--- tmate-decoder.c | 9 +++++++-- tmate.h | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/monitor/monitor.rb b/monitor/monitor.rb index 8ac1a2e8..9788e118 100755 --- a/monitor/monitor.rb +++ b/monitor/monitor.rb @@ -13,6 +13,8 @@ StatsD.server = 'monitor:8125' StatsD.logger = Logger.new(STDERR) StatsD.mode = 'production' +hostname = Socket.gethostname + loop do server_count = 0 client_count = 0 @@ -30,9 +32,9 @@ loop do end end - StatsD.gauge('tmate.servers', server_count) - StatsD.gauge('tmate.clients', client_count) - StatsD.gauge('tmate.unique_ips', ips.uniq.count) + 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 diff --git a/tmate-decoder.c b/tmate-decoder.c index 5fca3722..cd4065ac 100644 --- a/tmate-decoder.c +++ b/tmate-decoder.c @@ -1,4 +1,5 @@ #include +#include #include "tmate.h" char *tmate_left_status, *tmate_right_status; @@ -97,6 +98,7 @@ static void unpack_array(struct tmate_unpacker *uk, static void tmate_header(struct tmate_unpacker *uk) { + char hostname[128]; int protocol = unpack_int(uk); if (protocol != 1) @@ -104,8 +106,11 @@ static void tmate_header(struct tmate_unpacker *uk) tmate_debug("new master, protocol version: %d", protocol); - tmate_notify("Remote session: ssh %s@%s", - tmate_session_token, TMATE_HOST); + if (gethostname(hostname, sizeof(hostname)) < 0) + tmate_fatal("cannot get hostname"); + + tmate_notify("Remote session: ssh %s@%s.%s", + tmate_session_token, hostname, TMATE_DOMAIN); } extern u_int next_window_pane_id; diff --git a/tmate.h b/tmate.h index d8d5707e..d7af83bf 100644 --- a/tmate.h +++ b/tmate.h @@ -17,7 +17,7 @@ do { \ /* tmate-encoder.c */ -#define TMATE_HOST "a.tmate.io" +#define TMATE_DOMAIN "tmate.io" enum tmate_client_commands { TMATE_NOTIFY,