|
| 1 | +#!/usr/bin/python |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | +# $Id: hostvmstats.py 10054 2010-06-29 22:09:31Z abhishek $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/hypervisor/xenserver/hostvmstats.py $ |
| 19 | + |
| 20 | +import XenAPI |
| 21 | +import urllib |
| 22 | +import time |
| 23 | +import logging |
| 24 | +logging.basicConfig(filename='/tmp/xapilog',level=logging.DEBUG) |
| 25 | + |
| 26 | +def get_stats(session, collect_host_stats, consolidation_function, interval, start_time): |
| 27 | + try: |
| 28 | + |
| 29 | + if collect_host_stats == "true" : |
| 30 | + url = "http://localhost/rrd_updates?" |
| 31 | + url += "session_id=" + session._session |
| 32 | + url += "&host=" + collect_host_stats |
| 33 | + url += "&cf=" + consolidation_function |
| 34 | + url += "&interval=" + str(interval) |
| 35 | + url += "&start=" + str(int(time.time())-100) |
| 36 | + else : |
| 37 | + url = "http://localhost/rrd_updates?" |
| 38 | + url += "session_id=" + session._session |
| 39 | + url += "&host=" + collect_host_stats |
| 40 | + url += "&cf=" + consolidation_function |
| 41 | + url += "&interval=" + str(interval) |
| 42 | + url += "&start=" + str(int(time.time())-100) |
| 43 | + |
| 44 | + logging.debug("Calling URL: %s",url) |
| 45 | + sock = urllib.URLopener().open(url) |
| 46 | + xml = sock.read() |
| 47 | + sock.close() |
| 48 | + logging.debug("Size of returned XML: %s",len(xml)) |
| 49 | + return xml |
| 50 | + except Exception,e: |
| 51 | + logging.exception("get_stats() failed") |
| 52 | + raise |
0 commit comments