當前位置: 首頁>>代碼示例>>Python>>正文


Python MetricCache.get方法代碼示例

本文整理匯總了Python中carbon.cache.MetricCache.get方法的典型用法代碼示例。如果您正苦於以下問題:Python MetricCache.get方法的具體用法?Python MetricCache.get怎麽用?Python MetricCache.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在carbon.cache.MetricCache的用法示例。


在下文中一共展示了MetricCache.get方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: stringReceived

# 需要導入模塊: from carbon.cache import MetricCache [as 別名]
# 或者: from carbon.cache.MetricCache import get [as 別名]
  def stringReceived(self, rawRequest):
    request = self.unpickler.loads(rawRequest)
    cache = MetricCache()
    if request['type'] == 'cache-query':
      metric = request['metric']
      datapoints = list(cache.get(metric, {}).items())
      result = dict(datapoints=datapoints)
      if settings.LOG_CACHE_HITS:
        log.query('[%s] cache query for \"%s\" returned %d values' % (
          self.peerAddr, metric, len(datapoints)
        ))
      instrumentation.increment('cacheQueries')

    elif request['type'] == 'cache-query-bulk':
      datapointsByMetric = {}
      metrics = request['metrics']
      for metric in metrics:
        datapointsByMetric[metric] = list(cache.get(metric, {}).items())

      result = dict(datapointsByMetric=datapointsByMetric)

      if settings.LOG_CACHE_HITS:
        log.query('[%s] cache query bulk for \"%d\" metrics returned %d values' % (
          self.peerAddr,
          len(metrics),
          sum([len(datapoints) for datapoints in datapointsByMetric.values()])
        ))
      instrumentation.increment('cacheBulkQueries')
      instrumentation.append('cacheBulkQuerySize', len(metrics))

    elif request['type'] == 'get-metadata':
      result = management.getMetadata(request['metric'], request['key'])

    elif request['type'] == 'set-metadata':
      result = management.setMetadata(request['metric'], request['key'], request['value'])

    else:
      result = dict(error="Invalid request type \"%s\"" % request['type'])

    response = pickle.dumps(result, protocol=2)
    self.sendString(response)
開發者ID:NixM0nk3y,項目名稱:carbon,代碼行數:43,代碼來源:protocols.py

示例2: stringReceived

# 需要導入模塊: from carbon.cache import MetricCache [as 別名]
# 或者: from carbon.cache.MetricCache import get [as 別名]
 def stringReceived(self, metric):
   values = MetricCache.get(metric, [])
   log.query('cache query for %s returned %d values' % (metric, len(values)))
   response = pickle.dumps(values, protocol=-1)
   self.sendString(response)
   increment('cacheQueries')
開發者ID:mtodd,項目名稱:graphite,代碼行數:8,代碼來源:protocols.py


注:本文中的carbon.cache.MetricCache.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。