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
11 years ago
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():
"""
)
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
.
startReporting
(
metricCollectors
=
collectables
.
collectables
.
provide
All
(
))
cli
.
startReporting
(
metricCollectors
=
collectables
.
collectables
.
provide
(
metrics
))
if
__name__
==
"__main__"
:
main
()
This diff is collapsed.
Click to expand it.
src/__pycache__/__init__.cpython-33.pyc
View file @
19408133
No preview for this file type
This diff is collapsed.
Click to expand it.
src/__pycache__/cnfparse.cpython-33.pyc
View file @
19408133
No preview for this file type
This diff is collapsed.
Click to expand it.
src/__pycache__/metrics.cpython-33.pyc
View file @
19408133
No preview for this file type
This diff is collapsed.
Click to expand it.
src/cnfparse.py
View file @
19408133
...
...
@@ -5,6 +5,7 @@ def importConf(path_to_file):
try
:
config
.
read
(
path_to_file
)
params
=
{}
metrics
=
{}
params
[
"frequency"
]
=
config
.
get
(
"Client"
,
"Frequency"
)
params
[
"debugMode"
]
=
config
.
get
(
"Client"
,
"Debug"
)
params
[
"server_address"
]
=
config
.
get
(
"Server"
,
"Address"
)
...
...
@@ -12,13 +13,13 @@ def importConf(path_to_file):
params
[
"amqp_queue"
]
=
config
.
get
(
"AMQP"
,
"Queue"
)
params
[
"amqp_user"
]
=
config
.
get
(
"AMQP"
,
"User"
)
params
[
"amqp_pass"
]
=
config
.
get
(
"AMQP"
,
"Pass"
)
param
s
[
"cpu.usage"
]
=
config
.
get
(
"Metrics"
,
"cpuUsage"
)
param
s
[
"memory.usage"
]
=
config
.
get
(
"Metrics"
,
"memoryUsage"
)
param
s
[
"user.count"
]
=
config
.
get
(
"Metrics"
,
"userCount"
)
param
s
[
"swap.usage"
]
=
config
.
get
(
"Metrics"
,
"swapUsage"
)
param
s
[
"system.boot_time"
]
=
config
.
get
(
"Metrics"
,
"systemBootTime"
)
param
s
[
"package.traffic"
]
=
config
.
get
(
"Metrics"
,
"packageTraffic"
)
param
s
[
"data.traffic"
]
=
config
.
get
(
"Metrics"
,
"dataTraffic"
)
metric
s
[
"cpu.usage"
]
=
config
.
get
(
"Metrics"
,
"cpuUsage"
)
metric
s
[
"memory.usage"
]
=
config
.
get
(
"Metrics"
,
"memoryUsage"
)
metric
s
[
"user.count"
]
=
config
.
get
(
"Metrics"
,
"userCount"
)
metric
s
[
"swap.usage"
]
=
config
.
get
(
"Metrics"
,
"swapUsage"
)
metric
s
[
"system.boot_time"
]
=
config
.
get
(
"Metrics"
,
"systemBootTime"
)
metric
s
[
"package.traffic"
]
=
config
.
get
(
"Metrics"
,
"packageTraffic"
)
metric
s
[
"data.traffic"
]
=
config
.
get
(
"Metrics"
,
"dataTraffic"
)
except
configparser
.
NoSectionError
:
print
(
"Config file contains error! Reason: Missing section."
)
raise
...
...
@@ -29,6 +30,6 @@ def importConf(path_to_file):
print
(
"Config file contains error! Reason: Missing section-header."
)
raise
return
params
return
params
,
metrics
This diff is collapsed.
Click to expand it.
src/collectables.py
View file @
19408133
from
metrics
import
*
class
collectables
:
class
collectables
:
__collectables
=
{
std
.
cpu
.
usage
.
name
:
[
std
.
cpu
.
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_received
.
name
:
[
std
.
network
.
packages_received
],
std
.
network
.
bytes_sent
.
name
:
[
std
.
network
.
bytes_sent
],
...
...
@@ -27,10 +28,12 @@ class collectables:
def
listMetricsNameToKey
(
key
):
return
[
x
.
name
for
x
in
collectables
.
__collectables
[
key
]]
@staticmethod
@staticmethod
def
provide
(
requests
=
[]):
valid_keys
=
collectables
.
listKeys
()
reqs
=
[
request
for
request
,
value
in
requests
.
items
()
if
value
==
"True"
]
collectors
=
[]
for
request
in
req
uest
s
:
for
request
in
reqs
:
for
item
in
collectables
.
__collectables
[
request
]:
collectors
.
append
(
item
.
harvest
)
seen
=
set
()
...
...
This diff is collapsed.
Click to expand it.
src/metrics.py
View file @
19408133
...
...
@@ -51,10 +51,10 @@ class std (Collection):
class
user
(
Collection
.
Group
):
class
count
(
Collection
.
Group
.
Metric
):
name
=
"user.count"
@staticmethod
def
harvest
():
return
Metrics
(
"user.count"
,
len
(
ps
.
get_users
()))
return
Metrics
(
std
.
user
.
count
.
name
,
len
(
ps
.
get_users
()))
class
network
(
Collection
.
Group
):
...
...
This diff is collapsed.
Click to expand it.
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