Package: django-command-monitor
Django Command MonitoringDescriptionDjango Command Monitoring is a tool that logs the progress of django commands. It writes the progress into FireBase where you can then read and do whatever you want with the data. Currently it keeps the log of the last 100 iterations for each command to avoid overuse of Firebase database.Currently supports:Django>=1.11Python 2 & 3How to installPackage installationUsepip install django-command-monitorpip install git+https://github.com/orfium/django-command-monitoring.gitSet up environmentIn your django settings file you have to include your FireBase credentials and the FireBase folder that identifies your
project.For your FireBase credentials:FIREBASE_MONITORING={'API_KEY':'<your FireBase API key>','DOMAIN':'<your FireBase domain>','NAME':'<your FireBase name>','PROJECT_ID':'<your FireBase project id>','SENDER_ID':'<your FireBase sender id>'}For your FireBase folder:FIREBASE_MONITORING_KEY='monitor-myapp-production'How to run with django-command-monitoringWhen you are done setting up the only thing you have to do is to include the tool and useMonitoredCommandclass
instead of Django'sBaseCommandfromdjango_command_monitorimportmonitorclassCommand(monitor.MonitoredCommand):...Settings variables and command inputsTo disable the command monitoring feature for one command for development runs you can include the input--disable_monitoras argument in your commandIf you want to disable the monitoring in the testing env, you can add a variable in your testing settings:TESTING=TrueTo set the time between each ping set the following variable in settingsFIREBASE_MONITORING_INTERVAL_PING=<secs>, where<secs>is integer, default is 30 seconds.To disable the monitoring for the entire project set the variable in settingsFIREBASE_MONITORING_RUN=FalseAfter installationYour data in FireBase will look like this:{"monitor-myapp-production":{"commands":{"<the name of your command with arguments>":{"log":[{"finished":"<DATETIME>","id":"<COMMAND ID>","latest":"<DATETIME>","message":"<MESSAGE>","name":"<COMMAND NAME>","params":"<PARAMETERS>","started":"<DATETIME>","status":"<STATUS>","exception_type":"<EXCEPTION AS STRING>"},{"...":"..."},"..."]},"<another command>":{"...":"..."}}}}First of all the name of the FireBase table is the same as the one in settingsFIREBASE_TABLE.
Under the keycommandsall the commands that have ran under themonitor.MonitoredCommandare listed there.Each command is identified by its name along side with its parameters i.e. when runningpython manage.py test_command --verbosity=2the command name is transformed totest_command__verbosity_2.Under each command there is the keylogthat contains a list of all runs of this command with the respective detailsFor each log it keeps the following data:id: the identifier of the command(for now is the same as the key of the command mentioned above)name: The name of the command i.e. when runningpython manage.py test_command --verbossity=2the name istest_commandstatus: the status of the commandSTARTED: The command has just startedRUNNING: The command currently runningFINISHED: The command has naturally finishedFAILED: There was an error when running the command.messageholds the error message andexception_typeholds the type of the exceptionSYSTEM_KILL: The command is killed by the system i.e. Heroku restarts the dyno based on the given interval. This
status is assigned when the same command starts a new cycle and the previous log has statusRUNNING, meaning the
command is forced to stop before writing to FireBasestarted: The datetime of when the process startedfinished: The datetime of when the process finished. If the process is not yet finished the value is Nonelatest: The datetime of the latest ping. The process is running under a thread where it pings to FireBase under a
time intervalmessage: The message of the failed commandexception_type: The type of the exception when the command failedparams: The parameters of the command i.e.python manage.py test_command --verbosity=2goes toverbosity=2.
Multiple parameters are comma separatedFinally the<DATETIME>format is as follows: YYYY-MM-DDTHH:MM:SS.(float)ZTODOHandle the timeouts on FireBase, with at least 3 times retryAdd support for other command classes other thanBaseCommand