Skip to content

Instantly share code, notes, and snippets.

@burnsie7
Last active September 19, 2018 19:51
Show Gist options
  • Save burnsie7/4f275da026b9c8869c5e02cbfd4c24e9 to your computer and use it in GitHub Desktop.
Save burnsie7/4f275da026b9c8869c5e02cbfd4c24e9 to your computer and use it in GitHub Desktop.
PingCheck example
from checks import AgentCheck
import os
'''
This is for demostration purposes only and not recommended for production use.
Because of the nature of ping, it could result in a very long running check if there are excessive timeouts.
Long running checks could potentially result in other metrics and checks being skipped.
Example conf.yaml:
init_config:
instances:
- name: ping_test
min_collection_interval: 60
'''
class PingCheck(AgentCheck):
def check(self, instance):
hostnames = ["google.com", "datadog.com", "127.0.0.1", "192.168.55.5"]
for host in hostnames:
res = os.system("ping " + host + " -W 1 -c 1")
self.log.info("host: %s - res: %d" % (host, res))
if res != 0:
res = 2
self.service_check('network.ping', status=res, tags=['ping_host:'+host])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment