def flush(self): ts = flatten([x for x in self.timing.values()]) avg = 1000 * sum(ts) / len(ts) es = [] self.addEvent(es, 'dns_average', avg) self.addEvent(es, 'dns_max', 1000 * max(ts)) self.addEvent(es, 'dns_count', len(ts)) self.addEvent(es, 'dns_orphans', self.orphans) msg = bernhard.Message(events=es) self.riemann.transmit(msg)
def send(n, msgs): raw = encoded_events(n) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(('localhost', 5555)) buff = struct.pack('!I', len(raw)) + raw for i in range(0, msgs): sock.sendall(buff) received = 0 for i in range(0, msgs): rxlen = struct.unpack('!I', sock.recv(4, socket.MSG_WAITALL))[0] msg = bernhard.Message(raw=sock.recv(rxlen, socket.MSG_WAITALL)) assert (msg.ok) received += 1 print "ok: %i" % received
def send(self, events): message = bernhard.Message(events=[bernhard.Event(params=e) for e in events]) response = self.transmit(message) return response.ok
def encoded_events(n): msg = bernhard.Message(events=events(n)) return msg.raw