コード例 #1
0
 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')
コード例 #2
0
    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)
コード例 #3
0
ファイル: protocols.py プロジェクト: NixM0nk3y/carbon
  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)
コード例 #4
0
ファイル: protocols.py プロジェクト: mtodd/graphite
 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')