1 package PVE
::Status
::Plugin
;
7 use PVE
::Cluster
qw(cfs_register_file);
8 use PVE
::SectionConfig
;
10 use base
qw(PVE::SectionConfig);
12 cfs_register_file
('status.cfg',
13 sub { __PACKAGE__-
>parse_config(@_); },
14 sub { __PACKAGE__-
>write_config(@_); }
20 description
=> "The ID of the entry.",
21 type
=> 'string', format
=> 'pve-configid',
24 description
=> "Plugin type.",
25 type
=> 'string', format
=> 'pve-configid',
28 description
=> "Flag to disable the plugin.",
33 type
=> 'string', format
=> 'address',
34 description
=> "server dns name or IP address",
38 description
=> "server network port",
44 description
=> "MTU for metrics transmission over UDP",
57 sub parse_section_header
{
58 my ($class, $line) = @_;
60 if ($line =~ m/^(\S+):\s*(\S+)?\s*$/) {
63 my $errmsg = undef; # set if you want to skip whole section
64 eval { PVE
::JSONSchema
::pve_verify_configid
($id) };
66 my $config = {}; # to return additional attributes
67 return ($type, $id, $errmsg, $config);
73 my ($class, $cfg, $id) = @_;
74 die "please implement inside plugin";
78 my ($class, $connection, $cfg) = @_;
80 $connection->close(); # overwrite if not a simple socket
83 # UDP cannot do more than 64k at once. Overwrite for different protocol limits.
84 sub _send_batch_size
{
85 my ($class, $cfg) = @_;
87 # default to 1500 MTU, empty IPv6 UDP packet needs 48 bytes overhead
88 my $mtu = $cfg->{mtu
} // 1500;
89 return $mtu - 50; # a bit more than 48byte to allow for safe room
92 # call with the smalles $data chunks possible
94 my ($class, $txn, $data) = @_;
95 return if !defined($data);
97 my $batch_size = $class->_send_batch_size($txn->{cfg
});
98 my $data_length = length($data) // 0;
99 my $dataq_len = length($txn->{data
}) // 0;
101 if (($dataq_len + $data_length) >= $batch_size) {
102 $class->flush_data($txn);
105 $txn->{data
} .= "$data";
109 my ($class, $txn) = @_;
111 if (!$txn->{connection
}) {
112 return if !$txn->{data
}; # OK, if data was already sent/flushed
113 die "cannot flush metric data, no connection available!\n";
115 return if !defined($txn->{data
}) || $txn->{data
} eq '';
117 my $data = delete $txn->{data
};
118 eval { $class->send($txn->{connection
}, $data, $txn->{cfg
}) };
119 die "metrics send error '$txn->{id}': $@" if $@;
123 my ($class, $connection, $data, $cfg) = @_;
125 defined($connection->send($data))
126 or die "failed to send metrics: $!\n";
129 sub test_connection
{
130 my ($class, $cfg, $id) = @_;
132 # do not check connection for disabled plugins
133 return if $cfg->{disable
};
135 my $conn = $class->_connect($cfg, $id);
136 $class->_disconnect($conn, $cfg);
139 sub update_node_status
{
140 my ($class, $txn, $node, $data, $ctime) = @_;
141 die "please implement inside plugin";
144 sub update_qemu_status
{
145 my ($class, $txn, $vmid, $data, $ctime, $nodename) = @_;
146 die "please implement inside plugin";
149 sub update_lxc_status
{
150 my ($class, $txn, $vmid, $data, $ctime, $nodename) = @_;
151 die "please implement inside plugin";
154 sub update_storage_status
{
155 my ($class, $txn, $nodename, $storeid, $data, $ctime) = @_;
156 die "please implement inside plugin";
160 my ($class, $id, $opts, $sensitive_opts) = @_;
162 # implement in subclass
168 my ($class, $id, $opts, $sensitive_opts) = @_;
170 # implement in subclass
176 my ($class, $id, $opts) = @_;
178 # implement in subclass