How Jenkins Implements Administrative Monitors and Alerts: A Deep Dive into the Extension Framework
Jenkins uses the AdministrativeMonitor abstract class as an extension point to surface warnings, health checks, and security notices to administrators through a pluggable, permission-aware framework.
The jenkinsci/jenkins repository provides a lightweight infrastructure for administrative monitors that allows plugins and core components to register alerts that appear on the Manage Jenkins page. This system leverages Jenkins' extension annotation framework to automatically discover monitors, handle URL routing, and enforce permission controls without requiring boilerplate code from implementers.
Core Architecture of Jenkins Administrative Monitors
The AdministrativeMonitor Extension Point
At the heart of the system lies hudson.model.AdministrativeMonitor, an abstract class that implements ExtensionPoint. According to the Jenkins source code, any plugin can create a subclass and annotate it with @Extension to automatically register with the Jenkins extension registry. This design follows the standard Jenkins pattern for extensible components, ensuring that monitors are discovered at runtime without explicit configuration.
The base class is defined in core/src/main/java/hudson/model/AdministrativeMonitor.java and provides the contract that all monitors must fulfill: a unique identifier, an activation check, and optionally a custom permission requirement.
Unique Identification and State Management
Every administrative monitor must have a permanent id field, either supplied via the constructor or derived from the class name. This ID serves as the persistent key for URL binding and for tracking whether an administrator has disabled the monitor. In AdministrativeMonitor.java, the constructor handles ID assignment, while the isEnabled() helper method checks against Jenkins.get().getDisabledAdministrativeMonitors() to determine if the monitor has been dismissed.
Activation Logic and Permission Model
The isActivated() Method
Subclasses must implement the boolean isActivated() method to determine when the alert should appear. According to the source code in AdministrativeMonitor.java, this method runs on the rendering thread, so implementations must be fast and read-only. When isActivated() returns true and the monitor is enabled, Jenkins includes the monitor in the active list and renders its message view.
Permission-Based Visibility
By default, monitors are visible only to users with Jenkins.ADMINISTER permission. However, implementations can override getRequiredPermission() or checkRequiredPermission() to allow broader visibility, such as SYSTEM_READ or MANAGE permissions. This granular control is defined in AdministrativeMonitor.java and evaluated by Jenkins.getActiveAdministrativeMonitors(), which filters the full extension list based on the current user's permissions.
UI Integration and Rendering
Jelly View Components
When a monitor is active, Jenkins renders its message.jelly view, located at core/src/main/resources/**/<monitor-class>/message.jelly. For example, the CSRF monitor uses jenkins/security/csrf/CSRFAdministrativeMonitor/message.jelly as its display template. The view must wrap content in the <l:adminMonitor> tag to inherit standard styling and behavior.
Header Icons and Manage Jenkins Page
The ManageJenkinsAction class in hudson/model/ManageJenkinsAction.java coordinates UI integration. It calls Jenkins.getActiveAdministrativeMonitors() to determine whether to display warning icons in the top-right admin bar and populates the administrative monitors section on the Manage Jenkins page. The URL binding at /administrativeMonitor/<id> is handled by Jenkins.getAdministrativeMonitor(String), which scans the extension registry.
Managing Monitor State
Enable and Disable Mechanism
Administrators can dismiss monitors via the UI using the Disable button, which invokes doDisable(). Internally, this adds the monitor's ID to the disabled set persisted in Jenkins configuration. The AdministrativeMonitorsConfiguration class in jenkins/management/AdministrativeMonitorsConfiguration.java provides the global configuration UI that renders checkboxes for all monitors, calling each monitor's disable(boolean) method to persist user choices.
Programmatic Control
Plugins can programmatically control monitor states using the Jenkins API:
AdministrativeMonitor monitor = Jenkins.get().getAdministrativeMonitor("master-executor-limit");
if (monitor != null && monitor.isEnabled()) {
monitor.disable(true); // persist disabled state
}
This allows automated maintenance scripts or setup wizards to suppress specific warnings without manual UI interaction.
Implementation Example: Creating a Custom Monitor
To implement a custom administrative monitor, extend AdministrativeMonitor and provide a Jelly view. Here is a complete example that warns when the master node has too many executors:
package org.example.jenkins.monitor;
import hudson.Extension;
import hudson.model.AdministrativeMonitor;
import jenkins.model.Jenkins;
/** Warns when the number of executors on the master exceeds a threshold. */
@Extension
public class MasterExecutorLimitMonitor extends AdministrativeMonitor {
private static final int MAX_EXECUTORS = 4;
public MasterExecutorLimitMonitor() {
super("master-executor-limit");
}
@Override
public boolean isActivated() {
// Fast read‑only check – no side effects.
return Jenkins.get().getNumExecutors() > MAX_EXECUTORS;
}
@Override
public String getDisplayName() {
return "Master Executor Limit Exceeded";
}
}
The corresponding view at src/main/resources/org/example/jenkins/monitor/MasterExecutorLimitMonitor/message.jelly:
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/hudson">
<l:adminMonitor>
<h2>Too many executors on the master</h2>
<p>The master is configured with more than 4 executors. This can lead
to resource contention. Consider moving builds to agents.</p>
</l:adminMonitor>
</j:jelly>
To access active monitors from a Jelly view, iterate over the filtered list:
<j:forEach var="monitor" items="${it.getActiveAdministrativeMonitors()}">
<j:include page="${monitor.getUrl()}/message"/>
</j:forEach>
Summary
- Jenkins administrative monitors use the
AdministrativeMonitorabstract class inhudson/model/AdministrativeMonitor.javaas an extension point for surfacing alerts. - Monitors are automatically discovered via the
@Extensionannotation and registered in the Jenkins extension registry. - The
isActivated()method determines visibility and must be fast and read-only since it runs on the rendering thread. - Permission controls default to
Jenkins.ADMINISTERbut can be customized viagetRequiredPermission(). - The
Jenkinsclass injenkins/model/Jenkins.javaprovides URL binding viagetAdministrativeMonitor(String)and filtered access viagetActiveAdministrativeMonitors(). - UI rendering uses Jelly views named
message.jelly, integrated into the Manage Jenkins page byManageJenkinsAction. - State persistence is handled through
AdministrativeMonitorsConfiguration, which manages the disabled monitors set.
Frequently Asked Questions
What is an Administrative Monitor in Jenkins?
An administrative monitor is a plugin component that extends hudson.model.AdministrativeMonitor to display warnings, health checks, or security notices to Jenkins administrators. These monitors appear on the Manage Jenkins page and can trigger warning icons in the administrative header when their isActivated() method returns true.
How do I disable a Jenkins administrative monitor?
Administrators can disable a monitor by clicking the Disable button on the alert message, which calls doDisable() and adds the monitor's ID to the disabled set. Alternatively, navigate to Manage Jenkins > System and uncheck the monitor in the administrative monitors configuration section, or use the API: monitor.disable(true).
What permissions are required to view administrative monitors?
By default, only users with Jenkins.ADMINISTER permission can view administrative monitors. However, monitor implementations can override getRequiredPermission() to allow SYSTEM_READ or MANAGE permissions, enabling delegated operators to see specific alerts without full administrative access.
How do I create a custom administrative monitor plugin?
Create a class that extends AdministrativeMonitor, annotate it with @Extension, implement isActivated() to define when the alert shows, and override getDisplayName() for the UI label. Package a message.jelly file in the resources directory under your class's package path to define the HTML content. Jenkins automatically registers the monitor and handles URL routing at /administrativeMonitor/<your-id>.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →