3
3
namespace Laravel \Pulse \Recorders ;
4
4
5
5
use Carbon \CarbonInterval as Interval ;
6
- use DateInterval ;
7
- use DateTimeInterface ;
8
6
use Illuminate \Config \Repository ;
9
- use Illuminate \Support \Facades \App ;
10
7
use Illuminate \Support \InteractsWithTime ;
11
8
use Illuminate \Support \Str ;
12
- use Laravel \Pulse \Events \IsolatedBeat ;
13
9
use Laravel \Pulse \Events \SharedBeat ;
14
10
use Laravel \Pulse \Pulse ;
15
11
use Laravel \Pulse \Support \CacheStoreResolver ;
20
16
*/
21
17
class Servers
22
18
{
23
- use InteractsWithTime, Concerns \Intervals;
19
+ use Concerns \Intervals, InteractsWithTime ;
24
20
25
21
/**
26
22
* The events to listen for.
@@ -55,23 +51,23 @@ public function record(SharedBeat $event): void
55
51
'Linux ' => intval (`cat /proc/meminfo | grep MemTotal | grep -E -o '[0-9]+' ` / 1024 ),
56
52
'Windows ' => intval (((int ) trim (`wmic ComputerSystem get TotalPhysicalMemory | more +1 `)) / 1024 / 1024 ),
57
53
'BSD ' => intval (`sysctl hw.physmem | grep -Eo '[0-9]+' ` / 1024 / 1024 ),
58
- default => throw new RuntimeException ('The pulse:check command does not currently support ' .PHP_OS_FAMILY ),
54
+ default => throw new RuntimeException ('The pulse:check command does not currently support ' .PHP_OS_FAMILY ),
59
55
};
60
56
61
57
$ memoryUsed = match (PHP_OS_FAMILY ) {
62
58
'Darwin ' => $ memoryTotal - intval (intval (`vm_stat | grep 'Pages free' | grep -Eo '[0-9]+' `) * intval (`pagesize `) / 1024 / 1024 ), // MB
63
59
'Linux ' => $ memoryTotal - intval (`cat /proc/meminfo | grep MemAvailable | grep -E -o '[0-9]+' ` / 1024 ), // MB
64
60
'Windows ' => $ memoryTotal - intval (((int ) trim (`wmic OS get FreePhysicalMemory | more +1 `)) / 1024 ), // MB
65
61
'BSD ' => intval (intval (`( sysctl vm.stats.vm.v_cache_count | grep -Eo '[0-9]+' ; sysctl vm.stats.vm.v_inactive_count | grep -Eo '[0-9]+' ; sysctl vm.stats.vm.v_active_count | grep -Eo '[0-9]+' ) | awk '{s+=$1} END {print s}' `) * intval (`pagesize `) / 1024 / 1024 ), // MB
66
- default => throw new RuntimeException ('The pulse:check command does not currently support ' .PHP_OS_FAMILY ),
62
+ default => throw new RuntimeException ('The pulse:check command does not currently support ' .PHP_OS_FAMILY ),
67
63
};
68
64
69
65
$ cpu = match (PHP_OS_FAMILY ) {
70
66
'Darwin ' => (int ) `top -l 1 | grep -E "^CPU" | tail -1 | awk '{ print $3 + $5 }' `,
71
67
'Linux ' => (int ) `top -bn1 | grep -E '^(%Cpu|CPU)' | awk '{ print $2 + $4 }' `,
72
68
'Windows ' => (int ) trim (`wmic cpu get loadpercentage | more +1 `),
73
69
'BSD ' => (int ) `top -b -d 2| grep 'CPU: ' | tail -1 | awk '{print$10}' | grep -Eo '[0-9]+\.[0-9]+' | awk '{ print 100 - $1 }' `,
74
- default => throw new RuntimeException ('The pulse:check command does not currently support ' .PHP_OS_FAMILY ),
70
+ default => throw new RuntimeException ('The pulse:check command does not currently support ' .PHP_OS_FAMILY ),
75
71
};
76
72
77
73
$ this ->pulse ->record ('cpu ' , $ slug , $ cpu , $ event ->time )->avg ()->onlyBuckets ();
@@ -87,7 +83,7 @@ public function record(SharedBeat $event): void
87
83
'total ' => $ total = intval (round (disk_total_space ($ directory ) / 1024 / 1024 )), // MB
88
84
'used ' => intval (round ($ total - (disk_free_space ($ directory ) / 1024 / 1024 ))), // MB
89
85
])
90
- ->all (),
86
+ ->all (),
91
87
], flags: JSON_THROW_ON_ERROR ), $ event ->time );
92
88
});
93
89
}
0 commit comments