Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
coco
Project
Project
Details
Activity
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
ops
coco
Commits
a697a601
Commit
a697a601
authored
Jan 21, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改会话新建
parent
0981f8e6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
22 deletions
+51
-22
app.py
coco/app.py
+36
-20
conf.py
coco/conf.py
+1
-1
proxy.py
coco/proxy.py
+6
-0
session.py
coco/session.py
+8
-1
No files found.
coco/app.py
View file @
a697a601
...
...
@@ -9,6 +9,7 @@ import threading
import
json
import
signal
import
copy
from
collections
import
defaultdict
import
psutil
...
...
@@ -88,19 +89,19 @@ class Coco:
# @ignore_error
def
heartbeat
(
self
):
sessions
=
list
(
Session
.
sessions
.
keys
())
p
=
psutil
.
Process
(
os
.
getpid
())
cpu_used
=
p
.
cpu_percent
(
interval
=
1.0
)
memory_used
=
int
(
p
.
memory_info
()
.
rss
/
1024
/
1024
)
connections
=
len
(
p
.
connections
())
threads
=
p
.
num_threads
()
session_online
=
len
(
sessions
)
#
p = psutil.Process(os.getpid())
#
cpu_used = p.cpu_percent(interval=1.0)
#
memory_used = int(p.memory_info().rss / 1024 / 1024)
#
connections = len(p.connections())
#
threads = p.num_threads()
#
session_online = len(sessions)
data
=
{
"cpu_used"
:
cpu_used
,
"memory_used"
:
memory_used
,
"connections"
:
connections
,
"threads"
:
threads
,
"boot_time"
:
p
.
create_time
(),
"session_online"
:
session_online
,
#
"cpu_used": cpu_used,
#
"memory_used": memory_used,
#
"connections": connections,
#
"threads": threads,
#
"boot_time": p.create_time(),
#
"session_online": session_online,
"sessions"
:
sessions
,
}
tasks
=
app_service
.
terminal_heartbeat
(
data
)
...
...
@@ -134,23 +135,38 @@ class Coco:
def
monitor_sessions_replay
(
self
):
interval
=
10
log_dir
=
os
.
path
.
join
(
config
[
'LOG_DIR'
])
max_try
=
5
upload_failed
=
defaultdict
(
int
)
def
func
():
while
not
self
.
stop_evt
.
is_set
():
active_sessions
=
[
sid
for
sid
in
Session
.
sessions
]
for
filename
in
os
.
listdir
(
log_dir
):
suffix
=
filename
.
split
(
'.'
)[
-
1
]
if
suffix
!=
'gz'
:
continue
session_id
=
filename
.
split
(
'.'
)[
0
]
full_path
=
os
.
path
.
join
(
log_dir
,
filename
)
if
len
(
session_id
)
!=
36
:
continue
full_path
=
os
.
path
.
join
(
log_dir
,
filename
)
stat
=
os
.
stat
(
full_path
)
# 是否是一天前的,因为现在多个coco共享了日志目录,
# 不能单纯判断session是否关闭
if
stat
.
st_mtime
>
time
.
time
()
-
24
*
60
*
60
:
continue
# 失败次数过多
if
session_id
in
upload_failed
\
and
upload_failed
[
session_id
]
>=
max_try
:
continue
recorder
=
get_replay_recorder
()
if
session_id
not
in
active_sessions
:
recorder
.
file_path
=
full_path
ok
=
recorder
.
upload_replay
(
session_id
,
1
)
if
not
ok
and
os
.
path
.
getsize
(
full_path
)
==
0
:
os
.
unlink
(
full_path
)
recorder
.
file_path
=
full_path
ok
=
recorder
.
upload_replay
(
session_id
,
1
)
if
ok
:
upload_failed
.
pop
(
session_id
,
None
)
elif
not
ok
and
os
.
path
.
getsize
(
full_path
)
==
0
:
os
.
unlink
(
full_path
)
else
:
upload_failed
[
session_id
]
+=
1
time
.
sleep
(
1
)
time
.
sleep
(
interval
)
thread
=
threading
.
Thread
(
target
=
func
)
...
...
coco/conf.py
View file @
a697a601
...
...
@@ -344,7 +344,7 @@ defaults = {
'LANGUAGE_CODE'
:
'zh'
,
'SECURITY_MAX_IDLE_TIME'
:
60
,
'ASSET_LIST_PAGE_SIZE'
:
'auto'
,
'SFTP_ROOT'
:
'tmp'
,
'SFTP_ROOT'
:
'
/
tmp'
,
}
...
...
coco/proxy.py
View file @
a697a601
...
...
@@ -72,6 +72,12 @@ class ProxyServer:
self
.
server
.
close
()
return
session
=
Session
.
new_session
(
self
.
client
,
self
.
server
)
if
not
session
:
msg
=
_
(
"Connect with api server failed"
)
logger
.
error
(
msg
)
self
.
client
.
send_unicode
(
msg
)
self
.
server
.
close
()
try
:
session
.
bridge
()
finally
:
...
...
coco/session.py
View file @
a697a601
...
...
@@ -48,7 +48,14 @@ class Session:
session
.
set_command_recorder
(
command_recorder
)
session
.
set_replay_recorder
(
replay_recorder
)
cls
.
sessions
[
session
.
id
]
=
session
app_service
.
create_session
(
session
.
to_json
())
_session
=
None
for
i
in
range
(
5
):
_session
=
app_service
.
create_session
(
session
.
to_json
())
if
_session
:
break
time
.
sleep
(
0.2
)
if
_session
is
None
:
return
None
return
session
@classmethod
...
...
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