]>
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)",
42 enum
=> ['udp', 'tcp'],
43 description
=> "Protocol to send graphite data. TCP or UDP (default)",
52 port
=> { optional
=> 1 },
53 mtu
=> { optional
=> 1 },
54 proto
=> { optional
=> 1 },
55 timeout
=> { optional
=> 1 },
56 path
=> { optional
=> 1 },
57 disable
=> { optional
=> 1 },
61 # Plugin implementation
62 sub update_node_status
{
63 my ($class, $txn, $node, $data, $ctime) = @_;
65 return assemble
($class, $txn, $data, $ctime, "nodes.$node");
69 sub update_qemu_status
{
70 my ($class, $txn, $vmid, $data, $ctime, $nodename) = @_;
72 return assemble
($class, $txn, $data, $ctime, "qemu.$vmid");
75 sub update_lxc_status
{
76 my ($class, $txn, $vmid, $data, $ctime, $nodename) = @_;
78 return assemble
($class, $txn, $data, $ctime, "lxc.$vmid");
81 sub update_storage_status
{
82 my ($class, $txn, $nodename, $storeid, $data, $ctime) = @_;
84 return assemble
($class, $txn, $data, $ctime, "storages.$nodename.$storeid");
87 sub _send_batch_size
{
88 my ($class, $cfg) = @_;
89 my $proto = $cfg->{proto
} || 'udp';
90 if ($proto eq 'tcp') {
93 return $class->SUPER::_send_batch_size
($cfg);
97 my ($class, $cfg) = @_;
99 my $host = $cfg->{server
};
100 my $port = $cfg->{port
} || 2003;
101 my $proto = $cfg->{proto
} || 'udp';
102 my $timeout = $cfg->{timeout
} // 1;
104 my $carbon_socket = IO
::Socket
::IP-
>new(
109 ) || die "couldn't create carbon socket [$host]:$port - $@\n";
111 if ($proto eq 'tcp') {
113 my $timeout_struct = pack( 'l!l!', $timeout, 0);
114 setsockopt($carbon_socket, SOL_SOCKET
, SO_SNDTIMEO
, $timeout_struct);
115 setsockopt($carbon_socket, SOL_SOCKET
, SO_RCVTIMEO
, $timeout_struct);
118 return $carbon_socket;
122 my ($class, $txn, $data, $ctime, $object) = @_;
124 my $path = $txn->{cfg
}->{path
} // 'proxmox';
127 # we do not want boolean/state information to export to graphite
128 my $key_blacklist = {
135 my $assemble_graphite_data;
136 $assemble_graphite_data = sub {
137 my ($metric, $path) = @_;
139 for my $key (sort keys %$metric) {
140 my $value = $metric->{$key};
141 next if !defined($value);
144 my $metricpath = $path . ".$key";
146 if (ref($value) eq 'HASH') {
147 $assemble_graphite_data->($value, $metricpath);
148 } elsif ($value =~ m/^[+-]?[0-9]*\.?[0-9]+$/ && !$key_blacklist->{$key}) {
149 $class->add_metric_data($txn, "$metricpath $value $ctime\n");
153 $assemble_graphite_data->($data, $path);
155 $assemble_graphite_data = undef; # avoid cyclic reference!
158 PVE
::JSONSchema
::register_format
('graphite-path', \
&pve_verify_graphite_path
);
159 sub pve_verify_graphite_path
{
160 my ($path, $noerr) = @_;
162 my $regex = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
164 if ($path !~ /^(${regex}\.)*${regex}$/) {
165 return undef if $noerr;
166 die "value does not look like a valid graphite path\n";