move common metric server management part to own module

For now it only handles the plugin registration and the two recently
integrated helpers.
But, this is a prepartation to move the external metrics server
update mechanic from a stateless always-newly-connect-send-disconnect
to a statefull transaction based mechanis; see later patches

keep the PVE::Status::Plugin use in pvestatd, as we read the cfs
hosted status.cfg there, and the parser is defined by the common
status plugin base module.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2019-11-16 16:17:07 +01:00
parent 6ed1a93245
commit 99e3d4f605
4 changed files with 41 additions and 31 deletions

35
PVE/ExtMetric.pm Normal file
View File

@ -0,0 +1,35 @@
package PVE::ExtMetric;
use strict;
use warnings;
use PVE::Status::Plugin;
use PVE::Status::Graphite;
use PVE::Status::InfluxDB;
PVE::Status::Graphite->register();
PVE::Status::InfluxDB->register();
PVE::Status::Plugin->init();
sub foreach_plug($&) {
my ($status_cfg, $code) = @_;
for my $plugin_config (values %{$status_cfg->{ids}}) {
next if $plugin_config->{disable};
my $plugin = PVE::Status::Plugin->lookup($plugin_config->{type});
$code->($plugin, $plugin_config);
}
}
sub update_all($$@) {
my ($cfg, $subsystem, @params) = @_;
my $method = "update_${subsystem}_status";
foreach_plug($cfg, sub {
my ($plugin, $plugin_config) = @_;
$plugin->$method($plugin_config, @params);
});
}
1;

View File

@ -8,6 +8,7 @@ PERLSOURCE = \
APLInfo.pm \
AutoBalloon.pm \
CertHelpers.pm \
ExtMetric.pm \
HTTPServer.pm \
NodeConfig.pm \
Report.pm \

View File

@ -27,13 +27,8 @@ use PVE::AccessControl;
use PVE::Ceph::Services;
use PVE::Ceph::Tools;
use PVE::ExtMetric;
use PVE::Status::Plugin;
use PVE::Status::Graphite;
use PVE::Status::InfluxDB;
PVE::Status::Graphite->register();
PVE::Status::InfluxDB->register();
PVE::Status::Plugin->init();
use base qw(PVE::Daemon);
@ -131,7 +126,7 @@ sub update_node_status {
$node_metric->{cpustat}->@{qw(avg1 avg5 avg15)} = ($avg1, $avg5, $avg15);
$node_metric->{cpustat}->{cpus} = $maxcpu;
PVE::Status::Plugin::update_all($status_cfg, 'node', $nodename, $node_metric, $ctime);
PVE::ExtMetric::update_all($status_cfg, 'node', $nodename, $node_metric, $ctime);
}
sub auto_balloning {
@ -189,7 +184,7 @@ sub update_qemu_status {
}
PVE::Cluster::broadcast_rrd("pve2.3-vm/$vmid", $data);
PVE::Status::Plugin::update_all($status_cfg, 'qemu', $vmid, $d, $ctime, $nodename);
PVE::ExtMetric::update_all($status_cfg, 'qemu', $vmid, $d, $ctime, $nodename);
}
}
@ -383,7 +378,7 @@ sub update_lxc_status {
}
PVE::Cluster::broadcast_rrd("pve2.3-vm/$vmid", $data);
PVE::Status::Plugin::update_all($status_cfg, 'lxc', $vmid, $d, $ctime, $nodename);
PVE::ExtMetric::update_all($status_cfg, 'lxc', $vmid, $d, $ctime, $nodename);
}
}
@ -403,7 +398,7 @@ sub update_storage_status {
my $key = "pve2-storage/${nodename}/$storeid";
PVE::Cluster::broadcast_rrd($key, $data);
PVE::Status::Plugin::update_all($status_cfg, 'storage', $nodename, $storeid, $d, $ctime);
PVE::ExtMetric::update_all($status_cfg, 'storage', $nodename, $storeid, $d, $ctime);
}
}

View File

@ -55,27 +55,6 @@ sub parse_section_header {
return undef;
}
sub foreach_plug($&) {
my ($status_cfg, $code) = @_;
for my $plugin_config (values %{$status_cfg->{ids}}) {
next if $plugin_config->{disable};
my $plugin = __PACKAGE__->lookup($plugin_config->{type});
$code->($plugin, $plugin_config);
}
}
sub update_all($$@) {
my ($cfg, $subsystem, @params) = @_;
my $method = "update_${subsystem}_status";
foreach_plug($cfg, sub {
my ($plugin, $plugin_config) = @_;
$plugin->$method($plugin_config, @params);
});
}
sub _connect {
my ($class, $cfg) = @_;