]>
git.proxmox.com Git - pve-manager.git/blob - PVE/Status/Graphite.pm
b744968990567e3542df6609cd7b90cd85de9861
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
=> 'dns-name',
25 description
=> "server dns name",
29 description
=> "network port",
32 type
=> 'string', format
=> 'graphite-path',
33 description
=> "root graphite path (ex: proxmox.mycluster.mykey)",
41 port
=> { optional
=> 1 },
42 path
=> { optional
=> 1 },
43 disable
=> { optional
=> 1 },
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) = @_;
57 write_graphite_hash
($plugin_config, $data, $ctime, "qemu.$vmid");
60 sub update_lxc_status
{
61 my ($class, $plugin_config, $vmid, $data, $ctime) = @_;
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(
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);
105 $carbon_socket->send( "$path $value $ctime" );
112 PVE
::JSONSchema
::register_format
('graphite-path', \
&pve_verify_graphite_path
);
113 sub pve_verify_graphite_path
{
114 my ($path, $noerr) = @_;
116 my $regex = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
118 if ($path !~ /^(${regex}\.)*${regex}$/) {
119 return undef if $noerr;
120 die "value does not look like a valid graphite path\n";