Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ioc_sixiang_license
Project
Project
Details
Activity
Releases
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
zengtianlai3
ioc_sixiang_license
Commits
87a136de
Commit
87a136de
authored
Jun 10, 2022
by
zengtianlai3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加告警
parent
9819106c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
23 deletions
+46
-23
OperateSAMStatusResponseEventHandler.java
...g/license/event/OperateSAMStatusResponseEventHandler.java
+16
-0
ForwardConnectionListener.java
...ot/sixiang/license/forward/ForwardConnectionListener.java
+14
-16
OperateConnectionListener.java
...ot/sixiang/license/operate/OperateConnectionListener.java
+16
-7
No files found.
license/src/main/java/iot/sixiang/license/event/OperateSAMStatusResponseEventHandler.java
View file @
87a136de
...
...
@@ -5,6 +5,7 @@ import iot.sixiang.license.device.DeviceProtocol;
import
iot.sixiang.license.model.SamInfo
;
import
iot.sixiang.license.model.SamMonitor
;
import
iot.sixiang.license.operate.OperateManager
;
import
iot.sixiang.license.service.AlarmService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.event.EventListener
;
...
...
@@ -22,6 +23,9 @@ public class OperateSAMStatusResponseEventHandler {
@Autowired
public
OperateManager
operateManager
;
@Autowired
private
AlarmService
alarmService
;
public
OperateSAMStatusResponseEventHandler
()
{
}
...
...
@@ -36,6 +40,12 @@ public class OperateSAMStatusResponseEventHandler {
for
(
SamInfo
samInfo
:
samInfoList
)
{
if
(
samInfo
.
getStatus
()
==
0
||
samInfo
.
getStatus
()
==
1
||
samInfo
.
getStatus
()
==
2
||
samInfo
.
getStatus
()
==
4
)
{
onlineCount
++;
}
else
{
int
index
=
samInfo
.
getIndex
();
int
typeId
=
2
;
String
title
=
"SAM故障"
;
String
content
=
"index为"
+
index
+
"的SAM发生故障"
;
alarmService
.
addAlarm
(
typeId
,
title
,
content
);
}
}
SamMonitor
samMonitor
=
new
SamMonitor
();
...
...
@@ -43,5 +53,11 @@ public class OperateSAMStatusResponseEventHandler {
samMonitor
.
setOnlineCount
(
onlineCount
);
samMonitor
.
setSamCount
(
samCount
);
operateManager
.
putSamMonitorMap
(
serverIp
,
samMonitor
);
if
(
onlineCount
/
samCount
>
0.7
)
{
int
typeId
=
3
;
String
title
=
"SAM不足"
;
String
content
=
"当前在线客户端已超过70%"
;
alarmService
.
addAlarm
(
typeId
,
title
,
content
);
}
}
}
license/src/main/java/iot/sixiang/license/forward/ForwardConnectionListener.java
View file @
87a136de
package
iot
.
sixiang
.
license
.
forward
;
import
io.netty.channel.ChannelFuture
;
import
io.netty.channel.EventLoop
;
import
io.netty.channel.socket.SocketChannel
;
import
iot.sixiang.license.device.DeviceProtocol
;
import
iot.sixiang.license.event.DeviceClientBeForcedOfflineEvent
;
...
...
@@ -9,32 +8,31 @@ import iot.sixiang.license.event.DeviceClientLicenseEvent;
import
iot.sixiang.license.event.EventPublisher
;
import
iot.sixiang.license.event.ForwardClientConnectEvent
;
import
iot.sixiang.license.net.BaseConnectionListener
;
import
iot.sixiang.license.service.AlarmService
;
import
iot.sixiang.license.util.SpringUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.
stereotype.Component
;
import
org.springframework.
beans.factory.annotation.Autowired
;
import
java.
util.concurrent.TimeUnit
;
import
java.
net.InetSocketAddress
;
@Slf4j
public
class
ForwardConnectionListener
extends
BaseConnectionListener
{
@Autowired
private
AlarmService
alarmService
;
@Override
public
void
operationComplete
(
ChannelFuture
channelFuture
)
throws
Exception
{
if
(!
channelFuture
.
isSuccess
())
{
// final EventLoop loop = channelFuture.channel().eventLoop();
// loop.schedule(new Runnable() {
// @Override
// public void run() {
// log.debug("ForwardConnectionListener ...operationComplete");
// log.info("forward client connect fail ..." + appId);
//// ForwardManager forwardManager = SpringUtil.getBean(ForwardManager.class);
//// log.debug("channelActive.forwardManager:" + forwardManager);
//
//// log.warn("The client is not connected and starts to reconnect..." + forwardManager);
//// forwardManager.startTcpClient(appId);
// }
// }, 10L, TimeUnit.SECONDS);
//TODO 中转失败进行告警
InetSocketAddress
socketAddress
=
(
InetSocketAddress
)
channelFuture
.
channel
().
remoteAddress
();
String
remoteIp
=
socketAddress
.
getHostString
();
String
remotePort
=
String
.
valueOf
(
socketAddress
.
getPort
());
int
typeId
=
1
;
String
title
=
"中转失败"
;
String
content
=
"中转到服务器:"
+
remoteIp
+
":"
+
remotePort
+
"失败"
;
alarmService
.
addAlarm
(
typeId
,
title
,
content
);
//TODO forward client连接失败,则强制踢掉设备客户端
DeviceClientBeForcedOfflineEvent
deviceClientBeForcedOfflineEvent
=
new
DeviceClientBeForcedOfflineEvent
();
...
...
license/src/main/java/iot/sixiang/license/operate/OperateConnectionListener.java
View file @
87a136de
...
...
@@ -3,27 +3,36 @@ package iot.sixiang.license.operate;
import
io.netty.channel.ChannelFuture
;
import
io.netty.channel.socket.SocketChannel
;
import
iot.sixiang.license.device.DeviceProtocol
;
import
iot.sixiang.license.event.*
;
import
iot.sixiang.license.event.EventPublisher
;
import
iot.sixiang.license.event.OperateSAMStatusRequestEvent
;
import
iot.sixiang.license.net.BaseConnectionListener
;
import
iot.sixiang.license.service.AlarmService
;
import
iot.sixiang.license.util.SpringUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.net.InetSocketAddress
;
@Slf4j
public
class
OperateConnectionListener
extends
BaseConnectionListener
{
@Autowired
private
AlarmService
alarmService
;
@Override
public
void
operationComplete
(
ChannelFuture
channelFuture
)
throws
Exception
{
if
(!
channelFuture
.
isSuccess
())
{
//TODO 失败进行告警
InetSocketAddress
socketAddress
=
(
InetSocketAddress
)
channelFuture
.
channel
().
remoteAddress
();
String
remoteIp
=
socketAddress
.
getHostString
();
String
remotePort
=
String
.
valueOf
(
socketAddress
.
getPort
());
int
typeId
=
1
;
String
title
=
"连接服器失败"
;
String
content
=
"连接服务器:"
+
remoteIp
+
":"
+
remotePort
+
"失败"
;
alarmService
.
addAlarm
(
typeId
,
title
,
content
);
}
else
{
//TODO 查询SAM状态
OperateSAMStatusRequestEvent
operateSAMStatusQueryEvent
=
new
OperateSAMStatusRequestEvent
();
short
stx
=
21930
;
int
len
=
2
;
byte
cmd
=
0x5f
;
...
...
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