Example #1
0
 def start(self):
     if self.listeners:
         raise AssertionError('WSGIServer.start() cannot be called more than once')
     sock = HTTPServer.start(self, self.address, backlog=self.backlog)
     self.address = sock.getsockname()
     env = self.base_env.copy()
     env.update( {'SERVER_NAME': socket.getfqdn(self.server_host),
                  'SERVER_PORT': str(self.server_port) } )
     self.base_env = env
     return sock
Example #2
0
 def start(self):
     if self.listeners:
         raise AssertionError(
             'WSGIServer.start() cannot be called more than once')
     sock = HTTPServer.start(self, self.address, backlog=self.backlog)
     self.address = sock.getsockname()
     env = self.base_env.copy()
     env.update({
         'SERVER_NAME': socket.getfqdn(self.server_host),
         'SERVER_PORT': str(self.server_port)
     })
     self.base_env = env
     return sock
Example #3
0
                  ', 100ms<t<1s: ' + str(mysql_stat["ttl100ms1s"]) + \
                  ', 1s<t<10s: ' + str(mysql_stat["ttl1s10s"]) + \
                  ', 10s<t: ' + str(mysql_stat["ttlmore10s"]) + "\n"
            i += 1
        request.add_output_header('Connection', 'close')
        request.add_output_header('Content-type', 'text/plain')
        request.add_output_header('Content-length', str(len(msg)))
        request.send_reply(200, 'OK', msg)
    pass

def process_stats():
    print "This is a stats processing thread"
    while True:
        time.sleep(60)
        print "Let's process stats"

setproctitle("yybal")
mysql_stats = []
# The connection state should not be defined globally, it should be isolated at a connection level
# to prevent situations when a server becomes alive for not properly initialized conns
# We use this global state for reporting only
#       Question: what to do with persistent connections?
mysql_stats.append({"globalstate":"alive", "numqueries":0, "ttlless1ms":0, "ttl1ms10ms":0, "ttl10ms100ms":0, "ttl100ms1s":0, "ttl1s10s":0, "ttlmore10s":0})
mysql_stats.append({"globalstate":"alive", "numqueries":0, "ttlless1ms":0, "ttl1ms10ms":0, "ttl10ms100ms":0, "ttl100ms1s":0, "ttl1s10s":0, "ttlmore10s":0})
thread.start_new_thread(process_stats, ())
gevent.monkey.patch_socket()
statsserver = HTTPServer(('', 9080), stathandler)
statsserver.start()
server = StreamServer(('127.0.0.1', 33306), handle) # creates a new server
server.serve_forever() # start accepting new connections