]>
git.proxmox.com Git - pve-manager.git/blob - PVE/Status/Graphite.pm
1 package PVE
::Status
::Graphite
;
7 use Socket
qw(SOL_SOCKET SO_SNDTIMEO SO_RCVTIMEO);
9 use PVE
::Status
::Plugin
;
12 # example config (/etc/pve/status.cfg)
17 # path proxmox.mycluster
21 use base
('PVE::Status::Plugin');
30 type
=> 'string', format
=> 'graphite-path',
31 description
=> "root graphite path (ex: proxmox.mycluster.mykey)",
35 description
=> "graphite tcp socket timeout (default=1)",
40 enum
=> ['udp', 'tcp'],
41 description
=> "send graphite data using tcp or udp (default)",
50 port
=> { optional
=> 1 },
51 proto
=> { optional
=> 1 },
52 timeout
=> { optional
=> 1 },
53 path
=> { optional
=> 1 },
54 disable
=> { optional
=> 1 },
58 # we do not want boolean/state information to export to graphite
66 # Plugin implementation
67 sub update_node_status
{
68 my ($class, $plugin_config, $node, $data, $ctime) = @_;
70 write_graphite_hash
($plugin_config, $data, $ctime, "nodes.$node");
74 sub update_qemu_status
{
75 my ($class, $plugin_config, $vmid, $data, $ctime, $nodename) = @_;
76 write_graphite_hash
($plugin_config, $data, $ctime, "qemu.$vmid");
79 sub update_lxc_status
{
80 my ($class, $plugin_config, $vmid, $data, $ctime, $nodename) = @_;
82 write_graphite_hash
($plugin_config, $data, $ctime, "lxc.$vmid");
85 sub update_storage_status
{
86 my ($class, $plugin_config, $nodename, $storeid, $data, $ctime) = @_;
88 write_graphite_hash
($plugin_config, $data, $ctime, "storages.$nodename.$storeid");
91 sub write_graphite_hash
{
92 my ($plugin_config, $d, $ctime, $object) = @_;
94 my $host = $plugin_config->{server
};
95 my $port = $plugin_config->{port
} || 2003;
96 my $path = $plugin_config->{path
} // 'proxmox';
97 my $proto = $plugin_config->{proto
} || 'udp';
98 my $timeout = $plugin_config->{timeout
} // 1;
100 my $carbon_socket = IO
::Socket
::IP-
>new(
105 ) || die "couldn't create carbon socket [$host]:$port - $@\n";
107 if ( $proto eq 'tcp' ) {
109 my $timeout_struct = pack( 'l!l!', $timeout, 0);
110 setsockopt($carbon_socket, SOL_SOCKET
, SO_SNDTIMEO
, $timeout_struct);
111 setsockopt($carbon_socket, SOL_SOCKET
, SO_RCVTIMEO
, $timeout_struct);
113 write_graphite
($carbon_socket, $d, $ctime, $path.".$object");
115 $carbon_socket->close() if $carbon_socket;
120 my ($carbon_socket, $d, $ctime, $path) = @_;
122 for my $key (keys %$d) {
124 my $value = $d->{$key};
129 if ( defined $value ) {
130 if ( ref $value eq 'HASH' ) {
131 write_graphite
($carbon_socket, $value, $ctime, $path);
132 } elsif ($value =~ m/^[+-]?[0-9]*\.?[0-9]+$/ &&
133 !$key_blacklist->{$key}) {
134 $carbon_socket->send( "$path $value $ctime\n" );
136 # do not send blacklisted or non-numeric values
143 PVE
::JSONSchema
::register_format
('graphite-path', \
&pve_verify_graphite_path
);
144 sub pve_verify_graphite_path
{
145 my ($path, $noerr) = @_;
147 my $regex = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
149 if ($path !~ /^(${regex}\.)*${regex}$/) {
150 return undef if $noerr;
151 die "value does not look like a valid graphite path\n";