[pve-devel] [PATCH manager] add graphite tcp support
Martin Verges
martin.verges at croit.io
Tue Nov 5 17:40:45 CET 2019
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.verges at croit.io>
---
PVE/Status/Graphite.pm | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/PVE/Status/Graphite.pm b/PVE/Status/Graphite.pm
index d0e1563d..88eaa000 100644
--- a/PVE/Status/Graphite.pm
+++ b/PVE/Status/Graphite.pm
@@ -9,6 +9,7 @@ use PVE::Status::Plugin;
#graphite:
# server test
# port 2003
+# proto udp
# path proxmox.mycluster
# disable 0
#
@@ -25,6 +26,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 +44,8 @@ sub options {
return {
server => {},
port => { optional => 1 },
+ proto => { optional => 1 },
+ timeout => { optional => 1 },
path => { optional => 1 },
disable => { optional => 1 },
};
@@ -76,13 +90,18 @@ 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";
+ $socket->read_timeout($timeout);
+
write_graphite($carbon_socket, $d, $ctime, $path.".$object");
$carbon_socket->close() if $carbon_socket;
--
2.20.1
More information about the pve-devel
mailing list