Skip to content

Instantly share code, notes, and snippets.

@ryaan-anthony
Created May 21, 2015 14:21
Show Gist options
  • Select an option

  • Save ryaan-anthony/31848e1addcc19c06301 to your computer and use it in GitHub Desktop.

Select an option

Save ryaan-anthony/31848e1addcc19c06301 to your computer and use it in GitHub Desktop.
Simple PHP healthcheck for elasticsearch (add to crontab)
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "127.0.0.1");
curl_setopt($ch, CURLOPT_PORT, "9200");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
if(curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200){
mail(
"[email protected]",
"Elasticsearch is down (".gethostname().")",
"Please restart the service as soon as possible!"
);
echo 'failed'.PHP_EOL;
} else {
echo 'passed'.PHP_EOL;
}
curl_close($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment