Ignore:
Timestamp:
06/12/13 11:14:57 (11 years ago)
Author:
jripsl
Message:

Timeout test impl.
Add timestamp.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Monitoring/Analyze/analyze

    r859 r876  
    2121from datetime import datetime 
    2222 
    23 from smon import repo_io 
     23 
     24# line below is to include "smon" package in the search path 
     25sys.path.append("/home/jripsl/snapshot/Monitoring") 
     26 
     27import smon.repo_io as repo_io 
     28import smon.types as types 
    2429 
    2530 
    26  
    27 """ 
    28 Code list reminder 
    29  
    30 0000 (la simulation démarre) 
    31 1000 (le job d'une simulation démarre) 
    32 2000 (PushStack) 
    33 3000 (PopStack OK) 
    34 9000 (PopStack NOK) 
    35 9999 (FATAL) 
    36 """ 
    3731 
    3832class CheckList(): 
     
    5246                diff=current_time-msg_time 
    5347 
     48                # debug 
     49                print "diff=%s"%diff 
    5450 
    5551                if diff>cls.max_time_between_msg: 
     
    6864                  changing the simulation status  
    6965                """ 
    70                 running_simulations=repo_io.get_running_simulations() 
    71                 for simulation in running_simulations: 
    72                         message=repo_io.retrieve_last_messages(simulation) 
     66 
     67 
     68                for simulation in repo_io.get_running_simulations(): 
     69 
     70                        print "checking heartbeat for '%s'"%simulation.name 
     71 
     72                        try: 
     73 
     74                                message=repo_io.retrieve_last_message(simulation) 
     75                        except types.MessageNotFoundException, e: 
     76 
     77                                continue 
     78 
    7379 
    7480                        if msg_timeout(message): 
    7581 
    76                                 repo_io.update_simulation_status(simulation) #from "running" to "killed" 
     82                                simulation.status="error" 
     83 
     84                                repo_io.update_simulation_status(simulation) 
     85 
     86                                print "heartbeat NOK (simulation status set to 'error')"%simulation.name 
     87 
     88 
     89                        else: 
     90                                print "heartbeat OK"%simulation.name 
    7791 
    7892class Analyzer(): 
     
    8094        @classmethod 
    8195        def start(cls): 
    82                 pass 
     96                repo_io.init() # open DB connection 
     97 
     98                Analyzer.main() 
    8399 
    84100        @classmethod 
    85101        def stop(cls): 
    86                 pass 
     102                repo_io.free() # close DB connection 
    87103 
    88104        @classmethod 
     
    104120                print ' [*] Analyzer running. To exit press CTRL+C' 
    105121 
    106                 CheckList.C0001() 
     122                while True: 
     123 
     124                        print "checking simulations heartbeats" 
     125 
     126                        CheckList.C0001() 
    107127 
    108128 
    109                 sleep(10) 
     129                        time.sleep(1) 
    110130 
    111131                """ 
     
    115135def signal_handler(signal, frame): 
    116136                print 'You pressed Ctrl+C!' 
     137 
     138                Analyzer.stop() 
     139 
    117140                sys.exit(0) 
    118141 
     
    122145 
    123146        try: 
    124                 Analyzer.main() 
     147                Analyzer.start() 
    125148 
    126149                sys.exit(0) 
Note: See TracChangeset for help on using the changeset viewer.