Spring Boot and @MonitoredSchedule
Put @MonitoredSchedule on a @Scheduled method and the starter
creates its check when your application starts, from the method's own schedule: its cron
expression and zone, or its fixedRate or fixedDelay.
A job that stops firing after a deploy is caught, because the check was armed before its first
run was due.
Will it hurt my application?
No: the starter never blocks or slows your job and never throws into it, every request runs in the background behind a 2-second timeout, and if Marsolen is unreachable it logs a warning and your job carries on as if it were not there.
What happens, and when
| Application starts | Every annotated method is found and its check registered from its
@Scheduled trigger. Registering again with the same name updates the check, so
every instance of a scaled service and every redeploy share one check. |
| Method is called | A start is sent, so the run is timed and can be held to a run
limit. marsolen.send-start=false turns it off. |
| Method returns | A ping is sent and the check is up. |
| Method throws | A failure is sent and you are alerted within a minute, without waiting for the next run. The exception is never sent, and your code gets it back unchanged. To have the alert say which exception it was, see below. |
If Marsolen cannot be reached when the application starts, the check is registered on the method's first run instead.
fixedRate and fixedDelay
A job that runs every so often, rather than at set times, is watched by the gap since its last
ping. The check is late one interval after that ping, rounded up to a whole minute, and you are
alerted five minutes later, plus the method's initialDelay if it has one. A run that
comes early is never late: the next one is simply expected one interval after it.
@Scheduled(fixedDelayString = "${outbox.poll:PT5M}", initialDelay = 30_000)
@MonitoredSchedule("outbox-drainer")
void drainOutbox() {
outbox.drain();
}
Write the trigger however you already do: fixedRate, fixedDelay, their
String forms with property placeholders and durations such as PT15M or
45m, timeUnit and initialDelay. The starter reads them with
your own Spring version, so the check has the period your job really runs at.
What the five minutes are for
With fixedDelay the next run starts one delay after the last one ended, so two
pings are a delay plus a run apart. The starter times every run, and once one takes longer than a
minute it registers the check again with your interval plus that run, so an hourly export that
takes eight minutes is expected every 68 minutes. The five minutes cover shorter runs, ordinary
jitter, and a redeploy that keeps the application down for a couple of minutes. The first run after
a start has not been timed yet, so if it can take more than five minutes longer than the interval,
lengthen the grace on the check's page. Registering again never shortens it; it only raises a grace
that is too short to survive a restart.
After a restart
The job runs again after its initialDelay and pings when that run ends, which is why
the initialDelay is added to the grace. Starting the application does not reset the
check's clock, so one that crashes on every start still alerts. A run that finishes before the
check has been registered, as the first run after startup usually does, is still pinged.
Jobs that run more often than once a minute
A fixedDelay = 1000 poller does not ping every second. A minute is the shortest period
Marsolen watches, so the check is registered at one minute and the starter sends one ping every 30
seconds to say the job is still running; a run in between sends nothing and costs your application
no request. When every run in those 30 seconds throws, the failure is reported instead, and you are
alerted within a minute. Each reported failure is an alert, followed by a recovery when a later run
succeeds, so catch the errors the job expects inside the method: a poller that fails for half a
minute at a time, again and again, alerts that often. A run that throws now and then between
successes is a job that is running, and is reported as one. Such a job sends no start, so its check
has no run durations and no run limit, and its AI agent runs are not
reported.
What cannot be monitored
A schedule Marsolen cannot read exactly is refused rather than approximated, because an approximated
schedule is a check that pages you on the wrong night. Registration answers 400 for:
| Sub-minute schedules | Marsolen schedules to the minute, so the seconds field must be a
fixed value: 0 */5 * * * *, not */30 * * * * *. |
Quartz L, W and # | Last day, nearest weekday and nth weekday have no five-field cron equivalent. |
| A year-restricted expression | A seventh Quartz field other than *. |
| A date that never comes | 0 0 0 31 2 * starts, and no date matches it,
so it never runs. 29 February is rare, not never, and registers. |
The starter logs the refusal at startup and creates nothing. Two more triggers are not registered,
because neither has a next run to be late for: a job switched off with cron = "-",
and a one-time task, which has an initialDelay and nothing else.
Things that will bite
Spring and Quartz count the days of the week differently
Spring writes six fields, seconds first, and counts Sunday as 0. Quartz counts Sunday as 1. The starter sends your expression as written, with which dialect it is, and Marsolen converts it, so do not translate it yourself. A Quartz expression pasted into a check that reads Spring's numbering would watch the nightly job on the wrong day. The cron expression explainer reads either, says which day each number means, and shows the five-field form Marsolen stores.
A method called from its own bean never pings
The ping is sent by a Spring proxy, so a monitored method called from another method of the
same bean does not go through it, and the check you can see in the dashboard waits for a ping that never
comes. Call it from another bean, or let the scheduler call it. private and
final methods are never monitored; package-private ones are.
Quartz jobs
Put the annotation on the job's execute method. The schedule is read from the job's
CronTrigger. A SimpleTrigger is not registered: it can end by design,
after a repeat count or at an end time, and a check waiting for a job that finished as planned
would page you for nothing. It is logged and skipped.
The whole integration
Create an SDK key in Settings, API keys. It starts with msk_ and can
register checks and nothing else, so it is safe in an application's configuration. Then paste
these three files into your project and replace the key. The example runs every minute, so the
check turns green within a minute of starting; change the cron to your job's.
The starter needs Java 21 and Spring Boot 4.1. On Spring Boot 3.5 (Java 17 and up), use
marsolen-spring-boot3-starter instead; everything else is the same. The starter
reaches Maven Central at launch.
<dependency>
<groupId>com.marsolen</groupId>
<artifactId>marsolen-spring-boot-starter</artifactId>
<version>0.1.0</version>
</dependency>
marsolen.enabled=true
marsolen.api-key=msk_...
marsolen.base-url=https://staging.marsolen.com
import io.marsolen.core.MonitoredSchedule;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Configuration
@EnableScheduling
class SchedulingConfig {
}
@Component
class HelloJob {
@Scheduled(cron = "0 * * * * *", zone = "Europe/Paris")
@MonitoredSchedule("hello-marsolen")
void run() {
System.out.println("Hello from a monitored job");
}
}
Start the application: hello-marsolen appears on your checks page straight away, and
turns green after its first run. Every other @Scheduled method you annotate works the
same way.
AI agents
If the method calls a model through Spring AI, the starter also counts what the run did and sends it with the ping: model calls, tokens, the model's name and each tool's name with how often it was called. Prompts, replies and tool arguments are never read. The check's page lists the latest runs, and on a paid plan its AI agent rules can alert you when a run did nothing, used too many tokens, kept hitting provider errors, never called a tool it must, or pinged without sending its report. Both starters do this: Spring AI 2.0 on Spring Boot 4, Spring AI 1.1 on Spring Boot 3.5.
Mark the method agent = true so a run that called no model at all is reported too:
that is the run that "did nothing".
@Scheduled(cron = "0 */15 * * * *")
@MonitoredSchedule(value = "inbox-triage", agent = true)
void triage() {
int handled = chatClient.prompt()
.user("Triage the new tickets")
.tools(ticketTools)
.call()
.entity(TriageResult.class)
.handled();
AgentRun.current().items(handled); // optional: what the run produced
}
Spring AI reports its calls through Micrometer, so the application needs an
ObservationRegistry, which spring-boot-starter-actuator provides. A
model called on another thread is counted only when the observation context reaches that thread:
set spring.reactor.context-propagation=auto for streaming. Until it does, a run whose
calls went missing is not reported, rather than reported as having done nothing.
marsolen.agent-runs=false turns all of it off.
Saying why a run failed
By default a run that throws sends the failure and nothing about the exception. Two switches make
the alert say which exception it was, both off until you turn them on: set
marsolen.failure-details=true in the application, and tick Keep the output of
failed runs on the check's form. The starter then sends the exception's class and message
and its root cause's, never a stack trace:
java.lang.IllegalStateException: Could not export the report
Caused by: java.net.ConnectException: Connection refused
An exception message is your application's data and can hold anything, which is why the application has to ask. We keep it as long as we keep the ping and blank the obvious secrets in it. Email alerts quote both lines; chat channels, PagerDuty and webhooks get the last one.
Without the annotation
Any job can call its check's ping URL when it finishes, in any language. For creating checks from a script or CI, see the API.