Changeset 857 for trunk/Monitoring


Ignore:
Timestamp:
05/15/13 15:25:03 (11 years ago)
Author:
jripsl
Message:
  • start database communication implementation.
  • add usleep( 200 000 ) in CNClient to prevent overflow on the server side.
Location:
trunk/Monitoring
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Monitoring/CNClient

    • Property svn:ignore set to
      sendAMQPMsg
  • trunk/Monitoring/CNClient/send_AMQP_msg.c

    r854 r857  
    260260      case 'e': 
    261261        fprintf(stderr, "Usage: amqp_producer host port rate_limit message_count\n"); 
    262         fprintf(stderr, "Example 1: ./sendAMQPMsg -h localhost -p 5672 -b '{\"jobid\":\"toto\"}'\n"); 
     262 
     263        fprintf(stderr, "Example 1: ./sendAMQPMsg -h localhost -p 5672 -b 'eyJqb2JpZCI6InRvdG8iLCJjb2RlIjoiMDAwMCJ9Cg=='\n"); 
     264 
     265        // obsolete (from now all sent data must be B64 encoded) 
    263266        fprintf(stderr, "Example 2: ./sendAMQPMsg -h localhost -p 5672 -f /home/foobar/config.card -b '{\"jobid\":\"toto\"}'\n"); 
     267 
     268        fprintf(stderr, "Example 3: ./sendAMQPMsg -h localhost -p 5672 -b 'am9iaWQ6dG90byBjb2RlOjAwMDAK' -f ../sample/config.card.base64\n"); 
    264269        exit(0); 
    265270      case 'f': 
     
    363368    free(buf); 
    364369 
     370 
     371  //this is to prevent overwhelming rabbitMQ server (and to prevent triggering rabbitMQ defensive behaviours (e.g. connection blocking)) 
     372  usleep( 200 000 ); // O.2 second 
     373 
     374 
    365375  return 0; 
    366376} 
  • trunk/Monitoring/Watch/watch

    r854 r857  
    1818import json 
    1919import sys 
     20import signal 
    2021import traceback 
    2122import smtplib 
    2223from email.mime.text import MIMEText 
     24from datetime import datetime 
     25 
     26 
     27 
     28 
     29sys.path.append("/home/jripsl/snapshot/src")  
     30import elixir 
     31import prodiguer_repository 
     32 
     33#import prodiguer_repository.operations.mq_hooks_stub as mq_hooks 
     34import prodiguer_repository.operations.mq_hooks as mq_hooks 
     35 
     36 
     37 
     38""" 
     39mq_hooks.retrieve_simulation(name) 
     40mq_hooks.delete_simulation(name) 
     41mq_hooks.create_simulation(activity, 
     42mq_hooks.update_simulation_status(name, 
     43mq_hooks.retrieve_messages(name) 
     44mq_hooks.delete_messages(name) 
     45""" 
     46 
     47""" 
     48from prodiguer_repository.models import ( 
     49        ExecutionState, 
     50        EXECUTION_STATE_RUNNING, 
     51        EXECUTION_STATE_SET, 
     52        Message, 
     53        Simulation, 
     54        SIMULATION_SPACE_TEST 
     55) 
     56""" 
     57 
     58 
     59 
     60""" 
     61scenarios from ticket 136 
     62 
     63libIGCM simulent des erreurs (killed, segfault, 1% d'erreur) 
     64le watcher temps réel change le status des erreurs détéctés 
     65le watcher temps différé détécte et change le statut des killed  
     66""" 
    2367 
    2468class Watcher(): 
    25         message_code_action_mapping = {"0000":["log","mail"],"1000":["log"],"2000":["log"],"3000":["log"],"9000":["log"],"9999":["log","mail"]} 
     69        # prod 
     70        #message_code_action_mapping = {"0000":["log","mail"],"1000":["log"],"2000":["log"],"3000":["log"],"9000":["log"],"9999":["log","mail"]} 
     71 
     72        # dev 
     73        message_code_action_mapping = {"0000":["log","print_stdout"],"1000":[],"2000":[],"3000":[],"9000":["log"],"9999":["log"]} 
     74        #message_code_action_mapping = {"0000":[],"1000":[],"2000":[],"3000":[],"9000":["log"],"9999":["log"]} 
     75 
     76        # debug 
     77        #message_code_action_mapping = {"0000":["print_stdout"],"1000":["log"],"2000":[],"3000":[],"9000":["log"],"9999":["log"]} 
    2678 
    2779        @classmethod 
     
    68120 
    69121        @classmethod 
     122        def print_stdout(cls,message): 
     123                # used for debug 
     124 
     125                if "file" in message: 
     126                        print "%s %s %s\n"%(message["code"],message["jobid"],message["file"]) 
     127                else: 
     128                        print "%s %s\n"%(message["code"],message["jobid"]) 
     129 
     130        @classmethod 
    70131        def log(cls,message): 
    71132 
    72133                with open("/home/jripsl/supervisor/log/supervisor.log", "a") as log_file: 
    73                         log_file.write("%s %s\n"%(message["code"],message["jobid"])) 
     134                        log_file.write("%s %s %s\n"%(datetime.now().strftime('%Y%m%d_%H%M%S'), message["code"],message["jobid"])) 
    74135 
    75136        @classmethod 
     
    88149                                raise Exception("WATCH-ERR002","procedure error (%s,%s)"%(proc_name,str(e))) 
    89150 
    90 def main(): 
    91  
    92         """ 
    93         # parse args 
    94         parser = argparse.ArgumentParser(prog='watcher') 
    95         parser.add_argument('-v', dest='verbose',required=False,action='store_true') 
    96         args = parser.parse_args() 
    97  
    98         # check 
    99         if not os.path.exists(SMON.smon_home): 
     151        @classmethod 
     152        def main(self): 
     153 
     154                """ 
     155                _CONNECTION = "postgresql://postgres:Silence107!@localhost:5432/prodiguer" # Repo connection string. 
     156                prodiguer_repository.connect(_CONNECTION) # Connect to repo. 
     157                mq_hooks.create_message("test", 2, "bla") 
     158                elixir.session.commit() 
     159                #elixir.session.rollback() 
     160                """ 
     161                mq_hooks.create_message() 
     162 
     163                """ 
     164                # parse args 
     165                parser = argparse.ArgumentParser(prog='watcher') 
     166                parser.add_argument('-v', dest='verbose',required=False,action='store_true') 
     167                args = parser.parse_args() 
     168 
     169                # check 
     170                if not os.path.exists(SMON.smon_home): 
     171                        sys.exit(1) 
     172 
     173                SMON.init_singleton() 
     174                """ 
     175 
     176                connection = pika.BlockingConnection(pika.ConnectionParameters( host='localhost')) 
     177                self.channel = connection.channel() 
     178 
     179                #self.channel.queue_declare(queue='myqueue') 
     180 
     181                print ' [*] Waiting for messages. To exit press CTRL+C' 
     182 
     183                def callback(ch, method, properties, raw_msg): 
     184                        # 
     185                        #return 
     186 
     187                        base64_decoded_msg=base64.b64decode(raw_msg) 
     188 
     189                        # debug 
     190                        #print " [x] Received %s" % raw_msg 
     191                        #print " [x] Received %s (uudecoded)" % base64_decoded_msg  
     192 
     193                        message=None 
     194                        try: 
     195                                message=json.loads(base64_decoded_msg) 
     196 
     197                                # message code based action 
     198                                Watcher.execActions(message) 
     199                        except Exception,e: 
     200                                print "Exception occurs (exception=%s,msg=%s)"%(str(e),base64_decoded_msg) 
     201 
     202                self.channel.basic_consume(callback, queue='myqueue', no_ack=True) 
     203 
     204                self.channel.start_consuming() 
     205 
     206 
     207                """ 
     208                SMON.free_singleton() 
     209                """ 
     210 
     211def signal_handler(signal, frame): 
     212                print 'You pressed Ctrl+C!' 
     213                Watcher.channel.stop_consuming() 
     214                sys.exit(0) 
     215 
     216if __name__ == '__main__': 
     217 
     218        signal.signal(signal.SIGINT, signal_handler) 
     219        #print 'Press Ctrl+C' 
     220 
     221        try: 
     222                Watcher.main() 
     223 
     224                sys.exit(0) 
     225 
     226        except Exception, e: 
     227 
     228                traceback.print_exc() 
     229 
    100230                sys.exit(1) 
    101  
    102         SMON.init_singleton() 
    103         """ 
    104  
    105         connection = pika.BlockingConnection(pika.ConnectionParameters( host='localhost')) 
    106         channel = connection.channel() 
    107  
    108         #channel.queue_declare(queue='myqueue') 
    109  
    110         print ' [*] Waiting for messages. To exit press CTRL+C' 
    111  
    112         def callback(ch, method, properties, raw_msg): 
    113                 # 
    114                 #return 
    115  
    116                 base64_decoded_msg=base64.b64decode(raw_msg) 
    117  
    118                 # debug 
    119                 #print " [x] Received %s" % raw_msg 
    120                 #print " [x] Received %s (uudecoded)" % base64_decoded_msg  
    121  
    122                 try: 
    123                         message=json.loads(base64_decoded_msg) 
    124                 except Exception,e: 
    125                         print base64_decoded_msg 
    126                  
    127                 # message code based action 
    128                 Watcher.execActions(message) 
    129  
    130         channel.basic_consume(callback, queue='myqueue', no_ack=True) 
    131  
    132         channel.start_consuming() 
    133  
    134  
    135         """ 
    136         SMON.free_singleton() 
    137         """ 
    138  
    139 if __name__ == '__main__': 
    140         try: 
    141                 main() 
    142  
    143                 sys.exit(0) 
    144  
    145         except Exception, e: 
    146  
    147                 traceback.print_exc() 
    148  
    149                 sys.exit(1) 
  • trunk/Monitoring/doc/README

    r854 r857  
    99                - Virtualenv installation 
    1010                        - TODO: add virtual env install instructions here 
    11                 - libraries installation 
    12                         - cd /opt 
    13                         - cd python2.6_ve/ 
    14                         - cd bin 
    15                         - source activate 
    16                         - pip install pika         # RabbitMQ client library 
    17                         - pip install Sqlalchemy 
    18                         - pip install elixir 
     11                - Python PYPI libraries installation 
     12                        - procedure (as root) 
     13                                - cd /opt 
     14                                - cd python2.6_ve/ 
     15                                - cd bin 
     16                                - source activate 
     17                                - pip install <package name> 
     18                        - packages list 
     19                                - packages below are needed by SMON 
     20                                        - pip install pika # RabbitMQ client library 
     21                                - packages below are needed by Prodiguer library 
     22                                        - 
     23                                                - pip install Sqlalchemy 
     24                                                - pip install elixir 
     25                                                - pip install simplejson 
     26                                        - note: some Elixir/SQLAlchemy versions are not compatible. 
     27                                          to be sure, you can use version below which are compatible 
     28                                                - Elixir-0.7.1-py2.6.egg-info 
     29                                                - SQLAlchemy-0.7.8-py2.6.egg-info 
     30                - Prodiguer library installation 
     31                        - svn co svn+ssh://<login here>@forge.ipsl.jussieu.fr/ipsl/forge/projets/prodiguer/svn/sw/src/python/trunk/prodiguer_repository/src 
     32                        - edit "watch" script and edit line below accordingly 
     33                                - sys.path.append("/home/jripsl/snapshot/src")  
Note: See TracChangeset for help on using the changeset viewer.