Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
65fdaa1f
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看板
提交
65fdaa1f
编写于
3月 30, 2020
作者:
B
barrierye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add hdfs-monitor
上级
889ac104
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
115 addition
and
62 deletion
+115
-62
python/paddle_serving_server/monitor.py
python/paddle_serving_server/monitor.py
+115
-62
未找到文件。
python/paddle_serving_server/monitor.py
浏览文件 @
65fdaa1f
...
@@ -20,6 +20,8 @@ Usage:
...
@@ -20,6 +20,8 @@ Usage:
import
os
import
os
import
time
import
time
import
argparse
import
argparse
import
commands
import
datetime
class
Monitor
(
object
):
class
Monitor
(
object
):
...
@@ -36,7 +38,7 @@ class Monitor(object):
...
@@ -36,7 +38,7 @@ class Monitor(object):
self
.
_local_donefile_name
=
None
self
.
_local_donefile_name
=
None
self
.
_interval
=
interval
self
.
_interval
=
interval
self
.
_remote_donefile_timestamp
=
None
self
.
_remote_donefile_timestamp
=
None
self
.
_local_tmp_
dir
=
None
self
.
_local_tmp_
path
=
None
def
set_remote_path
(
self
,
remote_path
):
def
set_remote_path
(
self
,
remote_path
):
self
.
_remote_path
=
remote_path
self
.
_remote_path
=
remote_path
...
@@ -56,8 +58,8 @@ class Monitor(object):
...
@@ -56,8 +58,8 @@ class Monitor(object):
def
set_local_donefile_name
(
self
,
donefile_name
):
def
set_local_donefile_name
(
self
,
donefile_name
):
self
.
_local_donefile_name
=
donefile_name
self
.
_local_donefile_name
=
donefile_name
def
set_local_tmp_
dir
(
self
,
tmp_dir
):
def
set_local_tmp_
path
(
self
,
tmp_path
):
self
.
_local_tmp_
dir
=
tmp_dir
self
.
_local_tmp_
path
=
tmp_path
def
_check_params
(
self
):
def
_check_params
(
self
):
if
self
.
_remote_path
is
None
:
if
self
.
_remote_path
is
None
:
...
@@ -72,50 +74,107 @@ class Monitor(object):
...
@@ -72,50 +74,107 @@ class Monitor(object):
raise
Exception
(
'local_path not set.'
)
raise
Exception
(
'local_path not set.'
)
if
self
.
_local_donefile_name
is
None
:
if
self
.
_local_donefile_name
is
None
:
raise
Exception
(
'local_donefile_name not set.'
)
raise
Exception
(
'local_donefile_name not set.'
)
if
self
.
_local_tmp_
dir
is
None
:
if
self
.
_local_tmp_
path
is
None
:
raise
Exception
(
'local_tmp_
dir
not set.'
)
raise
Exception
(
'local_tmp_
path
not set.'
)
def
run
(
self
):
def
run
(
self
):
'''
'''
Monitor the remote model by polling and update the local model.
Monitor the remote model by polling and update the local model.
'''
'''
self
.
_check_params
()
self
.
_check_params
()
if
not
os
.
path
.
exists
(
self
.
_local_tmp_
dir
):
if
not
os
.
path
.
exists
(
self
.
_local_tmp_
path
):
os
.
makedirs
(
self
.
_local_tmp_
dir
)
os
.
makedirs
(
self
.
_local_tmp_
path
)
while
True
:
while
True
:
[
flag
,
timestamp
]
=
self
.
_exist_remote_donefile
()
[
flag
,
timestamp
]
=
self
.
_exist_remote_file
(
self
.
_remote_path
,
self
.
_remote_donefile_name
)
if
flag
:
if
flag
:
if
self
.
_remote_donefile_timestamp
is
None
or
\
if
self
.
_remote_donefile_timestamp
is
None
or
\
timestamp
!=
self
.
_remote_donefile_timestamp
:
timestamp
!=
self
.
_remote_donefile_timestamp
:
self
.
_remote_donefile_timestamp
=
timestamp
self
.
_remote_donefile_timestamp
=
timestamp
self
.
_pull_remote_model
()
self
.
_pull_remote_dir
(
self
.
_remote_path
,
print
(
'[INFO] pull remote model'
)
self
.
_remote_model_name
,
self
.
_update_local_model
()
self
.
_local_tmp_path
)
print
(
'[INFO] update model'
)
print
(
'{} [INFO] pull remote model'
.
format
(
self
.
_update_local_donefile
()
datetime
.
datetime
.
now
().
strftime
(
'%Y-%m-%d %H:%M:%S'
)))
print
(
'[INFO] update local donefile'
)
self
.
_update_local_model
(
self
.
_local_tmp_path
,
self
.
_remote_model_name
,
self
.
_local_path
,
self
.
_local_model_name
)
print
(
'{} [INFO] update model'
.
format
(
datetime
.
datetime
.
now
(
).
strftime
(
'%Y-%m-%d %H:%M:%S'
)))
self
.
_update_local_donefile
(
self
.
_local_path
,
self
.
_local_model_name
,
self
.
_local_donefile_name
)
print
(
'{} [INFO] update local donefile'
.
format
(
datetime
.
datetime
.
now
().
strftime
(
'%Y-%m-%d %H:%M:%S'
)))
else
:
else
:
print
(
'[INFO] no donefile.'
)
print
(
'{} [INFO] no donefile.'
.
format
(
datetime
.
datetime
.
now
(
print
(
'[INFO] sleep {}s'
.
format
(
self
.
_interval
))
).
strftime
(
'%Y-%m-%d %H:%M:%S'
)))
print
(
'{} [INFO] sleep {}s'
.
format
(
datetime
.
datetime
.
now
().
strftime
(
'%Y-%m-%d %H:%M:%S'
),
self
.
_interval
))
time
.
sleep
(
self
.
_interval
)
time
.
sleep
(
self
.
_interval
)
def
_exist_remote_
donefile
(
self
):
def
_exist_remote_
file
(
self
,
path
,
filename
):
raise
Exception
(
'This function must be inherited.'
)
raise
Exception
(
'This function must be inherited.'
)
def
_pull_remote_
model
(
self
):
def
_pull_remote_
dir
(
self
,
remote_path
,
dirname
,
local_tmp_path
):
raise
Exception
(
'This function must be inherited.'
)
raise
Exception
(
'This function must be inherited.'
)
def
_update_local_model
(
self
):
def
_update_local_model
(
self
,
local_tmp_path
,
remote_model_name
,
local_path
,
raise
Exception
(
'This function must be inherited.'
)
local_model_name
):
tmp_model_path
=
os
.
path
.
join
(
local_tmp_path
,
remote_model_name
)
local_model_path
=
os
.
path
.
join
(
local_path
,
local_model_name
)
cmd
=
'cp -r {}/* {}'
.
format
(
tmp_model_path
,
local_model_path
)
if
os
.
system
(
cmd
)
!=
0
:
raise
Exception
(
'update local model failed.'
)
def
_update_local_donefile
(
self
,
local_path
,
local_model_name
,
local_donefile_name
):
donefile_path
=
os
.
path
.
join
(
local_path
,
local_model_name
,
local_donefile_name
)
cmd
=
'touch {}'
.
format
(
donefile_path
)
if
os
.
system
(
cmd
)
!=
0
:
raise
Exception
(
'update local donefile failed.'
)
def
_update_local_donefile
(
self
):
raise
Exception
(
'This function must be inherited.'
)
class
HDFSMonitor
(
Monitor
):
''' HDFS Monitor. '''
def
__init__
(
self
,
bin_path
,
interval
=
10
):
super
(
HDFSMonitor
,
self
).
__init__
(
interval
)
self
.
_hdfs_bin_path
=
bin_path
def
_exist_remote_file
(
self
,
path
,
filename
):
remote_filepath
=
os
.
path
.
join
(
path
,
filename
)
cmd
=
'{} dfs -stat "%Y" {}'
.
format
(
self
.
_hdfs_bin_path
,
remote_filepath
)
[
status
,
timestamp
]
=
commands
.
getstatusoutput
(
cmd
)
if
status
==
0
:
return
[
True
,
timestamp
]
else
:
return
[
False
,
None
]
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
,
local_tmp_path
)
if
os
.
system
(
cmd
)
!=
0
:
raise
Exception
(
'pull remote dir failed.'
)
def
_update_local_model
(
self
,
local_tmp_path
,
remote_model_name
,
local_path
,
local_model_name
):
tmp_model_path
=
os
.
path
.
join
(
local_tmp_path
,
remote_model_name
)
local_model_path
=
os
.
path
.
join
(
local_path
,
local_model_name
)
cmd
=
'cp -r {}/* {}'
.
format
(
tmp_model_path
,
local_model_path
)
if
os
.
system
(
cmd
)
!=
0
:
raise
Exception
(
'pull remote dir failed.'
)
class
FTPMonitor
(
Monitor
):
class
FTPMonitor
(
Monitor
):
''' FTP Monitor. '''
def
__init__
(
self
,
ftp_ip
,
ftp_port
,
username
=
""
,
password
=
""
,
interval
=
10
):
def
__init__
(
self
,
ftp_ip
,
ftp_port
,
username
=
""
,
password
=
""
,
interval
=
10
):
import
ftplib
super
(
FTPMonitor
,
self
).
__init__
(
interval
)
super
(
FTPMonitor
,
self
).
__init__
(
interval
)
import
ftplib
self
.
_ftp_ip
=
ftp_ip
self
.
_ftp_ip
=
ftp_ip
self
.
_ftp_port
=
ftp_port
self
.
_ftp_port
=
ftp_port
self
.
_ftp
=
ftplib
.
FTP
()
self
.
_ftp
=
ftplib
.
FTP
()
...
@@ -125,39 +184,26 @@ class FTPMonitor(Monitor):
...
@@ -125,39 +184,26 @@ class FTPMonitor(Monitor):
self
.
_ftp
.
connect
(
ftp_ip
,
ftp_port
)
self
.
_ftp
.
connect
(
ftp_ip
,
ftp_port
)
self
.
_ftp
.
login
(
username
,
password
)
self
.
_ftp
.
login
(
username
,
password
)
def
_exist_remote_
donefile
(
self
):
def
_exist_remote_
file
(
self
,
path
,
filename
):
import
ftplib
import
ftplib
try
:
try
:
donefile_path
=
'{}/{}'
.
format
(
self
.
_remote_path
,
filepath
=
os
.
path
.
join
(
path
,
filename
)
self
.
_remote_donefile_name
)
timestamp
=
self
.
_ftp
.
voidcmd
(
'MDTM {}'
.
format
(
filepath
))[
4
:].
strip
(
timestamp
=
self
.
_ftp
.
voidcmd
(
'MDTM {}'
.
format
(
donefile_path
))[
)
4
:].
strip
()
return
[
True
,
timestamp
]
return
[
True
,
timestamp
]
except
ftplib
.
error_perm
:
except
ftplib
.
error_perm
:
return
[
False
,
None
]
return
[
False
,
None
]
def
_pull_remote_model
(
self
):
def
_pull_remote_dir
(
self
,
remote_path
,
dirname
,
local_tmp_path
):
cmd
=
'wget -nH -r -P {} ftp://{}:{}/{}/{} &> /dev/null'
.
format
(
filepath
=
os
.
path
.
join
(
remote_path
,
dirname
)
self
.
_local_tmp_dir
,
self
.
_ftp_ip
,
self
.
_ftp_port
,
cmd
=
'wget -nH -r -P {} ftp://{}:{}/{} &> /dev/null'
.
format
(
self
.
_remote_path
,
self
.
_remote_model_name
)
local_tmp_path
,
self
.
_ftp_ip
,
self
.
_ftp_port
,
filepath
)
if
os
.
system
(
cmd
)
!=
0
:
raise
Exception
(
'pull remote model failed.'
)
def
_update_local_model
(
self
):
cmd
=
'cp -r {}/{}/* {}/{}'
.
format
(
self
.
_local_tmp_dir
,
self
.
_remote_model_name
,
self
.
_local_path
,
self
.
_local_model_name
)
if
os
.
system
(
cmd
)
!=
0
:
if
os
.
system
(
cmd
)
!=
0
:
raise
Exception
(
'update local model failed.'
)
raise
Exception
(
'pull remote dir failed.'
)
def
_update_local_donefile
(
self
):
cmd
=
'touch {}/{}/{}'
.
format
(
self
.
_local_path
,
self
.
_local_model_name
,
self
.
_local_donefile_name
)
if
os
.
system
(
cmd
)
!=
0
:
raise
Exception
(
'update local donefile failed.'
)
def
parse_args
():
def
parse_args
():
''' parse args. '''
parser
=
argparse
.
ArgumentParser
(
description
=
"Monitor"
)
parser
=
argparse
.
ArgumentParser
(
description
=
"Monitor"
)
parser
.
add_argument
(
parser
.
add_argument
(
"--type"
,
type
=
str
,
required
=
True
,
help
=
"Type of remote server"
)
"--type"
,
type
=
str
,
required
=
True
,
help
=
"Type of remote server"
)
...
@@ -183,30 +229,37 @@ def parse_args():
...
@@ -183,30 +229,37 @@ def parse_args():
required
=
True
,
required
=
True
,
help
=
"Local donfile name(fluid_time_file in model file)"
)
help
=
"Local donfile name(fluid_time_file in model file)"
)
parser
.
add_argument
(
parser
.
add_argument
(
"--local_tmp_
dir"
,
type
=
str
,
default
=
'tmp'
,
help
=
"Local tmp dir
"
)
"--local_tmp_
path"
,
type
=
str
,
default
=
'tmp'
,
help
=
"Local tmp path
"
)
parser
.
add_argument
(
parser
.
add_argument
(
"--interval"
,
type
=
int
,
default
=
10
,
help
=
"Time interval"
)
"--interval"
,
type
=
int
,
default
=
10
,
help
=
"Time interval"
)
parser
.
add_argument
(
"--ftp_ip"
,
type
=
str
,
help
=
"Ip the ftp"
)
parser
.
add_argument
(
"--ftp_ip"
,
type
=
str
,
help
=
"Ip the ftp"
)
parser
.
add_argument
(
"--ftp_port"
,
type
=
int
,
help
=
"Port the ftp"
)
parser
.
add_argument
(
"--ftp_port"
,
type
=
int
,
help
=
"Port the ftp"
)
parser
.
add_argument
(
"--hdfs_bin"
,
type
=
str
,
default
=
'hdfs'
,
help
=
"Hdfs binary file"
)
return
parser
.
parse_args
()
return
parser
.
parse_args
()
def
start_ftp_monitor
():
def
get_monitor
(
mtype
):
args
=
parse_args
()
if
mtype
==
'ftp'
:
obj
=
FTPMonitor
(
args
.
ftp_ip
,
args
.
ftp_port
,
interval
=
args
.
interval
)
return
FTPMonitor
(
args
.
ftp_ip
,
args
.
ftp_port
,
interval
=
args
.
interval
)
obj
.
set_remote_path
(
args
.
remote_path
)
elif
mtype
==
'hdfs'
:
obj
.
set_remote_model_name
(
args
.
remote_model_name
)
return
HDFSMonitor
(
args
.
hdfs_bin
,
interval
=
args
.
interval
)
obj
.
set_remote_donefile_name
(
args
.
remote_donefile_name
)
else
:
obj
.
set_local_path
(
args
.
local_path
)
raise
Exception
(
'unsupport type.'
)
obj
.
set_local_model_name
(
args
.
local_model_name
)
obj
.
set_local_donefile_name
(
args
.
local_donefile_name
)
obj
.
set_local_tmp_dir
(
args
.
local_tmp_dir
)
def
start_monitor
(
monitor
,
args
):
obj
.
run
()
monitor
.
set_remote_path
(
args
.
remote_path
)
monitor
.
set_remote_model_name
(
args
.
remote_model_name
)
monitor
.
set_remote_donefile_name
(
args
.
remote_donefile_name
)
monitor
.
set_local_path
(
args
.
local_path
)
monitor
.
set_local_model_name
(
args
.
local_model_name
)
monitor
.
set_local_donefile_name
(
args
.
local_donefile_name
)
monitor
.
set_local_tmp_path
(
args
.
local_tmp_path
)
monitor
.
run
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
args
=
parse_args
()
args
=
parse_args
()
if
args
.
type
==
'ftp'
:
monitor
=
get_monitor
(
args
.
type
)
start_ftp_monitor
()
start_monitor
(
monitor
,
args
)
else
:
raise
Exception
(
'unsupport type.'
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录