-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctr
More file actions
45 lines (40 loc) · 1.09 KB
/
ctr
File metadata and controls
45 lines (40 loc) · 1.09 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
#!/usr/bin/env perl
use strict;
use warnings;
sub alert {
my ($type, $title, $content) = @_;
system("notify-send -u $type -c \"$title\" \"$content\"");
}
my $HOUR = 3600;
my $GAP = 5 * 60;
my %games = (
"dota2" => {
"proc_name" => "dota2",
"limit" => 2 * $HOUR,
"union" => []
},
);
my %status = ();
for (;;) {
for my $name (keys %games) {
my $game = $games{$name};
my $pn = $game->{"proc_name"};
$status{$name} += $GAP if (`pidof $pn` ne "");
}
for my $name (keys %games) {
my $game = $games{$name};
my $pn = $game->{"proc_name"};
if (`pidof $pn` ne "") {
if (sub {
my $s = 0;
for my $k (@_) { $s += $k; }
return $s;
}->(map { ($status{$_} // 0) } @{$game->{"union"}}) + $status{$name} > $game->{"limit"}) {
alert("critical", "Limit exceeded", "Daily limit of $name exceeded.");
}
}
}
my $day = `date +%d`;
sleep $GAP;
%status = () if (`date +%d` ne $day);
}