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
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
pika
src/client.py
View file @
f615daec
...
@@ -16,9 +16,7 @@ level = os.environ.get('LOGLEVEL', 'INFO')
...
@@ -16,9 +16,7 @@ level = os.environ.get('LOGLEVEL', 'INFO')
logger
.
setLevel
(
level
)
logger
.
setLevel
(
level
)
class
Client
:
class
Client
:
env_config
=
{
env_config
=
{
"server_address"
:
"GRAPHITE_HOST"
,
"server_address"
:
"GRAPHITE_HOST"
,
"server_port"
:
"GRAPHITE_PORT"
,
"server_port"
:
"GRAPHITE_PORT"
,
...
@@ -43,7 +41,7 @@ class Client:
...
@@ -43,7 +41,7 @@ class Client:
Missing only one of these variables will cause the client not to work.
Missing only one of these variables will cause the client not to work.
"""
"""
self
.
name
=
'circle.
%
s'
%
gethostname
()
.
split
(
"."
)[
0
]
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
,
""
)
value
=
os
.
getenv
(
env_var
,
""
)
if
value
:
if
value
:
setattr
(
self
,
var
,
value
)
setattr
(
self
,
var
,
value
)
...
@@ -85,7 +83,7 @@ class Client:
...
@@ -85,7 +83,7 @@ class Client:
self
.
connection
.
close
()
self
.
connection
.
close
()
except
RuntimeError
as
e
:
except
RuntimeError
as
e
:
logger
.
error
(
'An error has occured while disconnecting.
%
s'
,
logger
.
error
(
'An error has occured while disconnecting.
%
s'
,
unicode
(
e
))
str
(
e
))
raise
raise
def
send
(
self
,
message
):
def
send
(
self
,
message
):
...
@@ -124,13 +122,13 @@ class Client:
...
@@ -124,13 +122,13 @@ class Client:
}
}
try
:
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
metrics
[
'disk.
%
s'
%
k
]
=
v
except
:
except
:
pass
pass
interfaces
=
psutil
.
net
work
_io_counters
(
pernic
=
True
)
interfaces
=
psutil
.
net_io_counters
(
pernic
=
True
)
for
interface
,
data
in
interfaces
.
ite
rite
ms
():
for
interface
,
data
in
interfaces
.
items
():
if
not
(
interface
.
startswith
(
'cloud'
)
or
if
not
(
interface
.
startswith
(
'cloud'
)
or
interface
.
endswith
(
'-EXT'
)
or
interface
.
endswith
(
'-EXT'
)
or
interface
.
startswith
(
'net'
)
or
interface
.
startswith
(
'net'
)
or
...
@@ -145,7 +143,7 @@ class Client:
...
@@ -145,7 +143,7 @@ class Client:
'name'
:
name
,
'name'
:
name
,
'val'
:
value
,
'val'
:
value
,
'time'
:
now
}
'time'
:
now
}
for
name
,
value
in
metrics
.
ite
rite
ms
()]
for
name
,
value
in
metrics
.
items
()]
def
collect_vms
(
self
):
def
collect_vms
(
self
):
"""
"""
...
@@ -158,7 +156,7 @@ class Client:
...
@@ -158,7 +156,7 @@ class Client:
running_vms
=
[]
running_vms
=
[]
try
:
try
:
for
entry
in
psutil
.
get_process_list
():
for
entry
in
psutil
.
process_iter
():
if
entry
.
name
()
in
(
'kvm'
,
'qemu-system-x86_64'
):
if
entry
.
name
()
in
(
'kvm'
,
'qemu-system-x86_64'
):
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'-name'
)
parser
.
add_argument
(
'-name'
)
...
@@ -166,36 +164,36 @@ class Client:
...
@@ -166,36 +164,36 @@ class Client:
args
,
unknown
=
parser
.
parse_known_args
(
args
,
unknown
=
parser
.
parse_known_args
(
entry
.
cmdline
()[
1
:])
entry
.
cmdline
()[
1
:])
# for Red Hat style parametering of kvm
# 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"^guest="
,
""
,
args
.
name
)
args
.
name
=
re
.
sub
(
r",debug-threads=.*$"
,
""
,
args
.
name
)
args
.
name
=
re
.
sub
(
r",debug-threads=.*$"
,
""
,
args
.
name
)
process
=
self
.
processes
.
get
(
entry
.
pid
,
None
)
process
=
self
.
processes
.
get
(
entry
.
pid
,
None
)
if
not
process
or
process
.
cmdline
()
!=
entry
.
cmdline
():
if
not
process
or
process
.
cmdline
()
!=
entry
.
cmdline
():
process
=
psutil
.
Process
(
entry
.
pid
)
process
=
psutil
.
Process
(
entry
.
pid
)
logger
.
info
(
'New process:
%
s'
,
process
)
logger
.
info
(
'New process:
%
s'
,
process
)
self
.
processes
[
entry
.
pid
]
=
process
self
.
processes
[
entry
.
pid
]
=
process
mem_perc
=
(
float
(
process
.
get_memory_info
()
.
rss
)
mem_perc
=
(
float
(
process
.
get_memory_info
()
.
rss
)
/
(
args
.
memory_size
*
1024
**
2
)
*
90
)
/
(
args
.
memory_size
*
1024
**
2
)
*
90
)
metrics
.
append
(
'vm.
%(name)
s.memory.usage
%(value)
f '
metrics
.
append
(
'vm.
%(name)
s.memory.usage
%(value)
f '
'
%(time)
d'
%
{
'name'
:
args
.
name
,
'
%(time)
d'
%
{
'name'
:
args
.
name
,
'value'
:
mem_perc
,
'value'
:
mem_perc
,
'time'
:
now
})
'time'
:
now
})
cpu_perc
=
process
.
get_cpu_percent
()
cpu_perc
=
process
.
get_cpu_percent
()
metrics
.
append
(
'vm.
%(name)
s.cpu.percent
%(value)
f '
metrics
.
append
(
'vm.
%(name)
s.cpu.percent
%(value)
f '
'
%(time)
d'
%
{
'name'
:
args
.
name
,
'
%(time)
d'
%
{
'name'
:
args
.
name
,
'value'
:
cpu_perc
,
'value'
:
cpu_perc
,
'time'
:
now
})
'time'
:
now
})
running_vms
.
append
(
args
.
name
)
running_vms
.
append
(
args
.
name
)
else
:
else
:
logger
.
warning
(
'Pid:
%
d args.name is empty?:
%
s
%
s'
,
entry
.
pid
,
entry
.
name
(),
entry
.
cmdline
())
logger
.
warning
(
'Pid:
%
d args.name is empty?:
%
s
%
s'
,
entry
.
pid
,
entry
.
name
(),
entry
.
cmdline
())
except
(
psutil
.
NoSuchProcess
,
TypeError
):
except
(
psutil
.
NoSuchProcess
,
TypeError
):
logger
.
warning
(
'Process
%
d lost. Entry:
%
s'
,
entry
.
pid
,
entry
.
cmdline
()[
0
:])
logger
.
warning
(
'Process
%
d lost. Entry:
%
s'
,
entry
.
pid
,
entry
.
cmdline
()[
0
:])
interfaces
=
psutil
.
net
work
_io_counters
(
pernic
=
True
)
interfaces
=
psutil
.
net_io_counters
(
pernic
=
True
)
for
interface
,
data
in
interfaces
.
ite
rite
ms
():
for
interface
,
data
in
interfaces
.
items
():
try
:
try
:
vm
,
vlan
=
interface
.
rsplit
(
'-'
,
1
)
vm
,
vlan
=
interface
.
rsplit
(
'-'
,
1
)
except
ValueError
:
except
ValueError
:
...
@@ -207,10 +205,10 @@ class Client:
...
@@ -207,10 +205,10 @@ class Client:
'vm.
%(name)
s.network.
%(metric)
s-'
'vm.
%(name)
s.network.
%(metric)
s-'
'
%(interface)
s
%(data)
f
%(time)
d'
%
'
%(interface)
s
%(data)
f
%(time)
d'
%
{
'name'
:
vm
,
{
'name'
:
vm
,
'interface'
:
vlan
,
'interface'
:
vlan
,
'metric'
:
metric
,
'metric'
:
metric
,
'time'
:
now
,
'time'
:
now
,
'data'
:
getattr
(
data
,
metric
)})
'data'
:
getattr
(
data
,
metric
)})
metrics
.
append
(
metrics
.
append
(
'
%(host)
s.vmcount
%(data)
d
%(time)
d'
%
{
'
%(host)
s.vmcount
%(data)
d
%(time)
d'
%
{
...
@@ -224,7 +222,7 @@ class Client:
...
@@ -224,7 +222,7 @@ class Client:
def
_chunker
(
seq
,
size
):
def
_chunker
(
seq
,
size
):
"""Yield seq in size-long chunks.
"""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
)
yield
islice
(
seq
,
pos
,
pos
+
size
)
def
run
(
self
):
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