prometheus - How to stop a server over a particular period of time in python -
logfile = '/testprometheus/pushgateway.log' formatter = logging.formatter('%(asctime)s %(levelname)s %(message)s') hdlr = logging.handlers.rotatingfilehandler(logfile,mode='a', maxbytes=5*1024*1024, backupcount=2, encoding=none, delay=0) hdlr.setformatter(formatter) hdlr.setlevel(logging.info) logger = logging.getlogger('pushgateway') logger.setlevel(logging.info) logger.addhandler(hdlr) global alertlistsend class prometheusalert(basehttprequesthandler): def do_post(self): try: self.send_response(200) self.end_headers() data = self.rfile.read(int(self.headers['content-length'])) alertlist = json.loads(data) logger.info(alertlistsend) alertlistriggered=[] item,alertvalue in enumerate (alertlist): labels = alertvalue["labels"] name = str(labels["alertname"]) print name alertlistriggered.append(name) #break logger.info("alerts fired") logger.info(alertlistriggered) time.sleep(100) http.server_close() return except exception e: error_string = str(e) logger.critical("unable connect server " + error_string) return if __name__ == '__main__': print "script started" os.system("sudo python test_pushgateway.py") #counter=1 httpd = httpserver(('', 9334), prometheusalert) logger.info("server started") alertlistsend=["a","b","c"] logger.info("alerts send") logger.info(alertlistsend) #counter+=1 print "server started working" httpd.serve_forever() logger.info("done")
//i trying list down alerts send prometheus. problem these code.the code running infinite times.i want execute post method execute 5 mins , come out of post method , print "done".but unable so.
Comments
Post a Comment