Line | |
---|
1 | #!/bin/sh
|
---|
2 | # Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
|
---|
3 |
|
---|
4 | # This program is free software: you can redistribute it and/or modify
|
---|
5 | # it under the terms of the GNU General Public License as published by
|
---|
6 | # the Free Software Foundation, either version 3 of the License, or
|
---|
7 | # (at your option) any later version.
|
---|
8 |
|
---|
9 | # This program is distributed in the hope that it will be useful,
|
---|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | # GNU General Public License for more details.
|
---|
13 |
|
---|
14 | # You should have received a copy of the GNU General Public License
|
---|
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
16 |
|
---|
17 | TYPE="${BLOCK_INSTANCE:-mem}"
|
---|
18 |
|
---|
19 | awk -v type=$TYPE '
|
---|
20 | /^MemTotal:/ {
|
---|
21 | mem_total=$2
|
---|
22 | }
|
---|
23 | /^MemFree:/ {
|
---|
24 | mem_free=$2
|
---|
25 | }
|
---|
26 | /^Buffers:/ {
|
---|
27 | mem_free+=$2
|
---|
28 | }
|
---|
29 | /^Cached:/ {
|
---|
30 | mem_free+=$2
|
---|
31 | }
|
---|
32 | /^SwapTotal:/ {
|
---|
33 | swap_total=$2
|
---|
34 | }
|
---|
35 | /^SwapFree:/ {
|
---|
36 | swap_free=$2
|
---|
37 | }
|
---|
38 | END {
|
---|
39 | if (type == "swap") {
|
---|
40 | free=swap_free/1024
|
---|
41 | used=(swap_total-swap_free)/1024
|
---|
42 | total=swap_total/1024
|
---|
43 | } else {
|
---|
44 | free=mem_free/1024
|
---|
45 | used=(mem_total-mem_free)/1024
|
---|
46 | total=mem_total/1024
|
---|
47 | }
|
---|
48 |
|
---|
49 | pct=0
|
---|
50 | if (total > 0) {
|
---|
51 | pct=used/total*100
|
---|
52 | }
|
---|
53 |
|
---|
54 | # full text
|
---|
55 | printf("%s%.1i/%.1iMiB\n", "RAM: ", used, total)
|
---|
56 |
|
---|
57 | # color
|
---|
58 | if (pct > 90) {
|
---|
59 | print("#FF0000")
|
---|
60 | } else if (pct > 80) {
|
---|
61 | print("#FFAE00")
|
---|
62 | } else if (pct > 70) {
|
---|
63 | print("#FFF600")
|
---|
64 | }
|
---|
65 | }
|
---|
66 | ' /proc/meminfo
|
---|
Note:
See
TracBrowser
for help on using the repository browser.