Skip to content

Commit

Permalink
push everything into the installer
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronblohowiak committed Oct 19, 2011
1 parent 487df06 commit 82208d6
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 180 deletions.
2 changes: 1 addition & 1 deletion generated/public/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ with(locals || {}) {
}
}
, "agent/install.sh": function anonymous(obj) {
var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('#!/usr/bin/env bash\n\n##############################################################################\n#\n# _______ _______ \n# \\ ___ `\'. \\ ___ `\'. \n# \' |--.\\ \\ \' |--.\\ \\ \n# | | \\ \' | | \\ \' .| \n# | | | \' ____ _____ | | | \' .\' |_ \n# | | | |`. \\ .\' / | | | | .\' | \n# | | \' .\' `. `\' .\' | | \' .\'\'--. .-\' \n# | |___.\' /\' \'. .\' | |___.\' /\' | | \n# /_______.\'/ .\' `. /_______.\'/ | | \n# \\_______|/ .\' .\'`. `.\\_______|/ | \'.\n# .\' / `. `. | / \n# \'----\' \'----\' `\'-\' \n#\n#\n##############################################################################\n#\n#\n# https://dxdt.io Server Monitoring\n# This software is provided with NO WARRANTY, express or implied.\n# While we believe that it is a fine piece of code, we make no garauntees.\n# It might destroy your computer, or launch nukes at the USSR.\n# \n# By using this software, you agree to the terms and conditions at\n# https://dxdt.io/terms\n#\n#\n##############################################################################\n\n\n\n##############################################################################\n# Overview\n##############################################################################\n#\n# This script does a few things:\n# \n# 1. Check for all pre-requisite commands (grep, tar, lsof, ifconfig...)\n# 2. Create folder structure\n# 3. Install files into the appropriate location\n# 4. Report progress to dxdt\n# 5. Launch the stats collecting agent (dxdt-collectd)\n#\n# If you have any questions about how this works, email [email protected]\n#\n##############################################################################\n\n\n##############################################################################\n# Environment Variables (Options)\n##############################################################################\n#\n# Set DXDT_MACHINE_ID to a unique url-safe string for each computer\n# or to override default.\n# Note: we use this to connect data to the machine, so if you change it,\n# You will be creating a new machine!\n#\n# Set DXDT_BASE_DIR to the folder that you want DXDT to use as its root.\n# by default it is /opt/dxdt\n#\n# Note that we still put the conf in /etc/dxdt.conf\n#\n##############################################################################\n\n##############################################################################\n# Begin critical section; exit if any line returns anything non 0\n##############################################################################\nset -e\n##############################################################################\n\n\n\n# This should never change unless you are a dxdt developer :)\nDXDT_ENDPOINT="', endpoint ,'";\n\n# This is your account API Key. It is not a secret.\nDXDT_API_KEY="', apiKey ,'";\n\n#Tokens grant acess to a specific environment for a given account.\n# Every time you download the install.sh script, we generate a new token for you\n# this lets you revoke tokens in a fine-grained way.\n# The tokens created have read+write access, but not GRANT access.\nDXDT_TOKEN="', token ,'";\n\n# Machine id MUST be unique per account. A unique one is generated on download\n# OR use the env var DXDT_MACHINE_ID if you want to override it.\n# \n# If you are going to re-use the install script you have downloaded, you MUST\n# specify a new DXDT_MACHINE_ID for each new machine.\n\nif test "$DXDT_MACHINE_ID"\nthen DXDT_MACHINE_ID="$DXDT_MACHINE_ID"; #noop, but useful for readability.\nelse\n DXDT_MACHINE_ID="', machineId ,'" ;\nfi\n\n# Where to store the dxdt-collectd script\nif test "$DXDT_BASE_DIR"\nthen DXDT_BASE_DIR="$DXDT_BASE_DIR";\nelse DXDT_BASE_DIR="/opt/dxdt";\nfi\n\nfunction failedInstall {\n #TODO: include PATH\n code=`curl -d "machineid=$DXDT_MACHINE_ID" -d "failure=$1" --user "$DXDT_API_KEY:$DXDT_TOKEN" --write-out %{http_code} --silent --output /dev/null $DXDT_ENDPOINT/install-failed`;\n}\n\n# Start Capability Checks.\nif command -v md5 &>/dev/null; \n then hshcommand="md5"; #BSD\n else\n if command -v md5sum &>/dev/null\n then hshcommand="md5sum"; #LINUX\n else failedInstall "Please install md5 or md5sum and make sure it is in the PATH.";\n fi\nfi\n\nif command -v ifconfig &>/dev/null;\n then networkConfiguration=`ifconfig -a`;\n else failedInstall "Please install ifconfig and make sure it is in the PATH.";\nfi\n\n\nfunction testCommand {\n if command -v $1 &>/dev/null;\n then echo "Command found: $1";\n else failedInstall "Please install $1 and make sure it is in the PATH.";\n fi\n return 0\n}\n\nfor command in date rm time tar grep uptime lsof df ifconfig mkdir\ndo\n testCommand $command\ndone\n\n##############################################################################\n# Create directories\n##############################################################################\n\n#TODO: Report failure if it should occur.\nmkdir -p $DXDT_BASE_DIR\n\n##############################################################################\n# Write Config File\n##############################################################################\n\n(\ncat<<EOF\n#!/usr/bin/env bash\nexport DXDT_ENDPOINT="$DXDT_ENDPOINT"\nexport DXDT_API_KEY="$DXDT_API_KEY"\nexport DXDT_TOKEN="$DXDT_TOKEN"\nexport DXDT_MACHINE_ID="$DXDT_MACHINE_ID"\nexport DXDT_BASE_DIR="$DXDT_BASE_DIR"\nEOF\n)> /etc/dxdt-collectd.conf\n\n# we want to be able to execute it to set up our environment\nchmod +rx /etc/dxdt-collectd.conf\n\n\n');}return __p.join('');
var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('#!/usr/bin/env bash\n\n##############################################################################\n#\n# _______ _______ \n# \\ ___ `\'. \\ ___ `\'. \n# \' |--.\\ \\ \' |--.\\ \\ \n# | | \\ \' | | \\ \' .| \n# | | | \' ____ _____ | | | \' .\' |_ \n# | | | |`. \\ .\' / | | | | .\' | \n# | | \' .\' `. `\' .\' | | \' .\'\'--. .-\' \n# | |___.\' /\' \'. .\' | |___.\' /\' | | \n# /_______.\'/ .\' `. /_______.\'/ | | \n# \\_______|/ .\' .\'`. `.\\_______|/ | \'.\n# .\' / `. `. | / \n# \'----\' \'----\' `\'-\' \n#\n#\n##############################################################################\n#\n#\n# https://dxdt.io Server Monitoring\n# This software is provided with NO WARRANTY, express or implied.\n# While we believe that it is a fine piece of code, we make no garauntees.\n# It might destroy your computer, or launch nukes at the USSR.\n# \n# By using this software, you agree to the terms and conditions at\n# https://dxdt.io/terms\n#\n#\n##############################################################################\n\n\n\n##############################################################################\n# Overview\n##############################################################################\n#\n# This script does a few things:\n# \n# 1. Check for all pre-requisite commands (grep, tar, lsof, ifconfig...)\n# 2. Create folder structure\n# 3. Install files into the appropriate location\n# 4. Report progress to dxdt\n# 5. Launch the stats collecting agent (dxdt-collectd)\n#\n# If you have any questions about how this works, email [email protected]\n#\n##############################################################################\n\n\n##############################################################################\n# Environment Variables (Options)\n##############################################################################\n#\n# Set DXDT_MACHINE_ID to a unique url-safe string for each computer\n# or to override default.\n# Note: we use this to connect data to the machine, so if you change it,\n# You will be creating a new machine!\n#\n# Set DXDT_BASE_DIR to the folder that you want DXDT to use as its root.\n# by default it is /opt/dxdt\n#\n# Note that we still put the conf in /etc/dxdt.conf\n#\n##############################################################################\n\n##############################################################################\n# Begin critical section; exit if any line returns anything non 0\n##############################################################################\nset -e\n##############################################################################\n\n\n\n# This should never change unless you are a dxdt developer :)\nDXDT_ENDPOINT="', endpoint ,'";\n\n# This is your account API Key. It is not a secret.\nDXDT_API_KEY="', apiKey ,'";\n\n#Tokens grant acess to a specific environment for a given account.\n# Every time you download the install.sh script, we generate a new token for you\n# this lets you revoke tokens in a fine-grained way.\n# The tokens created have read+write access, but not GRANT access.\nDXDT_TOKEN="', token ,'";\n\n# Machine id MUST be unique per account. A unique one is generated on download\n# OR use the env var DXDT_MACHINE_ID if you want to override it.\n# \n# If you are going to re-use the install script you have downloaded, you MUST\n# specify a new DXDT_MACHINE_ID for each new machine.\n\nif test "$DXDT_MACHINE_ID"\nthen DXDT_MACHINE_ID="$DXDT_MACHINE_ID"; #noop, but useful for readability.\nelse\n DXDT_MACHINE_ID="', machineId ,'" ;\nfi\n\n# Where to store the dxdt-collectd script\nif test "$DXDT_BASE_DIR"\nthen DXDT_BASE_DIR="$DXDT_BASE_DIR";\nelse DXDT_BASE_DIR="/opt/dxdt";\nfi\n\nfunction failedInstall {\n #TODO: include PATH\n code=`curl -d "machineid=$DXDT_MACHINE_ID" -d "failure=$1" --user "$DXDT_API_KEY:$DXDT_TOKEN" --write-out %{http_code} --silent --output /dev/null $DXDT_ENDPOINT/install-failed`;\n}\n\n# Start Capability Checks.\nif command -v md5 &>/dev/null; \n then hshcommand="md5"; #BSD\n else\n if command -v md5sum &>/dev/null\n then hshcommand="md5sum"; #LINUX\n else failedInstall "Please install md5 or md5sum and make sure it is in the PATH.";\n fi\nfi\n\nif command -v ifconfig &>/dev/null;\n then networkConfiguration=`ifconfig -a`;\n else failedInstall "Please install ifconfig and make sure it is in the PATH.";\nfi\n\n\nfunction testCommand {\n if command -v $1 &>/dev/null;\n then echo "Command found: $1";\n else failedInstall "Please install $1 and make sure it is in the PATH.";\n fi\n return 0\n}\n\nfor command in date rm time tar grep uptime lsof df ifconfig mkdir\ndo\n testCommand $command\ndone\n\n##############################################################################\n# Create directories\n##############################################################################\n\n#TODO: Report failure if it should occur.\nmkdir -p $DXDT_BASE_DIR\n\n##############################################################################\n# Write Config File\n##############################################################################\n\n(\ncat<<EOF\n#!/usr/bin/env bash\nexport DXDT_ENDPOINT="$DXDT_ENDPOINT"\nexport DXDT_API_KEY="$DXDT_API_KEY"\nexport DXDT_TOKEN="$DXDT_TOKEN"\nexport DXDT_MACHINE_ID="$DXDT_MACHINE_ID"\nexport DXDT_BASE_DIR="$DXDT_BASE_DIR"\nEOF\n)> /etc/dxdt-collectd.conf\n\n# we want to be able to execute it to set up our environment\nchmod +rx /etc/dxdt-collectd.conf\n\n\n(\ncat<<"DXDT-COLLECTD-SOURCE"\n #!/usr/bin/env bash\n\n if [ -n /etc/dxdt-collectd.conf ]\n then source /etc/dxdt-collectd.conf;\n else \n echo "You MUST have an /etc/dxdt-collectd.conf that contains the DXDT_* environment variables.";\n exit;\n fi\n\n ###############################################################\n # Begin critical section; exit if any line returns anything bad\n ###############################################################\n set -e\n ###############################################################\n\n if [ -n "$1" ]\n then infodir="$1";\n else infodir="stats_`date +%s`"; \n fi\n\n process_dir="$infodir/processes"\n sys_dir="$infodir/sys"\n\n mkdir -p $infodir\n mkdir $process_dir\n mkdir $sys_dir\n\n\n if command -v md5 &>/dev/null; \n then hshcommand="md5"; #BSD\n else hshcommand="md5sum"; #LINUX\n fi\n\n if command -v vm_stat &>/dev/null;\n then vmcommand="vm_stat"; #OSX/BSD \n else vmcommand="vmstat"; #LINUX\n fi\n\n\n # Generic Run a command and save stdout and stderr to files\n\n function runAndRecordWithTime {\n # command directory basename\n /usr/bin/time -p bash -c "$1 1>$2/$3.stdout.txt 2>$2/$3.stderr.txt" 2> $2/$3.time.txt;\n }\n\n function runAndRecord {\n # command directory basename\n # optionally include the time to run the command (expensive.)\n $1 > "$2/$3.stdout.txt" 2> "$2/$3.stderr.txt";\n }\n\n function log {\n # command directory\n runAndRecord "$1" "$2" "$1"\n }\n\n\n # Process monitoring functions\n function runAndRecordProcess {\n # command basename\n runAndRecord "$1" "$process_dir" "$2"\n }\n\n # Utility function to get info about all the processes on the machine\n # Note that we have to do this with multiple calls to ps because the output of `ps` is otherwise not machine parseable\n pslist="ps -A -o pid -o"\n function getInfo {\n # ps format string\n runAndRecordProcess "$pslist $1" $1\n }\n\n function getInfoPercent {\n # ps format string that will be prepended with %\n runAndRecordProcess "$pslist %$1" $1\n }\n\n ###############################################################\n # END critical section; exit if any line returns anything bad\n ###############################################################\n set +e\n ###############################################################\n\n\n getInfo lstart #Full start time\n getInfo ucomm # simple name\n\n getInfo args # full command name with args (unless ps is in "safe mode")\n\n getInfo rss # resident size in Kbytes\n getInfo vsz # resident size in Kbytes\n getInfo utime # user CPU time\n getInfo time # user + system CPU time\n\n getInfoPercent cpu\n getInfoPercent mem\n\n #System-wide performance\n log $vmcommand "$sys_dir"\n log uptime "$sys_dir"\n runAndRecordWithTime "df -k" "$sys_dir" df\n\n runAndRecord "date +%s" "$sys_dir" date\n runAndRecord "lsof -iTCP -sTCP:LISTEN -P -Fpn" "$sys_dir" lsoftcp\n\n ###############################################################\n # Begin critical section; exit if any line returns anything bad\n ###############################################################\n set -e\n ###############################################################\n\n #Network info\n log "hostname" "$sys_dir"\n runAndRecord "ifconfig -a" "$sys_dir" ifconfig\n\n echo "$DXDT_MACHINE_ID" > $infodir/machineid;\n\n outputfilename="$infodir.tgz"\n tar -czf "$outputfilename" $infodir/\n rm -rf $infodir/\n\n ###############################################################\n # Begin uploading. Will attempt to upload all .tgz files in dir\n ###############################################################\n for filename in *.tgz; do\n set +e\n\n code=`curl -F "bulk=@$filename" --user "$DXDT_API_KEY:$DXDT_TOKEN" --write-out %{http_code} --silent --output /dev/null $DXDT_ENDPOINT`;\n set -e\n\n echo $code\n\n if [ "$code" == "200" ]; then\n `rm $filename`;\n else\n echo "upload of $filename failed, will not delete.";\n fi\n done\n\nDXDT-COLLECTD-SOURCE\n)> /opt/dxdt/dxdt-collectd.sh\n');}return __p.join('');
}
, "cpu": function anonymous(locals) {
with(locals || {}) {
Expand Down
Loading

0 comments on commit 82208d6

Please sign in to comment.