Changeset 940 for trunk/Monitoring/Watch
- Timestamp:
- 08/26/13 09:45:18 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Monitoring/Watch/watch
r937 r940 22 22 from email.mime.text import MIMEText 23 23 import datetime 24 import logging 24 25 25 26 # line below is to include "smon" package in the search path … … 31 32 CSTE_BROKER_HOST='cstest-broker.ipsl.jussieu.fr' # cstest 32 33 #CSTE_BROKER_HOST='localhost' # vesg4 34 CSTE_LOG_DIR='/var/log/cssupervisor' 35 CSTE_LOG_FILENAME_MAIN='supervisor.log' 36 CSTE_LOG_FILENAME_DEBUG='debug.log' 37 CSTE_LOG_FILENAME_MSG='message.log' # log AMQP msgs 38 CSTE_LOG_FILE_MAIN="%s/%s"%(CSTE_LOG_DIR,CSTE_LOG_FILENAME_MAIN) 39 40 # logger init. 41 logging.basicConfig(filename=CSTE_LOG_FILE_MAIN,level=logging.INFO,) 42 33 43 34 44 class Mail(): … … 116 126 simulation=smon.types.Simulation(name=message.simuid,status="running") 117 127 118 119 128 repo_io.create_simulation(simulation) 120 129 … … 124 133 125 134 @classmethod 126 def print_stdout(cls,message): 127 # used for debug 135 def log_debug(cls,line): 136 cls.log(CSTE_LOG_FILENAME_DEBUG,line) 137 138 @classmethod 139 def log(cls,filename,line): 140 with open("%s/%s"%(CSTE_LOG_DIR,filename), "a") as log_file: 141 log_file.write("%s %s\n"%(datetime.datetime.now().strftime('%Y%m%d_%H%M%S'), line)) 142 143 @classmethod 144 def log_msg(cls,message): 145 line="%s %s %s %s"%(message.code,message.jobid,message.timestamp,message.command) 146 cls.log(CSTE_LOG_FILENAME_MSG,line) 128 147 129 148 """ 130 149 if message.file is not None: 131 print"%s %s %s %s %s\n"%(message.code,message.jobid,message.command,message.timestamp,message.file)150 "%s %s %s %s %s\n"%(message.code,message.jobid,message.command,message.timestamp,message.file) 132 151 else: 133 print "%s %s %s %s\n"%(message.code,message.jobid,message.command,message.timestamp) 134 """ 135 136 print "%s %s %s %s\n"%(message.code,message.jobid,message.command,message.timestamp) 137 #pass 138 139 @classmethod 140 def log(cls,message): 141 with open("/opt/supervisor/log/supervisor.log", "a") as log_file: 142 log_file.write("%s %s %s %s %s\n"%(datetime.datetime.now().strftime('%Y%m%d_%H%M%S'), message.code,message.jobid,message.timestamp,message.command)) 152 "%s %s %s %s\n"%(message.code,message.jobid,message.command,message.timestamp) 153 """ 143 154 144 155 @classmethod … … 163 174 # TAG0001: note that crea_sim must be BEFORE store_msg in the list (because when we insert the msg, we need the simu_id) 164 175 # 165 mapping = { "0000":["crea_sim", "log ", "store_msg", "print_stdout"],166 "0100":["log ", "store_msg", "print_stdout", "set_sim_status_to_complete"],167 "1000":["log ", "store_msg", "print_stdout"],168 "1100":["log ", "store_msg", "print_stdout"],169 "2000":["log ", "store_msg", "print_stdout"],170 "3000":["log ", "store_msg", "print_stdout"],176 mapping = { "0000":["crea_sim", "log_msg", "store_msg"], 177 "0100":["log_msg", "store_msg", "set_sim_status_to_complete"], 178 "1000":["log_msg", "store_msg"], 179 "1100":["log_msg", "store_msg"], 180 "2000":["log_msg", "store_msg"], 181 "3000":["log_msg", "store_msg"], 171 182 "8888":["cleanup"], 172 "9000":["log ", "store_msg", "print_stdout"],173 "9999":["log ", "store_msg", "print_stdout", "set_sim_status_to_error"] }183 "9000":["log_msg", "store_msg"], 184 "9999":["log_msg", "store_msg", "set_sim_status_to_error"] } 174 185 175 186 # prod … … 178 189 # 179 190 """ 180 mapping = { "0000":["crea_sim", "log ", "store_msg"],181 "0100":["log ", "store_msg", "set_sim_status_to_complete"],182 "1000":["log ", "store_msg"],183 "1100":["log ", "store_msg"],184 "2000":["log ", "store_msg"],185 "3000":["log ", "store_msg"],191 mapping = { "0000":["crea_sim", "log_msg", "store_msg"], 192 "0100":["log_msg", "store_msg", "set_sim_status_to_complete"], 193 "1000":["log_msg", "store_msg"], 194 "1100":["log_msg", "store_msg"], 195 "2000":["log_msg", "store_msg"], 196 "3000":["log_msg", "store_msg"], 186 197 "8888":["cleanup"], 187 "9000":["log ", "store_msg", "mail"],188 "9999":["log ", "store_msg", "set_sim_status_to_error", "mail"] }198 "9000":["log_msg", "store_msg", "mail"], 199 "9999":["log_msg", "store_msg", "set_sim_status_to_error", "mail"] } 189 200 """ 190 201 … … 218 229 self.channel = connection.channel() 219 230 220 221 print ' [*] Waiting for messages. To exit press CTRL+C' 231 logging.info("[*] Waiting for messages") 222 232 223 233 def callback(ch, method, properties, raw_msg): … … 237 247 238 248 # debug 239 # print " [x] Received %s" % field249 #logging.debug(" [x] Received %s"%field) 240 250 241 251 splitted_field=field.split(":") … … 248 258 249 259 # debug 250 # print " [x] Received %s (encoded)" % l__tmp_dic["body"]260 #logging.debug(" [x] Received %s (encoded)" % l__tmp_dic["body"]) 251 261 252 262 … … 256 266 257 267 # debug 258 # print " [x] Received %s" % raw_msg259 # print " [x] Received %s (uudecoded)" % base64_decoded_msg260 # print " [x] Received %s (uudecoded)" % base64_decoded_msg268 #logging.debug(" [x] Received %s" % raw_msg) 269 #logging.debug(" [x] Received %s (uudecoded)" % base64_decoded_msg ) 270 #logging.debug(" [x] Received %s (uudecoded)" % base64_decoded_msg ) 261 271 262 272 … … 268 278 269 279 # non working 270 # print message.type280 #logging.debug("DEB003 - %s"%message.type) 271 281 272 282 # working 273 # print message.code283 #logging.debug("DEB009 - %s"%message.code) 274 284 275 285 276 286 277 287 except Exception,e: 278 print "ERR009 - exception occurs (exception=%s,msg=%s)"%(str(e),base64_decoded_msg) 279 280 traceback.print_exc() 288 289 logging.exception("ERR009 - exception occurs (exception=%s)"%(str(e),)) 290 291 Actions.log_debug("DEB021 - %s"%base64_decoded_msg) 292 281 293 raise 282 294 … … 301 313 302 314 except Exception,e: 303 print "ERR019 - exception occurs (exception=%s)"%(str(e)) 304 #print "ERR019 - exception occurs (exception=%s,msg=%s)"%(str(e),base64_decoded_msg) 305 306 traceback.print_exc() 315 logging.exception("ERR019 - exception occurs (exception=%s)"%(str(e),)) 316 317 Actions.log_debug("DEB020 - %s"%base64_decoded_msg) 307 318 308 319 raise … … 324 335 325 336 def signal_handler(signal, frame): 326 print 'You pressed Ctrl+C!'337 logging.info("TERM signal received: exiting.") 327 338 Watcher.channel.stop_consuming() 328 339 Watcher.stop() … … 331 342 if __name__ == '__main__': 332 343 344 signal.signal(signal.SIGTERM, signal_handler) 333 345 signal.signal(signal.SIGINT, signal_handler) 334 346 … … 348 360 349 361 sys.exit(1) 362 # vim: set ts=4 sw=4 :
Note: See TracChangeset
for help on using the changeset viewer.