Chinaunix首页 | 论坛 | 博客
  • 博客访问: 109905
  • 博文数量: 27
  • 博客积分: 573
  • 博客等级: 中士
  • 技术积分: 265
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-13 12:59
文章分类

全部博文(27)

文章存档

2012年(3)

2011年(24)

分类: LINUX

2012-04-29 00:21:42


点击(此处)折叠或打开

  1. #!/bin/sh
  2. # This program is part of Aspersa ()
  3. # ########################################################################
  4. # A script to summarize system information in a nice way.
  5. # Goals: work well on Linux; create a compact diff-able report that is
  6. # easy to paste into a wiki or email, and easy to scan and compare too.
  7. #
  8. # Usage: $ wget -O- |bash
  9. # Options are set through the ASPERSA_SKIP environment variable. Set this
  10. # variable to a comma-separated list of things you want to omit.
  11. # Options:
  12. # MOUNT: Don't print out mounted filesystems and disk fullness.
  13. # NETWORK: Don't print out information on network controllers & config.
  14. # PROCESS: Don't print out top processes and vmstat information.
  15. #
  16. # Authors:
  17. # Baron Schwartz
  18. # Kevin van Zonneveld (kvz@php.net || )
  19. # ########################################################################
  20. # ########################################################################
  21. # Globals, settings, helper functions
  22. # ########################################################################
  23. POSIXLY_CORRECT=1
  24. export POSIXLY_CORRECT
  25. # The awk code for fuzzy rounding. (It's used in a few places, so makes sense
  26. # not to duplicate). It fuzzy-rounds the variable named fuzzy_var. It goes in
  27. # steps of 5, 10, 25, then repeats by a factor of 10 larger (50, 100, 250), and
  28. # so on, until it finds a number that's large enough. The pattern is slightly
  29. # broken between the initial 1 and 50, because rounding to the nearest 2.5
  30. # doesn't seem right to me.
  31. fuzzy_formula='
  32. rounded = 0;
  33. if (fuzzy_var <= 10 ) {
  34. rounded = 1;
  35. }
  36. factor = 1;
  37. while ( rounded == 0 ) {
  38. if ( fuzzy_var <= 50 * factor ) {
  39. fuzzy_var = sprintf("%.0f", fuzzy_var / (5 * factor)) * 5 * factor;
  40. rounded = 1;
  41. }
  42. else if ( fuzzy_var <= 100 * factor) {
  43. fuzzy_var = sprintf("%.0f", fuzzy_var / (10 * factor)) * 10 * factor;
  44. rounded = 1;
  45. }
  46. else if ( fuzzy_var <= 250 * factor) {
  47. fuzzy_var = sprintf("%.0f", fuzzy_var / (25 * factor)) * 25 * factor;
  48. rounded = 1;
  49. }
  50. factor = factor * 10;
  51. }'
  52. # Does fuzzy rounding: rounds to nearest interval, but the interval gets larger
  53. # as the number gets larger. This is to make things easier to diff.
  54. fuzz () {
  55. echo $1 | $AP_AWK "{fuzzy_var=\$1; ${fuzzy_formula} print fuzzy_var;}"
  56. }
  57. # The temp files are for storing working results so we don't call commands many
  58. # times (gives inconsistent results, maybe adds load on things I don't want to
  59. # such as RAID controllers). They must not exist -- if they did, someone would
  60. # symlink them to /etc/passwd and then run this program as root. Call this
  61. # function with "rm" or "touch" as an argument.
  62. temp_files() {
  63. for file in /tmp/aspersa /tmp/aspersa2; do
  64. case "$1" in
  65. touch)
  66. if ! touch "${file}"; then
  67. echo "I can't make my temp file ${file}";
  68. exit 1;
  69. fi
  70. ;;
  71. rm)
  72. rm -f "${file}"
  73. ;;
  74. esac
  75. done
  76. }
  77. # Print a space-padded string into $line. Then translate spaces to hashes, and
  78. # underscores to spaces. End result is a line of hashes with words at the
  79. # start.
  80. section () {
  81. echo "$1" | awk '{l=sprintf("#_%-60s", $0 "_"); print l}' | sed -e 's/ /#/g' -e 's/_/ /g'
  82. }
  83. # Print a "name | value" line.
  84. name_val() {
  85. printf "%12s | %s\n" "$1" "$(echo $2)"
  86. }
  87. # Converts a value to units of power of 2. Arg 1: the value. Arg 2: precision (defaults to 2).
  88. shorten() {
  89. echo $@ | awk '{
  90. unit = "k";
  91. size = 1024;
  92. val = $1;
  93. prec = 2;
  94. if ( $2 ~ /./ ) {
  95. prec = $2;
  96. }
  97. if ( val >= 1099511627776 ) {
  98. size = 1099511627776;
  99. unit = "T";
  100. }
  101. else if ( val >= 1073741824 ) {
  102. size = 1073741824;
  103. unit = "G";
  104. }
  105. else if ( val >= 1048576 ) {
  106. size = 1048576;
  107. unit = "M";
  108. }
  109. printf "%." prec "f%s", val / size, unit;
  110. }'
  111. }
  112. # ##############################################################################
  113. # Function to take a file and collapse it into an aggregated list. This
  114. # function works on $1, which it expects to be created with 'sort |
  115. # uniq -c'. Leading whitespace is deleted. The result will look like
  116. # "4xabc, 1xdef" Copy any changes to 'mysql-summary' too.
  117. # ##############################################################################
  118. group_concat () {
  119. sed -e '{H; $!d}' -e 'x' -e 's/\n[[:space:]]*\([[:digit:]]*\)[[:space:]]*/, \1x/g' -e 's/[[:space:]][[:space:]]*/ /g' -e 's/, //' ${1}
  120. # In words: save the whole file into the hold space,
  121. # {H; $!d}
  122. # Swap it back into the pattern space,
  123. # x
  124. # Join lines with a comma, delete leading whitespace, and put an 'x' between
  125. # the number and the text that follows,
  126. # s/\n[[:space:]]*\([[:digit:]]*\)[[:space:]]*/, \1x/g
  127. # Collapse whitespace,
  128. # s/[[:space:]][[:space:]]*/ /g
  129. # And delete the leading comma-space.
  130. # s/, //
  131. }
  132. # ##############################################################################
  133. # Functions for parsing specific files and getting desired info from them.
  134. # These are called from within main() and are separated so they can be tested
  135. # easily. The calling convention is that the data they need to run is prepared
  136. # first by putting it into /tmp/aspersa. Then code that's testing just needs to
  137. # put sample data into /tmp/aspersa and call it.
  138. # ##############################################################################
  139. # ##############################################################################
  140. # Parse Linux's /proc/cpuinfo, which should be stored in /tmp/aspersa.
  141. # ##############################################################################
  142. parse_proc_cpuinfo () {
  143. # Physical processors are indicated by distinct 'physical id'. Virtual CPUs
  144. # are indicated by paragraphs -- one per paragraph. We assume that all
  145. # processors are identical, i.e. that there are not some processors with dual
  146. # cores and some with quad cores.
  147. virtual=$(grep -c ^processor /tmp/aspersa);
  148. physical=$(grep 'physical id' /tmp/aspersa | sort -u | wc -l);
  149. cores=$(grep 'cpu cores' /tmp/aspersa | head -n 1 | cut -d: -f2);
  150. # Older kernel won't have 'physical id' or 'cpu cores'.
  151. if [ "${physical}" = "0" ]; then physical=${virtual}; fi
  152. if [ -z "${cores}" ]; then cores=0; fi
  153. # Test for HTT; cannot trust the 'ht' flag. If physical * cores < virtual,
  154. # then hyperthreading is in use.
  155. cores=$((${cores} * ${physical}));
  156. if [ ${cores} -gt 0 -a $cores -lt $virtual ]; then htt=yes; else htt=no; fi
  157. name_val "Processors" "physical = ${physical}, cores = ${cores}, virtual = ${virtual}, hyperthreading = ${htt}"
  158. awk -F: '/cpu MHz/{print $2}' /tmp/aspersa \
  159. | sort | uniq -c > /tmp/aspersa2
  160. name_val "Speeds" "$(group_concat /tmp/aspersa2)"
  161. awk -F: '/model name/{print $2}' /tmp/aspersa \
  162. | sort | uniq -c > /tmp/aspersa2
  163. name_val "Models" "$(group_concat /tmp/aspersa2)"
  164. awk -F: '/cache size/{print $2}' /tmp/aspersa \
  165. | sort | uniq -c > /tmp/aspersa2
  166. name_val "Caches" "$(group_concat /tmp/aspersa2)"
  167. }
  168. # ##############################################################################
  169. # Parse sysctl -a output on FreeBSD, and format it as CPU info. The file is the
  170. # first argument.
  171. # ##############################################################################
  172. parse_sysctl_cpu_freebsd() {
  173. virtual="$(awk '/hw.ncpu/{print $2}' "$1")"
  174. name_val "Processors" "virtual = ${virtual}"
  175. name_val "Speeds" "$(awk '/hw.clockrate/{print $2}' "$1")"
  176. name_val "Models" "$(awk -F: '/hw.model/{print substr($2, 2)}' "$1")"
  177. }
  178. # ##############################################################################
  179. # Parse CPU info from psrinfo -v
  180. # ##############################################################################
  181. parse_psrinfo_cpus() {
  182. name_val Processors $(grep -c 'Status of .* processor' "$1")
  183. awk '/operates at/ {
  184. start = index($0, " at ") + 4;
  185. end = length($0) - start - 4
  186. print substr($0, start, end);
  187. }' "$1" | sort | uniq -c > /tmp/aspersa2
  188. name_val "Speeds" "$(group_concat /tmp/aspersa2)"
  189. }
  190. # ##############################################################################
  191. # Parse the output of 'free -b' plus the contents of /proc/meminfo
  192. # ##############################################################################
  193. parse_free_minus_b () {
  194. physical=$(awk '/Mem:/{print $3}' "${1}")
  195. swap=$(awk '/Swap:/{print $3}' "${1}")
  196. virtual=$(shorten $(($physical + $swap)))
  197. name_val Total $(shorten $(awk '/Mem:/{print $2}' "${1}"))
  198. name_val Free $(shorten $(awk '/Mem:/{print $4}' "${1}"))
  199. name_val Used "physical = $(shorten ${physical}), swap = $(shorten ${swap}), virtual = ${virtual}"
  200. name_val Buffers $(shorten $(awk '/Mem:/{print $6}' "${1}"))
  201. name_val Caches $(shorten $(awk '/Mem:/{print $7}' "${1}"))
  202. name_val Dirty "$(awk '/Dirty:/ {print $2, $3}' "${1}")"
  203. }
  204. # ##############################################################################
  205. # Parse FreeBSD memory info from sysctl output.
  206. # ##############################################################################
  207. parse_memory_sysctl_freebsd() {
  208. physical=$(awk '/hw.realmem:/{print $2}' "${1}")
  209. mem_hw=$(awk '/hw.physmem:/{print $2}' "${1}")
  210. mem_used=$(awk '
  211. /hw.physmem/ { mem_hw = $2; }
  212. /vm.stats.vm.v_inactive_count/ { mem_inactive = $2; }
  213. /vm.stats.vm.v_cache_count/ { mem_cache = $2; }
  214. /vm.stats.vm.v_free_count/ { mem_free = $2; }
  215. /hw.pagesize/ { pagesize = $2; }
  216. END {
  217. mem_inactive *= pagesize;
  218. mem_cache *= pagesize;
  219. mem_free *= pagesize;
  220. print mem_hw - mem_inactive - mem_cache - mem_free;
  221. }
  222. ' "$1");
  223. name_val Total $(shorten ${mem_hw} 1)
  224. name_val Virtual $(shorten ${physical} 1)
  225. name_val Used $(shorten ${mem_used} 1)
  226. }
  227. # ##############################################################################
  228. # Parse memory devices from the output of 'dmidecode', which should be stored in
  229. # /tmp/aspersa.
  230. # ##############################################################################
  231. parse_dmidecode_mem_devices () {
  232. echo " Locator Size Speed Form Factor Type Type Detail"
  233. echo " ========= ======== ================= ============= ============= ==========="
  234. # Print paragraphs containing 'Memory Device\n', extract the desired bits,
  235. # concatenate them into one long line, then format as a table. The data
  236. # comes out in this order for each paragraph:
  237. # $2 Size 2048 MB
  238. # $3 Form Factor
  239. # $4 Locator DIMM1
  240. # $5 Type
  241. # $6 Type Detail Synchronous
  242. # $7 Speed 667 MHz (1.5 ns)
  243. sed -e '/./{H;$!d;}' \
  244. -e 'x;/Memory Device\n/!d;' \
  245. -e 's/: /:/g' \
  246. -e 's/
  247. -e 's/>/}/g' \
  248. -e 's/[ \t]*\n/\n/g' \
  249. /tmp/aspersa \
  250. | awk -F: '/Size|Type|Form.Factor|Type.Detail|[^ ]Locator/{printf("|%s", $2)}/Speed/{print "|" $2}' \
  251. | sed -e 's/No Module Installed/{EMPTY}/' \
  252. | sort \
  253. | awk -F'|' '{printf(" %-9s %-8s %-17s %-13s %-13s %-8s\n", $4, $2, $7, $3, $5, $6);}'
  254. }
  255. # ##############################################################################
  256. # Parse the output of 'netstat -antp'
  257. # ##############################################################################
  258. parse_ip_s_link () {
  259. echo " interface rx_bytes rx_packets rx_errors tx_bytes tx_packets tx_errors"
  260. echo " ========= ========= ========== ========== ========== ========== =========="
  261. awk "/^[1-9][0-9]*:/ {
  262. save[\"iface\"] = substr(\$2, 0, index(\$2, \":\") - 1);
  263. new = 1;
  264. }
  265. \$0 !~ /[^0-9 ]/ {
  266. if ( new == 1 ) {
  267. new = 0;
  268. fuzzy_var = \$1; ${fuzzy_formula} save[\"bytes\"] = fuzzy_var;
  269. fuzzy_var = \$2; ${fuzzy_formula} save[\"packs\"] = fuzzy_var;
  270. fuzzy_var = \$3; ${fuzzy_formula} save[\"errs\"] = fuzzy_var;
  271. }
  272. else {
  273. fuzzy_var = \$1; ${fuzzy_formula} tx_bytes = fuzzy_var;
  274. fuzzy_var = \$2; ${fuzzy_formula} tx_packets = fuzzy_var;
  275. fuzzy_var = \$3; ${fuzzy_formula} tx_errors = fuzzy_var;
  276. printf \" %-8s %10d %10d %10d %10d %10d %10d\\n\", save[\"iface\"], save[\"bytes\"], save[\"packs\"], save[\"errs\"], tx_bytes, tx_packets, tx_errors;
  277. }
  278. }" $@
  279. }
  280. # ##############################################################################
  281. # Parse the output of 'netstat -antp' which should be in /tmp/aspersa.
  282. # ##############################################################################
  283. parse_netstat () {
  284. echo " Connections from remote IP addresses"
  285. awk '$1 ~ /^tcp/ && $5 ~ /^[1-9]/ {
  286. print substr($5, 0, index($5, ":") - 1);
  287. }' /tmp/aspersa | sort | uniq -c \
  288. | awk "{
  289. fuzzy_var=\$1;
  290. ${fuzzy_formula}
  291. printf \" %-15s %5d\\n\", \$2, fuzzy_var;
  292. }" \
  293. | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4
  294. echo " Connections to local IP addresses"
  295. awk '$1 ~ /^tcp/ && $5 ~ /^[1-9]/ {
  296. print substr($4, 0, index($4, ":") - 1);
  297. }' /tmp/aspersa | sort | uniq -c \
  298. | awk "{
  299. fuzzy_var=\$1;
  300. ${fuzzy_formula}
  301. printf \" %-15s %5d\\n\", \$2, fuzzy_var;
  302. }" \
  303. | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4
  304. echo " Connections to top 10 local ports"
  305. awk '$1 ~ /^tcp/ && $5 ~ /^[1-9]/ {
  306. print substr($4, index($4, ":") + 1);
  307. }' /tmp/aspersa | sort | uniq -c | sort -rn | head -n10 \
  308. | awk "{
  309. fuzzy_var=\$1;
  310. ${fuzzy_formula}
  311. printf \" %-15s %5d\\n\", \$2, fuzzy_var;
  312. }" | sort
  313. echo " States of connections"
  314. awk '$1 ~ /^tcp/ {
  315. print $6;
  316. }' /tmp/aspersa | sort | uniq -c | sort -rn \
  317. | awk "{
  318. fuzzy_var=\$1;
  319. ${fuzzy_formula}
  320. printf \" %-15s %5d\\n\", \$2, fuzzy_var;
  321. }" | sort
  322. }
  323. # ##############################################################################
  324. # Parse the joined output of 'mount' and 'df -hP'. $1 = file; $2 = ostype.
  325. # ##############################################################################
  326. parse_filesystems () {
  327. # Filesystem names and mountpoints can be very long. We try to align things
  328. # as nicely as possible by making columns only as wide as needed. This
  329. # requires two passes through the file. The first pass finds the max size of
  330. # these columns and prints out a printf spec, and the second prints out the
  331. # file nicely aligned.
  332. cat > /tmp/aspersa.awk <<-EOF
  333. BEGIN {
  334. device = 10;
  335. fstype = 4;
  336. options = 4;
  337. }
  338. /./ {
  339. f_device = \$1;
  340. f_fstype = \$10;
  341. f_options = substr(\$11, 2, length(\$11) - 2);
  342. if ( "$2" == "FreeBSD" ) {
  343. f_fstype = substr(\$9, 2, length(\$9) - 2);
  344. f_options = substr(\$0, index(\$0, ",") + 2);
  345. f_options = substr(f_options, 1, length(f_options) - 1);
  346. }
  347. if ( length(f_device) > device ) {
  348. device=length(f_device);
  349. }
  350. if ( length(f_fstype) > fstype ) {
  351. fstype=length(f_fstype);
  352. }
  353. if ( length(f_options) > options ) {
  354. options=length(f_options);
  355. }
  356. }
  357. END{
  358. print "%-" device "s %5s %4s %-" fstype "s %-" options "s %s";
  359. }
  360. EOF
  361. spec="$( awk -f /tmp/aspersa.awk "$1" )";
  362. #awk -f /tmp/aspersa.awk "$1"
  363. #return;
  364. cat > /tmp/aspersa.awk <<-EOF
  365. BEGIN {
  366. spec=" ${spec}\\n";
  367. printf spec, "Filesystem", "Size", "Used", "Type", "Opts", "Mountpoint";
  368. }
  369. {
  370. f_fstype = \$10;
  371. f_options = substr(\$11, 2, length(\$11) - 2);
  372. if ( "$2" == "FreeBSD" ) {
  373. f_fstype = substr(\$9, 2, length(\$9) - 2);
  374. f_options = substr(\$0, index(\$0, ",") + 2);
  375. f_options = substr(f_options, 1, length(f_options) - 1);
  376. }
  377. printf spec, \$1, \$2, \$5, f_fstype, f_options, \$6;
  378. }
  379. EOF
  380. awk -f /tmp/aspersa.awk "$1"
  381. }
  382. # ##############################################################################
  383. # Parse the output of fdisk -l, which should be in /tmp/aspersa; there might be
  384. # multiple fdisk -l outputs in the file.
  385. # ##############################################################################
  386. parse_fdisk () {
  387. awk '
  388. BEGIN {
  389. format="%-12s %4s %10s %10s %18s\n";
  390. printf(format, "Device", "Type", "Start", "End", "Size");
  391. printf(format, "============", "====", "==========", "==========", "==================");
  392. }
  393. /Disk.*bytes/ {
  394. disk = substr($2, 1, length($2) - 1);
  395. size = $5;
  396. printf(format, disk, "Disk", "", "", size);
  397. }
  398. /Units/ {
  399. units = $9;
  400. }
  401. /^\/dev/ {
  402. if ( $2 == "*" ) {
  403. start = $3;
  404. end = $4;
  405. }
  406. else {
  407. start = $2;
  408. end = $3;
  409. }
  410. printf(format, $1, "Part", start, end, sprintf("%.0f", (end - start) * units));
  411. }
  412. ' /tmp/aspersa
  413. }
  414. # ##############################################################################
  415. # Parse the output of dmesg, which should be in /tmp/aspersa, and detect
  416. # virtualization.
  417. # ##############################################################################
  418. parse_virtualization_dmesg () {
  419. if grep -qi -e vmware -e vmxnet -e 'paravirtualized kernel on vmi' /tmp/aspersa; then
  420. echo "VMWare";
  421. elif grep -qi -e 'paravirtualized kernel on xen' -e 'Xen virtual console' /tmp/aspersa; then
  422. echo "Xen";
  423. elif grep -qi qemu /tmp/aspersa; then
  424. echo "QEmu";
  425. elif grep -qi 'paravirtualized kernel on KVM' /tmp/aspersa; then
  426. echo "KVM";
  427. elif grep -q VBOX /tmp/aspersa; then
  428. echo "VirtualBox";
  429. elif grep -qi 'hd.: Virtual .., ATA.*drive' /tmp/aspersa; then
  430. echo "Microsoft VirtualPC";
  431. fi
  432. }
  433. # ##############################################################################
  434. # Try to figure out if a system is a guest by looking at prtdiag, smbios, etc.
  435. # ##############################################################################
  436. parse_virtualization_generic() {
  437. if grep -i -e virtualbox "$1" >/dev/null; then
  438. echo VirtualBox
  439. elif grep -i -e vmware "$1" >/dev/null; then
  440. echo VMWare
  441. fi
  442. }
  443. # ##############################################################################
  444. # Parse the output of lspci, which should be in /tmp/aspersa, and detect
  445. # Ethernet cards.
  446. # ##############################################################################
  447. parse_ethernet_controller_lspci () {
  448. grep -i ethernet /tmp/aspersa | cut -d: -f3 | while read line; do
  449. name_val Controller "${line}"
  450. done
  451. }
  452. # ##############################################################################
  453. # Parse the output of lspci, which should be in /tmp/aspersa, and detect RAID
  454. # controllers.
  455. # ##############################################################################
  456. parse_raid_controller_lspci () {
  457. if grep -q "RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS" /tmp/aspersa; then
  458. echo 'LSI Logic MegaRAID SAS'
  459. elif grep -q "Fusion-MPT SAS" /tmp/aspersa; then
  460. echo 'Fusion-MPT SAS'
  461. elif grep -q "RAID bus controller: LSI Logic / Symbios Logic Unknown" /tmp/aspersa; then
  462. echo 'LSI Logic Unknown'
  463. elif grep -q "RAID bus controller: Adaptec AAC-RAID" /tmp/aspersa; then
  464. echo 'AACRAID'
  465. elif grep -q "3ware [0-9]* Storage Controller" /tmp/aspersa; then
  466. echo '3Ware'
  467. elif grep -q "Hewlett-Packard Company Smart Array" /tmp/aspersa; then
  468. echo 'HP Smart Array'
  469. elif grep -q " RAID bus controller: " /tmp/aspersa; then
  470. awk -F: '/RAID bus controller\:/ {print $3" "$5" "$6}' /tmp/aspersa
  471. fi
  472. }
  473. # ##############################################################################
  474. # Parse the output of dmesg, which should be in /tmp/aspersa, and detect RAID
  475. # controllers.
  476. # ##############################################################################
  477. parse_raid_controller_dmesg () {
  478. pat='scsi[0-9].*: .*'
  479. if grep -qi "${pat}megaraid" /tmp/aspersa; then
  480. echo 'LSI Logic MegaRAID SAS'
  481. elif grep -q "Fusion MPT SAS" /tmp/aspersa; then
  482. echo 'Fusion-MPT SAS'
  483. elif grep -q "${pat}aacraid" /tmp/aspersa; then
  484. echo 'AACRAID'
  485. elif grep -q "${pat}3ware [0-9]* Storage Controller" /tmp/aspersa; then
  486. echo '3Ware'
  487. fi
  488. }
  489. # ##############################################################################
  490. # Parse the output of "hpacucli ctrl all show config", which should be stored in
  491. # /tmp/aspersa
  492. # ##############################################################################
  493. parse_hpacucli () {
  494. grep 'logicaldrive\|physicaldrive' /tmp/aspersa
  495. }
  496. # ##############################################################################
  497. # Parse the output of arcconf, which should be stored in /tmp/aspersa
  498. # ##############################################################################
  499. parse_arcconf () {
  500. model=$(awk -F: '/Controller Model/{print $2}' /tmp/aspersa)
  501. chan="$(awk -F: '/Channel description/{print $2}' /tmp/aspersa)"
  502. cache="$(awk -F: '/Installed memory/{print $2}' /tmp/aspersa)"
  503. status="$(awk -F: '/Controller Status/{print $2}' /tmp/aspersa)"
  504. name_val Specs "${model/ /},${chan},${cache} cache,${status}"
  505. battery=$(grep -A5 'Controller Battery Info' /tmp/aspersa \
  506. | awk '/Capacity remaining/ {c=$4}
  507. /Status/ {s=$3}
  508. /Time remaining/ {t=sprintf("%dd%dh%dm", $7, $9, $11)}
  509. END {printf("%d%%, %s remaining, %s", c, t, s)}')
  510. name_val Battery "${battery}"
  511. # ###########################################################################
  512. # Logical devices
  513. # ###########################################################################
  514. echo
  515. echo " LogicalDev Size RAID Disks Stripe Status Cache"
  516. echo " ========== ========= ==== ===== ====== ======= ======="
  517. for dev in $(awk '/Logical device number/{print $4}' /tmp/aspersa); do
  518. sed -n -e "/^Logical device .* ${dev}$/,/^$\|^Logical device number/p" \
  519. /tmp/aspersa \
  520. | awk '
  521. /Logical device name/ {d=$5}
  522. /Size/ {z=$3 " " $4}
  523. /RAID level/ {r=$4}
  524. /Group [0-9]/ {g++}
  525. /Stripe-unit size/ {p=$4 " " $5}
  526. /Status of logical/ {s=$6}
  527. /Write-cache mode.*Ena.*write-back/ {c="On (WB)"}
  528. /Write-cache mode.*Ena.*write-thro/ {c="On (WT)"}
  529. /Write-cache mode.*Disabled/ {c="Off"}
  530. END {
  531. printf(" %-10s %-9s %4d %5d %-6s %-7s %-7s\n",
  532. d, z, r, g, p, s, c);
  533. }'
  534. done
  535. # ###########################################################################
  536. # Physical devices
  537. # ###########################################################################
  538. echo
  539. echo " PhysiclDev State Speed Vendor Model Size Cache"
  540. echo " ========== ======= ============= ======= ============ =========== ======="
  541. # Find the paragraph with physical devices, tabularize with assoc arrays.
  542. tempresult=""
  543. sed -n -e '/Physical Device information/,/^$/p' /tmp/aspersa \
  544. | awk -F: '
  545. /Device #[0-9]/ {
  546. device=substr($0, index($0, "#"));
  547. devicenames[device]=device;
  548. }
  549. /Device is a/ {
  550. devices[device ",isa"] = substr($0, index($0, "is a") + 5);
  551. }
  552. /State/ {
  553. devices[device ",state"] = substr($2, 2);
  554. }
  555. /Transfer Speed/ {
  556. devices[device ",speed"] = substr($2, 2);
  557. }
  558. /Vendor/ {
  559. devices[device ",vendor"] = substr($2, 2);
  560. }
  561. /Model/ {
  562. devices[device ",model"] = substr($2, 2);
  563. }
  564. /Size/ {
  565. devices[device ",size"] = substr($2, 2);
  566. }
  567. /Write Cache/ {
  568. if ( $2 ~ /Enabled .write-back./ )
  569. devices[device ",cache"] = "On (WB)";
  570. else
  571. if ( $2 ~ /Enabled .write-th/ )
  572. devices[device ",cache"] = "On (WT)";
  573. else
  574. devices[device ",cache"] = "Off";
  575. }
  576. END {
  577. for ( device in devicenames ) {
  578. if ( devices[device ",isa"] ~ /Hard drive/ ) {
  579. printf(" %-10s %-7s %-13s %-7s %-12s %-11s %-7s\n",
  580. devices[device ",isa"],
  581. devices[device ",state"],
  582. devices[device ",speed"],
  583. devices[device ",vendor"],
  584. devices[device ",model"],
  585. devices[device ",size"],
  586. devices[device ",cache"]);
  587. }
  588. }
  589. }'
  590. }
  591. # ##############################################################################
  592. # Parse the output of "lsiutil -i -s" from /tmp/aspersa
  593. # ##############################################################################
  594. parse_fusionmpt_lsiutil () {
  595. echo
  596. awk '/LSI.*Firmware/ { print " ", $0 }' /tmp/aspersa
  597. grep . /tmp/aspersa | sed -n -e '/B___T___L/,$ {s/^/ /; p}'
  598. }
  599. # ##############################################################################
  600. # Parse the output of MegaCli64 -AdpAllInfo -aALL from /tmp/aspersa.
  601. # ##############################################################################
  602. parse_lsi_megaraid_adapter_info () {
  603. name=$(awk -F: '/Product Name/{print substr($2, 2)}' /tmp/aspersa);
  604. int=$(awk '/Host Interface/{print $4}' /tmp/aspersa);
  605. prt=$(awk '/Number of Backend Port/{print $5}' /tmp/aspersa);
  606. bbu=$(awk '/^BBU :/{print $3}' /tmp/aspersa);
  607. mem=$(awk '/Memory Size/{print $4}' /tmp/aspersa);
  608. vdr=$(awk '/Virtual Drives/{print $4}' /tmp/aspersa);
  609. dvd=$(awk '/Degraded/{print $3}' /tmp/aspersa);
  610. phy=$(awk '/^ Disks/{print $3}' /tmp/aspersa);
  611. crd=$(awk '/Critical Disks/{print $4}' /tmp/aspersa);
  612. fad=$(awk '/Failed Disks/{print $4}' /tmp/aspersa);
  613. name_val Model "${name}, ${int} interface, ${prt} ports"
  614. name_val Cache "${mem} Memory, BBU ${bbu}"
  615. }
  616. # ##############################################################################
  617. # Parse the output (saved in /tmp/aspersa) of
  618. # /opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuStatus -aALL
  619. # ##############################################################################
  620. parse_lsi_megaraid_bbu_status () {
  621. charge=$(awk '/Relative State/{print $5}' /tmp/aspersa);
  622. temp=$(awk '/^Temperature/{print $2}' /tmp/aspersa);
  623. soh=$(awk '/isSOHGood:/{print $2}' /tmp/aspersa);
  624. name_val BBU "${charge}% Charged, Temperature ${temp}C, isSOHGood=${soh}"
  625. }
  626. # ##############################################################################
  627. # Parse physical devices from the output (saved in /tmp/aspersa) of
  628. # /opt/MegaRAID/MegaCli/MegaCli64 -LdPdInfo -aALL
  629. # OR, it will also work with the output of
  630. # /opt/MegaRAID/MegaCli/MegaCli64 -PDList -aALL
  631. # ##############################################################################
  632. parse_lsi_megaraid_devices () {
  633. echo
  634. echo " PhysiclDev Type State Errors Vendor Model Size"
  635. echo " ========== ==== ======= ====== ======= ============ ==========="
  636. for dev in $(awk '/Device Id/{print $3}' /tmp/aspersa); do
  637. sed -e '/./{H;$!d;}' -e "x;/Device Id: ${dev}/!d;" /tmp/aspersa \
  638. | awk '
  639. /Media Type/ {d=substr($0, index($0, ":") + 2)}
  640. /PD Type/ {t=$3}
  641. /Firmware state/ {s=$3}
  642. /Media Error Count/ {me=$4}
  643. /Other Error Count/ {oe=$4}
  644. /Predictive Failure Count/ {pe=$4}
  645. /Inquiry Data/ {v=$3; m=$4;}
  646. /Raw Size/ {z=$3}
  647. END {
  648. printf(" %-10s %-4s %-7s %6s %-7s %-12s %-7s\n",
  649. substr(d, 0, 10), t, s, me "/" oe "/" pe, v, m, z);
  650. }'
  651. done
  652. }
  653. # ##############################################################################
  654. # Parse virtual devices from the output (saved in /tmp/aspersa) of
  655. # /opt/MegaRAID/MegaCli/MegaCli64 -LdPdInfo -aALL
  656. # OR, it will also work with the output of
  657. # /opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -Lall -aAll
  658. # ##############################################################################
  659. parse_lsi_megaraid_virtual_devices () {
  660. # Somewhere on the Internet, I found the following guide to understanding the
  661. # RAID level, but I don't know the source anymore.
  662. # Primary-0, Secondary-0, RAID Level Qualifier-0 = 0
  663. # Primary-1, Secondary-0, RAID Level Qualifier-0 = 1
  664. # Primary-5, Secondary-0, RAID Level Qualifier-3 = 5
  665. # Primary-1, Secondary-3, RAID Level Qualifier-0 = 10
  666. # I am not sure if this is always correct or not (it seems correct). The
  667. # terminology MegaRAID uses is not clear to me, and isn't documented that I
  668. # am aware of. Anyone who can clarify the above, please contact me.
  669. echo
  670. echo " VirtualDev Size RAID Level Disks SpnDpth Stripe Status Cache"
  671. echo " ========== ========= ========== ===== ======= ====== ======= ========="
  672. awk '
  673. /^Virtual Disk:/ {
  674. device = $3;
  675. devicenames[device] = device;
  676. }
  677. /Number Of Drives/ {
  678. devices[device ",numdisks"] = substr($0, index($0, ":") + 1);
  679. }
  680. /^Name:/ {
  681. devices[device ",name"] = $2 > "" ? $2 : "(no name)";
  682. }
  683. /RAID Level/ {
  684. devices[device ",primary"] = substr($3, index($3, "-") + 1, 1);
  685. devices[device ",secondary"] = substr($4, index($4, "-") + 1, 1);
  686. devices[device ",qualifier"] = substr($NF, index($NF, "-") + 1, 1);
  687. }
  688. /Span Depth/ {
  689. devices[device ",spandepth"] = substr($2, index($2, ":") + 1);
  690. }
  691. /Number of Spans/ {
  692. devices[device ",numspans"] = $4;
  693. }
  694. /^Size:/ {
  695. devices[device ",size"] = substr($0, index($0, ":") + 1);
  696. }
  697. /^State:/ {
  698. devices[device ",state"] = $2;
  699. }
  700. /^Stripe Size:/ {
  701. devices[device ",stripe"] = $3;
  702. }
  703. /^Current Cache Policy/ {
  704. devices[device ",wpolicy"] = $4 ~ /WriteBack/ ? "WB" : "WT";
  705. devices[device ",rpolicy"] = $5 ~ /ReadAheadNone/ ? "no RA" : "RA";
  706. }
  707. END {
  708. for ( device in devicenames ) {
  709. raid = 0;
  710. if ( devices[device ",primary"] == 1 ) {
  711. raid = 1;
  712. if ( devices[device ",secondary"] == 3 ) {
  713. raid = 10;
  714. }
  715. }
  716. else {
  717. if ( devices[device ",primary"] == 5 ) {
  718. raid = 5;
  719. }
  720. }
  721. printf(" %-10s %-9s %-10s %5d %7s %6s %-7s %s\n",
  722. device devices[device ",name"],
  723. devices[device ",size"],
  724. raid " (" devices[device ",primary"] "-" devices[device ",secondary"] "-" devices[device ",qualifier"] ")",
  725. devices[device ",numdisks"],
  726. devices[device ",spandepth"] "-" devices[device ",numspans"],
  727. devices[device ",stripe"], devices[device ",state"],
  728. devices[device ",wpolicy"] ", " devices[device ",rpolicy"]);
  729. }
  730. }' /tmp/aspersa
  731. }
  732. # ##############################################################################
  733. # Simplifies vmstat and aligns it nicely. We don't need the memory stats, the
  734. # system activity is enough.
  735. # ##############################################################################
  736. format_vmstat () {
  737. cat > /tmp/aspersa.awk <<-EOF
  738. BEGIN {
  739. format = " %2s %2s %4s %4s %5s %5s %6s %6s %3s %3s %3s %3s %3s\n";
  740. }
  741. /procs/ {
  742. print " procs ---swap-- -----io---- ---system---- --------cpu--------";
  743. }
  744. /bo/ {
  745. printf format, "r", "b", "si", "so", "bi", "bo", "ir", "cs", "us", "sy", "il", "wa", "st";
  746. }
  747. \$0 !~ /r/ {
  748. fuzzy_var = \$1; ${fuzzy_formula} r = fuzzy_var;
  749. fuzzy_var = \$2; ${fuzzy_formula} b = fuzzy_var;
  750. fuzzy_var = \$7; ${fuzzy_formula} si = fuzzy_var;
  751. fuzzy_var = \$8; ${fuzzy_formula} so = fuzzy_var;
  752. fuzzy_var = \$9; ${fuzzy_formula} bi = fuzzy_var;
  753. fuzzy_var = \$10; ${fuzzy_formula} bo = fuzzy_var;
  754. fuzzy_var = \$11; ${fuzzy_formula} ir = fuzzy_var;
  755. fuzzy_var = \$12; ${fuzzy_formula} cs = fuzzy_var;
  756. fuzzy_var = \$13; us = fuzzy_var;
  757. fuzzy_var = \$14; sy = fuzzy_var;
  758. fuzzy_var = \$15; il = fuzzy_var;
  759. fuzzy_var = \$16; wa = fuzzy_var;
  760. fuzzy_var = \$17; st = fuzzy_var;
  761. printf format, r, b, si, so, bi, bo, ir, cs, us, sy, il, wa, st;
  762. }
  763. EOF
  764. awk -f /tmp/aspersa.awk /tmp/aspersa
  765. }
  766. # ##############################################################################
  767. # The main() function is called at the end of the script. This makes it
  768. # testable. Major bits of parsing are separated into functions for testability.
  769. # As a general rule, we cannot 'cp' files from /proc, because they might be
  770. # empty afterwards. (I've seen 'cp /proc/cpuinfo' create an empty file.) But
  771. # 'cat' works okay.
  772. # ##############################################################################
  773. main () {
  774. # Begin by setting the $PATH to include some common locations that are not
  775. # always in the $PATH, including the "sbin" locations, and some common
  776. # locations for proprietary management software, such as RAID controllers.
  777. export PATH="${PATH}:/usr/local/bin:/usr/bin:/bin:/usr/libexec"
  778. export PATH="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
  779. export PATH="${PATH}:/usr/StorMan/:/opt/MegaRAID/MegaCli/";
  780. # Set up temporary files.
  781. temp_files "rm"
  782. temp_files "touch"
  783. section Aspersa_System_Summary_Report
  784. # ########################################################################
  785. # Grab a bunch of stuff and put it into temp files for later.
  786. # ########################################################################
  787. sysctl -a > /tmp/aspersa.sysctl 2>/dev/null
  788. # ########################################################################
  789. # General date, time, load, etc
  790. # ########################################################################
  791. platform="$(uname -s)"
  792. name_val "Date" "`date -u +'%F %T UTC'` (local TZ: `date +'%Z %z'`)"
  793. name_val "Hostname" "$(uname -n)"
  794. name_val "Uptime" "$(uptime | awk '{print substr($0, index($0, "up") + 3)}')"
  795. if which dmidecode > /dev/null 2>&1; then
  796. vendor="$(dmidecode -s system-manufacturer 2>/dev/null | sed 's/ *$//g')"
  797. if [ "${vendor}" ]; then
  798. product="$(dmidecode -s system-product-name 2>/dev/null | sed 's/ *$//g')"
  799. version="$(dmidecode -s system-version 2>/dev/null | sed 's/ *$//g')"
  800. chassis="$(dmidecode -s chassis-type 2>/dev/null | sed 's/ *$//g')"
  801. system="${vendor}; ${product}; v${version} (${chassis})"
  802. name_val "System" "${system}";
  803. servicetag="$(dmidecode -s system-serial-number 2>/dev/null | sed 's/ *$//g')"
  804. name_val "Service Tag" "${servicetag:-Not found}";
  805. fi
  806. fi
  807. name_val "Platform" "${platform}"
  808. if [ "${platform}" = "SunOS" ]; then
  809. if which zonename >/dev/null 2>&1 ; then
  810. name_val "Zonename" "$(zonename)"
  811. fi
  812. fi
  813. # Try to find all sorts of different files that say what the release is.
  814. if [ "${platform}" = "Linux" ]; then
  815. kernel="$(uname -r)"
  816. if [ -e /etc/fedora-release ]; then
  817. release=$(cat /etc/fedora-release);
  818. elif [ -e /etc/redhat-release ]; then
  819. release=$(cat /etc/redhat-release);
  820. elif [ -e /etc/system-release ]; then
  821. release=$(cat /etc/system-release);
  822. elif which lsb_release >/dev/null 2>&1; then
  823. release="$(lsb_release -ds) ($(lsb_release -cs))"
  824. elif [ -e /etc/lsb-release ]; then
  825. release=$(grep DISTRIB_DESCRIPTION /etc/lsb-release |awk -F'=' '{print $2}' |sed 's#"##g');
  826. elif [ -e /etc/debian_version ]; then
  827. release="Debian-based version $(cat /etc/debian_version)";
  828. if [ -e /etc/apt/sources.list ]; then
  829. code=`cat /etc/apt/sources.list |awk '/^deb/ {print $3}' |awk -F/ '{print $1}'| awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -rn |head -n1 |awk '{print $2}'`
  830. release="${release} (${code})"
  831. fi
  832. elif ls /etc/*release >/dev/null 2>&1; then
  833. if grep -q DISTRIB_DESCRIPTION /etc/*release; then
  834. release=$(grep DISTRIB_DESCRIPTION /etc/*release | head -n1);
  835. else
  836. release=$(cat /etc/*release | head -n1);
  837. fi
  838. fi
  839. elif [ "${platform}" = "FreeBSD" ]; then
  840. release="$(uname -r)"
  841. kernel="$(sysctl -n kern.osrevision)"
  842. elif [ "${platform}" = "SunOS" ]; then
  843. release="$(head -n1 /etc/release)"
  844. if [ -z "${release}" ]; then
  845. release="$(uname -r)"
  846. fi
  847. kernel="$(uname -v)"
  848. fi
  849. name_val Release "${release}"
  850. name_val Kernel "${kernel}"
  851. CPU_ARCH='32-bit'
  852. OS_ARCH='32-bit'
  853. if [ "${platform}" = "Linux" ]; then
  854. if grep -q ' lm ' /proc/cpuinfo; then
  855. CPU_ARCH='64-bit'
  856. fi
  857. elif [ "${platform}" = "FreeBSD" ]; then
  858. if sysctl hw.machine_arch | grep -v 'i[36]86' >/dev/null; then
  859. CPU_ARCH='64-bit'
  860. fi
  861. elif [ "${platform}" = "SunOS" ]; then
  862. if isainfo -b | grep 64 >/dev/null ; then
  863. CPU_ARCH="64-bit"
  864. fi
  865. fi
  866. if file /bin/sh | grep '64-bit' >/dev/null; then
  867. OS_ARCH='64-bit'
  868. fi
  869. name_val "Architecture" "CPU = $CPU_ARCH, OS = $OS_ARCH"
  870. # Threading library
  871. if [ "${platform}" = "Linux" ]; then
  872. name_val Threading "$(getconf GNU_LIBPTHREAD_VERSION)"
  873. fi
  874. if [ -x /lib/libc.so.6 ]; then
  875. name_val "Compiler" "$(/lib/libc.so.6 | grep 'Compiled by' | cut -c13-)"
  876. fi
  877. if [ "${platform}" = "Linux" ]; then
  878. if getenforce >/dev/null 2>&1; then
  879. getenforce="$(getenforce 2>&1)";
  880. fi
  881. name_val "SELinux" "${getenforce:-No SELinux detected}";
  882. fi
  883. # We look in dmesg for virtualization information first, because it's often
  884. # available to non-root users and usually has telltale signs. It's most
  885. # reliable to look at /var/log/dmesg if possible. There are a number of
  886. # other ways to find out if a system is virtualized.
  887. cat /var/log/dmesg > /tmp/aspersa 2>/dev/null
  888. if [ ! -s /tmp/aspersa ]; then
  889. dmesg > /tmp/aspersa 2>/dev/null
  890. fi
  891. if [ -s /tmp/aspersa ]; then
  892. virt="$(parse_virtualization_dmesg)"
  893. fi
  894. if [ -z "${virt}" ]; then
  895. if which lspci >/dev/null 2>&1; then
  896. lspci > /tmp/aspersa 2>/dev/null
  897. if grep -qi virtualbox /tmp/aspersa; then
  898. virt=VirtualBox
  899. elif grep -qi vmware /tmp/aspersa; then
  900. virt=VMWare
  901. elif [ -e /proc/user_beancounters ]; then
  902. virt="OpenVZ/Virtuozzo"
  903. fi
  904. fi
  905. elif [ "${platform}" = "FreeBSD" ]; then
  906. if ps -o stat | grep J ; then
  907. virt="FreeBSD Jail"
  908. fi
  909. elif [ "${platform}" = "SunOS" ]; then
  910. if which prtdiag >/dev/null 2>&1 && prtdiag > /tmp/aspersa.prtdiag 2>/dev/null; then
  911. virt="$(parse_virtualization_generic /tmp/aspersa.prtdiag)"
  912. elif which smbios >/dev/null 2>&1 && smbios > /tmp/aspersa.smbios 2>/dev/null; then
  913. virt="$(parse_virtualization_generic /tmp/aspersa.smbios)"
  914. fi
  915. fi
  916. name_val Virtualized "${virt:-No virtualization detected}"
  917. # ########################################################################
  918. # Processor/CPU, Memory, Swappiness, dmidecode
  919. # ########################################################################
  920. section Processor
  921. if [ -f /proc/cpuinfo ]; then
  922. cat /proc/cpuinfo > /tmp/aspersa 2>/dev/null
  923. parse_proc_cpuinfo
  924. elif [ "${platform}" = "FreeBSD" ]; then
  925. parse_sysctl_cpu_freebsd /tmp/aspersa.sysctl
  926. elif [ "${platform}" = "SunOS" ]; then
  927. psrinfo -v > /tmp/aspersa
  928. parse_psrinfo_cpus /tmp/aspersa
  929. # TODO: prtconf -v actually prints the CPU model name etc.
  930. fi
  931. section Memory
  932. if [ "${platform}" = "Linux" ]; then
  933. free -b > /tmp/aspersa
  934. cat /proc/meminfo >> /tmp/aspersa
  935. parse_free_minus_b /tmp/aspersa
  936. elif [ "${platform}" = "FreeBSD" ]; then
  937. parse_memory_sysctl_freebsd /tmp/aspersa.sysctl
  938. elif [ "${platform}" = "SunOS" ]; then
  939. name_val Memory "$(prtconf | awk -F: '/Memory/{print $2}')"
  940. fi
  941. rss=$(ps -eo rss 2>/dev/null | awk '/[0-9]/{total += $1 * 1024} END {print total}')
  942. name_val UsedRSS "$(shorten ${rss} 1)"
  943. if [ "${platform}" = "Linux" ]; then
  944. name_val Swappiness "$(sysctl vm.swappiness 2>&1)"
  945. name_val DirtyPolicy "$(sysctl vm.dirty_ratio 2>&1), $(sysctl vm.dirty_background_ratio 2>&1)"
  946. if sysctl vm.dirty_bytes > /dev/null 2>&1; then
  947. name_val DirtyStatus "$(sysctl vm.dirty_bytes 2>&1), $(sysctl vm.dirty_background_bytes 2>&1)"
  948. fi
  949. fi
  950. if which dmidecode >/dev/null 2>&1 && dmidecode > /tmp/aspersa 2>/dev/null; then
  951. parse_dmidecode_mem_devices
  952. fi
  953. # ########################################################################
  954. # Disks, RAID, Filesystems
  955. # ########################################################################
  956. # TODO: Add info about software RAID
  957. if echo "${ASPERSA_SKIP}" | grep -v MOUNT >/dev/null; then
  958. if [ "${platform}" != "SunOS" ]; then
  959. section "Mounted_Filesystems"
  960. cmd="df -h"
  961. if [ "${platform}" = "Linux" ]; then
  962. cmd="df -h -P"
  963. fi
  964. $cmd | sort > /tmp/aspersa2
  965. mount | sort | join /tmp/aspersa2 - > /tmp/aspersa
  966. parse_filesystems /tmp/aspersa "${platform}"
  967. fi
  968. fi
  969. if [ "${platform}" = "Linux" ]; then
  970. section "Disk_Schedulers_And_Queue_Size"
  971. echo "" > /tmp/aspersa
  972. for disk in $(ls /sys/block/ | grep -v -e ram -e loop -e 'fd[0-9]'); do
  973. if [ -e "/sys/block/${disk}/queue/scheduler" ]; then
  974. name_val "${disk}" "$(cat /sys/block/${disk}/queue/scheduler | grep -o '\[.*\]') $(cat /sys/block/${disk}/queue/nr_requests)"
  975. fdisk -l "/dev/${disk}" >> /tmp/aspersa 2>/dev/null
  976. fi
  977. done
  978. # Relies on /tmp/aspersa having data from the Disk Schedulers loop.
  979. section "Disk_Partioning"
  980. parse_fdisk
  981. section "Kernel_Inode_State"
  982. for file in dentry-state file-nr inode-nr; do
  983. name_val "${file}" "$(cat /proc/sys/fs/${file} 2>&1)"
  984. done
  985. section "LVM_Volumes"
  986. if which lvs >/dev/null 2>&1 && test -x "$(which lvs)"; then
  987. lvs 2>&1
  988. else
  989. echo "Cannot execute 'lvs'";
  990. fi
  991. fi
  992. section "RAID_Controller"
  993. # ########################################################################
  994. # We look in lspci first because it's more reliable, then dmesg, because it's
  995. # often available to non-root users. It's most reliable to look at
  996. # /var/log/dmesg if possible.
  997. # ########################################################################
  998. if which lspci >/dev/null 2>&1 && lspci > /tmp/aspersa 2>/dev/null; then
  999. controller="$(parse_raid_controller_lspci)"
  1000. fi
  1001. if [ -z "${controller}" ]; then
  1002. cat /var/log/dmesg > /tmp/aspersa 2>/dev/null
  1003. if [ ! -s /tmp/aspersa ]; then
  1004. dmesg > /tmp/aspersa 2>/dev/null
  1005. fi
  1006. controller="$(parse_raid_controller_dmesg)"
  1007. fi
  1008. name_val Controller "${controller:-No RAID controller detected}"
  1009. # ########################################################################
  1010. # Attempt to get, parse, and print RAID controller status from possibly
  1011. # proprietary management software. Any executables that are normally stored
  1012. # in a weird location, such as /usr/StorMan/arcconf, should have their
  1013. # location added to $PATH at the beginning of main().
  1014. # ########################################################################
  1015. notfound=""
  1016. if [ "${controller}" = "AACRAID" ]; then
  1017. if arcconf getconfig 1 > /tmp/aspersa 2>/dev/null; then
  1018. parse_arcconf
  1019. elif ! which arcconf >/dev/null 2>&1; then
  1020. notfound="e.g. "
  1021. fi
  1022. elif [ "${controller}" = "HP Smart Array" ]; then
  1023. if hpacucli ctrl all show config > /tmp/aspersa 2>/dev/null; then
  1024. parse_hpacucli
  1025. elif ! which hpacucli >/dev/null 2>&1; then
  1026. notfound="your package repository or the manufacturer's website"
  1027. fi
  1028. elif [ "${controller}" = "LSI Logic MegaRAID SAS" ]; then
  1029. if MegaCli64 -AdpAllInfo -aALL -NoLog > /tmp/aspersa 2>/dev/null; then
  1030. parse_lsi_megaraid_adapter_info
  1031. elif ! which MegaCli64 >/dev/null 2>&1; then
  1032. notfound="your package repository or the manufacturer's website"
  1033. fi
  1034. if MegaCli64 -AdpBbuCmd -GetBbuStatus -aALL -NoLog > /tmp/aspersa 2>/dev/null; then
  1035. parse_lsi_megaraid_bbu_status
  1036. fi
  1037. if MegaCli64 -LdPdInfo -aALL -NoLog > /tmp/aspersa 2>/dev/null; then
  1038. parse_lsi_megaraid_virtual_devices
  1039. parse_lsi_megaraid_devices
  1040. fi
  1041. fi
  1042. if [ "${notfound}" ]; then
  1043. echo " RAID controller software not found; try getting it from"
  1044. echo " ${notfound}"
  1045. fi
  1046. if echo "${ASPERSA_SKIP}" | grep -v NETWORK >/dev/null; then
  1047. # #####################################################################
  1048. # Network stuff
  1049. # #####################################################################
  1050. if [ "${platform}" = "Linux" ]; then
  1051. section Network_Config
  1052. if which lspci > /dev/null 2>&1 && lspci > /tmp/aspersa 2>/dev/null; then
  1053. parse_ethernet_controller_lspci
  1054. fi
  1055. if sysctl net.ipv4.tcp_fin_timeout > /dev/null 2>&1; then
  1056. name_val "FIN Timeout" "$(sysctl net.ipv4.tcp_fin_timeout)"
  1057. name_val "Port Range" "$(sysctl net.ipv4.ip_local_port_range)"
  1058. fi
  1059. fi
  1060. # TODO cat /proc/sys/net/ipv4/ip_conntrack_max ; it might be
  1061. # /proc/sys/net/netfilter/nf_conntrack_max or /proc/sys/net/nf_conntrack_max
  1062. # in new kernels like Fedora 12?
  1063. if which ip >/dev/null 2>&1 && ip -s link > /tmp/aspersa 2>/dev/null; then
  1064. section Interface_Statistics
  1065. parse_ip_s_link /tmp/aspersa
  1066. fi
  1067. if [ "${platform}" = "Linux" ]; then
  1068. section Network_Connections
  1069. if netstat -antp > /tmp/aspersa 2>/dev/null; then
  1070. parse_netstat
  1071. fi
  1072. fi
  1073. fi
  1074. # ########################################################################
  1075. # Processes, load, etc
  1076. # ########################################################################
  1077. if echo "${ASPERSA_SKIP}" | grep -v PROCESS >/dev/null; then
  1078. section Top_Processes
  1079. if which prstat > /dev/null 2>&1; then
  1080. prstat | head
  1081. elif which top > /dev/null 2>&1 ; then
  1082. cmd="top -bn 1"
  1083. if [ "${platform}" = "FreeBSD" ]; then
  1084. cmd="top -b -d 1"
  1085. fi
  1086. $cmd | sed -e 's# *$##g' -e '/./{H;$!d;}' -e 'x;/PID/!d;' | grep . | head
  1087. fi
  1088. if which vmstat > /dev/null 2>&1 ; then
  1089. section "Simplified_and_fuzzy_rounded_vmstat_(wait_please)"
  1090. vmstat 1 5 > /tmp/aspersa
  1091. if [ "${platform}" = "Linux" ]; then
  1092. format_vmstat
  1093. else
  1094. # TODO: simplify/format for other platforms
  1095. cat /tmp/aspersa
  1096. fi
  1097. fi
  1098. fi
  1099. # ########################################################################
  1100. # All done. Signal the end so it's explicit.
  1101. # ########################################################################
  1102. temp_files "rm"
  1103. temp_files "check"
  1104. section The_End
  1105. }
  1106. # Execute the program if it was not included from another file. This makes it
  1107. # possible to include without executing, and thus test.
  1108. if [ "$(basename "$0")" = "summary" ] || [ "$(basename "$0")" = "bash" -a "$_" = "$0" ]; then
  1109. main $@
  1110. fi
这是我开发机器上的信息

点击(此处)折叠或打开

  1. # Aspersa System Summary Report ##############################
  2. Date | 2011-06-12 08:56:30 UTC (local TZ: CST +0800)
  3. Hostname | ubuntu1104-dev01
  4. Uptime | 2 days, 6:37, 2 users, load average: 0.00, 0.01, 0.05
  5. System | Dell Inc.; OptiPlex 990; v01 (Mini Tower)
  6. Service Tag | XXXXXXX
  7. Platform | Linux
  8. Release | Ubuntu 11.04 (natty)
  9. Kernel | 2.6.38-8-generic
  10. Architecture | CPU = 64-bit, OS = 64-bit
  11. Threading | NPTL 2.13
  12. SELinux | No SELinux detected
  13. Virtualized | No virtualization detected
  14. # Processor ##################################################
  15. Processors | physical = 1, cores = 4, virtual = 8, hyperthreading = yes
  16. Speeds | 7x1600.000, 1x2600.000
  17. Models | 8xIntel(R) Core(TM) i7-2600 CPU @ 3.40GHz
  18. Caches | 8x8192 KB
  19. # Memory #####################################################
  20. Total | 15.66G
  21. Free | 13.08G
  22. Used | physical = 2.59G, swap = 0.00k, virtual = 2.59G
  23. Buffers | 175.48M
  24. Caches | 1.55G
  25. Dirty | 40 kB
  26. UsedRSS | 746.0M
  27. Swappiness | vm.swappiness = 60
  28. DirtyPolicy | vm.dirty_ratio = 10, vm.dirty_background_ratio = 5
  29. DirtyStatus | vm.dirty_bytes = 0, vm.dirty_background_bytes = 0
  30. Locator Size Speed Form Factor Type Type Detail
  31. ========= ======== ================= ============= ============= ===========
  32. ChannelA-DIMM0 4096 MB 1333 MHz (0.8 ns) DIMM {OUT OF SPEC} Synchronous
  33. ChannelA-DIMM1 4096 MB 1333 MHz (0.8 ns) DIMM {OUT OF SPEC} Synchronous
  34. ChannelB-DIMM0 4096 MB 1333 MHz (0.8 ns) DIMM {OUT OF SPEC} Synchronous
  35. ChannelB-DIMM1 4096 MB 1333 MHz (0.8 ns) DIMM {OUT OF SPEC} Synchronous
  36. # Mounted Filesystems ########################################
  37. Filesystem Size Used Type Opts Mountpoint
  38. /dev/sda1 902G 2% ext4 rw,errors=remount-ro,commit=0 /
  39. none 7.9G 0% devpts rw,noexec,nosuid,gid=5,mode=0620 /var/lock
  40. none 7.9G 0% tmpfs rw,nosuid,nodev /var/lock
  41. none 7.9G 0% devtmpfs rw,mode=0755 /var/lock
  42. none 7.9G 0% debugfs rw /var/lock
  43. none 7.9G 0% securityfs rw /var/lock
  44. none 7.9G 0% sysfs rw,noexec,nosuid,nodev /var/lock
  45. none 7.9G 0% tmpfs rw,noexec,nosuid,nodev /var/lock
  46. none 7.9G 0% tmpfs rw,nosuid,mode=0755 /var/lock
  47. none 7.9G 1% devpts rw,noexec,nosuid,gid=5,mode=0620 /dev/shm
  48. none 7.9G 1% tmpfs rw,nosuid,nodev /dev/shm
  49. none 7.9G 1% devtmpfs rw,mode=0755 /dev/shm
  50. none 7.9G 1% debugfs rw /dev/shm
  51. none 7.9G 1% securityfs rw /dev/shm
  52. none 7.9G 1% sysfs rw,noexec,nosuid,nodev /dev/shm
  53. none 7.9G 1% tmpfs rw,noexec,nosuid,nodev /dev/shm
  54. none 7.9G 1% tmpfs rw,nosuid,mode=0755 /dev/shm
  55. none 7.9G 1% devpts rw,noexec,nosuid,gid=5,mode=0620 /dev
  56. none 7.9G 1% tmpfs rw,nosuid,nodev /dev
  57. none 7.9G 1% devtmpfs rw,mode=0755 /dev
  58. none 7.9G 1% debugfs rw /dev
  59. none 7.9G 1% securityfs rw /dev
  60. none 7.9G 1% sysfs rw,noexec,nosuid,nodev /dev
  61. none 7.9G 1% tmpfs rw,noexec,nosuid,nodev /dev
  62. none 7.9G 1% tmpfs rw,nosuid,mode=0755 /dev
  63. none 7.9G 1% devpts rw,noexec,nosuid,gid=5,mode=0620 /var/run
  64. none 7.9G 1% tmpfs rw,nosuid,nodev /var/run
  65. none 7.9G 1% devtmpfs rw,mode=0755 /var/run
  66. none 7.9G 1% debugfs rw /var/run
  67. none 7.9G 1% securityfs rw /var/run
  68. none 7.9G 1% sysfs rw,noexec,nosuid,nodev /var/run
  69. none 7.9G 1% tmpfs rw,noexec,nosuid,nodev /var/run
  70. none 7.9G 1% tmpfs rw,nosuid,mode=0755 /var/run
  71. # Disk Schedulers And Queue Size #############################
  72. sda | [cfq] 128
  73. sr0 | [cfq] 128
  74. # Disk Partioning ############################################
  75. Device Type Start End Size
  76. ============ ==== ========== ========== ==================
  77. /dev/sda Disk 1000204886016
  78. /dev/sda1 Part 1 119519 983069015040
  79. /dev/sda2 Part 119519 121602 17133258240
  80. /dev/sda5 Part 119519 121602 17133258240
  81. # Kernel Inode State #########################################
  82. dentry-state | 153236 143621 45 0 0 0
  83. file-nr | 5664 0 1601386
  84. inode-nr | 76942 2365
  85. # LVM Volumes ################################################
  86. Cannot execute 'lvs'
  87. # RAID Controller ############################################
  88. Controller | Intel Corporation 82801 SATA RAID Controller (rev 04)
  89. # Network Config #############################################
  90. Controller | Intel Corporation 82579LM Gigabit Network Connection (rev 04)
  91. FIN Timeout | net.ipv4.tcp_fin_timeout = 60
  92. Port Range | net.ipv4.ip_local_port_range = 32768 61000
  93. # Interface Statistics #######################################
  94. interface rx_bytes rx_packets rx_errors tx_bytes tx_packets tx_errors
  95. ========= ========= ========== ========== ========== ========== ==========
  96. l 2000000000 12500000 0 2000000000 12500000 0
  97. eth 100000000 350000 0 12500000 80000 0
  98. vboxnet 0 0 0 0 0 0
  99. # Network Connections ########################################
  100. Connections from remote IP addresses
  101. 127.0.0. 2
  102. 192.168.0.23 1
  103. Connections to local IP addresses
  104. 127.0.0. 2
  105. 192.168.0.24 1
  106. Connections to top 10 local ports
  107. 22 1
  108. 4369 1
  109. 45022 1
  110. States of connections
  111. ESTABLISHED 3
  112. LISTEN 8
  113. # Top Processes ##############################################
  114. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  115. 1 root 20 0 24008 2212 1356 S 0 0.0 0:01.78 init
  116. 2 root 20 0 0 0 0 S 0 0.0 0:00.00 kthreadd
  117. 3 root 20 0 0 0 0 S 0 0.0 0:01.98 ksoftirqd/0
  118. 5 root 20 0 0 0 0 S 0 0.0 0:00.25 kworker/u:0
  119. 6 root RT 0 0 0 0 S 0 0.0 0:00.00 migration/0
  120. 7 root RT 0 0 0 0 S 0 0.0 0:00.00 migration/1
  121. 8 root 20 0 0 0 0 S 0 0.0 0:03.52 kworker/1:0
  122. 9 root 20 0 0 0 0 S 0 0.0 0:00.77 ksoftirqd/1
  123. 11 root RT 0 0 0 0 S 0 0.0 0:00.00 migration/2
  124. # Simplified and fuzzy rounded vmstat (wait please) ##########
  125. procs ---swap-- -----io---- ---system---- --------cpu--------
  126. r b si so bi bo ir cs us sy il wa st
  127. 0 0 0 0 1 1 25 1 0 0 99 0
  128. 0 0 0 0 0 0 250 450 0 0 100 0
  129. 0 0 0 0 0 125 150 250 0 0 99 1
  130. 0 0 0 0 0 0 100 150 0 0 100 0
  131. 0 0 0 0 0 0 100 225 0 0 100 0
  132. # The End ####################################################
转自http://jinghong.iteye.com/blog/900078
阅读(2042) | 评论(0) | 转发(0) |
0

上一篇:【转】10个工具让你的 shell 脚本更强大

下一篇:没有了

给主人留下些什么吧!~~