#!/bin/bash
#################################################
#
#      Filename: monitor_ntp_offset.sh
#
#        Author: scott.liu@ucloud.cn
#   Description: ---
#        Create: 2019-03-07 17:23:51
# Last Modified: 2019-03-07 17:31:14
#################################################
ps -e | grep ntpd | grep -v grep 1>/dev/null 2>&1
stat=`echo $?`
if [ "$stat" -ne 0 ];then
    echo '[{"value":100000,"tags":""}]'
    exit 0
fi

offset=`ntpq -np4 2>/dev/null|grep -E '^\*' |tail -n1|awk '{print $9}'|awk -F . '{print $1}'|sed 's/-//g'`
if [ "$offset" == "" ];then
	echo '[{"value":100000,"tags":""}]'
        exit 0
fi

echo "[{\"value\":$offset,\"tags\":\"\"}]"
