You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

230 lines
12 KiB

  1. #!/bin/bash
  2. #####################################################################
  3. # Benchmark Script 2 by Hidden Refuge from FreeVPS #
  4. # Copyright(C) 2015 - 2016 by Hidden Refuge #
  5. # Github: https://github.com/hidden-refuge/bench-sh-2 #
  6. #####################################################################
  7. # Original script by akamaras/camarg #
  8. # Original: http://www.akamaras.com/linux/linux-server-info-script/ #
  9. # Original Copyright (C) 2011 by akamaras/camarg #
  10. #####################################################################
  11. # The speed test was added by dmmcintyre3 from FreeVPS.us as a #
  12. # modification to the original script. #
  13. # Modded Script: https://freevps.us/thread-2252.html #
  14. # Copyright (C) 2011 by dmmcintyre3 for the modification #
  15. #####################################################################
  16. sysinfo () {
  17. # Removing existing bench.log
  18. rm -rf $HOME/bench.log
  19. # Reading out system information...
  20. # Reading CPU model
  21. cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' )
  22. # Reading amount of CPU cores
  23. cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo )
  24. # Reading CPU frequency in MHz
  25. freq=$( awk -F: ' /cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' )
  26. # Reading total memory in MB
  27. tram=$( free -m | awk 'NR==2 {print $2}' )
  28. # Reading Swap in MB
  29. vram=$( free -m | awk 'NR==4 {print $2}' )
  30. # Reading system uptime
  31. up=$( uptime | awk '{ $1=$2=$(NF-6)=$(NF-5)=$(NF-4)=$(NF-3)=$(NF-2)=$(NF-1)=$NF=""; print }' | sed 's/^[ \t]*//;s/[ \t]*$//' )
  32. # Reading operating system and version (simple, didn't filter the strings at the end...)
  33. opsy=$( cat /etc/issue.net | awk 'NR==1 {print}' ) # Operating System & Version
  34. arch=$( uname -m ) # Architecture
  35. lbit=$( getconf LONG_BIT ) # Architecture in Bit
  36. hn=$( hostname ) # Hostname
  37. kern=$( uname -r )
  38. # Date of benchmark
  39. bdates=$( date )
  40. echo "Benchmark started on $bdates" | tee -a $HOME/bench.log
  41. echo "Full benchmark log: $HOME/bench.log" | tee -a $HOME/bench.log
  42. echo "" | tee -a $HOME/bench.log
  43. # Output of results
  44. echo "System Info" | tee -a $HOME/bench.log
  45. echo "-----------" | tee -a $HOME/bench.log
  46. echo "Processor : $cname" | tee -a $HOME/bench.log
  47. echo "CPU Cores : $cores" | tee -a $HOME/bench.log
  48. echo "Frequency : $freq MHz" | tee -a $HOME/bench.log
  49. echo "Memory : $tram MB" | tee -a $HOME/bench.log
  50. echo "Swap : $vram MB" | tee -a $HOME/bench.log
  51. echo "Uptime : $up" | tee -a $HOME/bench.log
  52. echo "" | tee -a $HOME/bench.log
  53. echo "OS : $opsy" | tee -a $HOME/bench.log
  54. echo "Arch : $arch ($lbit Bit)" | tee -a $HOME/bench.log
  55. echo "Kernel : $kern" | tee -a $HOME/bench.log
  56. echo "" | tee -a $HOME/bench.log
  57. echo "" | tee -a $HOME/bench.log
  58. }
  59. speedtest4 () {
  60. ipiv=$( wget -qO- ipv4.icanhazip.com ) # Getting IPv4
  61. # Speed test via wget for IPv4 only with 10x 100 MB files. 1 GB bandwidth will be used!
  62. echo "Speedtest (IPv4 only)" | tee -a $HOME/bench.log
  63. echo "---------------------" | tee -a $HOME/bench.log
  64. echo "" | tee -a $HOME/bench.log
  65. # Cachefly CDN speed test
  66. echo "Location Provider Speed" | tee -a $HOME/bench.log
  67. cachefly=$( wget -4 -O /dev/null http://cachefly.cachefly.net/100mb.test 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
  68. echo "CDN Cachefly $cachefly" | tee -a $HOME/bench.log
  69. echo "" | tee -a $HOME/bench.log
  70. # United States speed test
  71. coloatatl=$( wget -4 -O /dev/null http://speed.atl.coloat.com/100mb.test 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
  72. echo "Atlanta, GA, US Coloat $coloatatl " | tee -a $HOME/bench.log
  73. slwdc=$( wget -4 -O /dev/null http://speedtest.wdc01.softlayer.com/downloads/test100.zip 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
  74. echo "Washington, DC, US Softlayer $slwdc " | tee -a $HOME/bench.log
  75. echo "" | tee -a $HOME/bench.log
  76. # Asia speed test
  77. linodejp=$( wget -4 -O /dev/null http://speedtest.tokyo.linode.com/100MB-tokyo.bin 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
  78. echo "Tokyo, Japan Linode $linodejp " | tee -a $HOME/bench.log
  79. slsg=$( wget -4 -O /dev/null http://speedtest.sng01.softlayer.com/downloads/test100.zip 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
  80. echo "Singapore Softlayer $slsg " | tee -a $HOME/bench.log
  81. echo "" | tee -a $HOME/bench.log
  82. # Europe speed test
  83. i3d=$( wget -4 -O /dev/null http://mirror.i3d.net/100mb.bin 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
  84. echo "Rotterdam, Netherlands id3.net $i3d" | tee -a $HOME/bench.log
  85. leaseweb=$( wget -4 -O /dev/null http://mirror.leaseweb.com/speedtest/100mb.bin 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
  86. echo "Haarlem, Netherlands Leaseweb $leaseweb " | tee -a $HOME/bench.log
  87. ovh=$( wget -4 -O /dev/null http://speedtest.virtubox.host/files/100Mio.dat 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
  88. echo "Paris, France OVH $ovh " | tee -a $HOME/bench.log
  89. echo "" | tee -a $HOME/bench.log
  90. echo "" | tee -a $HOME/bench.log
  91. }
  92. speedtest6 () {
  93. ipvii=$( wget -qO- ipv6.icanhazip.com ) # Getting IPv6
  94. # Speed test via wget for IPv6 only with 10x 100 MB files. 1 GB bandwidth will be used! No CDN - Cachefly not IPv6 ready...
  95. echo "Speedtest (IPv6 only)" | tee -a $HOME/bench.log
  96. echo "---------------------" | tee -a $HOME/bench.log
  97. echo "Your public IPv6 is $ipvii" | tee -a $HOME/bench.log
  98. echo "" | tee -a $HOME/bench.log
  99. echo "Location Provider Speed" | tee -a $HOME/bench.log
  100. # United States speed test
  101. v6atl=$( wget -6 -O /dev/null http://speedtest.atlanta.linode.com/100MB-atlanta.bin 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
  102. echo "Atlanta, GA, US Linode $v6atl" | tee -a $HOME/bench.log
  103. v6chi=$( wget -6 -O /dev/null http://testfile.chi.steadfast.net/data.bin 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
  104. echo "Chicago, IL, US Steadfast $v6chi" | tee -a $HOME/bench.log
  105. echo "" | tee -a $HOME/bench.log
  106. # Asia speed test
  107. v6tok=$( wget -6 -O /dev/null http://speedtest.tokyo.linode.com/100MB-tokyo.bin 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
  108. echo "Tokyo, Japan Linode $v6tok" | tee -a $HOME/bench.log
  109. v6sin=$( wget -6 -O /dev/null http://speedtest.singapore.linode.com/100MB-singapore.bin 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
  110. echo "Singapore Linode $v6sin" | tee -a $HOME/bench.log
  111. echo "" | tee -a $HOME/bench.log
  112. # Europe speed test
  113. v6fra=$( wget -6 -O /dev/null http://speedtest.frankfurt.linode.com/100MB-frankfurt.bin 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
  114. echo "Frankfurt, Germany Linode $v6fra" | tee -a $HOME/bench.log
  115. v6lon=$( wget -6 -O /dev/null http://speedtest.london.linode.com/100MB-london.bin 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
  116. echo "London, UK Linode $v6lon" | tee -a $HOME/bench.log
  117. v6har=$( wget -6 -O /dev/null http://mirror.nl.leaseweb.net/speedtest/100mb.bin 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
  118. echo "Haarlem, Netherlands Leaseweb $v6har" | tee -a $HOME/bench.log
  119. echo "" | tee -a $HOME/bench.log
  120. echo "" | tee -a $HOME/bench.log
  121. }
  122. iotest () {
  123. echo "Disk Speed" | tee -a $HOME/bench.log
  124. echo "----------" | tee -a $HOME/bench.log
  125. # Measuring disk speed with DD
  126. io=$( ( dd if=/dev/zero of=test_$$ bs=64k count=16k conv=fdatasync && rm -f test_$$ ) 2>&1 | awk -F, '{io=$NF} END { print io}' | sed 's/^[ \t]*//;s/[ \t]*$//' )
  127. io2=$( ( dd if=/dev/zero of=test_$$ bs=64k count=16k conv=fdatasync && rm -f test_$$ ) 2>&1 | awk -F, '{io=$NF} END { print io}' | sed 's/^[ \t]*//;s/[ \t]*$//' )
  128. io3=$( ( dd if=/dev/zero of=test_$$ bs=64k count=16k conv=fdatasync && rm -f test_$$ ) 2>&1 | awk -F, '{io=$NF} END { print io}' | sed 's/^[ \t]*//;s/[ \t]*$//' )
  129. # Calculating avg I/O (better approach with awk for non int values)
  130. ioraw=$( echo $io | awk 'NR==1 {print $1}' )
  131. ioraw2=$( echo $io2 | awk 'NR==1 {print $1}' )
  132. ioraw3=$( echo $io3 | awk 'NR==1 {print $1}' )
  133. ioall=$( awk 'BEGIN{print '$ioraw' + '$ioraw2' + '$ioraw3'}' )
  134. ioavg=$( awk 'BEGIN{print '$ioall'/3}' )
  135. # Output of DD result
  136. echo "I/O (1st run) : $io" | tee -a $HOME/bench.log
  137. echo "I/O (2nd run) : $io2" | tee -a $HOME/bench.log
  138. echo "I/O (3rd run) : $io3" | tee -a $HOME/bench.log
  139. echo "Average I/O : $ioavg MB/s" | tee -a $HOME/bench.log
  140. echo "" | tee -a $HOME/bench.log
  141. }
  142. gbench () {
  143. # Improved version of my code by thirthy_speed https://freevps.us/thread-16943-post-191398.html#pid191398
  144. echo "" | tee -a $HOME/bench.log
  145. echo "System Benchmark (Experimental)" | tee -a $HOME/bench.log
  146. echo "-------------------------------" | tee -a $HOME/bench.log
  147. echo "" | tee -a $HOME/bench.log
  148. echo "Note: The benchmark might not always work (eg: missing dependencies)." | tee -a $HOME/bench.log
  149. echo "Failures are highly possible. We're using Geekbench for this test." | tee -a $HOME/bench.log
  150. echo "" | tee -a $HOME/bench.log
  151. gb_page=http://www.primatelabs.com/geekbench/download/linux/
  152. gb_dl=$(wget -qO - $gb_page | \
  153. sed -n 's/.*\(https\?:[^:]*\.tar\.gz\).*/\1/p')
  154. gb_noext=${gb_dl##*/}
  155. gb_noext=${gb_noext%.tar.gz}
  156. gb_name=${gb_noext//-/ }
  157. echo "File is located at $gb_dl" | tee -a $HOME/bench.log
  158. echo "Downloading and extracting $gb_name" | tee -a $HOME/bench.log
  159. wget -qO - "$gb_dl" | tar xzv 2>&1 >/dev/null
  160. echo "" | tee -a $HOME/bench.log
  161. echo "Starting $gb_name" | tee -a $HOME/bench.log
  162. echo "The system benchmark may take a while." | tee -a $HOME/bench.log
  163. echo "Don't close your terminal/SSH session!" | tee -a $HOME/bench.log
  164. echo "All output is redirected into a result file." | tee -a $HOME/bench.log
  165. echo "" >> $HOME/bench.log
  166. echo "--- Geekbench Results ---" >> $HOME/bench.log
  167. sleep 2
  168. $HOME/dist/$gb_noext/geekbench_x86_32 >> $HOME/bench.log
  169. echo "--- Geekbench Results End ---" >> $HOME/bench.log
  170. echo "" >> $HOME/bench.log
  171. echo "Finished. Removing Geekbench files" | tee -a $HOME/bench.log
  172. sleep 1
  173. rm -rf $HOME/dist/
  174. echo "" | tee -a $HOME/bench.log
  175. gbl=$(sed -n '/following link/,/following link/ {/following link\|^$/b; p}' $HOME/bench.log | sed 's/^[ \t]*//;s/[ \t]*$//' )
  176. echo "Benchmark Results: $gbl" | tee -a $HOME/bench.log
  177. echo "Full report available at $HOME/bench.log" | tee -a $HOME/bench.log
  178. echo "" | tee -a $HOME/bench.log
  179. }
  180. hlp () {
  181. echo ""
  182. echo "(C) Bench.sh 2 by Hidden Refuge <me at hiddenrefuge got eu dot org>"
  183. echo ""
  184. echo "Usage: bench.sh <option>"
  185. echo ""
  186. echo "Available options:"
  187. echo "No option : System information, IPv4 only speedtest and disk speed benchmark will be run."
  188. echo "-sys : Displays system information such as CPU, amount CPU cores, RAM and more."
  189. echo "-io : Runs a disk speed test and a IOPing benchmark and displays the results."
  190. echo "-6 : Normal benchmark but with a IPv6 only speedtest (run when you have IPv6)."
  191. echo "-46 : Normal benchmark with IPv4 and IPv6 speedtest."
  192. echo "-64 : Same as above."
  193. echo "-b : Normal benchmark with IPv4 only speedtest, I/O test and Geekbench system benchmark."
  194. echo "-b6 : Normal benchmark with IPv6 only speedtest, I/O test and Geekbench system benchmark."
  195. echo "-b46 : Normal benchmark with IPv4 and IPv6 speedtest, I/O test and Geekbench system benchmark."
  196. echo "-b64 : Same as above."
  197. echo "-h : This help page."
  198. echo ""
  199. echo "The Geekbench system benchmark is experimental. So beware of failure!"
  200. echo ""
  201. }
  202. case $1 in
  203. '-sys')
  204. sysinfo;;
  205. '-io')
  206. iotest;;
  207. '-6' )
  208. sysinfo; speedtest6; iotest;;
  209. '-46' )
  210. sysinfo; speedtest4; speedtest6; iotest;;
  211. '-64' )
  212. sysinfo; speedtest4; speedtest6; iotest;;
  213. '-b' )
  214. sysinfo; speedtest4; iotest; gbench;;
  215. '-b6' )
  216. sysinfo; speedtest6; iotest; gbench;;
  217. '-b46' )
  218. sysinfo; speedtest4; speedtest6; iotest; gbench;;
  219. '-b64' )
  220. sysinfo; speedtest4; speedtest6; iotest; gbench;;
  221. '-h' )
  222. hlp;;
  223. *)
  224. sysinfo; speedtest4; iotest;;
  225. esac
  226. #################################################################################
  227. # Contributors: #
  228. # thirthy_speed https://freevps.us/thread-16943-post-191398.html#pid191398 #
  229. #################################################################################