Пример #1
0
def cacheTSMetaByTypeForAlpha(qtype, alphabet):
    r = requests.get(
        str("%s:%d%s?type=%s&q=%s&%s" %
            (config['dataprovider']['uri'], config['dataprovider']['port'],
             config['dataprovider']['search_endpoint'], qtype, alphabet,
             CACHE_QUERY_PARAMS)))
    metricList = r.json()
    if qtype == 'metrics':
        newList = [{
            '_id': "metric:%s" % (m),
            'name': m,
            'type': 'metric'
        } for m in metricList]
    else:
        newList = [{
            '_id': "%s:%s" % (qtype, m),
            'name': m,
            'type': qtype
        } for m in metricList]

    if len(newList) < 1:
        return {'status': 'No metrics', 'query': alphabet, 'type': qtype}
    mcd = MetricCacheDatastore(
        **dict([(k, v)
                for k, v in config['cache']['datastore']['mongodb'].items()] +
               [('retention_period',
                 config['cache']['retention_period'] * 60)]))
    resp = mcd.bulkCache(newList)
    mcd.close()
    return {
        'status': "refreshed %d" % (len(newList)),
        'query': alphabet,
        'type': qtype,
        'response': resp
    }
Пример #2
0
def expire_metrics_cache():
    mcd = MetricCacheDatastore(
        **dict([(k, v)
                for k, v in config['cache']['datastore']['mongodb'].items()] +
               [('retention_period',
                 config['cache']['retention_period'] * 60)]))
    return mcd.expireCache()