def read_rules(self): if not exists(self.rules_file): self.clear() return # Only read if the rules file has been modified try: mtime = getmtime(self.rules_file) except OSError: log.err("Failed to get mtime of %s" % self.rules_file) return if mtime <= self.rules_last_read: return # Read new rules log.aggregator("reading new aggregation rules from %s" % self.rules_file) new_rules = [] for line in open(self.rules_file): line = line.strip() if line.startswith('#') or not line: continue rule = self.parse_definition(line) new_rules.append(rule) log.aggregator("clearing aggregation buffers") BufferManager.clear() self.rules = new_rules self.rules_last_read = mtime
def send(self, metric, datapoint): if len(self.queue) >= settings.MAX_QUEUE_SIZE: log.aggregator('send queue full for %s, dropping data' % self.remoteAddr) elif self.connectedProtocol: self.connectedProtocol.send(metric, datapoint) else: self.queue.append( (metric, datapoint) )
def send(self, metric, datapoint): if len(self.queue) >= settings.MAX_QUEUE_SIZE: log.aggregator('send queue full for %s, dropping data' % self.remoteAddr) elif self.connectedProtocol: self.connectedProtocol.send(metric, datapoint) else: self.queue.append((metric, datapoint))
def clientConnectionFailed(self, connector, reason): ReconnectingClientFactory.clientConnectionFailed(self, connector, reason) log.aggregator("connection attempt to %s failed: %s" % (self.remoteAddr, reason.value))
def clientConnectionLost(self, connector, reason): ReconnectingClientFactory.clientConnectionLost(self, connector, reason) self.connectedProtocol = None log.aggregator("connection to %s lost: %s" % (self.remoteAddr, reason.value))
def buildProtocol(self, addr): log.aggregator('connection to %s established' % self.remoteAddr) self.connectedProtocol = MetricPickleSender() self.connectedProtocol.factory = self self.connectedProtocol.queue = self.queue return self.connectedProtocol
def startedConnecting(self, connector): log.aggregator('connecting to %s' % self.remoteAddr)
def get_buffer(self, metric_path): if metric_path not in self.buffers: log.aggregator("Allocating new buffer for %s" % metric_path) self.buffers[metric_path] = AggregationBuffer(metric_path) return self.buffers[metric_path]
def get_buffer(self, metric_path): if metric_path not in self.buffers: log.aggregator("Allocating new metric buffer for %s" % metric_path) self.buffers[metric_path] = MetricBuffer(metric_path) return self.buffers[metric_path]
def clientConnectionFailed(self, connector, reason): ReconnectingClientFactory.clientConnectionFailed( self, connector, reason) log.aggregator("connection attempt to %s failed: %s" % (self.remoteAddr, reason.value))