Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
9591cf3e
Commit
9591cf3e
authored
Nov 16, 2020
by
ZhengJie
Browse files
[代码优化](v2.6):服务监控兼容Mac Os Big Sur,交换空间查询优化
parent
7b6f5af6
Changes
3
Hide whitespace changes
Inline
Side-by-side
eladmin-system/pom.xml
View file @
9591cf3e
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
<properties>
<properties>
<jjwt.version>
0.11.1
</jjwt.version>
<jjwt.version>
0.11.1
</jjwt.version>
<!-- oshi监控需要指定jna版本, 问题详见 https://github.com/oshi/oshi/issues/1040 -->
<!-- oshi监控需要指定jna版本, 问题详见 https://github.com/oshi/oshi/issues/1040 -->
<jna.version>
5.
5
.0
</jna.version>
<jna.version>
5.
6
.0
</jna.version>
</properties>
</properties>
<dependencies>
<dependencies>
...
@@ -84,7 +84,7 @@
...
@@ -84,7 +84,7 @@
<dependency>
<dependency>
<groupId>
com.github.oshi
</groupId>
<groupId>
com.github.oshi
</groupId>
<artifactId>
oshi-core
</artifactId>
<artifactId>
oshi-core
</artifactId>
<version>
5.
0.1
</version>
<version>
5.
3.6
</version>
</dependency>
</dependency>
</dependencies>
</dependencies>
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MonitorServiceImpl.java
View file @
9591cf3e
...
@@ -50,7 +50,6 @@ public class MonitorServiceImpl implements MonitorService {
...
@@ -50,7 +50,6 @@ public class MonitorServiceImpl implements MonitorService {
HardwareAbstractionLayer
hal
=
si
.
getHardware
();
HardwareAbstractionLayer
hal
=
si
.
getHardware
();
// 系统信息
// 系统信息
resultMap
.
put
(
"sys"
,
getSystemInfo
(
os
));
resultMap
.
put
(
"sys"
,
getSystemInfo
(
os
));
// cpu 信息
// cpu 信息
resultMap
.
put
(
"cpu"
,
getCpuInfo
(
hal
.
getProcessor
()));
resultMap
.
put
(
"cpu"
,
getCpuInfo
(
hal
.
getProcessor
()));
// 内存信息
// 内存信息
...
@@ -75,9 +74,11 @@ public class MonitorServiceImpl implements MonitorService {
...
@@ -75,9 +74,11 @@ public class MonitorServiceImpl implements MonitorService {
FileSystem
fileSystem
=
os
.
getFileSystem
();
FileSystem
fileSystem
=
os
.
getFileSystem
();
List
<
OSFileStore
>
fsArray
=
fileSystem
.
getFileStores
();
List
<
OSFileStore
>
fsArray
=
fileSystem
.
getFileStores
();
for
(
OSFileStore
fs
:
fsArray
){
for
(
OSFileStore
fs
:
fsArray
){
diskInfo
.
put
(
"total"
,
fs
.
getTotalSpace
()
>
0
?
FileUtil
.
getSize
(
fs
.
getTotalSpace
())
:
"?"
);
long
available
=
fs
.
getUsableSpace
();
long
used
=
fs
.
getTotalSpace
()
-
fs
.
getUsableSpace
();
long
total
=
fs
.
getTotalSpace
();
diskInfo
.
put
(
"available"
,
FileUtil
.
getSize
(
fs
.
getUsableSpace
()));
long
used
=
total
-
available
;
diskInfo
.
put
(
"total"
,
total
>
0
?
FileUtil
.
getSize
(
total
)
:
"?"
);
diskInfo
.
put
(
"available"
,
FileUtil
.
getSize
(
available
));
diskInfo
.
put
(
"used"
,
FileUtil
.
getSize
(
used
));
diskInfo
.
put
(
"used"
,
FileUtil
.
getSize
(
used
));
diskInfo
.
put
(
"usageRate"
,
df
.
format
(
used
/(
double
)
fs
.
getTotalSpace
()
*
100
));
diskInfo
.
put
(
"usageRate"
,
df
.
format
(
used
/(
double
)
fs
.
getTotalSpace
()
*
100
));
}
}
...
@@ -91,10 +92,17 @@ public class MonitorServiceImpl implements MonitorService {
...
@@ -91,10 +92,17 @@ public class MonitorServiceImpl implements MonitorService {
*/
*/
private
Map
<
String
,
Object
>
getSwapInfo
(
GlobalMemory
memory
)
{
private
Map
<
String
,
Object
>
getSwapInfo
(
GlobalMemory
memory
)
{
Map
<
String
,
Object
>
swapInfo
=
new
LinkedHashMap
<>();
Map
<
String
,
Object
>
swapInfo
=
new
LinkedHashMap
<>();
swapInfo
.
put
(
"total"
,
FormatUtil
.
formatBytes
(
memory
.
getVirtualMemory
().
getSwapTotal
()));
VirtualMemory
virtualMemory
=
memory
.
getVirtualMemory
();
swapInfo
.
put
(
"used"
,
FormatUtil
.
formatBytes
(
memory
.
getVirtualMemory
().
getSwapUsed
()));
long
total
=
virtualMemory
.
getSwapTotal
();
swapInfo
.
put
(
"available"
,
FormatUtil
.
formatBytes
(
memory
.
getVirtualMemory
().
getSwapTotal
()
-
memory
.
getVirtualMemory
().
getSwapUsed
()));
long
used
=
virtualMemory
.
getSwapUsed
();
swapInfo
.
put
(
"usageRate"
,
df
.
format
(
memory
.
getVirtualMemory
().
getSwapUsed
()/(
double
)
memory
.
getVirtualMemory
().
getSwapTotal
()
*
100
));
swapInfo
.
put
(
"total"
,
FormatUtil
.
formatBytes
(
total
));
swapInfo
.
put
(
"used"
,
FormatUtil
.
formatBytes
(
used
));
swapInfo
.
put
(
"available"
,
FormatUtil
.
formatBytes
(
total
-
used
));
if
(
used
==
0
){
swapInfo
.
put
(
"usageRate"
,
0
);
}
else
{
swapInfo
.
put
(
"usageRate"
,
df
.
format
(
used
/(
double
)
total
*
100
));
}
return
swapInfo
;
return
swapInfo
;
}
}
...
...
pom.xml
View file @
9591cf3e
...
@@ -144,6 +144,7 @@
...
@@ -144,6 +144,7 @@
<artifactId>
ip2region
</artifactId>
<artifactId>
ip2region
</artifactId>
<version>
1.7.2
</version>
<version>
1.7.2
</version>
</dependency>
</dependency>
<!--lombok插件-->
<!--lombok插件-->
<dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<groupId>
org.projectlombok
</groupId>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment