This change allows sending statistics to graphite over TCP. So far only UDP is possible, which is not available in some environments, like behind a loadbalancer.
Configuration example: ~ $ cat /etc/pve/status.cfg graphite: server 10.20.30.40 port 2003 path proxmox proto tcp timeout 3 Signed-off-by: Martin Verges <martin.ver...@croit.io> --- PVE/Status/Graphite.pm | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/PVE/Status/Graphite.pm b/PVE/Status/Graphite.pm index d0e1563d..4b224360 100644 --- a/PVE/Status/Graphite.pm +++ b/PVE/Status/Graphite.pm @@ -4,11 +4,13 @@ use strict; use warnings; use PVE::Status::Plugin; +use IO::Socket::Timeout; # example config (/etc/pve/status.cfg) #graphite: # server test # port 2003 +# proto udp # path proxmox.mycluster # disable 0 # @@ -25,6 +27,17 @@ sub properties { type => 'string', format => 'graphite-path', description => "root graphite path (ex: proxmox.mycluster.mykey)", }, + timeout => { + type => 'integer', + description => "graphite tcp socket timeout (default=3)", + optional => 1 + }, + proto => { + type => 'string', + enum => ['udp', 'tcp'], + description => "send graphite data using tcp or udp (default)", + optional => 1, + }, }; } @@ -32,6 +45,8 @@ sub options { return { server => {}, port => { optional => 1 }, + proto => { optional => 1 }, + timeout => { optional => 1 }, path => { optional => 1 }, disable => { optional => 1 }, }; @@ -76,13 +91,21 @@ sub write_graphite_hash { my $host = $plugin_config->{server}; my $port = $plugin_config->{port} ? $plugin_config->{port} : 2003; my $path = $plugin_config->{path} ? $plugin_config->{path} : 'proxmox'; + my $proto = $plugin_config->{proto} ? $plugin_config->{proto} : 'udp'; + my $timeout = $plugin_config->{timeout} ? $plugin_config->{timeout} : 3; my $carbon_socket = IO::Socket::IP->new( PeerAddr => $host, PeerPort => $port, - Proto => 'udp', + Proto => $proto, + Timeout => $timeout, ) || die "couldn't create carbon socket [$host]:$port - $@\n"; + if ( $proto eq 'tcp' ) { + IO::Socket::Timeout->enable_timeouts_on($carbon_socket); + $carbon_socket->read_timeout($timeout); + $carbon_socket->write_timeout($timeout); + } write_graphite($carbon_socket, $d, $ctime, $path.".$object"); $carbon_socket->close() if $carbon_socket; -- 2.20.1 _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel