mirror of
https://git.proxmox.com/git/pve-manager
synced 2025-08-06 13:50:28 +00:00
status plugins: add _connect to plugin method interface
in preparation of doing real transactions, with one batch connect + send + disconnect, and not hundreds of those per update cycle.. Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
5e82aaac89
commit
68f58b5d59
@ -80,14 +80,13 @@ sub update_storage_status {
|
||||
write_graphite_hash($plugin_config, $data, $ctime, "storages.$nodename.$storeid");
|
||||
}
|
||||
|
||||
sub write_graphite_hash {
|
||||
my ($plugin_config, $d, $ctime, $object) = @_;
|
||||
sub _connect {
|
||||
my ($class, $cfg) = @_;
|
||||
|
||||
my $host = $plugin_config->{server};
|
||||
my $port = $plugin_config->{port} || 2003;
|
||||
my $path = $plugin_config->{path} // 'proxmox';
|
||||
my $proto = $plugin_config->{proto} || 'udp';
|
||||
my $timeout = $plugin_config->{timeout} // 1;
|
||||
my $host = $cfg->{server};
|
||||
my $port = $cfg->{port} || 2003;
|
||||
my $proto = $cfg->{proto} || 'udp';
|
||||
my $timeout = $cfg->{timeout} // 1;
|
||||
|
||||
my $carbon_socket = IO::Socket::IP->new(
|
||||
PeerAddr => $host,
|
||||
@ -96,12 +95,23 @@ sub write_graphite_hash {
|
||||
Timeout => $timeout,
|
||||
) || die "couldn't create carbon socket [$host]:$port - $@\n";
|
||||
|
||||
if ( $proto eq 'tcp' ) {
|
||||
if ($proto eq 'tcp') {
|
||||
# seconds and µs
|
||||
my $timeout_struct = pack( 'l!l!', $timeout, 0);
|
||||
setsockopt($carbon_socket, SOL_SOCKET, SO_SNDTIMEO, $timeout_struct);
|
||||
setsockopt($carbon_socket, SOL_SOCKET, SO_RCVTIMEO, $timeout_struct);
|
||||
}
|
||||
|
||||
return $carbon_socket;
|
||||
}
|
||||
|
||||
sub write_graphite_hash {
|
||||
my ($plugin_config, $d, $ctime, $object) = @_;
|
||||
|
||||
my $path = $plugin_config->{path} // 'proxmox';
|
||||
|
||||
my $carbon_socket = __PACKAGE__->_connect($plugin_config);
|
||||
|
||||
write_graphite($carbon_socket, $d, $ctime, $path.".$object");
|
||||
|
||||
$carbon_socket->close() if $carbon_socket;
|
||||
|
@ -82,15 +82,11 @@ sub update_storage_status {
|
||||
write_influxdb_hash($plugin_config, $data, $ctime, $object);
|
||||
}
|
||||
|
||||
sub write_influxdb_hash {
|
||||
my ($plugin_config, $d, $ctime, $tags) = @_;
|
||||
sub _connect {
|
||||
my ($class, $cfg) = @_;
|
||||
|
||||
my $payload = {};
|
||||
|
||||
build_influxdb_payload($payload, $d, $ctime, $tags);
|
||||
|
||||
my $host = $plugin_config->{server};
|
||||
my $port = $plugin_config->{port};
|
||||
my $host = $cfg->{server};
|
||||
my $port = $cfg->{port};
|
||||
|
||||
my $socket = IO::Socket::IP->new(
|
||||
PeerAddr => $host,
|
||||
@ -98,9 +94,21 @@ sub write_influxdb_hash {
|
||||
Proto => 'udp',
|
||||
) || die "couldn't create influxdb socket [$host]:$port - $@\n";
|
||||
|
||||
$socket->send($payload->{string});
|
||||
$socket->close() if $socket;
|
||||
return $socket;
|
||||
}
|
||||
|
||||
sub write_influxdb_hash {
|
||||
my ($plugin_config, $d, $ctime, $tags) = @_;
|
||||
|
||||
my $payload = {};
|
||||
|
||||
build_influxdb_payload($payload, $d, $ctime, $tags);
|
||||
|
||||
my $socket = __PACKAGE__->_connect($plugin_config);
|
||||
|
||||
$socket->send($payload->{string});
|
||||
|
||||
$socket->close() if $socket;
|
||||
}
|
||||
|
||||
sub build_influxdb_payload {
|
||||
|
@ -75,6 +75,12 @@ sub update_all($$@) {
|
||||
});
|
||||
}
|
||||
|
||||
sub _connect {
|
||||
my ($class, $cfg) = @_;
|
||||
|
||||
die "please implement inside plugin";
|
||||
}
|
||||
|
||||
sub update_node_status {
|
||||
my ($class, $plugin_config, $node, $data, $ctime) = @_;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user