Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Ambari alerts for Hive smoke testing

Ambari alerts for Hive smoke testing

Super Collaborator

Ambari alerts only check process and port health, yes? There are no smoke tests being ran by Ambari unless a manual service check is ran?

I was able to write a bash script to detect a timeout from a simple COUNT query, but later found out that Ambari only accepts Python scripts as alerts.

What are my options if I would like to periodically run a Hive query and do a validity check against a Hive table?

This script works on it's own in bash, but I need help calling it / re-doing it using Python if I want to use Ambari alerts

#!/usr/bin/env bash
set -u
TIMEOUT=1m
BEELINE=/usr/hdp/current/hive-client/bin/beeline
RUNAS=hive
TEZ_QUEUE=infrastructure
OUTPUT_FILE=/tmp/hivecanary.out
CONNECT_URI=jdbc:hive2://localhost:10000?tez.queue.name=infrastructure
if [[ ! -x $BEELINE ]]; then
  echo CRITICAL
  exit 2
fi
if [[ -f $OUTPUT_FILE ]]; then
  rm -f "$OUTPUT_FILE"
fi
echo "$BEELINE --showHeader=false --outputformat=tsv2 -n hive -u 'jdbc:hive2://localhost:10000?tez.queue.name=infrastructure' -e 'SELECT COUNT(*) FROM default.customers'" | bash &
a=0
sleep 10
while true;do
  a=$(($a+1))
  PID=$(ps aux | grep beeline | grep -v grep | grep 'SELECT COUNT' | awk '{ print $2 }')
  if [ -z "$PID" ]; then
    echo OK
    exit 0
  else
    if [ "$a" -gt 60 ]; then
      echo CRITICAL
      exit 1
    fi
  fi
sleep 1
done
3 REPLIES 3

Re: Ambari alerts for Hive smoke testing

Mentor

@Jordan Moore

There is a great example here

It allows you to execute most shell commands as native python functions.

Example:

import sh
sh.cd('/path/to/Development')
print(sh.pwd())
# => /path/to/Development
Highlighted

Re: Ambari alerts for Hive smoke testing

Super Collaborator

It depends on which service and component. Some only do simple checks like port and PID status.

Hive Server actually runs beeline commands

Hive Metastore runs a show databases command

Re: Ambari alerts for Hive smoke testing

Super Collaborator

@Geoffrey Shelton Okot - That requires installing sh module into the Ambari python installation, which I do not want to maintain. If I could do that, then I would use a Python Hive driver.

Don't have an account?
Coming from Hortonworks? Activate your account here