]> git.proxmox.com Git - pve-manager-legacy.git/blame - PVE/ExtMetric.pm
bump version to 7.4-4
[pve-manager-legacy.git] / PVE / ExtMetric.pm
CommitLineData
99e3d4f6
TL
1package PVE::ExtMetric;
2
3use strict;
4use warnings;
5
6use PVE::Status::Plugin;
7use PVE::Status::Graphite;
8use PVE::Status::InfluxDB;
9
10PVE::Status::Graphite->register();
11PVE::Status::InfluxDB->register();
12PVE::Status::Plugin->init();
13
14sub foreach_plug($&) {
15 my ($status_cfg, $code) = @_;
16
f3e584e0
TL
17 for my $id (sort keys %{$status_cfg->{ids}}) {
18 my $plugin_config = $status_cfg->{ids}->{$id};
99e3d4f6 19 next if $plugin_config->{disable};
f3e584e0 20
99e3d4f6 21 my $plugin = PVE::Status::Plugin->lookup($plugin_config->{type});
f3e584e0 22 $code->($plugin, $id, $plugin_config);
99e3d4f6
TL
23 }
24}
25
26sub update_all($$@) {
f3e584e0 27 my ($transactions, $subsystem, @params) = @_;
99e3d4f6
TL
28
29 my $method = "update_${subsystem}_status";
30
f3e584e0
TL
31 for my $txn (@$transactions) {
32 my $plugin = PVE::Status::Plugin->lookup($txn->{cfg}->{type});
33
34 $plugin->$method($txn, @params);
f3e584e0
TL
35 }
36}
37
38# must return a transaction hash with the format:
39# {
40# cfg => $plugin_config,
41# connection => ..., # the connected socket
42# data => '', # payload, will be sent at the trannsaction flush
43# }
f3e584e0
TL
44sub transactions_start {
45 my ($cfg) = @_;
46
e16c4137 47 my $transactions = [];
f3e584e0 48
99e3d4f6 49 foreach_plug($cfg, sub {
f3e584e0
TL
50 my ($plugin, $id, $plugin_config) = @_;
51
98959268 52 my $connection = $plugin->_connect($plugin_config, $id);
f3e584e0
TL
53
54 push @$transactions, {
55 connection => $connection,
56 cfg => $plugin_config,
57 id => $id,
58 data => '',
59 };
99e3d4f6 60 });
f3e584e0
TL
61
62 return $transactions;
63}
64
bab146a4
TL
65sub transactions_finish {
66 my ($transactions) = @_;
f3e584e0 67
bab146a4
TL
68 for my $txn (@$transactions) {
69 my $plugin = PVE::Status::Plugin->lookup($txn->{cfg}->{type});
f3e584e0 70
bab146a4
TL
71 eval { $plugin->flush_data($txn) };
72 my $flush_err = $@;
73 warn "$flush_err" if $flush_err;
f3e584e0 74
98959268 75 $plugin->_disconnect($txn->{connection}, $txn->{cfg});
f3e584e0
TL
76 $txn->{connection} = undef;
77 # avoid log spam, already got a send error; disconnect would fail too
bab146a4 78 warn "disconnect failed: $@" if $@ && !$flush_err;
f3e584e0 79 }
99e3d4f6
TL
80}
81
821;