Skip to content

Commit

Permalink
Add FAN service
Browse files Browse the repository at this point in the history
  • Loading branch information
mmohamed committed Apr 5, 2020
1 parent 7dcedae commit a254038
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions k8s/master-agent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
# nohup sh master-agent.sh [YOUR-SECURITY-TOKEN] > /tmp/master-agent.log
if [ -z "$1" ]; then
echo "Security Token required !"
exit 1
fi

attempts=0
server="http[s]://[YOUR-API-BACKEN-URL]/k8s/collect/$1/temperature"

while true; do

temperature=$(cat /sys/class/thermal/thermal_zone0/temp)

if [ $? != 0 ] || [ -z "$temperature" ]; then
echo "Unable to determinate CPU temperature value !"
exit 1
fi

url="$server?node=master&value=$temperature"

responseCode=$(curl --silent --output /dev/null --write-out "%{http_code}" $url)

if [ $? != 0 ] || [ -z "$responseCode" ] || [ $responseCode -ne 200 ]; then
attempts=$((attempts + 1))
echo "[ATTEMP-$attempts] Failed sending data to server : $responseCode"
if [ $attempts = 20 ]; then
echo "Server response error after 20 attempts !"
exit 1
fi;
else
attempts=0
fi

sleep 5
done;

0 comments on commit a254038

Please sign in to comment.