Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
19
Merge Requests
19
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos.core
Commits
064ee487
Commit
064ee487
authored
Oct 26, 2018
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
146f0e0d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
23 deletions
+18
-23
slapos/collect/reporter.py
slapos/collect/reporter.py
+16
-21
slapos/tests/slap.py
slapos/tests/slap.py
+2
-2
No files found.
slapos/collect/reporter.py
View file @
064ee487
...
@@ -135,56 +135,53 @@ class ConsumptionReportBase(object):
...
@@ -135,56 +135,53 @@ class ConsumptionReportBase(object):
def
getPartitionCPULoadAverage
(
self
,
partition_id
,
date_scope
):
def
getPartitionCPULoadAverage
(
self
,
partition_id
,
date_scope
):
self
.
db
.
connect
()
self
.
db
.
connect
()
cpu_percent_sum
=
self
.
db
.
select
(
"user"
,
date_scope
,
(
cpu_percent_sum
,),
=
self
.
db
.
select
(
"user"
,
date_scope
,
columns
=
"SUM(cpu_percent)"
,
columns
=
"SUM(cpu_percent)"
,
where
=
"partition = '%s'"
%
partition_id
)
where
=
"partition = '%s'"
%
partition_id
)
if
len
(
cpu_percent_sum
)
and
cpu_percent_sum
[
0
][
0
]
is
None
:
if
cpu_percent_sum
is
None
:
return
return
sample_amount
=
self
.
db
.
select
(
"user"
,
date_scope
,
(
sample_amount
,),
=
self
.
db
.
select
(
"user"
,
date_scope
,
columns
=
"COUNT(DISTINCT time)"
,
columns
=
"COUNT(DISTINCT time)"
,
where
=
"partition = '%s'"
%
partition_id
)
where
=
"partition = '%s'"
%
partition_id
)
self
.
db
.
close
()
self
.
db
.
close
()
if
len
(
sample_amount
)
and
len
(
cpu_percent_sum
):
return
cpu_percent_sum
/
sample_amount
return
cpu_percent_sum
[
0
][
0
]
/
sample_amount
[
0
][
0
]
def
getPartitionUsedMemoryAverage
(
self
,
partition_id
,
date_scope
):
def
getPartitionUsedMemoryAverage
(
self
,
partition_id
,
date_scope
):
self
.
db
.
connect
()
self
.
db
.
connect
()
memory_sum
=
self
.
db
.
select
(
"user"
,
date_scope
,
(
memory_sum
,),
=
self
.
db
.
select
(
"user"
,
date_scope
,
columns
=
"SUM(memory_rss)"
,
columns
=
"SUM(memory_rss)"
,
where
=
"partition = '%s'"
%
partition_id
)
where
=
"partition = '%s'"
%
partition_id
)
if
len
(
memory_sum
)
and
memory_sum
[
0
][
0
]
is
None
:
if
memory_sum
is
None
:
return
return
sample_amount
=
self
.
db
.
select
(
"user"
,
date_scope
,
(
sample_amount
,),
=
self
.
db
.
select
(
"user"
,
date_scope
,
columns
=
"COUNT(DISTINCT time)"
,
columns
=
"COUNT(DISTINCT time)"
,
where
=
"partition = '%s'"
%
partition_id
)
where
=
"partition = '%s'"
%
partition_id
)
self
.
db
.
close
()
self
.
db
.
close
()
if
len
(
sample_amount
)
and
len
(
memory_sum
):
return
memory_sum
/
sample_amount
return
memory_sum
[
0
][
0
]
/
sample_amount
[
0
][
0
]
def
getPartitionDiskUsedAverage
(
self
,
partition_id
,
date_scope
):
def
getPartitionDiskUsedAverage
(
self
,
partition_id
,
date_scope
):
self
.
db
.
connect
()
self
.
db
.
connect
()
disk_used_sum
=
self
.
db
.
select
(
"folder"
,
date_scope
,
(
disk_used_sum
,),
=
self
.
db
.
select
(
"folder"
,
date_scope
,
columns
=
"SUM(disk_used)"
,
columns
=
"SUM(disk_used)"
,
where
=
"partition = '%s'"
%
partition_id
)
where
=
"partition = '%s'"
%
partition_id
)
if
len
(
disk_used_sum
)
and
disk_used_sum
[
0
][
0
]
is
None
:
if
disk_used_sum
is
None
:
return
return
collect_amount
=
self
.
db
.
select
(
"folder"
,
date_scope
,
(
collect_amount
,),
=
self
.
db
.
select
(
"folder"
,
date_scope
,
columns
=
"COUNT(DISTINCT time)"
,
columns
=
"COUNT(DISTINCT time)"
,
where
=
"partition = '%s'"
%
partition_id
)
where
=
"partition = '%s'"
%
partition_id
)
self
.
db
.
close
()
self
.
db
.
close
()
if
len
(
collect_amount
)
and
len
(
disk_used_sum
):
return
disk_used_sum
/
collect_amount
return
disk_used_sum
[
0
][
0
]
/
collect_amount
[
0
][
0
]
class
ConsumptionReport
(
ConsumptionReportBase
):
class
ConsumptionReport
(
ConsumptionReportBase
):
...
@@ -292,21 +289,19 @@ class ConsumptionReport(ConsumptionReportBase):
...
@@ -292,21 +289,19 @@ class ConsumptionReport(ConsumptionReportBase):
def
_getCpuLoadAverageConsumption
(
self
,
date_scope
):
def
_getCpuLoadAverageConsumption
(
self
,
date_scope
):
self
.
db
.
connect
()
self
.
db
.
connect
()
cpu_load_percent_list
=
self
.
db
.
select
(
"system"
,
date_scope
,
(
cpu_load_percent_list
,),
=
self
.
db
.
select
(
"system"
,
date_scope
,
columns
=
"SUM(cpu_percent)/COUNT(cpu_percent)"
)
columns
=
"SUM(cpu_percent)/COUNT(cpu_percent)"
)
self
.
db
.
close
()
self
.
db
.
close
()
if
len
(
cpu_load_percent_list
):
return
cpu_load_percent_list
return
cpu_load_percent_list
[
0
][
0
]
def
_getMemoryAverageConsumption
(
self
,
date_scope
):
def
_getMemoryAverageConsumption
(
self
,
date_scope
):
self
.
db
.
connect
()
self
.
db
.
connect
()
memory_used_list
=
self
.
db
.
select
(
"system"
,
date_scope
,
(
memory_used_list
,),
=
self
.
db
.
select
(
"system"
,
date_scope
,
columns
=
"SUM(memory_used)/COUNT(memory_used)"
)
columns
=
"SUM(memory_used)/COUNT(memory_used)"
)
self
.
db
.
close
()
self
.
db
.
close
()
if
len
(
memory_used_list
):
return
memory_used_list
return
memory_used_list
[
0
][
0
]
def
_getZeroEmissionContribution
(
self
):
def
_getZeroEmissionContribution
(
self
):
self
.
db
.
connect
()
self
.
db
.
connect
()
...
...
slapos/tests/slap.py
View file @
064ee487
...
@@ -1207,7 +1207,7 @@ class TestSoftwareProductCollection(SlapMixin):
...
@@ -1207,7 +1207,7 @@ class TestSoftwareProductCollection(SlapMixin):
self
.
assertEqual
(
self
.
product_collection
.
foo
,
'0'
)
self
.
assertEqual
(
self
.
product_collection
.
foo
,
'0'
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
print
(
'You can point to any SLAP server by setting TEST_SLAP_SERVER_URL
'
\
print
(
'You can point to any SLAP server by setting TEST_SLAP_SERVER_URL
'
'
environment variable'
)
'
environment variable'
)
unittest
.
main
()
unittest
.
main
()
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