Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
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
c5cc5350
authored
Oct 09, 2013
by
Nagy Gergő
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored client.
parent
3dafc1a1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
49 deletions
+58
-49
src/__pycache__/metrics.cpython-33.pyc
+0
-0
src/collectables.py
+18
-14
src/metrics.py
+40
-35
No files found.
src/__pycache__/metrics.cpython-33.pyc
View file @
c5cc5350
No preview for this file type
src/collectables.py
View file @
c5cc5350
...
@@ -3,28 +3,32 @@ from metrics import *
...
@@ -3,28 +3,32 @@ from metrics import *
class
collectables
:
class
collectables
:
__collectables
=
{
__collectables
=
{
"cpu.usage"
:
[
std
.
cpu
.
usage
],
std
.
cpu
.
usage
.
name
:
[
std
.
cpu
.
usage
],
"memory.usage"
:
[
std
.
memory
.
usage
],
std
.
memory
.
usage
.
name
:
[
std
.
memory
.
usage
],
"network.packages_sent"
:
[
std
.
network
.
packages_sent
],
std
.
network
.
packages_sent
.
name
:
[
std
.
network
.
packages_sent
],
"network.packages_received"
:
[
std
.
network
.
packages_received
],
std
.
network
.
packages_received
.
name
:
[
std
.
network
.
packages_received
],
"network.bytes_sent"
:
[
std
.
network
.
bytes_sent
],
std
.
network
.
bytes_sent
.
name
:
[
std
.
network
.
bytes_sent
],
"network.bytes_received"
:
[
std
.
network
.
bytes_received
],
std
.
network
.
bytes_received
.
name
:
[
std
.
network
.
bytes_received
],
"network"
:
[
std
.
network
.
bytes_sent
,
"network"
:
[
std
.
network
.
bytes_sent
,
std
.
network
.
bytes_received
,
std
.
network
.
bytes_received
,
std
.
network
.
packages_sent
,
std
.
network
.
packages_sent
,
std
.
network
.
packages_received
],
std
.
network
.
packages_received
],
}
}
@staticmethod
@staticmethod
def
list
():
def
list
Keys
():
return
list
(
collectables
.
__collectables
.
keys
())
return
list
(
collectables
.
__collectables
.
keys
())
@staticmethod
@staticmethod
def
keyToSet
(
key
):
def
listMetricsToKey
(
key
):
return
collectables
.
__collectables
[
key
]
return
collectables
.
__collectables
[
key
]
@staticmethod
@staticmethod
def
provide
(
requests
=
[]):
def
listMetricsNameToKey
(
key
):
return
[
x
.
name
for
x
in
collectables
.
__collectables
[
key
]]
@staticmethod
def
provide
(
requests
=
[]):
collectors
=
[]
collectors
=
[]
for
request
in
requests
:
for
request
in
requests
:
for
item
in
collectables
.
__collectables
[
request
]:
for
item
in
collectables
.
__collectables
[
request
]:
...
@@ -35,6 +39,6 @@ class collectables:
...
@@ -35,6 +39,6 @@ class collectables:
@staticmethod
@staticmethod
def
provideAll
():
def
provideAll
():
return
collectables
.
provide
(
collectables
.
list
())
return
collectables
.
provide
(
collectables
.
list
Keys
())
src/metrics.py
View file @
c5cc5350
...
@@ -7,34 +7,45 @@ import collections
...
@@ -7,34 +7,45 @@ import collections
Metrics
=
collections
.
namedtuple
(
"Metrics"
,
[
"name"
,
"value"
])
Metrics
=
collections
.
namedtuple
(
"Metrics"
,
[
"name"
,
"value"
])
class
Collection
(
object
):
class
Collection
(
object
):
class
Group
(
object
):
class
Group
(
object
):
class
Metric
(
object
):
name
=
"unknown"
collector_function
=
0
collector_function_arguments
=
{}
collector_function_result_attr
=
""
@classmethod
def
harvest
(
cls
):
query
=
cls
.
collector_function
(
**
cls
.
collector_function_arguments
)
if
((
isinstance
(
query
,
list
))
or
(
isinstance
(
query
,
dict
))):
return
Metrics
(
cls
.
name
,
query
[
cls
.
collector_function_result_attr
])
elif
(
isinstance
(
query
,
tuple
)):
return
Metrics
(
cls
.
name
,
query
.
__getattribute__
(
cls
.
collector_function_result_attr
))
else
:
return
Metrics
(
cls
.
name
,
query
)
class
Metric
(
object
):
@staticmethod
def
harvest
():
raise
NotImplementedError
(
"You must implement the harvest method."
)
####################################################################################
####################################################################################
class
std
(
Collection
):
class
std
(
Collection
):
class
cpu
(
Collection
.
Group
):
class
cpu
(
Collection
.
Group
):
class
usage
(
Collection
.
Group
.
Metric
):
class
usage
(
Collection
.
Group
.
Metric
):
collector_function
=
ps
.
cpu_percent
@staticmethod
collector_function_arguments
=
{
def
harvest
():
'interval'
:
0
,
return
Metrics
(
"cpu.usage"
,
ps
.
cpu_percent
(
0
))
}
name
=
"cpu.usage"
class
memory
(
Collection
.
Group
):
class
memory
(
Collection
.
Group
):
class
usage
(
Collection
.
Group
.
Metric
):
class
usage
(
Collection
.
Group
.
Metric
):
name
=
"memory.usage"
@staticmethod
collector_function
=
ps
.
virtmem_usage
def
harvest
():
collector_function_result_attr
=
"percent"
return
Metrics
(
"memory.usage"
,
ps
.
virtmem_usage
()
.
percent
)
class
user
(
Collection
.
Group
):
class
user
(
Collection
.
Group
):
...
@@ -48,33 +59,27 @@ class std (Collection):
...
@@ -48,33 +59,27 @@ class std (Collection):
class
network
(
Collection
.
Group
):
class
network
(
Collection
.
Group
):
class
packages_sent
(
Collection
.
Group
.
Metric
):
class
packages_sent
(
Collection
.
Group
.
Metric
):
name
=
"network.packages_sent"
@staticmethod
collector_function
=
ps
.
network_io_counters
def
harvest
():
collector_function_result_attr
=
"packets_sent"
return
Metrics
(
"network.packages_sent"
,
ps
.
network_io_counters
()
.
packets_sent
)
class
packages_received
(
Collection
.
Group
.
Metric
):
class
packages_received
(
Collection
.
Group
.
Metric
):
name
=
"network.packages_received"
@staticmethod
collector_function
=
ps
.
network_io_counters
def
harvest
():
collector_function_result_attr
=
"packets_recv"
return
Metrics
(
"network.packages_received"
,
ps
.
network_io_counters
()
.
packets_recv
)
class
bytes_sent
(
Collection
.
Group
.
Metric
):
class
bytes_sent
(
Collection
.
Group
.
Metric
):
name
=
"network.bytes_sent"
@staticmethod
collector_function
=
ps
.
network_io_counters
def
harvest
():
collector_function_result_attr
=
"bytes_sent"
return
Metrics
(
"network.bytes_sent"
,
ps
.
network_io_counters
()
.
bytes_sent
)
class
bytes_received
(
Collection
.
Group
.
Metric
):
class
bytes_received
(
Collection
.
Group
.
Metric
):
name
=
"network.bytes_received"
@staticmethod
collector_function
=
ps
.
network_io_counters
def
harvest
():
collector_function_result_attr
=
"bytes_recv"
return
Metrics
(
"network.bytes_recv"
,
ps
.
network_io_counters
()
.
bytes_recv
)
class
system
(
Collection
.
Group
):
class
system
(
Collection
.
Group
):
class
boot_time
(
Collection
.
Group
.
Metric
):
class
boot_time
(
Collection
.
Group
.
Metric
):
name
=
"system.boot_time"
@staticmethod
collector_function
=
ps
.
get_boot_time
def
harvest
():
return
Metrics
(
"system.boot_time"
,
ps
.
get_boot_time
())
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