Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ops
/
monitor-service
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
simba
9 years ago
Commit
f605078b5983d233d985087739ccd54b1f99adbb
1 parent
a56967b1
update
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
29 deletions
monitor-service-influxdb/src/main/java/com/monitor/influxdb/mapper/impl/ZkMapper.java
monitor-service-middleware/pom.xml
monitor-service-middleware/src/main/java/com/monitor/middleware/zookeeper/service/iml/ZkMonitorServiceImpl.java
monitor-service-middleware/src/main/java/com/monitor/middleware/zookeeper/task/ZookeeperMonitorTask.java
monitor-service-web/src/main/resources/META-INF/spring/spring-web-context.xml
monitor-service-influxdb/src/main/java/com/monitor/influxdb/mapper/impl/ZkMapper.java
View file @
f605078
package
com
.
monitor
.
influxdb
.
mapper
.
impl
;
import
com.monitor.common.contants.InfluxDBContants
;
import
com.monitor.influxdb.InfluxDBModel
;
import
com.monitor.influxdb.InfluxDBQuery
;
import
com.monitor.influxdb.InluxDBSingle
;
import
com.monitor.influxdb.mapper.IZkMapper
;
import
com.monitor.influxdb.model.ZkInfo
;
import
com.monitor.model.domain.PageBean
;
import
org.apache.commons.lang.StringUtils
;
import
org.influxdb.dto.Point
;
import
org.influxdb.dto.QueryResult
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
...
...
@@ -30,7 +33,6 @@ public class ZkMapper extends InfluxDBQuery implements IZkMapper {
public
void
insert
(
ZkInfo
zkInfo
)
{
Point
point
=
Point
.
measurement
(
InfluxDBContants
.
ZOOKEEPER_ALARM
)
.
addField
(
"id"
,
zkInfo
.
getId
())
.
addField
(
"hostIp"
,
zkInfo
.
getHostIp
())
.
addField
(
"isLive"
,
zkInfo
.
getIsLive
())
.
time
(
System
.
currentTimeMillis
()
*
1000000
+
random
.
nextInt
(
999999
),
TimeUnit
.
NANOSECONDS
)
...
...
@@ -42,12 +44,64 @@ public class ZkMapper extends InfluxDBQuery implements IZkMapper {
@Override
public
int
selectCountByCodition
(
PageBean
page
)
{
String
command
=
"SELECT COUNT(id) FROM "
+
InfluxDBContants
.
ZOOKEEPER_ALARM
;
StringBuffer
command
=
new
StringBuffer
();
command
.
append
(
"SELECT COUNT(hostIp) FROM "
+
InfluxDBContants
.
ZOOKEEPER_ALARM
)
;
String
hostIp
=(
String
)
page
.
getParams
().
get
(
"hostIP"
);
int
flag
=
0
;
if
(
StringUtils
.
isNotBlank
(
hostIp
)){
flag
=
1
;
command
.
append
(
"where hostIp='"
+
hostIp
+
"'"
);
}
String
time
=(
String
)
page
.
getParams
().
get
(
"time"
);
if
(
StringUtils
.
isNotBlank
(
hostIp
)){
if
(
flag
==
1
){
command
.
append
(
" and time>'"
+
time
+
"'"
);
}
else
{
command
.
append
(
" where time>'"
+
time
+
"'"
);
}
}
String
isLive
=(
String
)
page
.
getParams
().
get
(
"isLive"
);
if
(
StringUtils
.
isNotBlank
(
hostIp
)){
if
(
flag
==
1
){
command
.
append
(
" and time="
+
isLive
);
}
else
{
command
.
append
(
"where and time="
+
isLive
);
}
}
InfluxDBModel
influxDBModel
=
inluxDBSingle
.
getInfluxDBByName
(
InfluxDBContants
.
ALARM
);
QueryResult
result
=
query
(
influxDBModel
.
getName
(),
command
.
toString
(),
InfluxDBContants
.
MIDDLEWARE_ALARM
);
return
1
;
}
@Override
public
List
<
ZkInfo
>
selectZkInfosByCodition
(
PageBean
page
)
{
return
null
;
StringBuffer
command
=
new
StringBuffer
();
command
.
append
(
"SELECT hostIp,isLive,time FROM "
+
InfluxDBContants
.
ZOOKEEPER_ALARM
)
.
append
(
" where 1=1"
)
;
String
hostIp
=(
String
)
page
.
getParams
().
get
(
"hostIP"
);
int
flag
=
0
;
if
(
StringUtils
.
isNotBlank
(
hostIp
)){
flag
=
1
;
command
.
append
(
"where hostIp='"
+
hostIp
+
"'"
);
}
String
time
=(
String
)
page
.
getParams
().
get
(
"time"
);
if
(
StringUtils
.
isNotBlank
(
hostIp
)){
if
(
flag
==
1
){
command
.
append
(
" and time>'"
+
time
+
"'"
);
}
else
{
command
.
append
(
" where time>'"
+
time
+
"'"
);
}
}
String
isLive
=(
String
)
page
.
getParams
().
get
(
"isLive"
);
if
(
StringUtils
.
isNotBlank
(
hostIp
)){
if
(
flag
==
1
){
command
.
append
(
" and time="
+
isLive
);
}
else
{
command
.
append
(
"where and time="
+
isLive
);
}
}
command
.
append
(
"' ORDER BY time DESC LIMIT "
+
page
.
getPageSize
()
+
" OFFSET "
+
page
.
getStartIndex
());
InfluxDBModel
influxDBModel
=
inluxDBSingle
.
getInfluxDBByName
(
InfluxDBContants
.
ALARM
);
QueryResult
result
=
query
(
influxDBModel
.
getName
(),
command
.
toString
(),
InfluxDBContants
.
MIDDLEWARE_ALARM
);
return
null
;
}
}
...
...
monitor-service-middleware/pom.xml
View file @
f605078
...
...
@@ -38,17 +38,13 @@
<dependency>
<groupId>
org.apache.zookeeper
</groupId>
<artifactId>
zookeeper
</artifactId>
<exclusions>
<exclusion>
<artifactId>
log4j
</artifactId>
<groupId>
log4j
</groupId>
</exclusion>
<exclusion>
<artifactId>
slf4j-log4j12
</artifactId>
<groupId>
org.slf4j
</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
org.apache.curator
</groupId>
<artifactId>
curator-recipes
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
...
...
monitor-service-middleware/src/main/java/com/monitor/middleware/zookeeper/service/iml/ZkMonitorServiceImpl.java
View file @
f605078
...
...
@@ -3,7 +3,10 @@ package com.monitor.middleware.zookeeper.service.iml;
import
com.monitor.influxdb.mapper.IZkMapper
;
import
com.monitor.influxdb.model.ZkInfo
;
import
com.monitor.middleware.zookeeper.service.IZkMonitorService
;
import
org.apache.zookeeper.ZooKeeper
;
import
org.apache.curator.RetryPolicy
;
import
org.apache.curator.framework.CuratorFramework
;
import
org.apache.curator.framework.CuratorFrameworkFactory
;
import
org.apache.curator.retry.RetryOneTime
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -42,12 +45,7 @@ public class ZkMonitorServiceImpl implements IZkMonitorService {
List
<
ZkInfo
>
zkList
=
new
ArrayList
<
ZkInfo
>();
ZkInfo
zk
=
null
;
for
(
String
ip:
ipList
){
int
result
=
1
;
try
{
result
=
checkConnection
(
ip
);
}
catch
(
Exception
e
)
{
result
=
0
;
}
int
result
=
checkConnection1
(
ip
);
zookeeperMapper
.
insert
(
new
ZkInfo
(
ip
,
result
));
}
...
...
@@ -55,12 +53,19 @@ public class ZkMonitorServiceImpl implements IZkMonitorService {
}
private
int
checkConnection
(
String
ip
)
throws
Exception
{
ZooKeeper
zk
=
new
ZooKeeper
(
"192.168.102.205:2181"
,
2000
,
null
);
// 获取某路径下所有节点
List
<
String
>
children
=
zk
.
getChildren
(
"/"
,
false
);
// log.info("checkConnection is param { },size is { }",ip,null==children?0:children.size());
return
1
;
private
int
checkConnection1
(
String
ip
){
try
{
RetryPolicy
retryPolicy
=
new
RetryOneTime
(
1000
);
CuratorFramework
client
=
CuratorFrameworkFactory
.
newClient
(
ip
+
":2181"
,
retryPolicy
);
client
.
start
();
List
<
String
>
children
=
client
.
getChildren
().
forPath
(
"/"
);
}
catch
(
Exception
e
)
{
return
0
;
}
return
1
;
}
}
...
...
monitor-service-middleware/src/main/java/com/monitor/middleware/zookeeper/task/ZookeeperMonitorTask.java
View file @
f605078
...
...
@@ -4,7 +4,6 @@ import com.monitor.middleware.zookeeper.service.IZkMonitorService;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
/**
...
...
@@ -18,7 +17,7 @@ public class ZookeeperMonitorTask {
@Autowired
IZkMonitorService
zkMonitorService
;
@Scheduled
(
fixedRate
=
20000
)
//
@Scheduled(fixedRate=20000)
public
void
zookeeperMonitor
()
{
zkMonitorService
.
zookeeperMonitor
();
}
...
...
monitor-service-web/src/main/resources/META-INF/spring/spring-web-context.xml
View file @
f605078
...
...
@@ -16,7 +16,7 @@
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd"
>
<context:property-placeholder
location=
"classpath:/
produc
t/*.properties"
/>
<context:property-placeholder
location=
"classpath:/
tes
t/*.properties"
/>
<context:component-scan
base-package=
"com.monitor"
/>
<!-- 打开aop 注解 -->
<aop:aspectj-autoproxy
proxy-target-class=
"true"
/>
...
...
Please
register
or
login
to post a comment