Browse Source

[(no branch)] [trac763] log messages for stats.py(.in)

Jelte Jansen 14 years ago
parent
commit
a0209aebd7
2 changed files with 85 additions and 26 deletions
  1. 30 26
      src/bin/stats/stats.py.in
  2. 55 0
      src/bin/stats/stats_messages.mes

+ 30 - 26
src/bin/stats/stats.py.in

@@ -25,12 +25,19 @@ from collections import defaultdict
 from isc.config.ccsession import ModuleCCSession, create_answer
 from isc.config.ccsession import ModuleCCSession, create_answer
 from isc.cc import Session, SessionError
 from isc.cc import Session, SessionError
 
 
+import isc.log
+from stats_messages import *
+
+isc.log.init("b10-stats")
+logger = isc.log.Logger("stats")
+
+# Some constants for debug levels
+DBG_STATS_MESSAGING = 30
+
 # for setproctitle
 # for setproctitle
 import isc.util.process
 import isc.util.process
 isc.util.process.rename()
 isc.util.process.rename()
 
 
-import isc.log
-
 # If B10_FROM_SOURCE is set in the environment, we use data files
 # If B10_FROM_SOURCE is set in the environment, we use data files
 # from a directory relative to that, otherwise we use the ones
 # from a directory relative to that, otherwise we use the ones
 # installed on the system
 # installed on the system
@@ -205,8 +212,7 @@ class CCSessionListener(Listener):
                 kwargs = self.initialize_data(cmd["command_args"])
                 kwargs = self.initialize_data(cmd["command_args"])
                 self.add_event(Callback(name=name, callback=callback, args=(), kwargs=kwargs))
                 self.add_event(Callback(name=name, callback=callback, args=(), kwargs=kwargs))
             except AttributeError as ae:
             except AttributeError as ae:
-                sys.stderr.write("[b10-stats] Caught undefined command while parsing spec file: "
-                                 +str(cmd["command_name"])+"\n")
+                logger.error(STATS_UNKNOWN_COMMAND_IN_SPEC, cmd["command_name"])
 
 
     def start(self):
     def start(self):
         """
         """
@@ -219,8 +225,7 @@ class CCSessionListener(Listener):
         self.stats_data['stats.lname'] = self.session.lname
         self.stats_data['stats.lname'] = self.session.lname
         self.cc_session.start()
         self.cc_session.start()
         # request Bob to send statistics data
         # request Bob to send statistics data
-        if self.verbose:
-            sys.stdout.write("[b10-stats] request Bob to send statistics data\n")
+        logger.debug(DBG_STATS_MESSAGING, STATS_SEND_STATS_REQUEST_BOSS)
         cmd = isc.config.ccsession.create_command("sendstats", None)
         cmd = isc.config.ccsession.create_command("sendstats", None)
         seq = self.session.group_sendmsg(cmd, 'Boss')
         seq = self.session.group_sendmsg(cmd, 'Boss')
         self.session.group_recvmsg(True, seq)
         self.session.group_recvmsg(True, seq)
@@ -241,8 +246,8 @@ class CCSessionListener(Listener):
         """
         """
         handle a configure from the cc channel
         handle a configure from the cc channel
         """
         """
-        if self.verbose:
-            sys.stdout.write("[b10-stats] newconfig received: "+str(new_config)+"\n")
+        logger.debug(DBG_STATS_MESSAGING, STATS_RECEIVED_NEW_CONFIG,
+                     new_config)
 
 
         # do nothing currently
         # do nothing currently
         return create_answer(0)
         return create_answer(0)
@@ -264,8 +269,7 @@ class CCSessionListener(Listener):
         """
         """
         handle shutdown command
         handle shutdown command
         """
         """
-        if self.verbose:
-            sys.stdout.write("[b10-stats] 'shutdown' command received\n")
+        logger.info(STATS_RECEIVED_SHUTDOWN_COMMAND)
         self.subject.running = False
         self.subject.running = False
         return create_answer(0)
         return create_answer(0)
 
 
@@ -285,13 +289,14 @@ class CCSessionListener(Listener):
         """
         """
         handle remove command
         handle remove command
         """
         """
-        if self.verbose:
-            sys.stdout.write("[b10-stats] 'remove' command received, args: "+str(args)+"\n")
 
 
         # 'args' must be dictionary type
         # 'args' must be dictionary type
         if args and args['stats_item_name'] in self.stats_data:
         if args and args['stats_item_name'] in self.stats_data:
             stats_item_name = args['stats_item_name']
             stats_item_name = args['stats_item_name']
 
 
+        logger.debug(DBG_STATS_MESSAGING, STATS_RECEIVED_REMOVE_COMMAND,
+                     stats_item_name)
+
         # just remove one item
         # just remove one item
         self.stats_data.pop(stats_item_name)
         self.stats_data.pop(stats_item_name)
 
 
@@ -301,8 +306,6 @@ class CCSessionListener(Listener):
         """
         """
         handle show command
         handle show command
         """
         """
-        if self.verbose:
-            sys.stdout.write("[b10-stats] 'show' command received, args: "+str(args)+"\n")
 
 
         # always overwrite 'report_time' and 'stats.timestamp'
         # always overwrite 'report_time' and 'stats.timestamp'
         # if "show" command invoked
         # if "show" command invoked
@@ -312,16 +315,21 @@ class CCSessionListener(Listener):
         # if with args
         # if with args
         if args and args['stats_item_name'] in self.stats_data:
         if args and args['stats_item_name'] in self.stats_data:
             stats_item_name = args['stats_item_name']
             stats_item_name = args['stats_item_name']
+            logger.debug(DBG_STATS_MESSAGING,
+                         STATS_RECEIVED_SHOW_NAME_COMMAND,
+                         stats_item_name)
             return create_answer(0, {stats_item_name: self.stats_data[stats_item_name]})
             return create_answer(0, {stats_item_name: self.stats_data[stats_item_name]})
 
 
+        logger.debug(DBG_STATS_MESSAGING,
+                     STATS_RECEIVED_SHOW_ALL_COMMAND)
         return create_answer(0, self.stats_data)
         return create_answer(0, self.stats_data)
 
 
     def command_reset(self, args):
     def command_reset(self, args):
         """
         """
         handle reset command
         handle reset command
         """
         """
-        if self.verbose:
-            sys.stdout.write("[b10-stats] 'reset' command received\n")
+        logger.debug(DBG_STATS_MESSAGING,
+                     STATS_RECEIVED_RESET_COMMAND)
 
 
         # re-initialize internal variables
         # re-initialize internal variables
         self.stats_data = self.initialize_data(self.stats_spec)
         self.stats_data = self.initialize_data(self.stats_spec)
@@ -338,8 +346,7 @@ class CCSessionListener(Listener):
         """
         """
         handle status command
         handle status command
         """
         """
-        if self.verbose:
-            sys.stdout.write("[b10-stats] 'status' command received\n")
+        logger.debug(DBG_STATS_MESSAGING, STATS_RECEIVED_STATUS_COMMAND)
         # just return "I'm alive."
         # just return "I'm alive."
         return create_answer(0, "I'm alive.")
         return create_answer(0, "I'm alive.")
 
 
@@ -347,9 +354,7 @@ class CCSessionListener(Listener):
         """
         """
         handle an unknown command
         handle an unknown command
         """
         """
-        if self.verbose:
-            sys.stdout.write("[b10-stats] Unknown command received: '"
-                             + str(command) + "'\n")
+        logger.error(STATS_RECEIVED_UNKNOWN_COMMAND, command)
         return create_answer(1, "Unknown command: '"+str(command)+"'")
         return create_answer(1, "Unknown command: '"+str(command)+"'")
 
 
 
 
@@ -403,13 +408,12 @@ def main(session=None):
             subject.check()
             subject.check()
         subject.stop()
         subject.stop()
 
 
-    except OptionValueError:
-        sys.stderr.write("[b10-stats] Error parsing options\n")
+    except OptionValueError as ove:
+        logger.fatal(STATS_BAD_OPTION_VALUE, ove)
     except SessionError as se:
     except SessionError as se:
-        sys.stderr.write("[b10-stats] Error creating Stats module, "
-              + "is the command channel daemon running?\n")
+        logger.fatal(STATS_CC_SESSION_ERROR, se)
     except KeyboardInterrupt as kie:
     except KeyboardInterrupt as kie:
-        sys.stderr.write("[b10-stats] Interrupted, exiting\n")
+        logger.info(STATS_STOPPED_BY_KEYBOARD)
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
     main()
     main()

+ 55 - 0
src/bin/stats/stats_messages.mes

@@ -15,3 +15,58 @@
 # No namespace declaration - these constants go in the global namespace
 # No namespace declaration - these constants go in the global namespace
 # of the stats_messages python module.
 # of the stats_messages python module.
 
 
+% STATS_BAD_OPTION_VALUE bad command line argument: %1
+The stats module was called with a bad command-line argument, and will
+not start.
+
+% STATS_RECEIVED_NEW_CONFIG received new configuration: %1
+This debug message is printed when the configuration manager has sent
+the stats module a configuration update.
+
+% STATS_RECEIVED_REMOVE_COMMAND received command to remove %1
+A remove command for the given name was sent to the stats module, and
+it will now be removed.
+
+% STATS_RECEIVED_RESET_COMMAND received command to reset all statistics
+The stats module received a command to reset all collected statistics.
+
+% STATS_RECEIVED_SHOW_ALL_COMMAND received command to show all statistics
+The stats module received a command to show all statistics that it has
+collected.
+
+% STATS_RECEIVED_SHOW_NAME_COMMAND received command to show statistics for %1
+The stats module received a command to show the statistics that it has
+collected for the given item.
+
+% STATS_RECEIVED_SHUTDOWN_COMMAND shutdown command received
+A shutdown command was sent to the stats module, and it will now shut down.
+
+% STATS_RECEIVED_STATUS_COMMAND received command to return status
+A status command was sent to the stats module, and it will respond with
+'I'm alive'.
+
+% STATS_RECEIVED_UNKNOWN_COMMAND received unknown command: %1
+An unknown command has been sent to the stats module. The stats module
+will respond with an error, and the command will be ignored.
+
+% STATS_SEND_STATS_REQUEST_BOSS requesting boss to send statistics data
+This debug message is printed when a request is sent to the boss module
+to send statistics data to the stats module.
+
+% STATS_STOPPED_BY_KEYBOARD keyboard interrupt, shutting down
+There was a keyboard interrupt signal to stop the stats daemon. The
+daemon will now shut down.
+
+% STATS_CC_SESSION_ERROR error connecting to message bus: %1
+The stats module was unable to connect to the BIND 10 command and
+control channel. A likely problem is that the message bus daemon
+(b10-msgq) is not running. The stats module will now shut down.
+
+% STATS_UNKNOWN_COMMAND_IN_SPEC unknown command in specification file: %1
+The specification file for the stats module contains a command that
+is unknown in the implementation. The most likely cause is an
+installation problem, where the specification file stats.spec is
+from a different version of BIND 10 than the stats module itself.
+Please check your installation.
+
+