Skip to main content

Django Command Monitoring

Description

Django 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 supports:

  • Django>=1.11
  • Python 2 & 3

How to install

Package installation

Use

  • pip install django-command-monitor
  • pip install git+https://github.com/orfium/django-command-monitoring.git

Set up environment

In 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-monitoring

When you are done setting up the only thing you have to do is to include the tool and use MonitoredCommand class instead of Django's BaseCommand

from django_command_monitor import monitor

class Command(monitor.MonitoredCommand):
...

Settings variables and command inputs

  • To disable the command monitoring feature for one command for development runs you can include the input --disable_monitor as argument in your command

  • If you want to disable the monitoring in the testing env, you can add a variable in your testing settings: TESTING=True

  • To set the time between each ping set the following variable in settings INTERVAL_PING=<secs>, where <secs> is integer, default is 30 seconds.

  • To disable the monitoring for the entire project set the variable in settings MONITORING=False

After installation

Your 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 settings FIREBASE_TABLE. Under the key commands all the commands that have ran under the monitor.MonitoredCommand are listed there.

Each command is identified by its name along side with its parameters i.e. when running python manage.py test_command --verbosity=2 the command name is transformed to test_command__verbosity_2.

Under each command there is the key log that contains a list of all runs of this command with the respective details

For 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 running python manage.py test_command --verbossity=2 the name is test_command
  • status: the status of the command
    • STARTED : The command has just started
    • RUNNING : The command currently running
    • FINISHED : The command has naturally finished
    • FAILED : There was an error when running the command. message holds the error message and exception_type holds the type of the exception
    • SYSTEM_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 status RUNNING, meaning the command is forced to stop before writing to FireBase
  • started : The datetime of when the process started
  • finished: The datetime of when the process finished. If the process is not yet finished the value is None
  • latest: The datetime of the latest ping. The process is running under a thread where it pings to FireBase under a time interval
  • message: The message of the failed command
  • exception_type : The type of the exception when the command failed
  • params: The parameters of the command i.e. python manage.py test_command --verbosity=2 goes to verbosity=2. Multiple parameters are comma separated

Finally the <DATETIME> format is as follows: YYYY-MM-DDTHH:MM:SS.(float)Z

TODO

  • Handle the timeouts on FireBase, with at least 3 times retry
  • Add support for other command classes other than BaseCommand

Metadata

Release files for django-command-monitor 0.1.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-command-monitor 0.1.14
File Size Uploaded
django_command_monitor-0.1.14.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-command-monitor 0.1.14
File Interpreter ABI Platform
django_command_monitor-0.1.14-py2-none-any.whl Python 2 none any Details

Total release size: 11.1 kB

Release files / django_command_monitor-0.1.14.tar.gz

Download URL django_command_monitor-0.1.14.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
638e534a4ffa1cbc44ce7e788627bdbdf278ec61fe60b16edf152efed7278128
BLAKE2b-256 checksum
How to use checksums
5a4e77dd3b882637c406d88c865929de09ad6f19c46dc3664873d8a2302fe3c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/2.7.14

Release files / django_command_monitor-0.1.14-py2-none-any.whl

Download URL django_command_monitor-0.1.14-py2-none-any.whl
Size 5.6 kB
Tags Python 2
SHA-256 checksum
How to use checksums
968f54cb927ceb34b2eb128be7a923d74c841715af489cfda5d62dbfa350915a
BLAKE2b-256 checksum
How to use checksums
d5a8820b3e79e43d47613bc1c8437cd22c22688aaa09f904cb6d60852a6d8968
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/2.7.14

Release history Release notifications | RSS feed

0.3.0

1 release file

0.2.9

1 release file

0.2.8

1 release file

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.1.16

1 release file

0.1.15

1 release file

This release

0.1.14 This release

2 release files

0.1.13

1 release file

0.1.12

1 release file

0.1.11

1 release file

0.1.10

1 release file

0.1.9

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

2 release files

0.1.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page