-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats
More file actions
executable file
·81 lines (66 loc) · 2.22 KB
/
Copy pathstats
File metadata and controls
executable file
·81 lines (66 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/awk -f
function pretty_time(s)
{
days = int(s / 86400)
s -= days * 86400
hours = int (s / 3600)
s -= hours * 3600
mins = int(s / 60)
s -= mins * 60
secs = s
return sprintf("%d days %d hours %d minutes %.2f seconds", days, hours, mins, secs)
}
function si(b, u)
{
if (u == "iB") m = 1024
else m = 1000
if (b < m)
return sprintf("%.2f %s", b, u)
if (b < m^2)
return sprintf("%.2f K%s", b/m, u)
if (b < m^3)
return sprintf("%.2f M%s", b/m^2, u)
if (b < m^4)
return sprintf("%.2f G%s", b/m^3, u)
if (b < m^5)
return sprintf("%.2f T%s", b/m^4, u)
}
BEGIN {
while (getline < "/proc/stat")
stat[$1] = $2
getline < "/proc/version"
print $0, "\n"
getline < "/proc/uptime"
uptime = $1
idle = $2
printf " %20s %15d %s\n", "Date", strftime("%s"), strftime("%c")
printf " %20s %15d %s\n", "Boot date", strftime("%s", stat["btime"]), strftime("%c", stat["btime"])
printf " %20s %15d %s\n", "Uptime", uptime, pretty_time(uptime)
printf " %20s %15d %s\n", "Idle time", idle, pretty_time(idle)
print ""
printf " %20s %15d %s (%.2f/s)\n", "Forks", stat["processes"], si(stat["processes"]), stat["processes"]/uptime
printf " %20s %15d %s (%.2f/s)\n", "Context Switches", stat["ctxt"], si(stat["ctxt"]), stat["ctxt"]/uptime
printf " %20s %15d %s (%.2f/s)\n", "Interrupts", stat["intr"], si(stat["intr"]), stat["intr"]/uptime
print ""
while (getline < "/proc/diskstats") {
if ($3 ~ /sd.$/) {
read_sda = $6 * 512
write_sda = $10 * 512
}
}
printf " %20s %15d %s (%s/s)\n", "Read", read_sda, si(read_sda, "iB"), si(read_sda/uptime, "iB")
printf " %20s %15d %s (%s/s)\n", "Write", write_sda, si(write_sda, "iB"), si(write_sda/uptime, "iB")
print ""
while ("ip address show" | getline) {
if (/inet.*global/)
interfaces[$NF] = 1
}
for (dev in interfaces) {
getline rx_bytes_dev < ("/sys/class/net/"dev"/statistics/rx_bytes")
getline tx_bytes_dev < ("/sys/class/net/"dev"/statistics/tx_bytes")
rx_bytes += rx_bytes_dev
tx_bytes += tx_bytes_dev
}
printf " %20s %15d %s (%s/s)\n", "Received", rx_bytes, si(rx_bytes, "iB"), si(rx_bytes/uptime, "iB")
printf " %20s %15d %s (%s/s)\n", "Transmitted", tx_bytes, si(tx_bytes, "iB"), si(tx_bytes/uptime, "iB")
}