Find below the different parameters and data types available for the service_check() function:
Parameter
Type
Required
Default Value
Description
name
string
yes
-
The name of the service check.
status
int
yes
-
A constant describing the service status: 0 for OK, 1 for Warning, 2 for Critical, and 3 for Unknown.
tags
list of strings
no
None
A list of tags to associate with this Service Check.
hostname
string
no
current host
A hostname to associate with this Service check. Defaults to the current host.
message
string
no
None
Additional information or a description of why this status occurred.
Example
Here is an example of a dummy Agent check sending only one service check periodically. See Writing a Custom Agent Check to learn more.
Create a new directory, service_check_example.d/, in the conf.d/ folder of your Agent.
In your service_check_example.d/ folder, create an empty configuration file named service_check_example.yaml with the following content:
instances:[{}]
Up one level from the conf.d/ folder, go to the checks.d/ folder.
Within this folder, create a custom check file named service_check_example.py with the content below:
service_check_example.py
fromdatadog_checks.baseimportAgentCheck__version__="1.0.0"classMyClass(AgentCheck):defcheck(self,instance):self.service_check('example_service_check',0,message='Example application is up and running.')