pastebin

Paste Search Dynamic
Recent pastes
/GenerateStatsMarkdown.sh
  1. #! /usr/bin/env bash
  2. # Author: Lilian BESSON
  3. # Email: Lilian.BESSON[AT]ens-cachan[DOT]fr
  4. # Web version: http://perso.crans.org/besson/bin/GenerateStatsMarkdown.sh
  5. # Web version (2): https://bitbucket.org/lbesson/bin/src/master/GenerateStatsMarkdown.sh
  6. # Date: 07-01-2017
  7. #
  8. # A small script to create a minimalistic Markdown status page for my machine, available locally at http://0.0.0.0/stats.html
  9. #
  10. # Hack: this markdown page is using http://lbo.k.vu/md/ (StrapDown.js) to be a good-looking HTML page !
  11. #
  12. BIN=GenerateStatsMarkdown
  13. version=1.8
  14.  
  15. # StrapDownJS nicest themes : united
  16. theme="${2:-united}"
  17. dest="${HOME}/Public/stats.html"
  18.  
  19. # Argument handling
  20. case "$1" in
  21.         bootstrap|cerulean|cosmo|cyborg|darkly|flatly|journal|lumen|paper|readable|sandstone|simplex|slate|spacelab|superhero|united|yeti)
  22.                 # cyborg|united|bootstrap|darkly|lumen|paper|simplex)
  23.                 echo -e "${red}Using $1 as a theme option...${white}"
  24.                 theme="$1"
  25.                 shift
  26.                 ;;
  27.         -h|--help)
  28.                 echo -e "${green}${BIN}${white} --help | [options]\n Creates a minimalistic statistics HTML report, to ${u}${black}${dest}${U}${white}.\n It uses ${u}${black}http://lbo.k.vu/md/${U}${white} (${cyan}StrapDown.js${white}) to improve the awesomeness of this mini munin clone."
  29.                 echo -e "\n${red}Options:${white}\n 1:\t${yellow}--help${white}\tto print this help,\n 1:\t${yellow}cron${white}\tto change logging behaviour (only if launched by cron),\n 1,2:\t${yellow}theme${white}\t${neg}bootstrap${Neg}, ${neg}cerulean${Neg}, ${neg}cosmo${Neg}, ${neg}cyborg${Neg}, ${neg}darkly${Neg}, ${neg}flatly${Neg}, ${neg}journal${Neg}, ${neg}lumen${Neg}, ${neg}paper${Neg}, ${neg}readable${Neg}, ${neg}sandstone${Neg}, ${neg}simplex${Neg}, ${neg}slate${Neg}, ${neg}spacelab${Neg}, ${neg}superhero${Neg}, ${neg}united${Neg}, ${neg}yeti${Neg} (${cyan}Default and best is ${neg}united${Neg}${white}.)\n\n"
  30.                 echo -e "${green}$BIN v$version : Copyleft: (c) Lilian Besson 2014-16.\nReleased under the term of the GPL v3 Licence (more details on http://perso.crans.org/besson/LICENSE.html).${white}\nIn particular, $BIN is provided WITHOUT ANY WARANTY."
  31.                 exit 0
  32.                 ;;
  33.         *)
  34.                 ;;
  35. esac
  36.  
  37. echo -e "${yellow}.: Lilian Besson presents :."
  38. echo -e "${cyan}${BIN}, v${version}${reset}"
  39.  
  40. theme="${theme:-united}"
  41. echo -e "${white}The report will be written to : ${black}${u}${dest}${U}${white}, with the theme ${magenta}${theme}${white}."
  42. if [ -f "$dest" ]; then
  43.         cp -vf "$dest" /tmp/
  44. fi
  45.  
  46. # Header
  47. hstn="$(hostname)"
  48. echo -e "<!DOCTYPE html><html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/><title>Stats pour ${hstn}</title></head><body><xmp theme=\"${theme}\">" > "$dest"
  49. echo -e "# Informations systèmes pour [*${hstn}*](http://0.0.0.0/)" >> "$dest"
  50. echo -e "> #### Signaler *tout problème* à [jarvis @ crans . org](mailto:jarvisATcransDOTorg) ou via [bitbucket](https://bitbucket.org/lbesson/bin/issues/new).\n> #### Données mises à jour le **$(date "+%c")**." >> "$dest"
  51. echo -e "> #### Consulter [*les rapports munin*](http://0.0.0.0/lns_munin/localdomain/localhost.localdomain/index.html) (plus complets) ? [*les stats uLogMe*](http://localhost:8124/index.html) ? [*les stats WakaTime*](https://wakatime.com/dashboard) ?" >> "$dest"
  52. echo -e "\n\n***\n" >> "$dest"
  53.  
  54. MY_IP=$(/sbin/ifconfig | awk '/inet adr:/ { print $2 } ' | sed -e s/addr://)
  55.  
  56. echo -e "## Nom de machine et version du noyau\n> <pre>" >> "$dest"
  57. uname -a | sed s/"x86_64 x86_64 x86_64"/"x86_64"/ >> "$dest"
  58.  
  59. echo -e "</pre>\n\n## Informations générales\n> <pre>" >> "$dest"
  60. landscape-sysinfo | head --lines=-3 | grep -v "^$" >> "$dest"
  61.  
  62. echo -e "</pre>\n\n***\n\n## [Utilisateurs connectés](munin/localdomain/localhost.localdomain/users.html)\n- $(w -h | wc -l) utilisateurs, $(w -h | awk '{ print $1 }' | uniq | wc -l) utilisateurs différents...\n- *Normalement*, juste *lilian* ! Liste : $(w -h | awk '{ print $1 }' | uniq)\n> <pre>" >> "$dest"
  63. w -h >> "$dest"
  64.  
  65. echo -e "</pre>\n\n## Adresse(s) IP locale(s)\n> <pre>" >> "$dest"
  66. echo "${MY_IP:-"Not connected"}" >> "$dest"
  67.  
  68. echo -e "</pre>\n\n## [Adresse IP externe](http://monip.org)\n> <pre>" >> "$dest"
  69. wget --tries=5 --quiet monip.org -O - | html2text -width 50 | grep -v "^$" >> "$dest"
  70. echo -e "</pre>\n<pre>" >> "$dest"
  71. if type ipinfo.sh &>/dev/null; then ipinfo.sh | sed s/'^'/'- '/; else curl --silent ipinfo.io | python -m json.tool | grep -v "\(\{\|\}\)" | sed s/'"'//g | sed s/'^   '/'-'/; fi | sort >> "$dest"
  72.  
  73. echo -e "</pre>\n\n## [Météo (forecast.io)](https://forecast.io/)\n<figure>" >> "$dest"
  74. echo -e "<iframe height='400' width='100%' style='border:none;' frameborder='0' scrolling='no' src='https://forecast.io/'><a href='https://forecast.io/'>Go see the forecast.io website.</a> Your browser seems to not be able to display a iframe tag.</iframe></figure>" >> "$dest"
  75.  
  76. echo -e "\n\n## [Statut NGinx](munin/localdomain/localhost.localdomain/index.html#nginx)\n> <pre>" >> "$dest"
  77. if type nginx_status.sh &>/dev/null; then nginx_status.sh; fi >> "$dest"
  78.  
  79. echo -e "</pre>\n\n## [Durée d'activité](munin/localdomain/localhost.localdomain/uptime.html) - $(uptime --pretty | sed s/'up '/''/)\n> <pre>" >> "$dest"
  80. uptime >> "$dest"
  81.  
  82. echo -e "</pre>\n\n***\n\n## [Disques locaux](munin/localdomain/localhost.localdomain/df.html)\n> <pre>" >> "$dest"
  83. df -h -T -l -t ext3 -t ext4 -t fuseblk >> "$dest"
  84.  
  85. echo -e "</pre>\n\n## [Mémoire RAM et swap](munin/localdomain/localhost.localdomain/memory.html)\n> <pre>" >> "$dest"
  86. free -h >> "$dest"
  87.  
  88. echo -e "</pre>\n\n## Message du jour\n> <pre>" >> "$dest"
  89. [ -f "${HOME}"/motd ] && cat "${HOME}"/motd | grep -v '^$' >> "$dest"
  90.  
  91. echo -e "</pre>\n\n## Séries en cours\n> <pre>" >> "$dest"
  92. [ -f "${HOME}"/current ] && head -n 3 "${HOME}"/current >> "$dest"
  93.  
  94. # Stats CUPS
  95. echo -e "</pre>\n\n## [Documents imprimés](munin/localdomain/localhost.localdomain/printed_docs.html) aujourd'hui\n> <pre>" >> "$dest"
  96. wget --quiet 'http://127.0.0.1:631/jobs?which_jobs=completed' -O /tmp/cups_completed_jogs_log.html
  97. echo "- Nombre de documents : $(html2text -width 1000 /tmp/cups_completed_jogs_log.html | grep -B 1 "$(date "+%a %d %b %Y")" | grep -c "completed")" >> "$dest"
  98. echo "- Nombre de pages : $(html2text -width 1000 /tmp/cups_completed_jogs_log.html | grep -B 1 "$(date "+%a %d %b %Y")" | grep "completed" | awk ' { print $3 }' | grep -o "[0-9]*" | python -c 'import sys; print(sum(map(int, sys.stdin)))')" >> "$dest"
  99.  
  100. # Stats uLogMe
  101. echo -e "</pre>\n\n## Stats <a href='https://github.com/Naereen/uLogMe/'>uLogMe</a>\n" >> "$dest"
  102. echo -e "\n- [Overview](http://localhost:8124/overview.html)" >> "$dest"
  103. echo -e "\n- [Single-day view](http://localhost:8124/index.html)" >> "$dest"
  104.  
  105. # Links to other self-statistics
  106. echo -e "\n\n## Autres statistiques\n" >> "$dest"
  107. echo -e "\n- [Monitoring Workstations SCEE](http://monitoring/) & [Munin SCEE](http://ws3/)" >> "$dest"
  108. echo -e "\n- [Suivi conso - Free Mobile](https://mobile.free.fr/moncompte/index.php?page=suiviconso)" >> "$dest"
  109. echo -e "\n- [Google Analytics](https://www.google.com/analytics/web/#home/a38514290w67185072p69122598/)" >> "$dest"
  110. echo -e "\n- [Google URL Shortener (goo.gl)](https://goo.gl/)" >> "$dest"
  111. echo -e "\n- [Bitbucket activity](https://bitbucket.org/lbesson/profile/repositories)" >> "$dest"
  112. echo -e "\n- [GitHub activity](https://github.com/Naereen?tab=activity)" >> "$dest"
  113.  
  114. # XXX Links to local self-statistics, need https://addons.mozilla.org/firefox/addon/281
  115. echo -e "\n\n## Statistiques locales\n" >> "$dest"
  116. echo -e "\n- <a href='resource://jid0-hynmqxa9zqgfjadreri4n2ahksi-at-jetpack/data/index.html' target='_blank'>Mind the Time</a> (Firefox browsing, local data)" >> "$dest"  # XXX resource:// link does not work from http(s?):// pages
  117. # echo -e "\n- <a href='file:///home/lilian/Public/stats.html' target='_blank'>Local version of this stats.html file</a>" >> "$dest"  # XXX file:// link does not work from http(s?):// pages
  118.  
  119. # Stats WakaTime.
  120. echo -e "\n\n## Stats <a href='https://wakatime.com/dashboard'>WakaTime</a>\n" >> "$dest"
  121. # wakatime.js -w >> "$dest"  # DEBUG that's not working!
  122. # mywakatime -w >> "$dest"   # DEBUG that's not working!
  123. echo -e "\n<figure><embed style='text_align:center;margin-left:auto;margin-right:auto;' width='680' type='image/svg+xml' src='https://wakatime.com/@lbesson/5d1ec603-73b0-44b9-b61e-5eeda2490e51.svg'></embed></figure>" >> "$dest"
  124. echo -e "\n<figure><embed style='text_align:center;margin-left:auto;margin-right:auto;' width='680' type='image/svg+xml' src='https://wakatime.com/@lbesson/9f6c0b0b-6806-4afa-9a4e-651ee6201be0.svg'></embed></figure>" >> "$dest"
  125.  
  126. # XXX it was costing too much CPU time
  127. # Optionnal Selfspy visualisation (selfstats, selfspy-vis, cf. https://github.com/Naereen/selfspy-vis))
  128. #type selfstats >/dev/null
  129. #if [ "X$?" = "X0" ]; then
  130. #       echo -e "\n\n## <a href='http://jarvis/selfvis.html'>Ratio clicks/keystrokes</a> (\`selfstats --human-readable --ratios\`)\n> <pre>" >> "$dest"
  131. #       selfstats --human-readable --ratios | sed '/^$/d' >> "$dest"
  132. #
  133. #       echo -e "</pre>\n\n## <a href='http://jarvis/selfvis.html'>Summary of clicks</a> (\`selfstats --human-readable --clicks\`)\n> <pre>" >> "$dest"
  134. #       selfstats --human-readable --clicks | sed '/^$/d' >> "$dest"
  135. #
  136. #       echo -e "</pre>\n\n## <a href='http://jarvis/selfvis.html'>Stats</a> <a href='https://github.com/gurgeh/selfspy#example-statistics'>selfspy</a> (\`selfstats --min-keys 10 --back 1w --human-readable --pactive\`)\n> <pre>" >> "$dest"
  137. #       selfstats --min-keys 10 --back 1w --human-readable --pactive | sed '/^$/d' >> "$dest"
  138. #fi
  139.  
  140. # Footer
  141. if [ "X$1" = "Xcron" ]; then
  142.         echo -e "</pre>\n\n***\n\n##### Mis-à-jour régulièrement via *cron*, avec [GenerateStatsMarkdown.sh](http://perso.crans.org/besson/bin/GenerateStatsMarkdown.sh) v${version}, un script Bash, [open-source](https://lbesson.mit-license.org/), écrit par et pour [Lilian Besson](http://perso.crans.org/besson/)." >> "$dest"
  143. else
  144.         echo -e "</pre>\n\n***\n\n##### Généré avec [GenerateStatsMarkdown.sh](http://perso.crans.org/besson/bin/GenerateStatsMarkdown.sh) v${version}, un script Bash, [open-source](https://lbesson.mit-license.org/), écrit par et pour [Lilian Besson](http://perso.crans.org/besson/)." >> "$dest"
  145. fi
  146.  
  147. # XXX add http://perso.crans.org/besson/ before _static/
  148. echo -e "\n</xmp><script type=\"text/javascript\" src=\"_static/md/strapdown.min.js?src=GSM.sh\"></script>\n<noscript><img alt=\"GA|Analytics\" style=\"visibility: hidden; display: none;\" src=\"https://ga-beacon.appspot.com/UA-38514290-1/stats.html/theme_${theme}/?pixel\"/></noscript>\n</body></html>" >> "$dest"
  149.  
  150.  
  151. # Notify the user
  152. if [ "X$1" = "Xcron" ]; then
  153.         echo -e "${blue}Tâche lancée via gnome-schedule ou cron ou crontab.${white}"
  154.         notify-send "GenerateStatsMarkdown.sh" "Fichier de statistiques bien généré (<i>$dest</i>).\n<small>(Tâche lancée via gnome-schedule ou cron ou crontab)</small>"
  155. else
  156.         notify-send "GenerateStatsMarkdown.sh" "Fichier de statistiques bien généré (<i>$dest</i>)."
  157. fi
  158.  
  159. echo -e "${green}Done !${white} (date: $(date))"
  160. # DONE
Parsed in 0.135 seconds