Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
shop
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
shop
Commits
53589c29
Commit
53589c29
authored
Aug 31, 2019
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
6ee38964
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
4 deletions
+20
-4
Usage.java
src/main/java/com/egolm/shop/util/Usage.java
+20
-4
No files found.
src/main/java/com/egolm/shop/util/Usage.java
View file @
53589c29
...
...
@@ -21,10 +21,30 @@ import org.hyperic.sigar.Sigar;
import
org.hyperic.sigar.SigarException
;
import
org.hyperic.sigar.Swap
;
import
com.alibaba.fastjson.JSON
;
/**
*
* 使用此类前,请先将hyperic-sigar运行库添加至系统变量PATH下
* hyperic-sigar版本1.6.4(与pom.xml中 sigar.jar 版本保持一致)
* @author Quxl
*
*/
public
class
Usage
{
public
static
void
main
(
String
[]
args
)
throws
SigarException
{
System
.
out
.
println
(
JSON
.
toJSONString
(
new
Usage
().
get
()));
}
private
final
Log
logger
=
LogFactory
.
getLog
(
Usage
.
class
);
private
Sigar
sigar
=
null
;
public
Usage
()
throws
SigarException
{
Sigar
.
load
();
sigar
=
new
Sigar
();
}
public
Map
<
String
,
?>
get
()
{
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<
String
,
Object
>();
map
.
put
(
"System"
,
getJvmInfo
());
...
...
@@ -86,7 +106,6 @@ public class Usage {
private
Map
<
String
,
Object
>
getMemoryInfo
()
{
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<
String
,
Object
>();
try
{
Sigar
sigar
=
new
Sigar
();
Mem
mem
=
sigar
.
getMem
();
Swap
swap
=
sigar
.
getSwap
();
map
.
put
(
"内存总量"
,
mem
.
getTotal
()
/
1024L
+
"K av"
);
...
...
@@ -104,7 +123,6 @@ public class Usage {
private
List
<
Map
<
String
,
Object
>>
getCpuInfo
()
{
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<
Map
<
String
,
Object
>>();
try
{
Sigar
sigar
=
new
Sigar
();
CpuInfo
infos
[]
=
sigar
.
getCpuInfoList
();
CpuPerc
cpuList
[]
=
null
;
cpuList
=
sigar
.
getCpuPercList
();
...
...
@@ -135,7 +153,6 @@ public class Usage {
private
List
<
Map
<
String
,
Object
>>
getFileSystemInfo
()
{
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<
Map
<
String
,
Object
>>();
try
{
Sigar
sigar
=
new
Sigar
();
FileSystem
fslist
[]
=
sigar
.
getFileSystemList
();
for
(
int
i
=
0
;
i
<
fslist
.
length
;
i
++)
{
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<
String
,
Object
>();
...
...
@@ -188,7 +205,6 @@ public class Usage {
private
List
<
Map
<
String
,
Object
>>
getNetworkInfo
()
{
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<
Map
<
String
,
Object
>>();
try
{
Sigar
sigar
=
new
Sigar
();
String
ifNames
[]
=
sigar
.
getNetInterfaceList
();
for
(
int
i
=
0
;
i
<
ifNames
.
length
;
i
++)
{
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<
String
,
Object
>();
...
...
Write
Preview
Markdown
is supported
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