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