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
19408133
authored
Oct 09, 2013
by
Nagy Gergő
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored config file parser and client
parent
c5cc5350
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
20 additions
and
16 deletions
+20
-16
manage.py
+3
-3
src/__pycache__/__init__.cpython-33.pyc
+0
-0
src/__pycache__/cnfparse.cpython-33.pyc
+0
-0
src/__pycache__/metrics.cpython-33.pyc
+0
-0
src/cnfparse.py
+9
-8
src/collectables.py
+6
-3
src/metrics.py
+2
-2
No files found.
manage.py
View file @
19408133
...
@@ -14,11 +14,11 @@ def main():
...
@@ -14,11 +14,11 @@ def main():
"""
)
"""
)
if
(
len
(
sys
.
argv
)
==
2
and
sys
.
argv
[
1
]
==
"run"
):
if
(
len
(
sys
.
argv
)
==
2
and
sys
.
argv
[
1
]
==
"run"
):
configuration
=
cnfparse
.
importConf
(
"config/client.conf"
)
configuration
,
metrics
=
cnfparse
.
importConf
(
"config/client.conf"
)
cli
=
client
.
Client
(
configuration
)
cli
=
client
.
Client
(
configuration
)
cli
.
startReporting
(
metricCollectors
=
cli
.
startReporting
(
metricCollectors
=
collectables
.
collectables
.
provide
All
(
))
collectables
.
collectables
.
provide
(
metrics
))
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
main
()
main
()
src/__pycache__/__init__.cpython-33.pyc
View file @
19408133
No preview for this file type
src/__pycache__/cnfparse.cpython-33.pyc
View file @
19408133
No preview for this file type
src/__pycache__/metrics.cpython-33.pyc
View file @
19408133
No preview for this file type
src/cnfparse.py
View file @
19408133
...
@@ -5,6 +5,7 @@ def importConf(path_to_file):
...
@@ -5,6 +5,7 @@ def importConf(path_to_file):
try
:
try
:
config
.
read
(
path_to_file
)
config
.
read
(
path_to_file
)
params
=
{}
params
=
{}
metrics
=
{}
params
[
"frequency"
]
=
config
.
get
(
"Client"
,
"Frequency"
)
params
[
"frequency"
]
=
config
.
get
(
"Client"
,
"Frequency"
)
params
[
"debugMode"
]
=
config
.
get
(
"Client"
,
"Debug"
)
params
[
"debugMode"
]
=
config
.
get
(
"Client"
,
"Debug"
)
params
[
"server_address"
]
=
config
.
get
(
"Server"
,
"Address"
)
params
[
"server_address"
]
=
config
.
get
(
"Server"
,
"Address"
)
...
@@ -12,13 +13,13 @@ def importConf(path_to_file):
...
@@ -12,13 +13,13 @@ def importConf(path_to_file):
params
[
"amqp_queue"
]
=
config
.
get
(
"AMQP"
,
"Queue"
)
params
[
"amqp_queue"
]
=
config
.
get
(
"AMQP"
,
"Queue"
)
params
[
"amqp_user"
]
=
config
.
get
(
"AMQP"
,
"User"
)
params
[
"amqp_user"
]
=
config
.
get
(
"AMQP"
,
"User"
)
params
[
"amqp_pass"
]
=
config
.
get
(
"AMQP"
,
"Pass"
)
params
[
"amqp_pass"
]
=
config
.
get
(
"AMQP"
,
"Pass"
)
param
s
[
"cpu.usage"
]
=
config
.
get
(
"Metrics"
,
"cpuUsage"
)
metric
s
[
"cpu.usage"
]
=
config
.
get
(
"Metrics"
,
"cpuUsage"
)
param
s
[
"memory.usage"
]
=
config
.
get
(
"Metrics"
,
"memoryUsage"
)
metric
s
[
"memory.usage"
]
=
config
.
get
(
"Metrics"
,
"memoryUsage"
)
param
s
[
"user.count"
]
=
config
.
get
(
"Metrics"
,
"userCount"
)
metric
s
[
"user.count"
]
=
config
.
get
(
"Metrics"
,
"userCount"
)
param
s
[
"swap.usage"
]
=
config
.
get
(
"Metrics"
,
"swapUsage"
)
metric
s
[
"swap.usage"
]
=
config
.
get
(
"Metrics"
,
"swapUsage"
)
param
s
[
"system.boot_time"
]
=
config
.
get
(
"Metrics"
,
"systemBootTime"
)
metric
s
[
"system.boot_time"
]
=
config
.
get
(
"Metrics"
,
"systemBootTime"
)
param
s
[
"package.traffic"
]
=
config
.
get
(
"Metrics"
,
"packageTraffic"
)
metric
s
[
"package.traffic"
]
=
config
.
get
(
"Metrics"
,
"packageTraffic"
)
param
s
[
"data.traffic"
]
=
config
.
get
(
"Metrics"
,
"dataTraffic"
)
metric
s
[
"data.traffic"
]
=
config
.
get
(
"Metrics"
,
"dataTraffic"
)
except
configparser
.
NoSectionError
:
except
configparser
.
NoSectionError
:
print
(
"Config file contains error! Reason: Missing section."
)
print
(
"Config file contains error! Reason: Missing section."
)
raise
raise
...
@@ -29,6 +30,6 @@ def importConf(path_to_file):
...
@@ -29,6 +30,6 @@ def importConf(path_to_file):
print
(
"Config file contains error! Reason: Missing section-header."
)
print
(
"Config file contains error! Reason: Missing section-header."
)
raise
raise
return
params
return
params
,
metrics
src/collectables.py
View file @
19408133
from
metrics
import
*
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
.
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
],
...
@@ -27,10 +28,12 @@ class collectables:
...
@@ -27,10 +28,12 @@ class collectables:
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
()
reqs
=
[
request
for
request
,
value
in
requests
.
items
()
if
value
==
"True"
]
collectors
=
[]
collectors
=
[]
for
request
in
req
uest
s
:
for
request
in
reqs
:
for
item
in
collectables
.
__collectables
[
request
]:
for
item
in
collectables
.
__collectables
[
request
]:
collectors
.
append
(
item
.
harvest
)
collectors
.
append
(
item
.
harvest
)
seen
=
set
()
seen
=
set
()
...
...
src/metrics.py
View file @
19408133
...
@@ -51,10 +51,10 @@ class std (Collection):
...
@@ -51,10 +51,10 @@ class std (Collection):
class
user
(
Collection
.
Group
):
class
user
(
Collection
.
Group
):
class
count
(
Collection
.
Group
.
Metric
):
class
count
(
Collection
.
Group
.
Metric
):
name
=
"user.count"
@staticmethod
@staticmethod
def
harvest
():
def
harvest
():
return
Metrics
(
"user.count"
,
len
(
ps
.
get_users
()))
return
Metrics
(
std
.
user
.
count
.
name
,
len
(
ps
.
get_users
()))
class
network
(
Collection
.
Group
):
class
network
(
Collection
.
Group
):
...
...
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