使用CMAPI獲取多個hiverserver2鏈接數shell
#!/bin/bash #用戶名密碼爲CDH客戶端admin用戶名密碼 user="admin" password="admin" host_ip="192.168.1.110" hiveserver2_hosts="hostname1|hostname2|hostname3" date_time=$(date +"%Y-%m-%dT%H∶%M:%S") start_time=$(date -d "20 hour ago"+"%Y一%m-%dT%H:%M:%S") echo "start_time: ${start_time } " echo "date_time: $ {date_time } " OLD_IFS="$IFS" IFS="|" for hiveserve2_host in ${hiveserver2_hosts[@]};do echo $hiveserve2_host curl -u $[user}:$(password) "http://${host_ip}:7180/api/v6/timeseries?query=select+hive_open_connections+where+hostname=%22${hiveserve2_host}22&contentType=application/json&from=${start_time}Z&to=${date_time}Z"| grep value | awk 'END {print "connected_num:"$3}'21 done