Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
monitor-client
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
f615daec
authored
Jan 07, 2022
by
Kohl Krisztofer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First 3.6 version
parent
5978a646
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
36 deletions
+34
-36
requirements.txt
+1
-1
src/client.py
+33
-35
No files found.
requirements.txt
View file @
f615daec
psutil
==2.1.1
psutil
pika
src/client.py
View file @
f615daec
...
...
@@ -16,9 +16,7 @@ level = os.environ.get('LOGLEVEL', 'INFO')
logger
.
setLevel
(
level
)
class
Client
:
env_config
=
{
"server_address"
:
"GRAPHITE_HOST"
,
"server_port"
:
"GRAPHITE_PORT"
,
...
...
@@ -43,7 +41,7 @@ class Client:
Missing only one of these variables will cause the client not to work.
"""
self
.
name
=
'circle.
%
s'
%
gethostname
()
.
split
(
"."
)[
0
]
for
var
,
env_var
in
self
.
env_config
.
items
(
):
for
var
,
env_var
in
list
(
self
.
env_config
.
items
()
):
value
=
os
.
getenv
(
env_var
,
""
)
if
value
:
setattr
(
self
,
var
,
value
)
...
...
@@ -85,7 +83,7 @@ class Client:
self
.
connection
.
close
()
except
RuntimeError
as
e
:
logger
.
error
(
'An error has occured while disconnecting.
%
s'
,
unicode
(
e
))
str
(
e
))
raise
def
send
(
self
,
message
):
...
...
@@ -124,13 +122,13 @@ class Client:
}
try
:
for
k
,
v
in
psutil
.
disk_io_counters
()
.
__dict__
.
items
(
):
for
k
,
v
in
list
(
psutil
.
disk_io_counters
()
.
__dict__
.
items
()
):
metrics
[
'disk.
%
s'
%
k
]
=
v
except
:
pass
interfaces
=
psutil
.
net
work
_io_counters
(
pernic
=
True
)
for
interface
,
data
in
interfaces
.
ite
rite
ms
():
interfaces
=
psutil
.
net_io_counters
(
pernic
=
True
)
for
interface
,
data
in
interfaces
.
items
():
if
not
(
interface
.
startswith
(
'cloud'
)
or
interface
.
endswith
(
'-EXT'
)
or
interface
.
startswith
(
'net'
)
or
...
...
@@ -145,7 +143,7 @@ class Client:
'name'
:
name
,
'val'
:
value
,
'time'
:
now
}
for
name
,
value
in
metrics
.
ite
rite
ms
()]
for
name
,
value
in
metrics
.
items
()]
def
collect_vms
(
self
):
"""
...
...
@@ -158,7 +156,7 @@ class Client:
running_vms
=
[]
try
:
for
entry
in
psutil
.
get_process_list
():
for
entry
in
psutil
.
process_iter
():
if
entry
.
name
()
in
(
'kvm'
,
'qemu-system-x86_64'
):
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'-name'
)
...
...
@@ -166,36 +164,36 @@ class Client:
args
,
unknown
=
parser
.
parse_known_args
(
entry
.
cmdline
()[
1
:])
# for Red Hat style parametering of kvm
if
isinstance
(
args
.
name
,
basestring
):
if
isinstance
(
args
.
name
,
str
):
args
.
name
=
re
.
sub
(
r"^guest="
,
""
,
args
.
name
)
args
.
name
=
re
.
sub
(
r",debug-threads=.*$"
,
""
,
args
.
name
)
process
=
self
.
processes
.
get
(
entry
.
pid
,
None
)
if
not
process
or
process
.
cmdline
()
!=
entry
.
cmdline
():
process
=
psutil
.
Process
(
entry
.
pid
)
logger
.
info
(
'New process:
%
s'
,
process
)
self
.
processes
[
entry
.
pid
]
=
process
mem_perc
=
(
float
(
process
.
get_memory_info
()
.
rss
)
/
(
args
.
memory_size
*
1024
**
2
)
*
90
)
metrics
.
append
(
'vm.
%(name)
s.memory.usage
%(value)
f '
'
%(time)
d'
%
{
'name'
:
args
.
name
,
'value'
:
mem_perc
,
'time'
:
now
})
cpu_perc
=
process
.
get_cpu_percent
()
metrics
.
append
(
'vm.
%(name)
s.cpu.percent
%(value)
f '
'
%(time)
d'
%
{
'name'
:
args
.
name
,
'value'
:
cpu_perc
,
'time'
:
now
})
running_vms
.
append
(
args
.
name
)
else
:
if
not
process
or
process
.
cmdline
()
!=
entry
.
cmdline
():
process
=
psutil
.
Process
(
entry
.
pid
)
logger
.
info
(
'New process:
%
s'
,
process
)
self
.
processes
[
entry
.
pid
]
=
process
mem_perc
=
(
float
(
process
.
get_memory_info
()
.
rss
)
/
(
args
.
memory_size
*
1024
**
2
)
*
90
)
metrics
.
append
(
'vm.
%(name)
s.memory.usage
%(value)
f '
'
%(time)
d'
%
{
'name'
:
args
.
name
,
'value'
:
mem_perc
,
'time'
:
now
})
cpu_perc
=
process
.
get_cpu_percent
()
metrics
.
append
(
'vm.
%(name)
s.cpu.percent
%(value)
f '
'
%(time)
d'
%
{
'name'
:
args
.
name
,
'value'
:
cpu_perc
,
'time'
:
now
})
running_vms
.
append
(
args
.
name
)
else
:
logger
.
warning
(
'Pid:
%
d args.name is empty?:
%
s
%
s'
,
entry
.
pid
,
entry
.
name
(),
entry
.
cmdline
())
except
(
psutil
.
NoSuchProcess
,
TypeError
):
logger
.
warning
(
'Process
%
d lost. Entry:
%
s'
,
entry
.
pid
,
entry
.
cmdline
()[
0
:])
interfaces
=
psutil
.
net
work
_io_counters
(
pernic
=
True
)
for
interface
,
data
in
interfaces
.
ite
rite
ms
():
interfaces
=
psutil
.
net_io_counters
(
pernic
=
True
)
for
interface
,
data
in
interfaces
.
items
():
try
:
vm
,
vlan
=
interface
.
rsplit
(
'-'
,
1
)
except
ValueError
:
...
...
@@ -207,10 +205,10 @@ class Client:
'vm.
%(name)
s.network.
%(metric)
s-'
'
%(interface)
s
%(data)
f
%(time)
d'
%
{
'name'
:
vm
,
'interface'
:
vlan
,
'metric'
:
metric
,
'time'
:
now
,
'data'
:
getattr
(
data
,
metric
)})
'interface'
:
vlan
,
'metric'
:
metric
,
'time'
:
now
,
'data'
:
getattr
(
data
,
metric
)})
metrics
.
append
(
'
%(host)
s.vmcount
%(data)
d
%(time)
d'
%
{
...
...
@@ -224,7 +222,7 @@ class Client:
def
_chunker
(
seq
,
size
):
"""Yield seq in size-long chunks.
"""
for
pos
in
x
range
(
0
,
len
(
seq
),
size
):
for
pos
in
range
(
0
,
len
(
seq
),
size
):
yield
islice
(
seq
,
pos
,
pos
+
size
)
def
run
(
self
):
...
...
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