当前位置: 首页>>代码示例>>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;未经允许,请勿转载。