def collect_cache_stats(url, rootdir, cache_max_fs_fraction=1.0):
    ' Collect stats on the cache server '
    start_time = time.time()
    parsed_url = urllib.parse.urlparse(url)
    try:
        if (parsed_url.scheme not in ('root', 'xroot')):
            raise Exception(("URL '%s' is not an xrootd url" % url))
        hostname = parsed_url.netloc
    except AttributeError:
        if (parsed_url[0] not in ('root', 'xroot')):
            raise Exception(("URL '%s' is not an xrootd url" % url))
        hostname = parsed_url[2][2:]
    result = {'MyType': 'Machine', 'Name': ('xrootd@%s' % hostname), 'stats_time': int(start_time)}
    result.update(test_xrootd_server(url))
    result.update(get_cache_info(rootdir, cache_max_fs_fraction))
    stats_per_vo = scan_cache_dirs(rootdir)
    totals = dict()
    most_recent_access = 0
    result['VO'] = {}
    for (vo, vostats) in stats_per_vo.items():
        for (k, v) in vostats.items():
            if (k == 'most_recent_access_time'):
                most_recent_access = max(most_recent_access, v)
            else:
                try:
                    totals[k] += v
                except KeyError:
                    totals[k] = v
        result['VO'][vo] = vostats
    result['used_cache_bytes'] = totals.pop('used_bytes', 0)
    for (k, v) in totals.items():
        result[('total_' + k)] = v
    if (most_recent_access > 0):
        result['most_recent_access_time'] = most_recent_access
    result['time_to_collect_stats'] = (time.time() - start_time)
    return classad.ClassAd(result)
Collect stats on the cache server
def collect_cache_stats(url, rootdir, cache_max_fs_fraction=1.0):
    '  '
    start_time = time.time()
    parsed_url = urllib.parse.urlparse(url)
    try:
        if (parsed_url.scheme not in ('root', 'xroot')):
            raise Exception(("URL '%s' is not an xrootd url" % url))
        hostname = parsed_url.netloc
    except AttributeError:
        if (parsed_url[0] not in ('root', 'xroot')):
            raise Exception(("URL '%s' is not an xrootd url" % url))
        hostname = parsed_url[2][2:]
    result = {'MyType': 'Machine', 'Name': ('xrootd@%s' % hostname), 'stats_time': int(start_time)}
    result.update(test_xrootd_server(url))
    result.update(get_cache_info(rootdir, cache_max_fs_fraction))
    stats_per_vo = scan_cache_dirs(rootdir)
    totals = dict()
    most_recent_access = 0
    result['VO'] = {}
    for (vo, vostats) in stats_per_vo.items():
        for (k, v) in vostats.items():
            if (k == 'most_recent_access_time'):
                most_recent_access = max(most_recent_access, v)
            else:
                try:
                    totals[k] += v
                except KeyError:
                    totals[k] = v
        result['VO'][vo] = vostats
    result['used_cache_bytes'] = totals.pop('used_bytes', 0)
    for (k, v) in totals.items():
        result[('total_' + k)] = v
    if (most_recent_access > 0):
        result['most_recent_access_time'] = most_recent_access
    result['time_to_collect_stats'] = (time.time() - start_time)
    return classad.ClassAd(result)