@@ -63,9 +63,9 @@ public function record(SharedBeat $event): void
63
63
[1] 5534304
64
64
top -bn1 | grep -E '^(%Cpu|CPU)' | awk '{ print $2 + $4 }'
65
65
[2] 18
66
- df --output=used,avail /
67
- [3] Used Avail
68
- [4] 34218600 473695292
66
+ df / | awk 'NR==2 {print $3 "\n" $4 }'
67
+ [3] 34218600
68
+ [4] 473695292
69
69
*/
70
70
71
71
$ memoryTotal = intval ($ remoteServerStats [0 ] / 1024 );
@@ -75,37 +75,32 @@ public function record(SharedBeat $event): void
75
75
$ storageDirectories = $ this ->config ->get ('pulse.recorders. ' . self ::class . '.directories ' );
76
76
77
77
if (count ($ storageDirectories ) == 1 && $ storageDirectories [0 ] == "/ " ) {
78
- $ storage = preg_replace ('/\s+/ ' , ' ' , $ remoteServerStats [4 ]); // replace multi space with single space
79
- $ storage = explode (" " , $ storage ); // break into segments based on sigle space
80
-
81
- $ storageTotal = $ storage [0 ] + $ storage [1 ]; // used and availble
82
- $ storageUsed = $ storage [0 ]; // used
83
-
84
78
$ storage = [collect ([
85
79
'directory ' => "/ " ,
86
- 'total ' => intval (round ($ storageTotal / 1024 )), // MB
87
- 'used ' => intval (round ($ storageUsed / 1024 )), // MB
80
+ 'total ' => (round (( intval ( $ remoteServerStats [ 3 ]) + intval ( $ remoteServerStats [ 4 ])) / 1024 )), // MB
81
+ 'used ' => (round (intval ( $ remoteServerStats [ 3 ]) / 1024 )), // MB
88
82
])];
89
83
} else {
90
84
$ storage = collect ($ storageDirectories )
91
- ->map (function (string $ directory ) use ($ remote_ssh ) {
92
- $ storage = match (PHP_OS_FAMILY ) {
93
- 'Darwin ' => (`$ remote_ssh 'df $ directory' `),
94
- 'Linux ' => (`$ remote_ssh 'df $ directory' `),
95
- default => throw new RuntimeException ('The pulse:check command does not currently support ' . PHP_OS_FAMILY ),
96
- };
97
-
98
- $ storage = explode ("\n" , $ storage ); // break in lines
99
- $ storage = preg_replace ('/\s+/ ' , ' ' , $ storage [1 ]); // replace multi space with single space
100
- $ storage = explode (" " , $ storage ); // break into segments based on sigle space
101
-
102
- $ storageTotal = $ storage [2 ] + $ storage [3 ]; // used and availble
103
- $ storageUsed = $ storage [2 ]; // used
104
-
85
+ ->map (function (string $ directory ) use ($ remote_ssh , $ remoteServerStats ) {
86
+ if ($ directory =="/ " ) {
87
+ $ storageTotal = intval ($ remoteServerStats [3 ]) + intval ($ remoteServerStats [4 ]); // used and availble
88
+ $ storageUsed = intval ($ remoteServerStats [3 ]); // used
89
+ } else {
90
+ $ storage = match (PHP_OS_FAMILY ) {
91
+ 'Darwin ' => (`$ remote_ssh 'df $ directory' | awk 'NR==2 {print $3 " \n" $4 }' `),
92
+ 'Linux ' => (`$ remote_ssh 'df $ directory' | awk 'NR==2 {print $3 " \n" $4 }' `),
93
+ default => throw new RuntimeException ('The pulse:check command does not currently support ' . PHP_OS_FAMILY ),
94
+ };
95
+ $ storage = explode ("\n" , $ storage ); // break in lines
96
+ $ storageTotal = intval ($ storage [0 ]) + intval ($ storage [1 ]); // used and availble
97
+ $ storageUsed = intval ($ storage [0 ]); // used
98
+ }
99
+
105
100
return [
106
101
'directory ' => $ directory ,
107
- 'total ' => intval (round ($ storageTotal / 1024 )), // MB
108
- 'used ' => intval (round ($ storageUsed / 1024 )), // MB
102
+ 'total ' => (round ($ storageTotal / 1024 )), // MB
103
+ 'used ' => (round ($ storageUsed / 1024 )), // MB
109
104
];
110
105
})
111
106
->all ();
0 commit comments