]>
git.proxmox.com Git - pve-manager.git/blob - PVE/Status/Graphite.pm
1 package PVE
::Status
::Graphite
;
5 use PVE
::Status
::Plugin
;
7 # example config (/etc/pve/status.cfg)
11 # path proxmox.mycluster
15 use base
('PVE::Status::Plugin');
24 type
=> 'string', format
=> 'graphite-path',
25 description
=> "root graphite path (ex: proxmox.mycluster.mykey)",
33 port
=> { optional
=> 1 },
34 path
=> { optional
=> 1 },
35 disable
=> { optional
=> 1 },
39 # we do not want boolean/state information to export to graphite
47 # Plugin implementation
48 sub update_node_status
{
49 my ($class, $plugin_config, $node, $data, $ctime) = @_;
51 write_graphite_hash
($plugin_config, $data, $ctime, "nodes.$node");
55 sub update_qemu_status
{
56 my ($class, $plugin_config, $vmid, $data, $ctime, $nodename) = @_;
57 write_graphite_hash
($plugin_config, $data, $ctime, "qemu.$vmid");
60 sub update_lxc_status
{
61 my ($class, $plugin_config, $vmid, $data, $ctime, $nodename) = @_;
63 write_graphite_hash
($plugin_config, $data, $ctime, "lxc.$vmid");
66 sub update_storage_status
{
67 my ($class, $plugin_config, $nodename, $storeid, $data, $ctime) = @_;
69 write_graphite_hash
($plugin_config, $data, $ctime, "storages.$nodename.$storeid");
72 sub write_graphite_hash
{
73 my ($plugin_config, $d, $ctime, $object) = @_;
75 my $host = $plugin_config->{server
};
76 my $port = $plugin_config->{port
} ?
$plugin_config->{port
} : 2003;
77 my $path = $plugin_config->{path
} ?
$plugin_config->{path
} : 'proxmox';
79 my $carbon_socket = IO
::Socket
::IP-
>new(
83 ) || die "couldn't create carbon socket [$host]:$port - $@\n";
85 write_graphite
($carbon_socket, $d, $ctime, $path.".$object");
87 $carbon_socket->close() if $carbon_socket;
92 my ($carbon_socket, $d, $ctime, $path) = @_;
94 for my $key (keys %$d) {
96 my $value = $d->{$key};
101 if ( defined $value ) {
102 if ( ref $value eq 'HASH' ) {
103 write_graphite
($carbon_socket, $value, $ctime, $path);
104 } elsif ($value =~ m/^[+-]?[0-9]*\.?[0-9]+$/ &&
105 !$key_blacklist->{$key}) {
106 $carbon_socket->send( "$path $value $ctime\n" );
108 # do not send blacklisted or non-numeric values
115 PVE
::JSONSchema
::register_format
('graphite-path', \
&pve_verify_graphite_path
);
116 sub pve_verify_graphite_path
{
117 my ($path, $noerr) = @_;
119 my $regex = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
121 if ($path !~ /^(${regex}\.)*${regex}$/) {
122 return undef if $noerr;
123 die "value does not look like a valid graphite path\n";