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
797d6c3a
Commit
797d6c3a
authored
Mar 11, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改一些小问题
parent
97865db8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
16 deletions
+71
-16
app.py
coco/app.py
+5
-14
conf.py
coco/conf.py
+1
-1
utils.py
coco/utils.py
+64
-0
cocod
cocod
+1
-1
No files found.
coco/app.py
View file @
797d6c3a
...
@@ -14,7 +14,10 @@ from .conf import config
...
@@ -14,7 +14,10 @@ from .conf import config
from
.sshd
import
SSHServer
from
.sshd
import
SSHServer
from
.httpd
import
HttpServer
from
.httpd
import
HttpServer
from
.tasks
import
TaskHandler
from
.tasks
import
TaskHandler
from
.utils
import
get_logger
,
ugettext
as
_
,
ignore_error
from
.utils
import
(
get_logger
,
ugettext
as
_
,
ignore_error
,
get_monitor_data
,
get_coco_monitor_data
)
from
.service
import
app_service
from
.service
import
app_service
from
.recorder
import
get_replay_recorder
from
.recorder
import
get_replay_recorder
from
.session
import
Session
from
.session
import
Session
...
@@ -89,20 +92,8 @@ class Coco:
...
@@ -89,20 +92,8 @@ class Coco:
# @ignore_error
# @ignore_error
def
heartbeat
(
self
):
def
heartbeat
(
self
):
sessions
=
list
(
Session
.
sessions
.
keys
())
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)
data
=
{
data
=
{
# "cpu_used": cpu_used,
'sessions'
:
sessions
,
# "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
)
tasks
=
app_service
.
terminal_heartbeat
(
data
)
...
...
coco/conf.py
View file @
797d6c3a
...
@@ -341,7 +341,7 @@ defaults = {
...
@@ -341,7 +341,7 @@ defaults = {
'TELNET_REGEX'
:
''
,
'TELNET_REGEX'
:
''
,
'PASSWORD_AUTH'
:
True
,
'PASSWORD_AUTH'
:
True
,
'PUBLIC_KEY_AUTH'
:
True
,
'PUBLIC_KEY_AUTH'
:
True
,
'SSH_TIMEOUT'
:
1
0
,
'SSH_TIMEOUT'
:
1
5
,
'ALLOW_SSH_USER'
:
[],
'ALLOW_SSH_USER'
:
[],
'BLOCK_SSH_USER'
:
[],
'BLOCK_SSH_USER'
:
[],
'HEARTBEAT_INTERVAL'
:
20
,
'HEARTBEAT_INTERVAL'
:
20
,
...
...
coco/utils.py
View file @
797d6c3a
...
@@ -4,11 +4,13 @@
...
@@ -4,11 +4,13 @@
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
import
time
import
logging
import
logging
import
re
import
re
import
os
import
os
import
gettext
import
gettext
import
gzip
import
gzip
import
psutil
from
io
import
StringIO
from
io
import
StringIO
from
binascii
import
hexlify
from
binascii
import
hexlify
from
werkzeug.local
import
Local
,
LocalProxy
from
werkzeug.local
import
Local
,
LocalProxy
...
@@ -472,4 +474,66 @@ def gzip_file(src_path, dst_path, unlink_ori=True):
...
@@ -472,4 +474,66 @@ def gzip_file(src_path, dst_path, unlink_ori=True):
os
.
unlink
(
src_path
)
os
.
unlink
(
src_path
)
def
get_cpu_info
():
cpus
=
[
'cpu
%
s'
%
i
for
i
in
range
(
psutil
.
cpu_count
())]
percents
=
psutil
.
cpu_percent
(
interval
=
0.5
,
percpu
=
True
)
return
dict
(
zip
(
cpus
,
percents
))
def
get_memory_info
():
mem
=
psutil
.
virtual_memory
()
return
{
'total'
:
mem
.
total
,
'avail'
:
mem
.
available
,
'used'
:
mem
.
used
,
'percent'
:
mem
.
percent
,
}
def
get_disk_info
():
partitions
=
psutil
.
disk_partitions
()
info
=
{}
for
partition
in
partitions
:
usage
=
psutil
.
disk_usage
(
partition
.
mountpoint
)
info
[
partition
.
device
]
=
{
'mountpoint'
:
partition
.
mountpoint
,
'device'
:
partition
.
device
,
'total'
:
usage
.
total
,
'used'
:
usage
.
used
,
'free'
:
usage
.
free
,
'percent'
:
usage
.
percent
}
return
info
def
get_net_info
():
counter
=
psutil
.
net_io_counters
()
return
{
'bytes_sent'
:
counter
.
bytes_sent
,
'bytes_recv'
:
counter
.
bytes_recv
,
}
def
get_coco_monitor_data
():
p
=
psutil
.
Process
(
os
.
getpid
())
cpu_used
=
p
.
cpu_percent
(
interval
=
0.5
)
memory_used
=
p
.
memory_info
()
.
rss
connections
=
len
(
p
.
connections
())
return
{
'p_cpu'
:
cpu_used
,
'p_memory'
:
memory_used
,
'p_conns'
:
connections
}
def
get_monitor_data
():
return
{
'timestamp'
:
int
(
time
.
time
()),
'cpu'
:
get_cpu_info
(),
'memory'
:
get_memory_info
(),
'disk'
:
get_disk_info
(),
'net'
:
get_net_info
(),
}
ugettext
=
LocalProxy
(
partial
(
_find
,
'LANGUAGE_CODE'
))
ugettext
=
LocalProxy
(
partial
(
_find
,
'LANGUAGE_CODE'
))
cocod
View file @
797d6c3a
...
@@ -22,7 +22,7 @@ BASE_DIR = os.path.abspath(os.path.dirname(__file__))
...
@@ -22,7 +22,7 @@ BASE_DIR = os.path.abspath(os.path.dirname(__file__))
sys
.
path
.
insert
(
0
,
BASE_DIR
)
sys
.
path
.
insert
(
0
,
BASE_DIR
)
dirs
=
(
'logs'
,
'keys'
)
dirs
=
(
'logs'
,)
for
d
in
dirs
:
for
d
in
dirs
:
d2
=
os
.
path
.
join
(
'data'
,
d
)
d2
=
os
.
path
.
join
(
'data'
,
d
)
if
not
os
.
path
.
isdir
(
d2
):
if
not
os
.
path
.
isdir
(
d2
):
...
...
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