From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [RFC ha-manager 2/3] env: add get_static_guest_stats method
Date: Fri, 18 Nov 2022 12:32:22 +0100 [thread overview]
Message-ID: <20221118113223.49305-3-f.ebner@proxmox.com> (raw)
In-Reply-To: <20221118113223.49305-1-f.ebner@proxmox.com>
which uses the efficient PVE::Cluster::get_guest_config_properties()
to retrieve the information and supports caching, so the information
can be passed around avoiding overhead from load_config().
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
src/PVE/HA/Env.pm | 6 ++++++
src/PVE/HA/Env/PVE2.pm | 15 +++++++++++++++
src/PVE/HA/Sim/Env.pm | 7 +++++++
3 files changed, 28 insertions(+)
diff --git a/src/PVE/HA/Env.pm b/src/PVE/HA/Env.pm
index 16603ec..2b422eb 100644
--- a/src/PVE/HA/Env.pm
+++ b/src/PVE/HA/Env.pm
@@ -275,4 +275,10 @@ sub get_static_node_stats {
return $self->{plug}->get_static_node_stats();
}
+sub get_static_guest_stats {
+ my ($self, $cached) = @_;
+
+ return $self->{plug}->get_static_guest_stats($cached);
+}
+
1;
diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm
index f6ebfeb..02b981e 100644
--- a/src/PVE/HA/Env/PVE2.pm
+++ b/src/PVE/HA/Env/PVE2.pm
@@ -476,4 +476,19 @@ sub get_static_node_stats {
return $stats;
}
+sub get_static_guest_stats {
+ my ($self, $cached) = @_;
+
+ return $self->{'static-guest-stats'} if $self->{'static-guest-stats'} && $cached;
+
+ # NOTE see get_static_stats in Resources/*.pm for what properties are required.
+ my $properties = ['cores', 'cpulimit', 'memory', 'sockets', 'vcpus'];
+ my $stats = eval { PVE::Cluster::get_guest_config_properties($properties); };
+ $self->log('warning', "unable to initialize cache for static service stats - $@") if $@;
+
+ $self->{'static-guest-stats'} = $stats;
+
+ return $stats // {};
+}
+
1;
diff --git a/src/PVE/HA/Sim/Env.pm b/src/PVE/HA/Sim/Env.pm
index c6ea73c..51690f5 100644
--- a/src/PVE/HA/Sim/Env.pm
+++ b/src/PVE/HA/Sim/Env.pm
@@ -442,4 +442,11 @@ sub get_static_node_stats {
return $self->{hardware}->get_static_node_stats();
}
+# FIXME actually return the stats here
+sub get_static_guest_stats {
+ my ($self, $cached) = @_;
+
+ return {};
+}
+
1;
--
2.30.2
next prev parent reply other threads:[~2022-11-18 11:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-18 11:32 [pve-devel] [RFC ha-manager] make static usage calculation faster Fiona Ebner
2022-11-18 11:32 ` [pve-devel] [RFC ha-manager 1/3] resources: get static stats: add cache parameter Fiona Ebner
2022-11-18 11:32 ` Fiona Ebner [this message]
2022-11-18 11:32 ` [pve-devel] [RFC ha-manager 3/3] manager/usage: cache static service stats to avoid overhead Fiona Ebner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221118113223.49305-3-f.ebner@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox