Commit 56678698 authored by Dietmar Maurer's avatar Dietmar Maurer

implement status plugin framework

parent a7dc5694
include ../defines.mk
SUBDIRS=API2 VZDump
SUBDIRS=API2 VZDump Status
PERLSOURCE = \
API2.pm \
......
package PVE::Status::Graphite;
use strict;
use warnings;
use PVE::Status::Plugin;
# example config (/etc/pve/status.cfg)
#graphite:
# graphiteserver test
# disable 0
#
use base('PVE::Status::Plugin');
sub type {
return 'graphite';
}
sub properties {
return {
graphiteserver => {
type => 'string',
description => "External graphite statistic server",
},
};
}
sub options {
return {
graphiteserver => {},
disable => { optional => 1 },
};
}
# Plugin implementation
sub update_node_status {
my ($plugin_config, $node, $data) = @_;
# implement me
}
sub update_qemu_status {
my ($plugin_config, $vmid, $data) = @_;
# implement me
}
sub update_lxc_status {
my ($plugin_config, $vmid, $data) = @_;
# implement me
}
sub update_storage_status {
my ($plugin_config, $storeid, $data) = @_;
# implement me
}
1;
include ../../defines.mk
PERLSOURCE = \
Graphite.pm \
Plugin.pm
all:
.PHONY: distclean
distclean: clean
.PHONY: clean
clean:
rm -rf *~
.PHONY: install
install: ${PERLSOURCE}
install -d ${PERLLIBDIR}/PVE/Status
install -m 0644 ${PERLSOURCE} ${PERLLIBDIR}/PVE/Status
package PVE::Status::Plugin;
use strict;
use warnings;
use PVE::Tools;
use PVE::JSONSchema;
use PVE::Cluster;
use Data::Dumper;
use base qw(PVE::SectionConfig);
PVE::Cluster::cfs_register_file('status.cfg',
sub { __PACKAGE__->parse_config(@_); },
sub { __PACKAGE__->write_config(@_); });
my $defaultData = {
propertyList => {
type => {
description => "Plugin type.",
type => 'string', format => 'pve-configid',
},
disable => {
description => "Flag to disable the plugun.",
type => 'boolean',
optional => 1,
},
},
};
sub private {
return $defaultData;
}
sub parse_section_header {
my ($class, $line) = @_;
if ($line =~ m/^(\S+):\s*$/) {
my $type = lc($1);
my $errmsg = undef; # set if you want to skip whole section
eval { PVE::JSONSchema::pve_verify_configid($type); };
$errmsg = $@ if $@;
my $config = {}; # to return additional attributes
return ($type, $type, $errmsg, $config);
}
return undef;
}
sub update_node_status {
my ($plugin_config, $node, $data) = @_;
die "please implement inside plugin";
}
sub update_qemu_status {
my ($plugin_config, $vmid, $data) = @_;
die "please implement inside plugin";
}
sub update_lxc_status {
my ($plugin_config, $vmid, $data) = @_;
die "please implement inside plugin";
}
sub update_storage_status {
my ($plugin_config, $storeid, $data) = @_;
die "please implement inside plugin";
}
1;
......@@ -18,6 +18,12 @@ use PVE::RPCEnvironment;
use PVE::API2::Subscription;
use PVE::AutoBalloon;
use PVE::Status::Plugin;
use PVE::Status::Graphite;
PVE::Status::Graphite->register();
PVE::Status::Plugin->init();
use base qw(PVE::Daemon);
my $opt_debug;
......@@ -66,6 +72,7 @@ sub hup {
}
sub update_node_status {
my ($status_cfg) = @_;
my ($avg1, $avg5, $avg15) = PVE::ProcFSTools::read_loadavg();
......@@ -106,6 +113,14 @@ sub update_node_status {
"$dinfo->{blocks}:$dused:$netin:$netout";
PVE::Cluster::broadcast_rrd("pve2-node/$nodename", $data);
foreach my $id (keys %{$status_cfg->{ids}}) {
my $plugin_config = $status_cfg->{ids}->{$id};
next if $plugin_config->{disable};
my $plugin = PVE::Status::Plugin->lookup($plugin_config->{type});
my $d = {}; # fixme: what data?
$plugin->update_node_status($plugin_config, $nodename, $d);
}
}
sub auto_balloning {
......@@ -149,6 +164,7 @@ sub auto_balloning {
}
sub update_qemu_status {
my ($status_cfg) = @_;
my $ctime = time();
......@@ -176,6 +192,13 @@ sub update_qemu_status {
":::";
}
PVE::Cluster::broadcast_rrd("pve2.3-vm/$vmid", $data);
foreach my $id (keys %{$status_cfg->{ids}}) {
my $plugin_config = $status_cfg->{ids}->{$id};
next if $plugin_config->{disable};
my $plugin = PVE::Status::Plugin->lookup($plugin_config->{type});
$plugin->update_qemu_status($plugin_config, $vmid, $d);
}
}
}
......@@ -194,6 +217,7 @@ sub remove_stale_lxc_consoles {
}
sub update_lxc_status {
my ($status_cfg) = @_;
my $ctime = time();
......@@ -215,10 +239,18 @@ sub update_lxc_status {
":::";
}
PVE::Cluster::broadcast_rrd("pve2.3-vm/$vmid", $data);
foreach my $id (keys %{$status_cfg->{ids}}) {
my $plugin_config = $status_cfg->{ids}->{$id};
next if $plugin_config->{disable};
my $plugin = PVE::Status::Plugin->lookup($plugin_config->{type});
$plugin->update_lxc_status($plugin_config, $vmid, $d);
}
}
}
sub update_storage_status {
my ($status_cfg) = @_;
my $cfg = cfs_read_file("storage.cfg");
......@@ -237,6 +269,13 @@ sub update_storage_status {
my $key = "pve2-storage/${nodename}/$storeid";
PVE::Cluster::broadcast_rrd($key, $data);
foreach my $id (keys %{$status_cfg->{ids}}) {
my $plugin_config = $status_cfg->{ids}->{$id};
next if $plugin_config->{disable};
my $plugin = PVE::Status::Plugin->lookup($plugin_config->{type});
$plugin->update_storage_status($plugin_config, $storeid, $d);
}
}
}
......@@ -252,26 +291,28 @@ sub update_status {
my $err = $@;
syslog('err', $err) if $err;
my $status_cfg = PVE::Cluster::cfs_read_file('status.cfg');
eval {
update_node_status();
update_node_status($status_cfg);
};
$err = $@;
syslog('err', "node status update error: $err") if $err;
eval {
update_qemu_status();
update_qemu_status($status_cfg);
};
$err = $@;
syslog('err', "qemu status update error: $err") if $err;
eval {
update_lxc_status();
update_lxc_status($status_cfg);
};
$err = $@;
syslog('err', "lxc status update error: $err") if $err;
eval {
update_storage_status();
update_storage_status($status_cfg);
};
$err = $@;
syslog('err', "storage status update error: $err") if $err;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment