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
qinchao
7 years ago
Commit
43d3f25d31084e4bc7e6fc4d0b61c5a28e61512b
1 parent
29ef34aa
修改
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
50 deletions
monitor-service-other/src/main/java/com/monitor/other/mysqlMonitor/ctrl/MysqlMonitorCtrl.java
monitor-service-other/src/main/java/com/monitor/other/mysqlMonitor/service/MysqlMonitorServiceImpl.java
monitor-service-other/src/main/java/com/monitor/other/mysqlMonitor/task/ExeShell.java
monitor-service-switch/src/main/java/com/monitor/switchs/CommodUtil.java
monitor-service-other/src/main/java/com/monitor/other/mysqlMonitor/ctrl/MysqlMonitorCtrl.java
View file @
43d3f25
...
...
@@ -2,12 +2,14 @@ package com.monitor.other.mysqlMonitor.ctrl;
import
com.monitor.cmdb.service.IMObjectInfoService
;
import
com.monitor.model.response.BaseResponse
;
import
com.monitor.other.mysqlMonitor.model.*
;
import
com.monitor.other.mysqlMonitor.model.AntvData
;
import
com.monitor.other.mysqlMonitor.model.AntvEdge
;
import
com.monitor.other.mysqlMonitor.model.MhaCfg
;
import
com.monitor.other.mysqlMonitor.model.MhaServer
;
import
com.monitor.other.mysqlMonitor.service.MysqlMonitorServiceImpl
;
import
com.monitor.other.mysqlMonitor.task.ExeShell
;
import
com.response.MysqlMobjectRep
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -33,20 +35,10 @@ public class MysqlMonitorCtrl {
*/
@RequestMapping
(
value
=
"/test"
)
@ResponseBody
public
String
test
()
{
String
loginAndhostIp
=
"ssh root@192.168.103.67 "
;
String
rootDir
=
"/etc/mha/"
;
public
BaseResponse
test
()
{
//ssh root@192.168.103.67 ls -F /etc/mha/ |grep '/$' 列出目录下的所有文件夹
//ssh root@192.168.103.67 find /etc/mha/app1/ -name app1.cnf 检查是否存在配置文件
//ssh root@192.168.103.67 cat /etc/mha/app1/app1.cnf 读取内容
String
cmd_mhaDirList
=
loginAndhostIp
+
" ls -F "
+
rootDir
+
" |grep '/$' "
;
String
result
=
ExeShell
.
exeCmd
(
cmd_mhaDirList
);
if
(!
ExeShell
.
errorRtn
.
equals
(
result
)){
}
return
result
;
return
mysqlMonitorService
.
test
();
}
/**
...
...
monitor-service-other/src/main/java/com/monitor/other/mysqlMonitor/service/MysqlMonitorServiceImpl.java
View file @
43d3f25
...
...
@@ -3,8 +3,10 @@ package com.monitor.other.mysqlMonitor.service;
import
com.monitor.influxdb.contants.InfluxDBContants
;
import
com.monitor.influxdb.mapper.MetricMapper
;
import
com.monitor.influxdb.mapper.MysqlMonitorMapper
;
import
com.monitor.model.response.BaseResponse
;
import
com.monitor.other.mysqlMonitor.model.MhaCfg
;
import
com.monitor.other.mysqlMonitor.model.MhaServer
;
import
com.monitor.other.mysqlMonitor.task.ExeShell
;
import
com.monitor.other.sqlOperate.constant.SqlQueryConstant
;
import
com.response.MysqlMobjectRep
;
import
org.apache.commons.lang.StringUtils
;
...
...
@@ -32,6 +34,26 @@ public class MysqlMonitorServiceImpl {
private
final
String
param
=
SqlQueryConstant
.
DB_PARAM
+
"&autoReconnect=false&connectTimeout=3000&socketTimeout=6000"
;
//private final String detectSQL="show databases";
public
BaseResponse
test
()
{
String
loginAndhostIp
=
"ssh root@192.168.103.67 "
;
String
rootDir
=
"/etc/mha/"
;
//ssh root@192.168.103.67 ls -F /etc/mha/ |grep '/$' 列出目录下的所有文件夹
//ssh root@192.168.103.67 find /etc/mha/app1/ -name app1.cnf 检查是否存在配置文件
//ssh root@192.168.103.67 cat /etc/mha/app1/app1.cnf 读取内容
String
cmd_mhaDirList
=
loginAndhostIp
+
" ls -F "
+
rootDir
+
" |grep '/$' "
;
BaseResponse
result
=
ExeShell
.
exeCmd
(
cmd_mhaDirList
);
if
(
200
!=
result
.
getCode
()||
StringUtils
.
isBlank
(
result
.
getMessage
())){
return
result
;
}
String
mhaDirs
=
result
.
getMessage
();
log
.
info
(
"MysqlMonitorServiceImpl mha ssh mhaDirList {} "
,
mhaDirs
);
String
[]
mhaDirAry
=
mhaDirs
.
trim
().
split
(
"/ "
);
return
null
;
}
public
List
<
MhaCfg
>
queryMhaList
()
{
List
<
MhaCfg
>
mhaCfgList
=
new
ArrayList
<>();
...
...
monitor-service-other/src/main/java/com/monitor/other/mysqlMonitor/task/ExeShell.java
View file @
43d3f25
package
com
.
monitor
.
other
.
mysqlMonitor
.
task
;
import
com.monitor.cloudtools.util.CommodUtil
;
import
com.monitor.model.response.BaseResponse
;
import
org.apache.commons.exec.CommandLine
;
import
org.apache.commons.exec.DefaultExecutor
;
import
org.apache.commons.exec.PumpStreamHandler
;
import
org.apache.commons.io.FileUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -12,9 +15,10 @@ public class ExeShell {
private
static
Logger
log
=
LoggerFactory
.
getLogger
(
ExeShell
.
class
);
public
static
final
String
errorRtn
=
"failed"
;
public
static
String
exeCmd
(
String
command
)
{
public
static
BaseResponse
exeCmd
(
String
command
)
{
boolean
errorFlag
=
false
;
String
msg
=
""
;
try
{
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
ByteArrayOutputStream
errorStream
=
new
ByteArrayOutputStream
();
...
...
@@ -25,13 +29,25 @@ public class ExeShell {
PumpStreamHandler
streamHandler
=
new
PumpStreamHandler
(
outputStream
,
errorStream
);
exec
.
setStreamHandler
(
streamHandler
);
exec
.
execute
(
commandline
);
String
out
=
outputStream
.
toString
(
"UTF-8"
);
String
out
=
outputStream
.
toString
(
"UTF-8"
);
String
error
=
errorStream
.
toString
(
"UTF-8"
);
return
out
+
error
;
if
(
error
!=
null
&&
error
.
length
()>
0
){
errorFlag
=
true
;
msg
=
error
;
}
else
{
msg
=
out
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
"ExeShell CMD failed {} ,{}"
,
command
,
e
);
return
errorRtn
;
log
.
error
(
"ExeShell exeCmd {} ,{} "
,
command
,
e
);
errorFlag
=
true
;
msg
=
e
.
getMessage
();
}
BaseResponse
response
=
new
BaseResponse
();
response
.
setMessage
(
msg
);
if
(
errorFlag
){
response
.
setCode
(
201
);
}
return
response
;
}
}
}
...
...
monitor-service-switch/src/main/java/com/monitor/switchs/CommodUtil.java
View file @
43d3f25
...
...
@@ -73,7 +73,7 @@ public class CommodUtil {
BufferedReader
input
=
null
;
try
{
String
command
=
BASE_DIR
+
commond
+
" "
+
param
;
logger
.
info
(
"
CommodUtil
- exe 2 parms - command="
+
command
);
logger
.
info
(
" - exe 2 parms - command="
+
command
);
process
=
Runtime
.
getRuntime
().
exec
(
command
);
input
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
()));
String
line
=
""
;
...
...
@@ -134,34 +134,11 @@ public class CommodUtil {
* @return
*/
public
static
List
<
String
>
exe
(
String
commond
)
{
// System.out.println(commond);
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// List<String> list = new ArrayList<>();
//
// if (commond.indexOf("getIPs") != -1){
// list.add("master@172.31.70.197@@master@172.31.70.198@@master@172.31.70.195@@master@172.31.70.196@@master@172.31.70.193@@master@172.31.70.194@@master@172.31.70.192@@master@172.31.70.191@@master@172.31.70.201@@master@172.31.70.202@@master@172.31.70.199@@master@172.31.70.200@@master@172.31.70.208@@master@172.31.70.209@@master@172.31.70.206@@master@172.31.70.207@@master@172.31.70.212");
// //list.add("@@master@172.31.70.197");
// }else if(commond.indexOf("checkstatus") != -1){
// list.add("aws@@master@172.31.70.197@@1@@10:50");
// list.add("aws@@master@172.31.70.198@@0@@10:50");
// list.add("qcloud@@master@10.66.10.1@@1@@10:50");
// list.add("qcloud@@master@10.66.10.2@@0@@10:50");
// list.add("qcloud@@master@10.66.10.3@@2@@10:50");
// } else{
// list.add("aws@@172.31.70.197@@end");
// }
// return list;
Process
process
;
List
<
String
>
list
=
new
ArrayList
<>();
BufferedReader
input
=
null
;
try
{
logger
.
info
(
"
CommodUtil
- exe 1 parms - command="
+
commond
);
logger
.
info
(
" - exe 1 parms - command="
+
commond
);
process
=
Runtime
.
getRuntime
().
exec
(
commond
);
input
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
()));
String
line
;
...
...
@@ -182,13 +159,13 @@ public class CommodUtil {
return
list
;
}
/*
*
/*
* dns切换查看
* @param commond
* @param param
* @return
*/
public
static
String
exeDns
(
String
commond
,
String
param
)
{
/*
public static String exeDns(String commond, String param) {
Process process = null;
StringBuilder sb = new StringBuilder();
BufferedReader input = null;
...
...
@@ -213,5 +190,5 @@ public class CommodUtil {
}
}
return sb.toString();
}
}
*/
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment