Access historical CPU and memory metrics - Xen Orchestra v5
-
@puneet336 @olivierlambert the lib is still working, but I'm usually use it with a local connection, running scripts inside
dom0
, with this code:def get_xapi_session(): session = XenAPI.xapi_local() try: session.xenapi.login_with_password('root', '', '', 'xcp-ng-tests session') except Exception as e: raise Exception('Cannot get XAPI session: {{}}'.format(e)) return session
Will check what happens with a remote session.
-
@puneet336 you need to make your connection to your pool master (not your XOA guest), that's where the XAPI endpoint is.
If you did not deploy TLS certificates on your pool,
XenAPI.Session(URL)
will complain that the SSL certificate is self-signed (which you can workaround by addingignore_ssl=True
as you did above, but don't keep this in production).You will also find a few guidelines to write a robust XenAPI client at https://xapi-project.github.io/xen-api/usage.html
-
@yann i tried running the following script from the xoa server.
#!/usr/bin/env python3 import XenAPI username = "username" password = "ldap password" #url = "https://xoaserver1.example.com" session = XenAPI.xapi_local() #session.xenapi.login_with_password('root', '', "", "xcp-ng-tests session") #session.xenapi.login_with_password(username, password, "1.0", "session_getter") session.xenapi.login_with_password(username, password, "", "xcp-ng-tests session") print(session._session)
i see following error :
Traceback (most recent call last): File "/home/user1/MC3/test.py", line 10, in <module> session.xenapi.login_with_password(username, password, "", "xcp-ng-tests session") File "/home/user1/MC3/envs/user1env/lib/python3.12/site-packages/XenAPI/XenAPI.py", line 260, in __call__ return self.__send(self.__name, args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user1/MC3/envs/user1env/lib/python3.12/site-packages/XenAPI/XenAPI.py", line 145, in xenapi_request self._login(methodname, params) File "/home/user1/MC3/envs/user1env/lib/python3.12/site-packages/XenAPI/XenAPI.py", line 182, in _login raise e File "/home/user1/MC3/envs/user1env/lib/python3.12/site-packages/XenAPI/XenAPI.py", line 170, in _login getattr(self, 'session.%s' % method)(*params)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user1/MC3/envs/user1env/lib/python3.12/xmlrpc/client.py", line 1122, in __call__ return self.__send(self.__name, args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user1/MC3/envs/user1env/lib/python3.12/xmlrpc/client.py", line 1461, in __request response = self.__transport.request( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user1/MC3/envs/user1env/lib/python3.12/xmlrpc/client.py", line 1166, in request return self.single_request(host, handler, request_body, verbose) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user1/MC3/envs/user1env/lib/python3.12/xmlrpc/client.py", line 1178, in single_request http_conn = self.send_request(host, handler, request_body, verbose) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user1/MC3/envs/user1env/lib/python3.12/xmlrpc/client.py", line 1291, in send_request self.send_content(connection, request_body) File "/home/user1/MC3/envs/user1env/lib/python3.12/xmlrpc/client.py", line 1321, in send_content connection.endheaders(request_body) File "/home/user1/MC3/envs/user1env/lib/python3.12/http/client.py", line 1331, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/home/user1/MC3/envs/user1env/lib/python3.12/http/client.py", line 1091, in _send_output self.send(msg) File "/home/user1/MC3/envs/user1env/lib/python3.12/http/client.py", line 1035, in send self.connect() File "/home/user1/MC3/envs/user1env/lib/python3.12/site-packages/XenAPI/XenAPI.py", line 99, in connect self.sock.connect(path) FileNotFoundError: [Errno 2] No such file or directory
Did i miss anything while running the script?
-
@puneet336
xapi_local()
will only work in thedom0
(it looks for a local socket to the XAPI daemon, which is why you get aFileNotFoundError
). If you run it from the XOA appliance (or from anywhere else than thedom0
, you'll needXenAPI.Session(URL)
, but again with a URL to the dom0, not your XOA appliance.Remember XAPI is a service running in the host's dom0, XOA is just a client connecting to that service.
-
Thank you for the response @yann . I was not aware about the dom0 and came across https://stackoverflow.com/questions/19147398/is-xen-dom0-a-guest-or-a-host ,
I believe i ran the python script from within the dom0 VM i.e. the server which hosts the Xen XOA Web UI. When i log in to the server ( which i beleive to be dom0 as of now) i see the following banner :
Is there a way to list out the IP of the dom0 vm ? or
Any method confirm if i am running the scripts from the dom0 VM (presence of any special file or any command which can list out the same)? -
Hi @yann ,
is there way to get the ip of dm0 vm via cli/ Web GUI? -
@puneet336 Hi,
The IP of the dom0 is the IP of the "host" you added in Xen Orchestra. You can find it the
settings -> server
tab -
@AtaxyaNetwork Thank you for the response,
I was unable to see settings Option from the Web UI,
but using Home>Pools, i saw following :
then i clicked on the 4x pools to get information on the hosts for this pool
I was able to get the name of the master server for this pool (tagged as master), say pool1.master.example.com
when i use hostname=pool1.master.example.com
#!/usr/bin/env python3 import XenAPI username = "root" password = "root account password" url = "https://pool1.master.example.com" session = XenAPI.Session(url) session.xenapi.login_with_password(username, password, "1.0", "session_getter") print(session._session)
i am able to see session tokens
identified uuid of one of the VM being managed by pool master
and i am able to download the data using :
wget -c "http://pool1.master.example.com/host_rrd?session_id=pool1.master.opaqreftoken&uuid=VM1uuid" --output-document test.xml
-
Hi @olivierlambert , @yann
I was able to get rrd data using instructions i mentioned in previous comment, But i am not sure if it contains historical data or this is just current metrics snapshot.wget -c "http://pool1.master.example.com/host_rrd?session_id=pool1.master.opaqreftoken&uuid=VM1uuid" --output-document test.xml
but the file which i downloaded was just 20MB file and this host has been up since last 1 year.
Not sure if the xml file which i got will have entire year's data as there is just 1 lastupdate tag in the document , i.e. <lastupdate>1718163483</lastupdate>I am looking to parse the xml for raw data and dump the same in following form for each hosts's xml file
timestamp1, cpu metrics1, memory usage metrics1
timestamp2, cpu metrics2, memory usage metrics2
timestamp3, cpu metrics3, memry usage metrics3
timestamp4, cpu metrics4, memry usage metrics4Could you please share some information or link which can help me understand the format of xml or,
if you could share information about the tags which i need to look upon ?Though i am going through the xml document , Any help hint which could help me understand the format or obtain memory and cpu metrics would help.
-
Have you read https://xapi-project.github.io/xen-api/metrics.html ? It explains the diff between getting all data and only the diff (delta). It's a must read to understand the way RRDs can be fetch.