Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cc-node
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
cc-node
Commits
ef83bc0c
Commit
ef83bc0c
authored
12 years ago
by
Anael Beutot
Browse files
Options
Downloads
Patches
Plain Diff
Implemented cpuuse tag for VMs.
parent
71ab2daf
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cloudcontrol/node/hypervisor/domains/__init__.py
+3
-0
3 additions, 0 deletions
cloudcontrol/node/hypervisor/domains/__init__.py
cloudcontrol/node/hypervisor/domains/vm_tags.py
+11
-2
11 additions, 2 deletions
cloudcontrol/node/hypervisor/domains/vm_tags.py
with
14 additions
and
2 deletions
cloudcontrol/node/hypervisor/domains/__init__.py
+
3
−
0
View file @
ef83bc0c
...
@@ -56,6 +56,9 @@ class VirtualMachine(object):
...
@@ -56,6 +56,9 @@ class VirtualMachine(object):
logger
.
debug
(
'
Virtual Machine tags: %s
'
,
self
.
tags
)
logger
.
debug
(
'
Virtual Machine tags: %s
'
,
self
.
tags
)
#: keep record of CPU stats (libev timestamp, cpu time)
self
.
cpu_stats
=
(
hypervisor
.
handler
.
main
.
evloop
.
now
(),
dom
.
info
()[
4
])
@property
@property
def
state
(
self
):
def
state
(
self
):
return
self
.
_state
return
self
.
_state
...
...
This diff is collapsed.
Click to expand it.
cloudcontrol/node/hypervisor/domains/vm_tags.py
+
11
−
2
View file @
ef83bc0c
...
@@ -76,8 +76,17 @@ def cpu(dom):
...
@@ -76,8 +76,17 @@ def cpu(dom):
@ttl
(
10
)
@ttl
(
10
)
@refresh
(
5
)
@refresh
(
5
)
def
cpuuse
():
@_vir_tag
pass
def
cpuuse
(
dom
):
"""
Represent CPU use in percent average on 5 seconds.
"""
state
,
_
,
_
,
vcpu
,
cpu_time
=
dom
.
lv_dom
.
info
()
if
state
!=
1
:
# if VM is not running
return
None
old_cpu_stats
=
dom
.
cpu_stats
dom
.
cpu_stats
=
(
dom
.
hypervisor
.
handler
.
main
.
evloop
.
now
(),
cpu_time
)
# calculate CPU percentage
return
'
%.2f
'
%
max
(
0.
,
min
(
100.
,
((
cpu_time
-
old_cpu_stats
[
1
])
*
100.
)
/
(
(
dom
.
cpu_stats
[
0
]
-
old_cpu_stats
[
0
])
*
1000.
*
1000.
*
1000.
)))
@_vir_tag
@_vir_tag
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment