예제 #1
0
파일: protocols.py 프로젝트: laiwei/carbon
  def stringReceived(self, rawRequest):
    request = self.unpickler.loads(rawRequest)
    if request['type'] == 'cache-query':
      metric = request['metric']
      datapoints = MetricCache.get(metric, [])
      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] = MetricCache.get(metric, [])

      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=-1)
    self.sendString(response)
예제 #2
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')
예제 #3
0
  def stringReceived(self, rawRequest):
    request = self.unpickler.loads(rawRequest)
    if request['type'] == 'cache-query':
      metric = request['metric']
      datapoints = MetricCache.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] = MetricCache.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=-1)
    self.sendString(response)
예제 #4
0
  def stringReceived(self, rawRequest):
    request = pickle.loads(rawRequest)
    if request['type'] == 'cache-query':
      metric = request['metric']
      datapoints = MetricCache.get(metric, [])
      result = dict(datapoints=datapoints)
      log.query('[%s] cache query for \"%s\" returned %d values' % (self.peerAddr, metric, len(datapoints)))
      instrumentation.increment('cacheQueries')

    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=-1)
    self.sendString(response)
예제 #5
0
  def stringReceived(self, rawRequest):
    request = self.unpickler.loads(rawRequest)
    if request['type'] == 'cache-query':
      metric = request['metric']
      datapoints = MetricCache.get(metric, [])
      result = dict(datapoints=datapoints)
      log.query('[%s] cache query for \"%s\" returned %d values' % (self.peerAddr, metric, len(datapoints)))
      instrumentation.increment('cacheQueries')

    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=-1)
    self.sendString(response)
예제 #6
0
    def stringReceived(self, rawRequest):
        request = self.unpickler.loads(rawRequest)
        if request["type"] == "cache-query":
            metric = request["metric"]
            datapoints = MetricCache.get(metric, [])
            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] = MetricCache.get(metric, [])

            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=-1)
        self.sendString(response)
예제 #7
0
  def lineReceived(self, rawRequest):
    log.query('[%s] query received: %s' % (self.peerAddr, rawRequest))
    request_type, request = rawRequest.split('|', 1)
    if request_type == 'cache-query':
      datapoints = MetricCache.get(request, [])
      result = dict(datapoints=datapoints)
      if settings.LOG_CACHE_HITS:
        log.query('[%s] cache query for \"%s\" returned %d values' % (self.peerAddr, request, len(datapoints)))
      instrumentation.increment('cacheQueries')

    elif request_type == 'cache-query-bulk':
      datapointsByMetric = {}
      metrics = request.split('|')
      for metric in metrics:
        datapointsByMetric[metric] = MetricCache.get(metric, [])

      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':
      metric, key = request.split('|')
      result = management.getMetadata(metric, key)

    else:
      result = dict(error="Invalid request type \"%s\"" % request_type)

    self.sendLine(json.dumps(result))
예제 #8
0
 def connectionLost(self, reason):
     if reason.check(ConnectionDone):
         log.query("%s disconnected" % self.peerAddr)
     else:
         log.query("%s connection lost: %s" % (self.peerAddr, reason.value))
예제 #9
0
 def connectionMade(self):
     peer = self.transport.getPeer()
     self.peerAddr = "%s:%d" % (peer.host, peer.port)
     log.query("%s connected" % self.peerAddr)
     self.unpickler = get_unpickler(
         insecure=settings.USE_INSECURE_UNPICKLER)
예제 #10
0
 def connectionLost(self, reason):
   if reason.check(ConnectionDone):
     log.query("%s disconnected" % self.peerAddr)
   else:
     log.query("%s connection lost: %s" % (self.peerAddr, reason.value))
예제 #11
0
 def connectionMade(self):
   peer = self.transport.getPeer()
   self.peerAddr = "%s:%d" % (peer.host, peer.port)
   log.query("%s connected" % self.peerAddr)
   self.unpickler = get_unpickler(insecure=settings.USE_INSECURE_UNPICKLER)
예제 #12
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')
예제 #13
0
 def connectionMade(self):
   peer = self.transport.getPeer()
   self.peerAddr = "%s:%d" % (peer.host, peer.port)
   log.query("%s connected" % self.peerAddr)