Skip to content
Moodle cron / task API lock statistics admin tool
PHP CSS
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
classes
db
lang/en
tests
.travis.yml
README.md
detail.php
historyreset.php
index.php
locks_detail.php
settings.php
styles.css
version.php

README.md

Travis integration: Build Status

tool_lockstats

A lock statistics admin tool, specifically tailored to report on cron task timings.

This tool exposes which tasks are currently running and where, and also shows a detailed history of how long each task has taken in the past.

How it works

It implements a proxy lock factory which adds instrumentation around the real lock factory. It will log details about each cron task when a lock is obtained and released. This is the data that is obtained:

  • Task name
  • Duration
  • Hostname
  • Time gained
  • Time released
  • PID

Most of the time, most cron tasks are quick and finish in seconds. These typically are not the tasks you are interesting in the history off. So this plugin compresses the history quick tasks so you still get overall stats for all tasks, and detailed stats for slower bigger tasks, and without bloating out the database with too much data. Old stats can be removed after a set time period too.

Installation

Install the plugin the same as any standard moodle plugin either via the Moodle plugin directory:

https://moodle.org/plugins/tool_lockstats

https://docs.moodle.org/en/Installing_plugins

OR you can use git to clone it into your source:

git clone git@github.com:catalyst/moodle-tool_lockstats.git admin/tool/lockstats

Configuration

This is an example of using the Postgres lock factory, add this to your config.php:

$CFG->lock_factory = "\\tool_lockstats\\proxy_lock_factory";
$CFG->proxied_lock_factory = "auto";

# If you want to be explicit you can do this:
$CFG->proxied_lock_factory = "\\core\\lock\\postgres_lock_factory";

// To allow unit tests to pass.
$CFG->phpunit_lock_factory = "\\tool_lockstats\\proxy_lock_factory";
$CFG->phpunit_proxied_lock_factory = "\\core\\lock\\postgres_lock_factory";

Using the UI you can configure additional settings at,

Site administration > Plugins > Admin tools > Lock statistics

The values you can configure are,

  • Blacklist (Default: core_cron)

This allows you to prevent logging the history for specific tasks.

  • History threshold (Default: 60)

If the task exceeds this value in seconds then a new history entry will be logged.

  • Cleanup history (Default: 30)

A task exists that will clean up history entries that exceed this value in days.

  • Debug (Default: No)

Provides additional debugging messages in the cron.log for when the locks are obtained and released.

Usage

You can view the current locked tasks, lock history and details via the UI at,

Site administration > Server > Lock statistics

You can’t perform that action at this time.