Skip to content

Instantly share code, notes, and snippets.

@ncracker
Forked from burnsie7/ping_test.py
Last active September 19, 2018 19:53
Show Gist options
  • Select an option

  • Save ncracker/08419af9e8b044c500b9a4e112054b91 to your computer and use it in GitHub Desktop.

Select an option

Save ncracker/08419af9e8b044c500b9a4e112054b91 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.gauge('network.ping.can_connect', 0, tags=['ping_host:'+host])
self.service_check('network.ping', status=res, tags=['ping_host:'+host])
self.gauge('network.ping.can_connect', 1, tags=['ping_host:'+host])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment