Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
cd2becb3
S
Serving
项目概览
PaddlePaddle
/
Serving
大约 1 年 前同步成功
通知
186
Star
833
Fork
253
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
105
列表
看板
标记
里程碑
合并请求
10
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Serving
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
105
Issue
105
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
cd2becb3
编写于
3月 31, 2020
作者:
B
barrierye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add afsMonitor
上级
d806b60a
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
69 addition
and
5 deletion
+69
-5
python/paddle_serving_server/monitor.py
python/paddle_serving_server/monitor.py
+69
-5
未找到文件。
python/paddle_serving_server/monitor.py
浏览文件 @
cd2becb3
...
...
@@ -22,6 +22,7 @@ import time
import
argparse
import
commands
import
datetime
import
shutil
class
Monitor
(
object
):
...
...
@@ -137,17 +138,57 @@ class Monitor(object):
raise
Exception
(
'update local donefile failed.'
)
class
AFSMonitor
(
Monitor
):
''' AFS Monitor(by hadoop-client). '''
def
__init__
(
self
,
hadoop_bin_path
,
hadoop_host
=
None
,
hadoop_ugi
=
None
,
interval
=
10
):
super
(
AFSMonitor
,
self
).
__init__
(
interval
)
self
.
_hadoop_bin
=
hadoop_bin_path
self
.
_hadoop_host
=
hadoop_host
self
.
_hadoop_ugi
=
hadoop_ugi
self
.
_cmd_prefix
=
'{} fs '
.
format
(
self
.
_hadoop_bin
)
if
not
self
.
_hadoop_host
and
not
self
.
_hadoop_ugi
:
self
.
_cmd_prefix
+=
'-D fs.default.name={} -D hadoop.job.ugi={} '
.
format
(
self
.
_hadoop_host
,
self
.
_hadoop_ugi
)
def
_exist_remote_file
(
self
,
path
,
filename
,
local_tmp_path
):
remote_filepath
=
os
.
path
.
join
(
path
,
filename
)
cmd
=
'{} -ls {}'
.
format
(
self
.
_cmd_prefix
,
remote_filepath
)
[
status
,
output
]
=
commands
.
getstatusoutput
(
cmd
)
if
status
==
0
:
[
_
,
_
,
_
,
_
,
_
,
mdate
,
mtime
,
_
]
=
output
.
split
(
'
\n
'
)[
-
1
]
timestr
=
mdate
+
mtime
return
[
True
,
timestr
]
else
:
return
[
False
,
None
]
def
_pull_remote_dir
(
self
,
remote_path
,
dirname
,
local_tmp_path
):
# remove old file before pull remote dir
local_dirpath
=
os
.
path
.
join
(
local_tmp_path
,
dirname
)
if
os
.
path
.
exists
(
local_dirpath
):
shutil
.
rmtree
(
local_dirpath
)
remote_dirpath
=
os
.
path
.
join
(
remote_path
,
dirname
)
cmd
=
'{} -get {} {}'
.
format
(
self
.
_cmd_prefix
,
remote_dirpath
,
local_dirpath
)
if
os
.
system
(
cmd
)
!=
0
:
raise
Exception
(
'pull remote dir failed.'
)
class
HDFSMonitor
(
Monitor
):
''' HDFS Monitor. '''
def
__init__
(
self
,
bin_path
,
interval
=
10
):
super
(
HDFSMonitor
,
self
).
__init__
(
interval
)
self
.
_hdfs_bin_path
=
bin_path
self
.
_prefix_cmd
=
'{} dfs '
.
format
(
self
.
_hdfs_bin_path
)
def
_exist_remote_file
(
self
,
path
,
filename
,
local_tmp_path
):
remote_filepath
=
os
.
path
.
join
(
path
,
filename
)
cmd
=
'{} dfs -stat "%Y" {}'
.
format
(
self
.
_hdfs_bin_path
,
remote_filepath
)
cmd
=
'{} -stat "%Y" {}'
.
format
(
self
.
_prefix_cmd
,
remote_filepath
)
[
status
,
timestamp
]
=
commands
.
getstatusoutput
(
cmd
)
if
status
==
0
:
return
[
True
,
timestamp
]
...
...
@@ -156,7 +197,7 @@ class HDFSMonitor(Monitor):
def
_pull_remote_dir
(
self
,
remote_path
,
dirname
,
local_tmp_path
):
remote_dirpath
=
os
.
path
.
join
(
remote_path
,
dirname
)
cmd
=
'{}
dfs -get -f {} {}'
.
format
(
self
.
_hdfs_bin_path
,
remote_dirpath
,
cmd
=
'{}
-get -f {} {}'
.
format
(
self
.
_prefix_cmd
,
remote_dirpath
,
local_tmp_path
)
if
os
.
system
(
cmd
)
!=
0
:
raise
Exception
(
'pull remote dir failed.'
)
...
...
@@ -280,20 +321,37 @@ def parse_args():
help
=
"Local tmp path"
)
parser
.
add_argument
(
"--interval"
,
type
=
int
,
default
=
10
,
help
=
"Time interval"
)
# general monitor
parser
.
add_argument
(
"--general_host"
,
type
=
str
,
help
=
"Host of general remote server"
)
# hdfs monitor
parser
.
add_argument
(
"--hdfs_bin"
,
type
=
str
,
help
=
"Hdfs binary file path"
)
# ftp monitor
parser
.
add_argument
(
"--ftp_host"
,
type
=
str
,
help
=
"Host of ftp"
)
parser
.
add_argument
(
"--ftp_port"
,
type
=
int
,
help
=
"Port of ftp"
)
parser
.
add_argument
(
"--ftp_username"
,
type
=
str
,
default
=
''
,
help
=
"Username of ftp"
)
parser
.
add_argument
(
"--ftp_password"
,
type
=
str
,
default
=
''
,
help
=
"Password of ftp"
)
# afs monitor
parser
.
add_argument
(
"--hadoop_bin_path"
,
type
=
str
,
help
=
"Hadoop_bin_path for afs"
)
parser
.
add_argument
(
"--hadoop_host"
,
type
=
str
,
default
=
None
,
help
=
"Hadoop_host for afs"
)
parser
.
add_argument
(
"--hadoop_ugi"
,
type
=
str
,
default
=
None
,
help
=
"Hadoop_ugi for afs"
)
return
parser
.
parse_args
()
def
get_monitor
(
mtype
):
''' get monitor. '''
""" generator monitor instance.
Args:
mtype: type of monitor
Returns:
monitor instance.
"""
if
mtype
==
'ftp'
:
return
FTPMonitor
(
args
.
ftp_host
,
...
...
@@ -305,6 +363,12 @@ def get_monitor(mtype):
return
HDFSMonitor
(
args
.
hdfs_bin
,
interval
=
args
.
interval
)
elif
mtype
==
'general'
:
return
GeneralMonitor
(
args
.
general_host
,
interval
=
args
.
interval
)
elif
mtype
==
'afs'
:
return
AFSMonitor
(
args
.
hadoop_bin_path
,
args
.
hadoop_host
,
args
.
hadoop_ugi
,
interval
=
args
.
interval
)
else
:
raise
Exception
(
'unsupport type.'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录