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
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
slapos.toolbox
Commits
ffb8836b
Commit
ffb8836b
authored
Sep 14, 2017
by
Rafael Monnerat
1
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():
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
:
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
)
self
.
uri
=
db_path
self
.
connection
=
None
self
.
cursor
=
None
def
connect
(
self
):
# XXX this code is duplicated with slapos.collect.db.Database.connect
self
.
connection
=
sqlite3
.
connect
(
self
.
uri
)
self
.
cursor
=
self
.
connection
.
cursor
()
def
close
(
self
):
# XXX this code is duplicated with slapos.collect.db.Database.connect
assert
self
.
connection
is
not
None
self
.
cursor
.
close
()
self
.
connection
.
close
()
def
_execute
(
self
,
sql
):
# XXX this code is duplicated with slapos.collect.db.Database.connect
assert
self
.
connection
is
not
None
return
self
.
cursor
.
execute
(
sql
)
def
select
(
self
,
table
,
date
=
None
,
columns
=
"*"
,
where
=
None
):
""" Query database for a full table information """
# XXX this code is duplicated with slapos.collect.db.Database.select
if
date
is
not
None
:
where_clause
=
" WHERE date = '%s' "
%
date
else
:
...
...
@@ -102,6 +112,7 @@ class ResourceCollect:
return
True
def
getPartitionCPULoadAverage
(
self
,
partition_id
,
date_scope
):
# XXX Code seems copied from slapos.collect.report.ConsumptionReport._getPartitionCPULoadAverage
self
.
connect
()
query_result_cursor
=
self
.
select
(
"user"
,
date_scope
,
columns
=
"SUM(cpu_percent)"
,
...
...
@@ -122,6 +133,7 @@ class ResourceCollect:
return
round
(
cpu_percent_sum
[
0
][
0
]
/
sample_amount
[
0
][
0
],
2
)
def
getPartitionUsedMemoryAverage
(
self
,
partition_id
,
date_scope
):
# XXX Code seems copied from slapos.collect.report.ConsumptionReport._getPartitionUsedMemoryAverage
self
.
connect
()
query_result_cursor
=
self
.
select
(
"user"
,
date_scope
,
columns
=
"SUM(memory_rss)"
,
...
...
@@ -142,6 +154,7 @@ class ResourceCollect:
return
round
(
memory_sum
[
0
][
0
]
/
(
sample_amount
[
0
][
0
]
*
1024
*
1024.0
),
2
)
def
getPartitionDiskUsedAverage
(
self
,
partition_id
,
date_scope
):
# XXX Code seems copied from slapos.collect.report.ConsumptionReport._getPartitionDiskUsedAverage
if
not
self
.
has_table
(
'folder'
):
return
self
.
db
.
connect
()
...
...
Hardik Juneja
@hjuneja
mentioned in merge request
!17 (merged)
·
Sep 19, 2017
mentioned in merge request
!17 (merged)
mentioned in merge request !17
Toggle commit list
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