Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
H
haikang-client
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
杨立
haikang-client
Commits
55e837da
提交
55e837da
authored
10月 12, 2021
作者:
yangli
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
.
上级
fc5447fa
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
90 行增加
和
31 行删除
+90
-31
ConfigController.java
...rc/main/java/com/priusis/controller/ConfigController.java
+15
-8
DeviceInfoController.java
...ain/java/com/priusis/controller/DeviceInfoController.java
+50
-16
ApqInfoApplication.java
...pc-info/src/main/java/com/priusis/ApqInfoApplication.java
+25
-7
没有找到文件。
apq-pc-client/src/main/java/com/priusis/controller/ConfigController.java
浏览文件 @
55e837da
package
com
.
priusis
.
controller
;
import
cn.hutool.json.JSONArray
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
com.priusis.client.service.MqttRpcDataMessage
;
import
com.priusis.client.service.TenantManagerService
;
...
...
@@ -15,6 +16,8 @@ import javax.annotation.PostConstruct;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
/**
* @author yangli
...
...
@@ -57,19 +60,23 @@ public class ConfigController {
@GetMapping
(
value
=
"get_data_reporting"
)
public
R
<
JSONArray
>
getDataReporting
()
throws
IOException
{
return
R
.
success
(
JSONUtil
.
parseArray
(
SysConfigUtil
.
getProperty
(
"data.reporting"
,
"["
+
JSONArray
defaultConf
=
JSONUtil
.
parseArray
(
"["
+
"{\"code\":\"operatingSystem\",\"name\":\"操作系统\",\"frequency\":60},"
+
"{\"code\":\"baseboard\",\"name\":\"主板\",\"frequency\":60},"
+
"{\"code\":\"ip\",\"name\":\"ip\",\"frequency\":60},"
+
"{\"code\":\"cpuLoad\",\"name\":\"CPU负载\",\"frequency\":3
0},"
+
"{\"code\":\"cpuTemp\",\"name\":\"CPU温度\",\"frequency\":3
0},"
+
"{\"code\":\"mac\",\"name\":\"MAC地址\",\"frequency\":3
0},"
+
"{\"code\":\"memoryAvailable\",\"name\":\"内存使用率\",\"frequency\":3
0},"
+
"{\"code\":\"cpuLoad\",\"name\":\"CPU负载\",\"frequency\":6
0},"
+
"{\"code\":\"cpuTemp\",\"name\":\"CPU温度\",\"frequency\":6
0},"
+
"{\"code\":\"mac\",\"name\":\"MAC地址\",\"frequency\":6
0},"
+
"{\"code\":\"memoryAvailable\",\"name\":\"内存使用率\",\"frequency\":6
0},"
+
"{\"code\":\"memoryCap\",\"name\":\"内存容量\",\"frequency\":60},"
+
"{\"code\":\"diskModel\",\"name\":\"硬盘型号\",\"frequency\":60},"
+
"{\"code\":\"diskCap\",\"name\":\"硬盘容量\",\"frequency\":60},"
+
"{\"code\":\"diskModel\",\"name\":\"硬盘型号\",\"frequency\":60}"
+
"]"
)));
"{\"code\":\"diskFree\",\"name\":\"硬盘剩余\",\"frequency\":60}"
+
"]"
);
JSONArray
conf
=
JSONUtil
.
parseArray
(
SysConfigUtil
.
getProperty
(
"data.reporting"
,
"[]"
));
Set
<
String
>
set
=
conf
.
stream
().
map
(
JSONObject
.
class
::
cast
).
map
(
o
->
o
.
getStr
(
"code"
)).
collect
(
Collectors
.
toSet
());
defaultConf
.
stream
().
map
(
JSONObject
.
class
::
cast
).
filter
(
o
->
!
set
.
contains
(
o
.
getStr
(
"code"
))).
forEach
(
conf:
:
add
);
return
R
.
success
(
conf
);
}
@PostMapping
(
value
=
"save_data_reporting"
)
...
...
apq-pc-client/src/main/java/com/priusis/controller/DeviceInfoController.java
浏览文件 @
55e837da
...
...
@@ -3,6 +3,7 @@ package com.priusis.controller;
import
cn.hutool.core.io.unit.DataSizeUtil
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.system.oshi.OshiUtil
;
import
com.priusis.lib.R
;
import
com.priusis.util.MacAddrUtil
;
...
...
@@ -12,8 +13,10 @@ import org.springframework.web.bind.annotation.GetMapping;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
oshi.hardware.HWDiskStore
;
import
oshi.hardware.HWPartition
;
import
javax.annotation.PostConstruct
;
import
java.io.File
;
import
java.net.InetAddress
;
import
java.net.SocketException
;
import
java.net.UnknownHostException
;
...
...
@@ -35,7 +38,7 @@ public class DeviceInfoController {
@GetMapping
(
value
=
"get"
)
public
R
<
Map
<
String
,
Object
>>
get
()
throws
UnknownHostException
,
SocketException
{
if
(
info
==
null
)
refresh
();
if
(
info
==
null
)
refresh
();
return
R
.
success
(
info
);
}
...
...
@@ -49,14 +52,28 @@ public class DeviceInfoController {
.
put
(
"cpuModel"
,
OshiUtil
.
getCpuInfo
(
0
).
getCpuModel
())
.
put
(
"cpuTemp"
,
Double
.
parseDouble
(
new
DecimalFormat
(
"#.00"
).
format
(
OshiUtil
.
getSensors
().
getCpuTemperature
())))
.
put
(
"memoryCap"
,
DataSizeUtil
.
format
(
OshiUtil
.
getMemory
().
getTotal
()))
.
put
(
"diskModel"
,
Arrays
.
stream
(
OshiUtil
.
getHardware
().
getDiskStores
())
.
map
(
HWDiskStore:
:
getModel
)
.
map
(
model
->
StrUtil
.
removeSuffix
(
model
,
" (标准磁盘驱动器)"
))
.
collect
(
Collectors
.
joining
(
", "
)))
.
put
(
"diskCap"
,
DataSizeUtil
.
format
(
Arrays
.
stream
(
OshiUtil
.
getHardware
().
getDiskStores
())
.
map
(
HWDiskStore:
:
getSize
)
.
mapToLong
(
Long:
:
longValue
)
.
sum
()))
.
put
(
"diskModel"
,
JSONUtil
.
parseObj
(
Arrays
.
stream
(
OshiUtil
.
getHardware
().
getDiskStores
())
.
map
(
store
->
Arrays
.
stream
(
store
.
getPartitions
())
.
map
(
HWPartition:
:
getMountPoint
)
.
filter
(
StrUtil:
:
isNotBlank
)
.
map
(
s
->
"\""
+
StrUtil
.
removeSuffix
(
s
,
":\\"
)
+
"盘\":\""
+
StrUtil
.
removeSuffix
(
store
.
getModel
(),
" (标准磁盘驱动器)"
)
+
"\""
)
.
collect
(
Collectors
.
joining
(
","
)))
.
collect
(
Collectors
.
joining
(
","
,
"{"
,
"}"
))))
.
put
(
"diskCap"
,
JSONUtil
.
parseObj
(
Arrays
.
stream
(
OshiUtil
.
getHardware
().
getDiskStores
())
.
map
(
HWDiskStore:
:
getPartitions
)
.
flatMap
(
Arrays:
:
stream
)
.
filter
(
partition
->
StrUtil
.
isNotBlank
(
partition
.
getMountPoint
()))
.
map
(
partition
->
"\""
+
StrUtil
.
removeSuffix
(
partition
.
getMountPoint
(),
":\\"
)
+
"盘\":\""
+
DataSizeUtil
.
format
(
partition
.
getSize
())
+
"\""
)
.
collect
(
Collectors
.
joining
(
","
,
"{"
,
"}"
))))
.
put
(
"diskFree"
,
JSONUtil
.
parseObj
(
Arrays
.
stream
(
OshiUtil
.
getHardware
().
getDiskStores
())
.
map
(
HWDiskStore:
:
getPartitions
)
.
flatMap
(
Arrays:
:
stream
)
.
filter
(
partition
->
StrUtil
.
isNotBlank
(
partition
.
getMountPoint
()))
.
map
(
partition
->
"\""
+
StrUtil
.
removeSuffix
(
partition
.
getMountPoint
(),
":\\"
)
+
"盘\":\""
+
new
DecimalFormat
(
"#.00"
).
format
(
100
d
*
new
File
(
partition
.
getMountPoint
()).
getFreeSpace
()
/
partition
.
getSize
())
+
"%\""
)
.
collect
(
Collectors
.
joining
(
","
,
"{"
,
"}"
))))
.
build
();
}
...
...
@@ -86,13 +103,30 @@ public class DeviceInfoController {
System
.
out
.
println
(
DataSizeUtil
.
format
(
OshiUtil
.
getMemory
().
getTotal
()));
System
.
out
.
println
(
"硬盘型号"
);
System
.
out
.
println
(
Arrays
.
stream
(
OshiUtil
.
getHardware
().
getDiskStores
())
.
map
(
HWDiskStore:
:
getModel
)
.
map
(
model
->
StrUtil
.
removeSuffix
(
model
,
" (标准磁盘驱动器)"
))
.
collect
(
Collectors
.
joining
(
", "
)));
.
map
(
store
->
Arrays
.
stream
(
store
.
getPartitions
())
.
map
(
HWPartition:
:
getMountPoint
)
.
filter
(
StrUtil:
:
isNotBlank
)
.
map
(
s
->
"\""
+
StrUtil
.
removeSuffix
(
s
,
":\\"
)
+
"盘\":\""
+
StrUtil
.
removeSuffix
(
store
.
getModel
(),
" (标准磁盘驱动器)"
)
+
"\""
)
.
collect
(
Collectors
.
joining
(
","
)))
.
collect
(
Collectors
.
joining
(
","
,
"{"
,
"}"
)));
System
.
out
.
println
(
"硬盘容量"
);
System
.
out
.
println
(
DataSizeUtil
.
format
(
Arrays
.
stream
(
OshiUtil
.
getHardware
().
getDiskStores
())
.
map
(
HWDiskStore:
:
getSize
)
.
mapToLong
(
Long:
:
longValue
)
.
sum
()));
System
.
out
.
println
(
Arrays
.
stream
(
OshiUtil
.
getHardware
().
getDiskStores
())
.
map
(
HWDiskStore:
:
getPartitions
)
.
flatMap
(
Arrays:
:
stream
)
.
filter
(
partition
->
StrUtil
.
isNotBlank
(
partition
.
getMountPoint
()))
.
map
(
partition
->
"\""
+
StrUtil
.
removeSuffix
(
partition
.
getMountPoint
(),
":\\"
)
+
"盘\":\""
+
DataSizeUtil
.
format
(
partition
.
getSize
())
+
"\""
)
.
collect
(
Collectors
.
joining
(
","
,
"{"
,
"}"
)));
System
.
out
.
println
(
"硬盘剩余"
);
DecimalFormat
formatter
=
new
DecimalFormat
(
"#.00"
);
System
.
out
.
println
(
Arrays
.
stream
(
OshiUtil
.
getHardware
().
getDiskStores
())
.
map
(
HWDiskStore:
:
getPartitions
)
.
flatMap
(
Arrays:
:
stream
)
.
filter
(
partition
->
StrUtil
.
isNotBlank
(
partition
.
getMountPoint
()))
.
map
(
partition
->
"\""
+
StrUtil
.
removeSuffix
(
partition
.
getMountPoint
(),
":\\"
)
+
"盘\":\""
+
formatter
.
format
(
100
d
*
new
File
(
partition
.
getMountPoint
()).
getFreeSpace
()
/
partition
.
getSize
())
+
"%\""
)
.
collect
(
Collectors
.
joining
(
","
,
"{"
,
"}"
)));
}
}
apq-pc-info/src/main/java/com/priusis/ApqInfoApplication.java
浏览文件 @
55e837da
...
...
@@ -23,6 +23,7 @@ import oshi.hardware.HWDiskStore;
import
oshi.hardware.HWPartition
;
import
oshi.util.FormatUtil
;
import
java.io.File
;
import
java.net.InetAddress
;
import
java.text.DecimalFormat
;
import
java.util.Arrays
;
...
...
@@ -86,6 +87,7 @@ public class ApqInfoApplication {
String
memoryAvailable
=
"memoryAvailable"
;
String
diskModel
=
"diskModel"
;
String
diskCap
=
"diskCap"
;
String
diskFree
=
"diskFree"
;
try
{
// 上报PC实时信息
...
...
@@ -101,14 +103,30 @@ public class ApqInfoApplication {
.
put
(
isNeedCollection
(
isNoneEven
,
memoryAvailable
,
mapParams
),
memoryAvailable
,
DataSizeUtil
.
format
(
OshiUtil
.
getMemory
().
getAvailable
()))
.
put
(
isNeedCollection
(
isNoneEven
,
diskModel
,
mapParams
),
diskModel
,
Arrays
.
stream
(
OshiUtil
.
getHardware
().
getDiskStores
())
.
map
(
HWDiskStore:
:
getModel
)
.
map
(
model
->
StrUtil
.
removeSuffix
(
model
,
" (标准磁盘驱动器)"
))
.
collect
(
Collectors
.
joining
(
", "
)))
.
map
(
store
->
Arrays
.
stream
(
store
.
getPartitions
())
.
map
(
HWPartition:
:
getMountPoint
)
.
filter
(
StrUtil:
:
isNotBlank
)
.
map
(
s
->
"\""
+
StrUtil
.
removeSuffix
(
s
,
":\\"
)
+
"盘\":\""
+
StrUtil
.
removeSuffix
(
store
.
getModel
(),
" (标准磁盘驱动器)"
)
+
"\""
)
.
collect
(
Collectors
.
joining
(
","
)))
.
collect
(
Collectors
.
joining
(
","
,
"{"
,
"}"
)))
.
put
(
isNeedCollection
(
isNoneEven
,
diskCap
,
mapParams
),
diskCap
,
DataSizeUtil
.
format
(
Arrays
.
stream
(
OshiUtil
.
getHardware
().
getDiskStores
())
.
map
(
HWDiskStore:
:
getSize
)
.
mapToLong
(
Long:
:
longValue
)
.
sum
()))
Arrays
.
stream
(
OshiUtil
.
getHardware
().
getDiskStores
())
.
map
(
store
->
Arrays
.
stream
(
store
.
getPartitions
())
.
map
(
HWPartition:
:
getMountPoint
)
.
filter
(
StrUtil:
:
isNotBlank
)
.
map
(
s
->
"\""
+
StrUtil
.
removeSuffix
(
s
,
":\\"
)
+
"盘\":\""
+
StrUtil
.
removeSuffix
(
store
.
getModel
(),
" (标准磁盘驱动器)"
)
+
"\""
)
.
collect
(
Collectors
.
joining
(
","
)))
.
collect
(
Collectors
.
joining
(
","
,
"{"
,
"}"
)))
.
put
(
isNeedCollection
(
isNoneEven
,
diskFree
,
mapParams
),
diskFree
,
Arrays
.
stream
(
OshiUtil
.
getHardware
().
getDiskStores
())
.
map
(
HWDiskStore:
:
getPartitions
)
.
flatMap
(
Arrays:
:
stream
)
.
filter
(
partition
->
StrUtil
.
isNotBlank
(
partition
.
getMountPoint
()))
.
map
(
partition
->
"\""
+
StrUtil
.
removeSuffix
(
partition
.
getMountPoint
(),
":\\"
)
+
"盘\":\""
+
new
DecimalFormat
(
"#.00"
).
format
(
100
d
*
new
File
(
partition
.
getMountPoint
()).
getFreeSpace
()
/
partition
.
getSize
())
+
"%\""
)
.
collect
(
Collectors
.
joining
(
","
,
"{"
,
"}"
)))
.
build
();
log
.
info
(
"采集数据,上报属性: mapData:{}"
,
data
);
Map
mapR
=
restTemplate
.
postForObject
(
"http://localhost:8765/uplink/oc-client"
,
data
,
Map
.
class
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论