因为公司需要做这方面的接口所以自己在网上查了好久才发现方法做了出来,其中遇到了不少的坑写一下以便以后再次遇到。
1、首先在xenAPI给的一些接口中虽然有关于这方面的接口但是现在的版本不能直接得到,如果直接调用VM_guest_metrics中的方法返回的数据是空的。
第二个链接https://wiki.xen.org/wiki/XAPI_RRDs
3、说一下获得的过程:
大致分三步 1、首先登陆要获取的服务器 2、得到RRD中的数据 3、解析数据
刚开始遇到最大的坑 就是登录认证不通过 原因在获取登录服务器 session_id是用session.handle处理一下就OK了基本上就没什么问题了。
python的参考代码
#!/usr/bin/python
# Example code for reading RRDs
# Contact: Jon Ludlam (jonathan.ludlam@eu.citrix.com)
#
# Mostly this script is taken from perfmon, by Alex Zeffert
#
import XenAPI
import urllib
from xml.dom import minidom
from xml.parsers.expat import ExpatError
import time
# Per VM dictionary (used by RRDUpdates to look up column numbers by variable names)
class VMReport(dict):
"""Used internally by RRDUpdates"""
def __init__(self, uuid):
self.uuid = uuid
# Per Host dictionary (used by RRDUpdates to look up column numbers by variable names)
class HostReport(dict):
"""Used internally by RRDUpdates"""
def __init__(self, uuid):
self.uuid = uuid
class RRDUpdates:
"&#