try: import gevent.subprocess as subprocess except ImportError: # may block. don't use this when gevent 1.0b3 is released. import subprocess class ExecPipeOutput(BufferedOutput): command = config_param('string') def start(self): preexec = getattr(os, 'setsid', None) self._proc = subprocess.Popen(self.command, shell=True, stdin=subprocess.PIPE, preexec_fn=preexec) super(ExecPipeOutput, self).start() def shutdown(self): super(ExecPipeOutput, self).shutdown() self._proc.stdin.close() self._proc.wait() self._proc = None def write(self, chunk): self._proc.stdin.write(chunk.read()) Plugin.register_output('exec_pipe', ExecPipeOutput)
self._nodes.append((host, port)) log.info("adding forwarding server %s:%s", host, port) def write(self, chunk): key = chunk.key data = chunk.read() log.debug("sending tag=%s data=%dbytes", key, len(data)) for node in self._nodes: try: self.send_data(node, key, data) break except Exception as e: log.warn("fail to send data to %s: %s", node, e) pass else: raise Exception("No nodes are available.") def send_data(self, node, tag, data): sock = socket.socket() header = b"\x92" + msgpack.packb(tag) + b"\xdb" + struct.pack( "!L", len(data)) sock.connect(node) try: sock.sendall(header) sock.sendall(data) finally: sock.close() Plugin.register_output('forward', ForwardOutput)
:license: Apache v2 """ from __future__ import print_function, division, absolute_import, with_statement import logging log = logging.getLogger(__name__) from fluenpy.plugin import Plugin from fluenpy.output import Output from fluenpy.config import config_param from datetime import datetime import json import sys class StdoutOutput(Output): autoflush = config_param('bool', False) def emit(self, tag, es, chain): for t, record in es: dt = datetime.fromtimestamp(t) print("%s %s: %s" % (dt, tag, json.dumps(record))) if self.autoflush: sys.stdout.flush() chain.next() Plugin.register_output('stdout', StdoutOutput)
~~~~~~~~~~~~~~~~~~~~~~~~~~ :copyright: (c) 2012 by INADA Naoki :license: Apache v2 """ from __future__ import print_function, division, absolute_import, with_statement from fluenpy.plugin import Plugin from fluenpy.output import Output from fluenpy.config import config_param from datetime import datetime import json import sys class StdoutOutput(Output): autoflush = config_param('bool', False) def emit(self, tag, es): for t, record in es: dt = datetime.fromtimestamp(t) print("%s %s: %s" % (dt, tag, json.dumps(record))) if self.autoflush: sys.stdout.flush() Plugin.register_output('stdout', StdoutOutput)
port = int(e.get("port", DEFAULT_LISTEN_PORT)) self._nodes.append((host, port)) log.info("adding forwarding server %s:%s", host, port) def write(self, chunk): key = chunk.key data = chunk.read() log.debug("sending tag=%s data=%dbytes", key, len(data)) for node in self._nodes: try: self.send_data(node, key, data) break except Exception as e: log.warn("fail to send data to %s: %s", node, e) pass else: raise Exception("No nodes are available.") def send_data(self, node, tag, data): sock = socket.socket() header = b"\x92" + msgpack.packb(tag) + b"\xdb" + struct.pack("!L", len(data)) sock.connect(node) try: sock.sendall(header) sock.sendall(data) finally: sock.close() Plugin.register_output("forward", ForwardOutput)
# coding: utf-8 """ fluenpy.plugins.out_null ~~~~~~~~~~~~~~~~~~~~~~~~~ :copyright: (c) 2012 by INADA Naoki :license: Apache v2 """ from __future__ import print_function, division, absolute_import, with_statement import logging log = logging.getLogger(__name__) from fluenpy import error from fluenpy.output import Output from fluenpy.plugin import Plugin class NullOutput(Output): def emit(self, tag, es): pass Plugin.register_output('null', NullOutput)
raise error.ConfigError( "Missing 'type' parameter on <store> directive") log.debug("adding store type=%r", type_) output = Plugin.new_output(type_) output.configure(e) self._outputs.append(output) def start(self): for o in self._outputs: o.start() def shutdown(self): for o in self._outputs: try: o.shutdown() except Exception: log.error("Error occured while shutdown:") log.error(traceback.format_exc()) def emit(self, tag, es): for o in self._outputs: try: o.emit(tag, es) except Exception: log.error("Error occured while emit:") log.error(traceback.format_exc()) Plugin.register_output('copy', CopyOutput)
try: import gevent.subprocess as subprocess except ImportError: # may block. don't use this when gevent 1.0b3 is released. import subprocess class ExecPipeOutput(BufferedOutput): command = config_param('string') def start(self): preexec = getattr(os, 'setsid', None) self._proc = subprocess.Popen(self.command, shell=True, stdin=subprocess.PIPE, preexec_fn=preexec) super(ExecPipeOutput, self).start() def shutdown(self): super(ExecPipeOutput, self).shutdown() self._proc.stdin.close() self._proc.wait() self._proc = None def write(self, chunk): self._proc.stdin.write(chunk.read()) Plugin.register_output('exec_pipe', ExecPipeOutput)
if type_ is None: raise error.ConfigError("Missing 'type' parameter on <store> directive") log.debug("adding store type=%r", type_) output = Plugin.new_output(type_) output.configure(e) self._outputs.append(output) def start(self): for o in self._outputs: o.start() def shutdown(self): for o in self._outputs: try: o.shutdown() except Exception: log.error("Error occured while shutdown:") log.error(traceback.format_exc()) def emit(self, tag, es): for o in self._outputs: try: o.emit(tag, es) except Exception: log.error("Error occured while emit:") log.error(traceback.format_exc()) Plugin.register_output('copy', CopyOutput)