Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write log to tmpfs when avaliable #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions hetrixtools_agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -789,17 +789,31 @@ json='{"version":"'"$Version"'","SID":"'"$SID"'","agent":"0","user":"'"$User"'",
# Compress payload
jsoncomp=$(echo -ne "$json" | gzip -cf | base64 -w 0 | sed 's/ //g' | sed 's/\//%2F/g' | sed 's/+/%2B/g')

# Set hetrixtools path
HetrixAgentLogPath="$ScriptPath/hetrixtools_agent.log"
# Get data path
if [ -d "/run" ]
then
# On newer Linux, tmpfs is mounted at /run
HetrixAgentLogPath="/run/hetrixtools_agent.log"
elif [ -d "/var/run" ]
then
# On older Linux, tmpfs is mounted at /var/run
HetrixAgentLogPath="/var/run/hetrixtools_agent.log"
fi
# The default path /run/hetrixtools_agent.log will be used if both /run and /var/run are missing

# Save data to file
echo "j=$jsoncomp" > "$ScriptPath"/hetrixtools_agent.log
echo "j=$jsoncomp" > $HetrixAgentLogPath

# DEBUG
if [ "$DEBUG" -eq 1 ]
then
# Post data
echo -e "$ScriptStartTime-$(date +%T]) Posting data" >> "$ScriptPath"/debug.log
wget -v --retry-connrefused --waitretry=1 -t 3 -T 15 -O- --post-file="$ScriptPath/hetrixtools_agent.log" $SecuredConnection https://sm.hetrixtools.net/v2/ &>> "$ScriptPath"/debug.log
wget -v --retry-connrefused --waitretry=1 -t 3 -T 15 -O- --post-file="$HetrixAgentLogPath" $SecuredConnection https://sm.hetrixtools.net/v2/ &>> "$ScriptPath"/debug.log
echo -e "$ScriptStartTime-$(date +%T]) Data posted" >> "$ScriptPath"/debug.log
else
# Post data
wget --retry-connrefused --waitretry=1 -t 3 -T 15 -qO- --post-file="$ScriptPath/hetrixtools_agent.log" $SecuredConnection https://sm.hetrixtools.net/v2/ &> /dev/null
wget --retry-connrefused --waitretry=1 -t 3 -T 15 -qO- --post-file="$HetrixAgentLogPath" $SecuredConnection https://sm.hetrixtools.net/v2/ &> /dev/null
fi