]>
git.proxmox.com Git - pve-manager.git/blob - PVE/Status/InfluxDB.pm
1 package PVE
::Status
::InfluxDB
;
5 use PVE
::Status
::Plugin
;
9 # example config (/etc/pve/status.cfg)
16 use base
('PVE::Status::Plugin');
26 disable
=> { optional
=> 1 },
30 # Plugin implementation
31 sub update_node_status
{
32 my ($class, $plugin_config, $node, $data, $ctime) = @_;
36 write_influxdb_hash
($plugin_config, $data, $ctime, "object=nodes,host=$node");
40 sub update_qemu_status
{
41 my ($class, $plugin_config, $vmid, $data, $ctime) = @_;
45 my $object = "object=qemu,vmid=$vmid";
46 if($data->{name
} && $data->{name
} ne '') {
47 $object .= ",host=$data->{name}";
49 $object =~ s/\s/\\ /g;
50 write_influxdb_hash
($plugin_config, $data, $ctime, $object);
53 sub update_lxc_status
{
54 my ($class, $plugin_config, $vmid, $data, $ctime) = @_;
58 my $object = "object=lxc,vmid=$vmid";
59 if($data->{name
} && $data->{name
} ne '') {
60 $object .= ",host=$data->{name}";
62 $object =~ s/\s/\\ /g;
64 write_influxdb_hash
($plugin_config, $data, $ctime, $object);
67 sub update_storage_status
{
68 my ($class, $plugin_config, $nodename, $storeid, $data, $ctime) = @_;
72 my $object = "object=storages,nodename=$nodename,host=$storeid";
73 if($data->{type
} && $data->{type
} ne '') {
74 $object .= ",type=$data->{type}";
76 $object =~ s/\s/\\ /g;
78 write_influxdb_hash
($plugin_config, $data, $ctime, $object);
81 sub write_influxdb_hash
{
82 my ($plugin_config, $d, $ctime, $tags) = @_;
86 build_influxdb_payload
($payload, $d, $ctime, $tags);
88 my $host = $plugin_config->{server
};
89 my $port = $plugin_config->{port
};
91 my $socket = IO
::Socket
::IP-
>new(
97 $socket->send($payload->{string
});
98 $socket->close() if $socket;
102 sub build_influxdb_payload
{
103 my ($payload, $d, $ctime, $tags, $measurement, $depth) = @_;
105 $depth = 0 if !$depth;
108 for my $key (keys %$d) {
110 my $value = $d->{$key};
113 if ( defined $value ) {
114 if ( ref $value eq 'HASH' ) {
119 $tags .= ",instance=$key";
123 build_influxdb_payload
($payload, $value, $ctime, $tags, $measurement, $depth);
126 }elsif ($value =~ m/^\d+$/) {
128 $measurement = "system" if !$measurement && $depth == 0;
129 push(@values, "$key=$value");
136 my $valuestr = join(',', @values);
137 $payload->{string
} .= $measurement.",$tags $valuestr $ctime\n";