(by @_ashish_tiwari)
It performs ps -ef | grep service_name | wc -l
command and gives response in 1 or 0.
- Install prometheus client by
pip install prometheus_client
. python service_up_exporter.py
- Go to localhost:8000/metrics
# HELP python_info Python platform information
# TYPE python_info gauge
python_info{implementation="CPython",major="2",minor="7",patchlevel="5",version="2.7.5"} 1.0
# HELP process_virtual_memory_bytes Virtual memory size in bytes.
# TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes 2.34754048e+08
# HELP process_resident_memory_bytes Resident memory size in bytes.
# TYPE process_resident_memory_bytes gauge
process_resident_memory_bytes 1.2378112e+07
# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.
# TYPE process_start_time_seconds gauge
process_start_time_seconds 1.56378317373e+09
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 0.14
# HELP process_open_fds Number of open file descriptors.
# TYPE process_open_fds gauge
process_open_fds 7.0
# HELP process_max_fds Maximum number of open file descriptors.
# TYPE process_max_fds gauge
process_max_fds 1024.0
# HELP service_health_status Check status of service
# TYPE service_health_status gauge
service_health_status{host="ashish",script_name_pattern="myprocess1"} 0.0
service_health_status{host="ashish",script_name_pattern="myprocess2"} 0.0
service_health_status{host="ashish",script_name_pattern="elasticsearch"} 1.0