forked from dbb/scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsysstats.pl
executable file
·85 lines (70 loc) · 1.23 KB
/
sysstats.pl
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
82
83
84
85
#!/usr/bin/perl -lw
use autodie;
use POSIX qw(strftime);
use strict;
# Subroutines #############################################################
sub act {
open(my $in, "<", "/proc/meminfo");
while (<$in>) {
if (/Active:/) {
$_ =~ /([0-9]+)/;
my $mb = int($1/1024);
print $mb . "MB";;
}
}
close $in;
}
sub bat {
$_ = (split " ", `acpi -b`)[-1];
print;
}
sub date {
$_ = strftime "%d/%m %R", localtime;
print;
}
sub help {
print " arg\t\t\tdescription\n".
"-a | act\t\tActive memory\n".
"-b | bat\t\tBattery charge %\n".
"-d | bat\t\ttime and Date %\n".
"-l | load\t\tavg Load in last minute\n".
"-t | temp\t\tfirst core Temperature\n"
;
}
sub load {
chop($_ = (split " ", `uptime`)[-3]);
# $_ = (split ':', `uptime`)[-1];
print;
}
sub temp {
foreach (split "\n", `sensors`) {
if (/0:/) {
$_ =~ /[+-]([0-9.]+)/;
print "$1C";
}
}
}
# Output ##################################################################
unless (defined($ARGV[0])) {
&help;
}
foreach (@ARGV) {
if (/act/ || /^-a$/ ) {
&act;
}
elsif (/bat/ || /^-b$/ ) {
&bat;
}
elsif (/date/ || /^-d$/ ) {
&date;
}
elsif (/load/ || /^-l$/) {
&load;
}
elsif (/temp/ || /^-t$/) {
&temp;
}
else {
&help;
}
}