service (linux)

check_service

Checks the state of one or multiple linux (systemctl) services.

There is a specific check_service for windows as well.

Implementation

WindowsLinuxFreeBSDMacOSX

Examples

Default Check

Checking all services except some excluded ones:

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

Or check a specific service and get some 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 - created: Fri 2023-11-17 20:34:01 CET |'docker'=4 'docker rss'=805200000B

Check memory usage of specific service:

check_service service=docker warn='rss > 1GB' warn='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 NRPE and Naemon

Naemon Config

define command{
    command_name         check_nrpe
    command_line         $USER1$/check_nrpe -H $HOSTADDRESS$ -n -c $ARG1$ -a $ARG2$
}

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

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)
ok-syntax%(status) - All %(count) service(s) are ok.
detail-syntax${name}=${state}

Check Specific Arguments

ArgumentDescription
excludeList of services to exclude from the check (mainly used when service is set to *)
serviceName of the service to check (set to * to check all services). Default: *

Attributes

Filter Keywords

these can be used 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 (unix timestamp)
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