Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
monitor-client
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
dd5f6fc0
authored
Feb 07, 2014
by
Gregory Nagy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flake8 and synchronized memory reporter function (celery collector)
parent
0a10962e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
69 deletions
+77
-69
src/client.py
+4
-0
src/cnfparse.py
+26
-26
src/collectables.py
+37
-37
src/metrics.py
+10
-6
No files found.
src/client.py
View file @
dd5f6fc0
...
@@ -208,6 +208,7 @@ class Client:
...
@@ -208,6 +208,7 @@ class Client:
"."
+
"network.packages_sent"
+
"."
+
"network.packages_sent"
+
"
%
d"
%
interfaces_list
[
"
%
d"
%
interfaces_list
[
iname
]
.
packets_sent
iname
]
.
packets_sent
+
"."
+
iname
+
"
%
d"
%
(
time
.
time
())
+
"
%
d"
%
(
time
.
time
())
))
))
metrics
.
append
((
"vm."
+
metrics
.
append
((
"vm."
+
...
@@ -215,6 +216,7 @@ class Client:
...
@@ -215,6 +216,7 @@ class Client:
"."
+
"network.packages_recv"
+
"."
+
"network.packages_recv"
+
"
%
d"
%
interfaces_list
[
"
%
d"
%
interfaces_list
[
iname
]
.
packets_recv
iname
]
.
packets_recv
+
"."
+
iname
+
"
%
d"
%
(
time
.
time
())
+
"
%
d"
%
(
time
.
time
())
))
))
metrics
.
append
((
"vm."
+
metrics
.
append
((
"vm."
+
...
@@ -222,6 +224,7 @@ class Client:
...
@@ -222,6 +224,7 @@ class Client:
".bytes_sent"
+
".bytes_sent"
+
"
%
d"
%
interfaces_list
[
"
%
d"
%
interfaces_list
[
iname
]
.
bytes_sent
iname
]
.
bytes_sent
+
"."
+
iname
+
"
%
d"
%
(
time
.
time
())
+
"
%
d"
%
(
time
.
time
())
))
))
metrics
.
append
((
"vm."
+
metrics
.
append
((
"vm."
+
...
@@ -229,6 +232,7 @@ class Client:
...
@@ -229,6 +232,7 @@ class Client:
".bytes_recv"
+
".bytes_recv"
+
"
%
d"
%
interfaces_list
[
"
%
d"
%
interfaces_list
[
iname
]
.
bytes_recv
iname
]
.
bytes_recv
+
"."
+
iname
+
"
%
d"
%
(
time
.
time
())
+
"
%
d"
%
(
time
.
time
())
))
))
return
metrics
return
metrics
...
...
src/cnfparse.py
View file @
dd5f6fc0
...
@@ -2,30 +2,30 @@ import ConfigParser as configparser
...
@@ -2,30 +2,30 @@ import ConfigParser as configparser
def
importConf
(
path_to_file
):
def
importConf
(
path_to_file
):
config
=
configparser
.
RawConfigParser
(
allow_no_value
=
False
)
config
=
configparser
.
RawConfigParser
(
allow_no_value
=
False
)
try
:
try
:
config
.
read
(
path_to_file
)
config
.
read
(
path_to_file
)
params
=
{}
params
=
{}
metrics
=
{}
metrics
=
{}
params
[
"debugMode"
]
=
config
.
get
(
"Client"
,
"Debug"
)
params
[
"debugMode"
]
=
config
.
get
(
"Client"
,
"Debug"
)
metrics
[
"cpu.usage"
]
=
int
(
config
.
get
(
"Metrics"
,
"cpuUsage"
))
metrics
[
"cpu.usage"
]
=
int
(
config
.
get
(
"Metrics"
,
"cpuUsage"
))
metrics
[
"memory.usage"
]
=
int
(
config
.
get
(
"Metrics"
,
"memoryUsage"
))
metrics
[
"memory.usage"
]
=
int
(
config
.
get
(
"Metrics"
,
"memoryUsage"
))
metrics
[
"user.count"
]
=
int
(
config
.
get
(
"Metrics"
,
"userCount"
))
metrics
[
"user.count"
]
=
int
(
config
.
get
(
"Metrics"
,
"userCount"
))
metrics
[
"swap.usage"
]
=
int
(
config
.
get
(
"Metrics"
,
"swapUsage"
))
metrics
[
"swap.usage"
]
=
int
(
config
.
get
(
"Metrics"
,
"swapUsage"
))
metrics
[
"system.boot_time"
]
=
int
(
config
.
get
(
"Metrics"
,
metrics
[
"system.boot_time"
]
=
int
(
config
.
get
(
"Metrics"
,
"systemBootTime"
))
"systemBootTime"
))
metrics
[
"network"
]
=
int
(
config
.
get
(
"Metrics"
,
"dataTraffic"
))
metrics
[
"network"
]
=
int
(
config
.
get
(
"Metrics"
,
"dataTraffic"
))
params
[
"kvmCpuUsage"
]
=
int
(
config
.
get
(
"KVM"
,
"cpuUsage"
))
params
[
"kvmCpuUsage"
]
=
int
(
config
.
get
(
"KVM"
,
"cpuUsage"
))
params
[
"kvmMemoryUsage"
]
=
int
(
config
.
get
(
"KVM"
,
"memoryUsage"
))
params
[
"kvmMemoryUsage"
]
=
int
(
config
.
get
(
"KVM"
,
"memoryUsage"
))
params
[
"kvmNetworkUsage"
]
=
int
(
config
.
get
(
"KVM"
,
"networkUsage"
))
params
[
"kvmNetworkUsage"
]
=
int
(
config
.
get
(
"KVM"
,
"networkUsage"
))
except
configparser
.
NoSectionError
:
except
configparser
.
NoSectionError
:
print
(
"Config file contains error! Reason: Missing section."
)
print
(
"Config file contains error! Reason: Missing section."
)
raise
raise
except
configparser
.
ParsingError
:
except
configparser
.
ParsingError
:
print
(
"Config file contains error! Reason: Cannot parse."
)
print
(
"Config file contains error! Reason: Cannot parse."
)
raise
raise
except
configparser
.
MissingSectionHeaderError
:
except
configparser
.
MissingSectionHeaderError
:
print
(
"Config file contains error! Reason: Missing section-header."
)
print
(
"Config file contains error! Reason: Missing section-header."
)
raise
raise
return
params
,
metrics
return
params
,
metrics
src/collectables.py
View file @
dd5f6fc0
...
@@ -2,45 +2,45 @@ from metrics import *
...
@@ -2,45 +2,45 @@ from metrics import *
class
collectables
:
class
collectables
:
__collectables
=
{
__collectables
=
{
std
.
cpu
.
usage
.
name
:
[
std
.
cpu
.
usage
],
std
.
cpu
.
usage
.
name
:
[
std
.
cpu
.
usage
],
std
.
memory
.
usage
.
name
:
[
std
.
memory
.
usage
],
std
.
memory
.
usage
.
name
:
[
std
.
memory
.
usage
],
std
.
swap
.
usage
.
name
:
[
std
.
swap
.
usage
],
std
.
swap
.
usage
.
name
:
[
std
.
swap
.
usage
],
std
.
user
.
count
.
name
:
[
std
.
user
.
count
],
std
.
user
.
count
.
name
:
[
std
.
user
.
count
],
std
.
network
.
packages_sent
.
name
:
[
std
.
network
.
packages_sent
],
std
.
network
.
packages_sent
.
name
:
[
std
.
network
.
packages_sent
],
std
.
network
.
packages_received
.
name
:
[
std
.
network
.
packages_received
],
std
.
network
.
packages_received
.
name
:
[
std
.
network
.
packages_received
],
std
.
network
.
bytes_sent
.
name
:
[
std
.
network
.
bytes_sent
],
std
.
network
.
bytes_sent
.
name
:
[
std
.
network
.
bytes_sent
],
std
.
network
.
bytes_received
.
name
:
[
std
.
network
.
bytes_received
],
std
.
network
.
bytes_received
.
name
:
[
std
.
network
.
bytes_received
],
std
.
system
.
boot_time
.
name
:
[
std
.
system
.
boot_time
],
std
.
system
.
boot_time
.
name
:
[
std
.
system
.
boot_time
],
"network"
:
[
std
.
network
.
bytes_sent
,
std
.
network
.
bytes_received
,
"network"
:
[
std
.
network
.
bytes_sent
,
std
.
network
.
bytes_received
,
std
.
network
.
packages_sent
,
std
.
network
.
packages_received
],
std
.
network
.
packages_sent
,
std
.
network
.
packages_received
],
}
}
@staticmethod
@staticmethod
def
listKeys
():
def
listKeys
():
return
list
(
collectables
.
__collectables
.
keys
())
return
list
(
collectables
.
__collectables
.
keys
())
@staticmethod
@staticmethod
def
listMetricsToKey
(
key
):
def
listMetricsToKey
(
key
):
return
collectables
.
__collectables
[
key
]
return
collectables
.
__collectables
[
key
]
@staticmethod
@staticmethod
def
listMetricsNameToKey
(
key
):
def
listMetricsNameToKey
(
key
):
return
[
x
.
name
for
x
in
collectables
.
__collectables
[
key
]]
return
[
x
.
name
for
x
in
collectables
.
__collectables
[
key
]]
@staticmethod
@staticmethod
def
provide
(
requests
=
[]):
def
provide
(
requests
=
[]):
#valid_keys = collectables.listKeys()
#valid_keys = collectables.listKeys()
reqs
=
[]
reqs
=
[]
for
requests
,
value
in
requests
.
items
():
for
requests
,
value
in
requests
.
items
():
if
value
>
0
:
if
value
>
0
:
reqs
.
append
([
requests
,
value
])
reqs
.
append
([
requests
,
value
])
collectors
=
[]
collectors
=
[]
for
request
in
reqs
:
for
request
in
reqs
:
for
item
in
collectables
.
__collectables
[
request
[
0
]]:
for
item
in
collectables
.
__collectables
[
request
[
0
]]:
collectors
.
append
([
item
.
harvest
,
request
[
1
]])
collectors
.
append
([
item
.
harvest
,
request
[
1
]])
return
collectors
return
collectors
@staticmethod
@staticmethod
def
provideAll
():
def
provideAll
():
return
collectables
.
provide
(
collectables
.
listKeys
())
return
collectables
.
provide
(
collectables
.
listKeys
())
src/metrics.py
View file @
dd5f6fc0
...
@@ -9,7 +9,9 @@ Metrics = collections.namedtuple("Metrics", ["name", "value"])
...
@@ -9,7 +9,9 @@ Metrics = collections.namedtuple("Metrics", ["name", "value"])
class
Collection
(
object
):
class
Collection
(
object
):
class
Group
(
object
):
class
Group
(
object
):
class
Metric
(
object
):
class
Metric
(
object
):
name
=
"unknown"
name
=
"unknown"
collector_function
=
0
collector_function
=
0
...
@@ -19,14 +21,14 @@ class Collection(object):
...
@@ -19,14 +21,14 @@ class Collection(object):
@classmethod
@classmethod
def
harvest
(
cls
):
def
harvest
(
cls
):
query
=
cls
.
collector_function
.
im_func
(
query
=
cls
.
collector_function
.
im_func
(
**
cls
.
collector_function_arguments
)
**
cls
.
collector_function_arguments
)
if
((
isinstance
(
query
,
list
))
or
(
isinstance
(
query
,
dict
))):
if
((
isinstance
(
query
,
list
))
or
(
isinstance
(
query
,
dict
))):
return
Metrics
(
cls
.
name
,
return
Metrics
(
cls
.
name
,
query
[
cls
.
collector_function_result_attr
])
query
[
cls
.
collector_function_result_attr
])
elif
(
isinstance
(
query
,
tuple
)):
elif
(
isinstance
(
query
,
tuple
)):
return
Metrics
(
cls
.
name
,
return
Metrics
(
cls
.
name
,
query
.
__getattribute__
(
query
.
__getattribute__
(
cls
.
collector_function_result_attr
))
cls
.
collector_function_result_attr
))
else
:
else
:
return
Metrics
(
cls
.
name
,
query
)
return
Metrics
(
cls
.
name
,
query
)
...
@@ -34,18 +36,21 @@ class Collection(object):
...
@@ -34,18 +36,21 @@ class Collection(object):
class
std
(
Collection
):
class
std
(
Collection
):
class
cpu
(
Collection
.
Group
):
class
cpu
(
Collection
.
Group
):
class
usage
(
Collection
.
Group
.
Metric
):
class
usage
(
Collection
.
Group
.
Metric
):
name
=
"cpu.usage"
name
=
"cpu.usage"
collector_function
=
ps
.
cpu_percent
collector_function
=
ps
.
cpu_percent
collector_function_arguments
=
{
collector_function_arguments
=
{
'interval'
:
0.0
,
'interval'
:
0.0
,
}
}
class
memory
(
Collection
.
Group
):
class
memory
(
Collection
.
Group
):
class
usage
(
Collection
.
Group
.
Metric
):
class
usage
(
Collection
.
Group
.
Metric
):
name
=
"memory.usage"
name
=
"memory.usage"
collector_function
=
ps
.
virtmem_usage
collector_function
=
ps
.
virtual_memory
collector_function_result_attr
=
"percent"
collector_function_result_attr
=
"percent"
class
swap
(
Collection
.
Group
):
class
swap
(
Collection
.
Group
):
...
@@ -86,4 +91,4 @@ class std(Collection):
...
@@ -86,4 +91,4 @@ class std(Collection):
class
system
(
Collection
.
Group
):
class
system
(
Collection
.
Group
):
class
boot_time
(
Collection
.
Group
.
Metric
):
class
boot_time
(
Collection
.
Group
.
Metric
):
name
=
"system.boot_time"
name
=
"system.boot_time"
collector_function
=
ps
.
get_boot_time
collector_function
=
ps
.
get_boot_time
\ No newline at end of file
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