Skip to main content

Job

Open dashboard

The Job monitor is designed to track execution of periodic jobs: backup scripts, cron jobs and other scheduled operations.


How it works

  1. You create a Job monitor and define the execution schedule
  2. When the job starts, the start signal is sent
  3. On successful completion the finish signal is sent
  4. On error the fail signal is sent
  5. The system tracks both timely starts and execution time

Parameters

Description

ParameterDescriptionRequired
NameUnique monitor nameYes
DescriptionA note about the task purposeNo
screenshot with monitor description

Details

Specify the expected interval between jobs and optionally the maximum execution time.

screenshot with details of the job monitor screenshot with details of the job monitor

Interval

Two types of schedule are supported:

Expected interval between signals:

ValueDescription
1 minuteSignal expected every minute
5 minutesSignal expected every 5 minutes
15 minutesSignal expected every 15 minutes
30 minutesSignal expected every 30 minutes
60 minutesSignal expected every hour

Execution time

The maximum job duration Running Time — if the job runs longer than the specified time, a notification is sent.

Notifications

The Job monitor sends notifications in the following cases:

ReasonDescription
FailThe job finished with an error (fail signal or exit code != 0)
Not RunningThe job did not start within the Grace Period
Long RunningThe job runs longer than the Running Time
RecoveryThe job recovered after an error

Here you can specify contact groups for notifications. If left unspecified, the user's email is used.

You can also set a waiting period — Grace Period. It is added to the expected time of the next signal. For example, if the interval is 5 minutes and the Grace Period is 2 minutes, the alert will be sent 7 minutes after the last signal. Repeated notifications remind you of the problem; you can set the interval and number of these reminders.

screenshot with monitor job details

Usage

The tuna monitor exec command automatically sends start, finish or fail signals:

tuna monitor exec MONITOR_ID -- ./backup.sh

If you want to control the signals manually:

# Start of execution
tuna monitor ping MONITOR_ID --state=start

# Run your job
./your-task.sh

# Successful completion
tuna monitor ping MONITOR_ID --state=finish

# Or error
tuna monitor ping MONITOR_ID --state=fail

Via HTTP

In addition to the tuna CLI, you can send signals directly via HTTP requests. This is useful when the CLI is unavailable or when you use other programming languages.

URL format:

https://monitor.tuna.am/{MONITOR_ID}/{slug-name}
tip

{slug-name} is optional and is mainly used for easy identification of the monitor in code.

# Simple ping
curl -s "https://monitor.tuna.am/MONITOR_ID/test"

# With explicit status
curl -s "https://monitor.tuna.am/MONITOR_ID/test?state=ping"
curl -s "https://monitor.tuna.am/MONITOR_ID/test?state=start"
curl -s "https://monitor.tuna.am/MONITOR_ID/test?state=finish"
curl -s "https://monitor.tuna.am/MONITOR_ID/test?state=fail"

# With a message (proper UTF-8 encoding)
curl -G "https://monitor.tuna.am/MONITOR_ID/test" \
--data-urlencode "message=Backup completed successfully"

# With host and message
curl -G "https://monitor.tuna.am/MONITOR_ID/test?host=server-01" \
--data-urlencode "message=All systems operational"

Request parameters

ParameterDescription
stateSignal status: ping, start, finish, fail
hostHost identifier (useful when there are multiple sources)
messageArbitrary message

See more: Working with monitors in the CLI


Statuses

StatusDescription
NewMonitor created, awaiting the first run
RunningThe job is running (the start signal was received)
UpThe job finished successfully (the finish signal was received)
DownThe job finished with an error or did not start in time

Logging

When tuna monitor exec is used, the system automatically captures stdout and stderr of your job. The logs can be viewed in the UI in the monitor's event history.

screenshot with the message field content

To disable sending logs use the --no-stdout flag:

tuna monitor exec MONITOR_ID --no-stdout -- ./task.sh

Examples

PostgreSQL backup

#!/bin/bash
# /scripts/backup-postgres.sh

tuna monitor exec MONITOR_ID -- pg_dump -U postgres mydb > /backups/mydb_$(date +%Y%m%d).sql

Data synchronization

#!/bin/bash
# /scripts/sync-data.sh

tuna monitor exec MONITOR_ID -- rsync -avz /data/ remote:/backup/data/

Crontab

# Database backup every night at 3:00
0 3 * * * tuna monitor exec MONITOR_ID -- /scripts/backup-db.sh

# Log cleanup every hour
0 * * * * tuna monitor exec MONITOR_ID -- /scripts/cleanup-logs.sh