Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Status API: Difference between revisions

From MoodleDocs
(Created page with "= Declaring a Metric =")
 
No edit summary
Line 1: Line 1:
= Declaring a Metric =
= Declaring a metric for a plugin =
 
Each plugin can declare as many metrics as they want. Each metric extends a base class, and it also registered with the Status API via a hook in lib.php:
 
'''/admin/tool/task/lib.php:'''
<code php>
function tool_task_define_metrics(){
    return array(
        '\tool_task\metric\cronlastrun',
        '\tool_task\metric\scheduledtask',
    );
}
</code>
 
Other plugins have done this via a static file the db directory, however it is important that the metrics registered with the system is dynamic and can change according to how moodle is configured. For instance auth_ldap could declare a bind test metric, but if the ldap auth is disabled then we don't want to know about the metric at all or show it in any reports or checks.
 
'''/admin/tool/task/lib.php:'''
<code php>
function auth_ldap_define_metrics(){
    return array(
        '\auth_ldap\metric\bindlatency',
    );
}
</code>
 
= Metric dependencies =

Revision as of 02:51, 11 August 2016

Declaring a metric for a plugin

Each plugin can declare as many metrics as they want. Each metric extends a base class, and it also registered with the Status API via a hook in lib.php:

/admin/tool/task/lib.php: function tool_task_define_metrics(){

   return array(
       '\tool_task\metric\cronlastrun',
       '\tool_task\metric\scheduledtask',
   );

}

Other plugins have done this via a static file the db directory, however it is important that the metrics registered with the system is dynamic and can change according to how moodle is configured. For instance auth_ldap could declare a bind test metric, but if the ldap auth is disabled then we don't want to know about the metric at all or show it in any reports or checks.

/admin/tool/task/lib.php: function auth_ldap_define_metrics(){

   return array(
       '\auth_ldap\metric\bindlatency',
   );

}

Metric dependencies