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
f57ae6e7
Commit
f57ae6e7
authored
Jan 16, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改目录
parent
bcd0b053
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
12 deletions
+46
-12
app.py
coco/app.py
+22
-4
conf.py
coco/conf.py
+22
-4
recorder.py
coco/recorder.py
+1
-2
service.py
coco/service.py
+0
-1
sshd.py
coco/sshd.py
+1
-1
No files found.
coco/app.py
View file @
f57ae6e7
...
@@ -10,6 +10,8 @@ import json
...
@@ -10,6 +10,8 @@ import json
import
signal
import
signal
import
copy
import
copy
import
psutil
from
.conf
import
config
from
.conf
import
config
from
.sshd
import
SSHServer
from
.sshd
import
SSHServer
from
.httpd
import
HttpServer
from
.httpd
import
HttpServer
...
@@ -83,10 +85,26 @@ class Coco:
...
@@ -83,10 +85,26 @@ class Coco:
self
.
monitor_sessions
()
self
.
monitor_sessions
()
self
.
monitor_sessions_replay
()
self
.
monitor_sessions_replay
()
@ignore_error
#
@ignore_error
def
heartbeat
(
self
):
def
heartbeat
(
self
):
_sessions
=
[
s
.
to_json
()
for
s
in
Session
.
sessions
.
values
()
if
s
]
sessions
=
list
(
Session
.
sessions
.
keys
())
tasks
=
app_service
.
terminal_heartbeat
(
_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
,
"sessions"
:
sessions
,
}
tasks
=
app_service
.
terminal_heartbeat
(
data
)
if
tasks
:
if
tasks
:
self
.
handle_task
(
tasks
)
self
.
handle_task
(
tasks
)
if
tasks
is
False
:
if
tasks
is
False
:
...
@@ -107,7 +125,7 @@ class Coco:
...
@@ -107,7 +125,7 @@ class Coco:
while
not
self
.
stop_evt
.
is_set
():
while
not
self
.
stop_evt
.
is_set
():
try
:
try
:
self
.
heartbeat
()
self
.
heartbeat
()
except
Exception
as
e
:
except
IndexError
as
e
:
logger
.
error
(
"Unexpected error occur: {}"
.
format
(
e
))
logger
.
error
(
"Unexpected error occur: {}"
.
format
(
e
))
time
.
sleep
(
config
[
"HEARTBEAT_INTERVAL"
])
time
.
sleep
(
config
[
"HEARTBEAT_INTERVAL"
])
thread
=
threading
.
Thread
(
target
=
func
)
thread
=
threading
.
Thread
(
target
=
func
)
...
...
coco/conf.py
View file @
f57ae6e7
...
@@ -300,11 +300,19 @@ class Config(dict):
...
@@ -300,11 +300,19 @@ class Config(dict):
def
__getattr__
(
self
,
item
):
def
__getattr__
(
self
,
item
):
return
self
.
__getitem__
(
item
)
return
self
.
__getitem__
(
item
)
def
__setattr__
(
self
,
key
,
value
):
return
self
.
__setitem__
(
key
,
value
)
def
__repr__
(
self
):
def
__repr__
(
self
):
return
'<
%
s
%
s>'
%
(
self
.
__class__
.
__name__
,
dict
.
__repr__
(
self
))
return
'<
%
s
%
s>'
%
(
self
.
__class__
.
__name__
,
dict
.
__repr__
(
self
))
access_key_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
root_path
,
'keys'
,
'.access_key'
))
access_key_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
root_path
,
'data'
,
'keys'
,
'.access_key'
)
)
host_key_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
root_path
,
'data'
,
'keys'
,
'host_rsa_key'
)
)
defaults
=
{
defaults
=
{
'NAME'
:
socket
.
gethostname
(),
'NAME'
:
socket
.
gethostname
(),
'CORE_HOST'
:
'http://127.0.0.1:8080'
,
'CORE_HOST'
:
'http://127.0.0.1:8080'
,
...
@@ -316,17 +324,17 @@ defaults = {
...
@@ -316,17 +324,17 @@ defaults = {
'HTTPD_PORT'
:
5000
,
'HTTPD_PORT'
:
5000
,
'COCO_ACCESS_KEY'
:
''
,
'COCO_ACCESS_KEY'
:
''
,
'ACCESS_KEY_FILE'
:
access_key_path
,
'ACCESS_KEY_FILE'
:
access_key_path
,
'HOST_KEY_FILE'
:
host_key_path
,
'SECRET_KEY'
:
'SDK29K03
%
MM0ksf'
,
'SECRET_KEY'
:
'SDK29K03
%
MM0ksf'
,
'LOG_LEVEL'
:
'INFO'
,
'LOG_LEVEL'
:
'INFO'
,
'LOG_DIR'
:
os
.
path
.
join
(
root_path
,
'logs'
),
'LOG_DIR'
:
os
.
path
.
join
(
root_path
,
'data'
,
'logs'
),
'SESSION_DIR'
:
os
.
path
.
join
(
root_path
,
'sessions'
),
'ASSET_LIST_SORT_BY'
:
'hostname'
,
# hostname, ip
'ASSET_LIST_SORT_BY'
:
'hostname'
,
# hostname, ip
'PASSWORD_AUTH'
:
True
,
'PASSWORD_AUTH'
:
True
,
'PUBLIC_KEY_AUTH'
:
True
,
'PUBLIC_KEY_AUTH'
:
True
,
'SSH_TIMEOUT'
:
10
,
'SSH_TIMEOUT'
:
10
,
'ALLOW_SSH_USER'
:
[],
'ALLOW_SSH_USER'
:
[],
'BLOCK_SSH_USER'
:
[],
'BLOCK_SSH_USER'
:
[],
'HEARTBEAT_INTERVAL'
:
5
,
'HEARTBEAT_INTERVAL'
:
20
,
'MAX_CONNECTIONS'
:
500
,
# Not use now
'MAX_CONNECTIONS'
:
500
,
# Not use now
'ADMINS'
:
''
,
'ADMINS'
:
''
,
'COMMAND_STORAGE'
:
{
'TYPE'
:
'server'
},
# server
'COMMAND_STORAGE'
:
{
'TYPE'
:
'server'
},
# server
...
@@ -380,3 +388,13 @@ def load_user_config():
...
@@ -380,3 +388,13 @@ def load_user_config():
config
=
load_user_config
()
config
=
load_user_config
()
old_host_key_path
=
os
.
path
.
join
(
root_path
,
'keys'
,
'host_rsa_key'
)
old_access_key_path
=
os
.
path
.
join
(
root_path
,
'keys'
,
'.access_key'
)
if
os
.
path
.
isfile
(
old_host_key_path
)
and
not
os
.
path
.
isfile
(
config
.
HOST_KEY_FILE
):
config
.
HOST_KEY_FILE
=
old_host_key_path
if
os
.
path
.
isfile
(
old_access_key_path
)
and
not
os
.
path
.
isfile
(
config
.
ACCESS_KEY_FILE
):
config
.
ACCESS_KEY_FILE
=
old_access_key_path
coco/recorder.py
View file @
f57ae6e7
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#
#
import
abc
import
threading
import
threading
import
time
import
time
import
os
import
os
...
@@ -13,7 +12,7 @@ from copy import deepcopy
...
@@ -13,7 +12,7 @@ from copy import deepcopy
import
jms_storage
import
jms_storage
from
.conf
import
config
from
.conf
import
config
from
.utils
import
get_logger
,
Singleton
from
.utils
import
get_logger
from
.struct
import
MemoryQueue
from
.struct
import
MemoryQueue
from
.service
import
app_service
from
.service
import
app_service
...
...
coco/service.py
View file @
f57ae6e7
...
@@ -6,7 +6,6 @@ from .conf import config
...
@@ -6,7 +6,6 @@ from .conf import config
inited
=
False
inited
=
False
app_service
=
AppService
(
config
)
app_service
=
AppService
(
config
)
if
not
inited
:
if
not
inited
:
...
...
coco/sshd.py
View file @
f57ae6e7
...
@@ -29,7 +29,7 @@ class SSHServer:
...
@@ -29,7 +29,7 @@ class SSHServer:
@property
@property
def
host_key
(
self
):
def
host_key
(
self
):
host_key_path
=
os
.
path
.
join
(
config
[
'ROOT_PATH'
],
'keys'
,
'host_rsa_key'
)
host_key_path
=
config
[
'HOST_KEY_FILE'
]
if
not
os
.
path
.
isfile
(
host_key_path
):
if
not
os
.
path
.
isfile
(
host_key_path
):
if
config
.
HOST_KEY
:
if
config
.
HOST_KEY
:
with
open
(
host_key_path
,
'w'
)
as
f
:
with
open
(
host_key_path
,
'w'
)
as
f
:
...
...
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