check_service (linux)

Checks the state of one or more Linux (systemctl) services.

For Windows services, use check_service for Windows.

Implementation

WindowsLinuxFreeBSDmacOS
✅

Argument Defaults

ArgumentDefault Value
filteractive != inactive
critical( state not in (‘running’, ‘oneshot’, ‘static’) || active = ‘failed’ ) && preset != ‘disabled’
empty-state3 (UNKNOWN)
empty-syntax%(status) - No services found
top-syntax%(status) - %(crit_list || ‘found %(count) services’)
ok-syntax%(status) - All %(count) service(s) are ok.
detail-syntax%(name)=%(state)

Check Specific Arguments

ArgumentDescription
excludeServices to exclude, mainly when service is set to *. Names are case insensitive and support wildcards.
serviceServices to check (case insensitive). Set to * to check all services. Default: *

Attributes

Filter Keywords

Use these attributes in filters and thresholds, along with the default attributes:

AttributeDescription
nameThe name of the service
serviceAlias for name
descDescription of the service
activeThe active attribute of a service, one of: active, inactive or failed
stateThe state of the service, one of: stopped, starting, oneshot, running, static or unknown
pidThe PID of the service
createdDate when service was started
ageSeconds since service was started
rssMemory RSS in bytes (main process)
vmsMemory VMS in bytes (main process)
cpuCPU usage in percent (main process)
presetThe preset attribute of the service, one of: enabled or disabled
tasksNumber of tasks for this service

Examples

Default Check

Check all services except those excluded:

check_service exclude=bluetooth
OK - All 74 service(s) are ok.

Check a specific service and show its metrics:

check_service service=docker ok-syntax='%(top-syntax)' top-syntax='%(status) - %(list)' detail-syntax='%(name) %(state) - memory: %(rss:h)B - age: %(age:duration)'
OK - docker running - memory: 805.2MB - age: 01:11h |'docker'=4 'docker rss'=805200000B

Check the memory usage of a specific service:

check_service service=docker warn='rss > 1GB' crit='rss > 2GB'
OK - All 1 service(s) are ok. |'docker'=4 'docker rss'=59691008B;;;0 'docker vms'=3166244864B;;;0 'docker cpu'=0.7%;;;0 'docker tasks'=20;;;0

Example using check_snclient and Naemon

Naemon Config

define command{
    command_name         check_snclient
    command_line         $USER1$/check_snclient -k -p 'your-password' -u 'https://$HOSTADDRESS$:8443' $ARG1$ $ARG2$
}

define service {
    host_name            testhost
    service_description  check_service
    use                  generic-service
    check_command        check_snclient!check_service!service=docker
}