コード例 #1
0
def initialize():
    global HOST
    global PORT

    # if DEV_MODE use defaults
    if not DEV_MODE:
        
        if not (tcp_bridge_conf and tcp_bridge_conf.enabled()):
            print >> sys.stderr, 'not enabled, or tcp_bridge_conf unavilable'
            sys.exit(13)

        # override local vars if available
        if tcp_bridge_conf.port():
            PORT = tcp_bridge_conf.port()

        if tcp_bridge_conf.host():
            HOST = tcp_bridge_conf.host()

    mydrop()

    # open watch after drop privs
    global watch
    if WATCH_ENABLE:
        watch = open(WATCHFILE, 'w', 0)

    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.bind((HOST, PORT))
        sock.listen(1)

    except socket.error, msg:
        print >> sys.stderr, 'could not open socket: %s' % msg
        sys.exit(1)
コード例 #2
0
ファイル: tcp_bridge.py プロジェクト: anrs/tcollector
def main():
    if not (tcp_bridge_conf and tcp_bridge_conf.enabled()):
        print >> sys.stderr, 'not enabled, or tcp_bridge_conf unavilable'
        sys.exit(13)
    utils.drop_privileges()

    def printm(string, time, value):
        out.write(m_namespace+string+' '+str(time)+' '+str(value)+'\n')

    def printmetrics():
        global m_delay
        global m_last

        ts = int(time.time())
        if ts > m_last+m_delay:
            printm('lines_read', ts, m_lines)
            printm('connections_processed', ts, m_connections)
            printm('processing_time', ts, m_ptime)
            printm('active', ts, 1)
            m_last = ts

    def clientthread(connection):
        global m_lines
        global m_connections
        global m_ptime

        start = time.time()
        f = connection.makefile()
        while True:
            data = f.readline()

            if not data:
                break

            data = removePut(data)
            out.write(data)
            m_lines += 1

        f.close()
        connection.close()

        end = time.time()
        m_ptime += (end - start)
        m_connections += 1
        printmetrics()

    def removePut(line):
        if line.startswith('put '):
            return line[4:]
        else:
            return line

    try:
        if tcp_bridge_conf.port():
            PORT = tcp_bridge_conf.port()

        if tcp_bridge_conf.host():
            HOST = tcp_bridge_conf.host()

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.bind((HOST, PORT))
        sock.listen(1)

    except socket.error, msg:
        utils.err('could not open socket: %s' % msg)
        sys.exit(1)
コード例 #3
0
ファイル: tcp_bridge.py プロジェクト: wangy1931/tcollector
def main():
    if not (tcp_bridge_conf and tcp_bridge_conf.enabled()):
        print >> sys.stderr, 'not enabled, or tcp_bridge_conf unavilable'
        sys.exit(13)
    with utils.lower_privileges(self._logger):

        def printm(string, time, value):
            out.write(m_namespace+string+' '+str(time)+' '+str(value)+'\n')

        def printmetrics():
            global m_delay
            global m_last

            ts = int(time.time())
            if ts > m_last+m_delay:
                printm('lines_read', ts, m_lines)
                printm('connections_processed', ts, m_connections)
                printm('processing_time', ts, m_ptime)
                printm('active', ts, 1)
                m_last = ts

        def clientthread(connection):
            global m_lines
            global m_connections
            global m_ptime

            start = time.time()
            f = connection.makefile()
            while True:
                data = f.readline()

                if not data:
                    break

                data = removePut(data)
                out.write(data)
                m_lines += 1

            f.close()
            connection.close()

            end = time.time()
            m_ptime += (end - start)
            m_connections += 1
            printmetrics()

        def removePut(line):
            if line.startswith('put '):
                return line[4:]
            else:
                return line

        try:
            if tcp_bridge_conf.port():
                PORT = tcp_bridge_conf.port()

            if tcp_bridge_conf.host():
                HOST = tcp_bridge_conf.host()

            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.bind((HOST, PORT))
            sock.listen(1)

        except socket.error, msg:
            utils.err('could not open socket: %s' % msg)
            sys.exit(1)

        try:
            flush_delay = tcp_bridge_conf.flush_delay()
        except AttributeError:
            flush_delay = 60

        try:
            try:
                while 1:
                    connection, address = sock.accept()
                    start_new_thread(clientthread, (connection,))

            except KeyboardInterrupt:
                utils.err("keyboard interrupt, exiting")

        finally:
            sock.close()
コード例 #4
0
def main():
    if not (tcp_bridge_conf and tcp_bridge_conf.enabled()):
        print >> sys.stderr, 'not enabled, or tcp_bridge_conf unavilable'
        sys.exit(13)
    with utils.lower_privileges(self._logger):

        def printm(string, time, value):
            out.write(m_namespace + string + ' ' + str(time) + ' ' +
                      str(value) + '\n')

        def printmetrics():
            global m_delay
            global m_last

            ts = int(time.time())
            if ts > m_last + m_delay:
                printm('lines_read', ts, m_lines)
                printm('connections_processed', ts, m_connections)
                printm('processing_time', ts, m_ptime)
                printm('active', ts, 1)
                m_last = ts

        def clientthread(connection):
            global m_lines
            global m_connections
            global m_ptime

            start = time.time()
            f = connection.makefile()
            while True:
                data = f.readline()

                if not data:
                    break

                data = removePut(data)
                out.write(data)
                m_lines += 1

            f.close()
            connection.close()

            end = time.time()
            m_ptime += (end - start)
            m_connections += 1
            printmetrics()

        def removePut(line):
            if line.startswith('put '):
                return line[4:]
            else:
                return line

        try:
            if tcp_bridge_conf.port():
                PORT = tcp_bridge_conf.port()

            if tcp_bridge_conf.host():
                HOST = tcp_bridge_conf.host()

            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.bind((HOST, PORT))
            sock.listen(1)

        except socket.error, msg:
            utils.err('could not open socket: %s' % msg)
            sys.exit(1)

        try:
            flush_delay = tcp_bridge_conf.flush_delay()
        except AttributeError:
            flush_delay = 60

        try:
            try:
                while 1:
                    connection, address = sock.accept()
                    start_new_thread(clientthread, (connection, ))

            except KeyboardInterrupt:
                utils.err("keyboard interrupt, exiting")

        finally:
            sock.close()
コード例 #5
0
ファイル: tcp_bridge.py プロジェクト: rshivane/xcollector
def main():
    if not (tcp_bridge_conf and tcp_bridge_conf.enabled()):
        print >> sys.stderr, 'not enabled, or tcp_bridge_conf unavilable'
        sys.exit(13)
    utils.drop_privileges()

    def printm(string, time, value):
        out.write(m_namespace + string + ' ' + str(time) + ' ' + str(value) +
                  '\n')

    def printmetrics():
        global m_delay
        global m_last

        ts = int(time.time())
        if ts > m_last + m_delay:
            printm('lines_read', ts, m_lines)
            printm('connections_processed', ts, m_connections)
            printm('processing_time', ts, m_ptime)
            printm('active', ts, 1)
            m_last = ts

    def clientthread(connection):
        global m_lines
        global m_connections
        global m_ptime

        start = time.time()
        f = connection.makefile()
        while True:
            data = f.readline()

            if not data:
                break

            data = removePut(data)
            out.write(data)
            m_lines += 1

        f.close()
        connection.close()

        end = time.time()
        m_ptime += (end - start)
        m_connections += 1
        printmetrics()

    def removePut(line):
        if line.startswith('put '):
            return line[4:]
        else:
            return line

    try:
        if tcp_bridge_conf.port():
            PORT = tcp_bridge_conf.port()

        if tcp_bridge_conf.host():
            HOST = tcp_bridge_conf.host()

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.bind((HOST, PORT))
        sock.listen(1)

    except socket.error, msg:
        utils.err('could not open socket: %s' % msg)
        sys.exit(1)