Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Boxiang Sun
slapos.toolbox
Commits
ffb8836b
Commit
ffb8836b
authored
Sep 14, 2017
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos.monitor: Comment horrible code duplications
parent
4287f054
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
0 deletions
+13
-0
slapos/monitor/collect.py
slapos/monitor/collect.py
+13
-0
No files found.
slapos/monitor/collect.py
View file @
ffb8836b
...
@@ -54,30 +54,40 @@ def parseArguments():
...
@@ -54,30 +54,40 @@ def parseArguments():
return
parser
.
parse_args
()
return
parser
.
parse_args
()
# XXX The code on the class below should be dropped and prefer to use
# the slapos.collect.db.Database directly:
# - https://lab.nexedi.com/nexedi/slapos.core/blob/master/slapos/collect/db.py
# the code duplication here is huge so be carefull to not reimplemnt what is
# already implement.
class
ResourceCollect
:
class
ResourceCollect
:
def
__init__
(
self
,
db_path
=
None
):
def
__init__
(
self
,
db_path
=
None
):
# XXX this code is duplicated with slapos.collect.db.Database.__init__
assert
os
.
path
.
exists
(
db_path
)
and
os
.
path
.
isfile
(
db_path
)
assert
os
.
path
.
exists
(
db_path
)
and
os
.
path
.
isfile
(
db_path
)
self
.
uri
=
db_path
self
.
uri
=
db_path
self
.
connection
=
None
self
.
connection
=
None
self
.
cursor
=
None
self
.
cursor
=
None
def
connect
(
self
):
def
connect
(
self
):
# XXX this code is duplicated with slapos.collect.db.Database.connect
self
.
connection
=
sqlite3
.
connect
(
self
.
uri
)
self
.
connection
=
sqlite3
.
connect
(
self
.
uri
)
self
.
cursor
=
self
.
connection
.
cursor
()
self
.
cursor
=
self
.
connection
.
cursor
()
def
close
(
self
):
def
close
(
self
):
# XXX this code is duplicated with slapos.collect.db.Database.connect
assert
self
.
connection
is
not
None
assert
self
.
connection
is
not
None
self
.
cursor
.
close
()
self
.
cursor
.
close
()
self
.
connection
.
close
()
self
.
connection
.
close
()
def
_execute
(
self
,
sql
):
def
_execute
(
self
,
sql
):
# XXX this code is duplicated with slapos.collect.db.Database.connect
assert
self
.
connection
is
not
None
assert
self
.
connection
is
not
None
return
self
.
cursor
.
execute
(
sql
)
return
self
.
cursor
.
execute
(
sql
)
def
select
(
self
,
table
,
date
=
None
,
columns
=
"*"
,
where
=
None
):
def
select
(
self
,
table
,
date
=
None
,
columns
=
"*"
,
where
=
None
):
""" Query database for a full table information """
""" Query database for a full table information """
# XXX this code is duplicated with slapos.collect.db.Database.select
if
date
is
not
None
:
if
date
is
not
None
:
where_clause
=
" WHERE date = '%s' "
%
date
where_clause
=
" WHERE date = '%s' "
%
date
else
:
else
:
...
@@ -102,6 +112,7 @@ class ResourceCollect:
...
@@ -102,6 +112,7 @@ class ResourceCollect:
return
True
return
True
def
getPartitionCPULoadAverage
(
self
,
partition_id
,
date_scope
):
def
getPartitionCPULoadAverage
(
self
,
partition_id
,
date_scope
):
# XXX Code seems copied from slapos.collect.report.ConsumptionReport._getPartitionCPULoadAverage
self
.
connect
()
self
.
connect
()
query_result_cursor
=
self
.
select
(
"user"
,
date_scope
,
query_result_cursor
=
self
.
select
(
"user"
,
date_scope
,
columns
=
"SUM(cpu_percent)"
,
columns
=
"SUM(cpu_percent)"
,
...
@@ -122,6 +133,7 @@ class ResourceCollect:
...
@@ -122,6 +133,7 @@ class ResourceCollect:
return
round
(
cpu_percent_sum
[
0
][
0
]
/
sample_amount
[
0
][
0
],
2
)
return
round
(
cpu_percent_sum
[
0
][
0
]
/
sample_amount
[
0
][
0
],
2
)
def
getPartitionUsedMemoryAverage
(
self
,
partition_id
,
date_scope
):
def
getPartitionUsedMemoryAverage
(
self
,
partition_id
,
date_scope
):
# XXX Code seems copied from slapos.collect.report.ConsumptionReport._getPartitionUsedMemoryAverage
self
.
connect
()
self
.
connect
()
query_result_cursor
=
self
.
select
(
"user"
,
date_scope
,
query_result_cursor
=
self
.
select
(
"user"
,
date_scope
,
columns
=
"SUM(memory_rss)"
,
columns
=
"SUM(memory_rss)"
,
...
@@ -142,6 +154,7 @@ class ResourceCollect:
...
@@ -142,6 +154,7 @@ class ResourceCollect:
return
round
(
memory_sum
[
0
][
0
]
/
(
sample_amount
[
0
][
0
]
*
1024
*
1024.0
),
2
)
return
round
(
memory_sum
[
0
][
0
]
/
(
sample_amount
[
0
][
0
]
*
1024
*
1024.0
),
2
)
def
getPartitionDiskUsedAverage
(
self
,
partition_id
,
date_scope
):
def
getPartitionDiskUsedAverage
(
self
,
partition_id
,
date_scope
):
# XXX Code seems copied from slapos.collect.report.ConsumptionReport._getPartitionDiskUsedAverage
if
not
self
.
has_table
(
'folder'
):
if
not
self
.
has_table
(
'folder'
):
return
return
self
.
db
.
connect
()
self
.
db
.
connect
()
...
...
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