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
c90bae3d
authored
Feb 16, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix flake8 errors
parent
dd5f6fc0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
84 deletions
+80
-84
manage.py
+10
-10
src/collectables.py
+1
-1
src/metrics.py
+69
-73
No files found.
manage.py
View file @
c90bae3d
...
...
@@ -3,18 +3,18 @@ from src import cnfparse, client, collectables
def
main
():
if
len
(
sys
.
argv
)
<
2
:
print
(
"usage: manage.py run [options]"
)
if
len
(
sys
.
argv
)
<
2
:
print
(
"usage: manage.py run [options]"
)
if
len
(
sys
.
argv
)
is
not
2
and
sys
.
argv
[
1
]
is
not
"run"
:
print
(
"[ERROR] Command cannot be parsed. Exiting..."
)
return
if
len
(
sys
.
argv
)
is
not
2
and
sys
.
argv
[
1
]
is
not
"run"
:
print
(
"[ERROR] Command cannot be parsed. Exiting..."
)
return
configuration
,
metrics
=
cnfparse
.
importConf
(
"config/client.conf"
)
cli
=
client
.
Client
(
configuration
)
cli
.
startReporting
(
metricCollectors
=
collectables
.
collectables
.
provide
(
metrics
))
configuration
,
metrics
=
cnfparse
.
importConf
(
"config/client.conf"
)
cli
=
client
.
Client
(
configuration
)
cli
.
startReporting
(
metricCollectors
=
collectables
.
collectables
.
provide
(
metrics
))
if
__name__
==
"__main__"
:
main
()
main
()
src/collectables.py
View file @
c90bae3d
from
metrics
import
*
from
metrics
import
std
class
collectables
:
...
...
src/metrics.py
View file @
c90bae3d
...
...
@@ -10,85 +10,81 @@ 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
.
im_func
(
**
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
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
.
im_func
(
**
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
std
(
Collection
):
class
cpu
(
Collection
.
Group
):
class
cpu
(
Collection
.
Group
):
class
usage
(
Collection
.
Group
.
Metric
):
name
=
"cpu.usage"
collector_function
=
ps
.
cpu_percent
collector_function_arguments
=
{
'interval'
:
0.0
,
}
class
usage
(
Collection
.
Group
.
Metric
):
name
=
"cpu.usage"
collector_function
=
ps
.
cpu_percent
collector_function_arguments
=
{
'interval'
:
0.0
}
class
memory
(
Collection
.
Group
):
class
usage
(
Collection
.
Group
.
Metric
):
name
=
"memory.usage"
class
memory
(
Collection
.
Group
):
class
usage
(
Collection
.
Group
.
Metric
):
name
=
"memory.usage"
collector_function
=
ps
.
virtual_memory
collector_function_result_attr
=
"percent"
class
swap
(
Collection
.
Group
):
class
usage
(
Collection
.
Group
.
Metric
):
name
=
"swap.usage"
collector_function
=
ps
.
swap_memory
collector_function_result_attr
=
"percent"
class
user
(
Collection
.
Group
):
class
count
(
Collection
.
Group
.
Metric
):
name
=
"user.count"
@classmethod
def
harvest
(
cls
):
return
Metrics
(
cls
.
name
,
len
(
ps
.
get_users
()))
class
network
(
Collection
.
Group
):
class
packages_sent
(
Collection
.
Group
.
Metric
):
name
=
"network.packages_sent"
collector_function
=
ps
.
network_io_counters
collector_function_result_attr
=
"packets_sent"
class
packages_received
(
Collection
.
Group
.
Metric
):
name
=
"network.packages_received"
collector_function
=
ps
.
network_io_counters
collector_function_result_attr
=
"packets_recv"
class
bytes_sent
(
Collection
.
Group
.
Metric
):
name
=
"network.bytes_sent"
collector_function
=
ps
.
network_io_counters
collector_function_result_attr
=
"bytes_sent"
class
bytes_received
(
Collection
.
Group
.
Metric
):
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
):
name
=
"system.boot_time"
collector_function
=
ps
.
get_boot_time
collector_function_result_attr
=
"percent"
class
swap
(
Collection
.
Group
):
class
usage
(
Collection
.
Group
.
Metric
):
name
=
"swap.usage"
collector_function
=
ps
.
swap_memory
collector_function_result_attr
=
"percent"
class
user
(
Collection
.
Group
):
class
count
(
Collection
.
Group
.
Metric
):
name
=
"user.count"
@classmethod
def
harvest
(
cls
):
return
Metrics
(
cls
.
name
,
len
(
ps
.
get_users
()))
class
network
(
Collection
.
Group
):
class
packages_sent
(
Collection
.
Group
.
Metric
):
name
=
"network.packages_sent"
collector_function
=
ps
.
network_io_counters
collector_function_result_attr
=
"packets_sent"
class
packages_received
(
Collection
.
Group
.
Metric
):
name
=
"network.packages_received"
collector_function
=
ps
.
network_io_counters
collector_function_result_attr
=
"packets_recv"
class
bytes_sent
(
Collection
.
Group
.
Metric
):
name
=
"network.bytes_sent"
collector_function
=
ps
.
network_io_counters
collector_function_result_attr
=
"bytes_sent"
class
bytes_received
(
Collection
.
Group
.
Metric
):
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
):
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