Skip to content

Instantly share code, notes, and snippets.

@mhausenblas
Last active October 9, 2016 12:05
Show Gist options
  • Save mhausenblas/44860b0a7e8688d1822ebaa02522656b to your computer and use it in GitHub Desktop.
Save mhausenblas/44860b0a7e8688d1822ebaa02522656b to your computer and use it in GitHub Desktop.
Takes a snapshot of the world view (user, processes, RAM, CPU, networking) and stores it in a epoch-now-timestamped file
#!/bin/bash -e
#
# Takes a snapshot of the machine world view (incl. user info,
# processes, memory, CPU, and networking) and stores it in a
# epoch-now-timestamped file. Note that the machine could be a
# physical server, a VM or a container.
#
# Example:
#
# $ ./gen-worldview.sh
# $ cat 1475942566
#
###############################################################################
set -e
set -o pipefail
worldview=$(date +%s)
touch $worldview
# add real and effective user and group IDs:
printf "== USER\n" >> $worldview
id >> $worldview
# add processes:
printf "\n\n== PROCESSES\n" >> $worldview
ps auxf | cut -c -120 >> $worldview
# add memory stats:
printf "\n\n== MEMORY\n" >> $worldview
free >> $worldview
# add CPU stats
printf "\n\n== CPU\n" >> $worldview
grep processor /proc/cpuinfo >> $worldview
# add networking stats
printf "\n\n== NETWORKING\n" >> $worldview
hostname >> $worldview
ip link >> $worldview
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment