]>
git.proxmox.com Git - pve-manager.git/blob - PVE/Status/Graphite.pm
1 package PVE
::Status
::Graphite
;
6 use PVE
::Status
::Plugin
;
7 use IO
::Socket
::Timeout
;
9 # example config (/etc/pve/status.cfg)
14 # path proxmox.mycluster
18 use base
('PVE::Status::Plugin');
27 type
=> 'string', format
=> 'graphite-path',
28 description
=> "root graphite path (ex: proxmox.mycluster.mykey)",
32 description
=> "graphite tcp socket timeout (default=3)",
37 enum
=> ['udp', 'tcp'],
38 description
=> "send graphite data using tcp or udp (default)",
47 port
=> { optional
=> 1 },
48 proto
=> { optional
=> 1 },
49 timeout
=> { optional
=> 1 },
50 path
=> { optional
=> 1 },
51 disable
=> { optional
=> 1 },
55 # we do not want boolean/state information to export to graphite
63 # Plugin implementation
64 sub update_node_status
{
65 my ($class, $plugin_config, $node, $data, $ctime) = @_;
67 write_graphite_hash
($plugin_config, $data, $ctime, "nodes.$node");
71 sub update_qemu_status
{
72 my ($class, $plugin_config, $vmid, $data, $ctime, $nodename) = @_;
73 write_graphite_hash
($plugin_config, $data, $ctime, "qemu.$vmid");
76 sub update_lxc_status
{
77 my ($class, $plugin_config, $vmid, $data, $ctime, $nodename) = @_;
79 write_graphite_hash
($plugin_config, $data, $ctime, "lxc.$vmid");
82 sub update_storage_status
{
83 my ($class, $plugin_config, $nodename, $storeid, $data, $ctime) = @_;
85 write_graphite_hash
($plugin_config, $data, $ctime, "storages.$nodename.$storeid");
88 sub write_graphite_hash
{
89 my ($plugin_config, $d, $ctime, $object) = @_;
91 my $host = $plugin_config->{server
};
92 my $port = $plugin_config->{port
} ?
$plugin_config->{port
} : 2003;
93 my $path = $plugin_config->{path
} ?
$plugin_config->{path
} : 'proxmox';
94 my $proto = $plugin_config->{proto
} ?
$plugin_config->{proto
} : 'udp';
95 my $timeout = $plugin_config->{timeout
} ?
$plugin_config->{timeout
} : 3;
97 my $carbon_socket = IO
::Socket
::IP-
>new(
102 ) || die "couldn't create carbon socket [$host]:$port - $@\n";
104 if ( $proto eq 'tcp' ) {
105 IO
::Socket
::Timeout-
>enable_timeouts_on($carbon_socket);
106 $carbon_socket->read_timeout($timeout);
107 $carbon_socket->write_timeout($timeout);
109 write_graphite
($carbon_socket, $d, $ctime, $path.".$object");
111 $carbon_socket->close() if $carbon_socket;
116 my ($carbon_socket, $d, $ctime, $path) = @_;
118 for my $key (keys %$d) {
120 my $value = $d->{$key};
125 if ( defined $value ) {
126 if ( ref $value eq 'HASH' ) {
127 write_graphite
($carbon_socket, $value, $ctime, $path);
128 } elsif ($value =~ m/^[+-]?[0-9]*\.?[0-9]+$/ &&
129 !$key_blacklist->{$key}) {
130 $carbon_socket->send( "$path $value $ctime\n" );
132 # do not send blacklisted or non-numeric values
139 PVE
::JSONSchema
::register_format
('graphite-path', \
&pve_verify_graphite_path
);
140 sub pve_verify_graphite_path
{
141 my ($path, $noerr) = @_;
143 my $regex = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
145 if ($path !~ /^(${regex}\.)*${regex}$/) {
146 return undef if $noerr;
147 die "value does not look like a valid graphite path\n";