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
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
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 *
class
collectables
:
__collectables
=
{
"cpu.usage"
:
[
std
.
cpu
.
usage
],
"memory.usage"
:
[
std
.
memory
.
usage
],
"network.packages_sent"
:
[
std
.
network
.
packages_sent
],
"network.packages_received"
:
[
std
.
network
.
packages_received
],
"network.bytes_sent"
:
[
std
.
network
.
bytes_sent
],
"network.bytes_received"
:
[
std
.
network
.
bytes_received
],
"network"
:
[
std
.
network
.
bytes_sent
,
std
.
network
.
bytes_received
,
std
.
network
.
packages_sent
,
std
.
network
.
packages_received
],
std
.
cpu
.
usage
.
name
:
[
std
.
cpu
.
usage
],
std
.
memory
.
usage
.
name
:
[
std
.
memory
.
usage
],
std
.
network
.
packages_sent
.
name
:
[
std
.
network
.
packages_sent
],
std
.
network
.
packages_received
.
name
:
[
std
.
network
.
packages_received
],
std
.
network
.
bytes_sent
.
name
:
[
std
.
network
.
bytes_sent
],
std
.
network
.
bytes_received
.
name
:
[
std
.
network
.
bytes_received
],
"network"
:
[
std
.
network
.
bytes_sent
,
std
.
network
.
bytes_received
,
std
.
network
.
packages_sent
,
std
.
network
.
packages_received
],
}
@staticmethod
def
list
():
def
list
Keys
():
return
list
(
collectables
.
__collectables
.
keys
())
@staticmethod
def
keyToSet
(
key
):
def
listMetricsToKey
(
key
):
return
collectables
.
__collectables
[
key
]
@staticmethod
def
provide
(
requests
=
[]):
def
listMetricsNameToKey
(
key
):
return
[
x
.
name
for
x
in
collectables
.
__collectables
[
key
]]
@staticmethod
def
provide
(
requests
=
[]):
collectors
=
[]
for
request
in
requests
:
for
item
in
collectables
.
__collectables
[
request
]:
...
...
@@ -35,6 +39,6 @@ class collectables:
@staticmethod
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
Metrics
=
collections
.
namedtuple
(
"Metrics"
,
[
"name"
,
"value"
])
class
Collection
(
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
cpu
(
Collection
.
Group
):
class
usage
(
Collection
.
Group
.
Metric
):
@staticmethod
def
harvest
():
return
Metrics
(
"cpu.usage"
,
ps
.
cpu_percent
(
0
))
collector_function
=
ps
.
cpu_percent
collector_function_arguments
=
{
'interval'
:
0
,
}
name
=
"cpu.usage"
class
memory
(
Collection
.
Group
):
class
usage
(
Collection
.
Group
.
Metric
):
@staticmethod
def
harvest
():
return
Metrics
(
"memory.usage"
,
ps
.
virtmem_usage
()
.
percent
)
name
=
"memory.usage"
collector_function
=
ps
.
virtmem_usage
collector_function_result_attr
=
"percent"
class
user
(
Collection
.
Group
):
...
...
@@ -48,33 +59,27 @@ class std (Collection):
class
network
(
Collection
.
Group
):
class
packages_sent
(
Collection
.
Group
.
Metric
):
@staticmethod
def
harvest
():
return
Metrics
(
"network.packages_sent"
,
ps
.
network_io_counters
()
.
packets_sent
)
name
=
"network.packages_sent"
collector_function
=
ps
.
network_io_counters
collector_function_result_attr
=
"packets_sent"
class
packages_received
(
Collection
.
Group
.
Metric
):
@staticmethod
def
harvest
():
return
Metrics
(
"network.packages_received"
,
ps
.
network_io_counters
()
.
packets_recv
)
name
=
"network.packages_received"
collector_function
=
ps
.
network_io_counters
collector_function_result_attr
=
"packets_recv"
class
bytes_sent
(
Collection
.
Group
.
Metric
):
@staticmethod
def
harvest
():
return
Metrics
(
"network.bytes_sent"
,
ps
.
network_io_counters
()
.
bytes_sent
)
name
=
"network.bytes_sent"
collector_function
=
ps
.
network_io_counters
collector_function_result_attr
=
"bytes_sent"
class
bytes_received
(
Collection
.
Group
.
Metric
):
@staticmethod
def
harvest
():
return
Metrics
(
"network.bytes_recv"
,
ps
.
network_io_counters
()
.
bytes_recv
)
name
=
"network.bytes_received"
collector_function
=
ps
.
network_io_counters
collector_function_result_attr
=
"bytes_recv"
class
system
(
Collection
.
Group
):
class
boot_time
(
Collection
.
Group
.
Metric
):
@staticmethod
def
harvest
():
return
Metrics
(
"system.boot_time"
,
ps
.
get_boot_time
())
name
=
"system.boot_time"
collector_function
=
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