]> git.proxmox.com Git - pve-manager.git/blame - PVE/ExtMetric.pm
report: format iptables output for readability
[pve-manager.git] / PVE / ExtMetric.pm
CommitLineData
f1f4bfef
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
87be2c19
TL
17 for my $id (sort keys %{$status_cfg->{ids}}) {
18 my $plugin_config = $status_cfg->{ids}->{$id};
f1f4bfef 19 next if $plugin_config->{disable};
87be2c19 20
f1f4bfef 21 my $plugin = PVE::Status::Plugin->lookup($plugin_config->{type});
87be2c19 22 $code->($plugin, $id, $plugin_config);
f1f4bfef
TL
23 }
24}
25
26sub update_all($$@) {
87be2c19 27 my ($transactions, $subsystem, @params) = @_;
f1f4bfef
TL
28
29 my $method = "update_${subsystem}_status";
30
87be2c19
TL
31 for my $txn (@$transactions) {
32 my $plugin = PVE::Status::Plugin->lookup($txn->{cfg}->{type});
33
34 $plugin->$method($txn, @params);
87be2c19
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# }
87be2c19
TL
44sub transactions_start {
45 my ($cfg) = @_;
46
e35f1d37 47 my $transactions = [];
87be2c19 48
f1f4bfef 49 foreach_plug($cfg, sub {
87be2c19
TL
50 my ($plugin, $id, $plugin_config) = @_;
51
fa978197 52 my $connection = $plugin->_connect($plugin_config, $id);
87be2c19
TL
53
54 push @$transactions, {
55 connection => $connection,
56 cfg => $plugin_config,
57 id => $id,
58 data => '',
59 };
f1f4bfef 60 });
87be2c19
TL
61
62 return $transactions;
63}
64
5c77a34f
TL
65sub transactions_finish {
66 my ($transactions) = @_;
87be2c19 67
5c77a34f
TL
68 for my $txn (@$transactions) {
69 my $plugin = PVE::Status::Plugin->lookup($txn->{cfg}->{type});
87be2c19 70
5c77a34f
TL
71 eval { $plugin->flush_data($txn) };
72 my $flush_err = $@;
73 warn "$flush_err" if $flush_err;
87be2c19 74
fa978197 75 $plugin->_disconnect($txn->{connection}, $txn->{cfg});
87be2c19
TL
76 $txn->{connection} = undef;
77 # avoid log spam, already got a send error; disconnect would fail too
5c77a34f 78 warn "disconnect failed: $@" if $@ && !$flush_err;
87be2c19 79 }
f1f4bfef
TL
80}
81
821;