Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
brian-polling-manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
brian
brian-polling-manager
Commits
20acf019
Commit
20acf019
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
refactor statsd usage a bit
parent
06c478c0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
brian_polling_manager/interfaces.py
+8
-7
8 additions, 7 deletions
brian_polling_manager/interfaces.py
brian_polling_manager/main.py
+31
-17
31 additions, 17 deletions
brian_polling_manager/main.py
with
39 additions
and
24 deletions
brian_polling_manager/interfaces.py
+
8
−
7
View file @
20acf019
...
...
@@ -70,7 +70,7 @@ def _checks_match(a, b) -> bool:
return
True
def
refresh
(
sensu_params
,
state
,
statsd
=
None
):
def
refresh
(
sensu_params
,
state
):
ifc_checks
=
load_ifc_checks
(
sensu_params
)
...
...
@@ -97,9 +97,10 @@ def refresh(sensu_params, state, statsd=None):
for
name
in
extra_checks
:
sensu
.
delete_check
(
sensu_params
,
name
)
if
statsd
:
statsd
.
gauge
(
'
checks
'
,
len
(
ifc_checks
))
statsd
.
gauge
(
'
interfaces
'
,
interfaces
)
statsd
.
gauge
(
'
checks_created
'
,
created
)
statsd
.
gauge
(
'
checks_updated
'
,
updated
)
statsd
.
gauge
(
'
checks_deleted
'
,
len
(
extra_checks
))
return
{
'
checks
'
:
len
(
ifc_checks
),
'
input
'
:
interfaces
,
'
created
'
:
created
,
'
updated
'
:
updated
,
'
deleted
'
:
len
(
extra_checks
)
}
This diff is collapsed.
Click to expand it.
brian_polling_manager/main.py
+
31
−
17
View file @
20acf019
...
...
@@ -34,6 +34,36 @@ from brian_polling_manager import inventory, interfaces, configuration
logger
=
logging
.
getLogger
(
__name__
)
def
refresh
(
config
,
force
=
False
):
"""
reload inventory data & update sensu checks
:param config: a dict returned by configuration.load_config
:param force: if True, reload inventory data even if timestamp is same
:return:
"""
state
=
configuration
.
State
(
config
[
'
statedir
'
])
last
=
inventory
.
last_update_timestamp
(
config
[
'
inventory
'
])
if
force
or
not
last
or
last
!=
state
.
last
:
state
.
last
=
last
state
.
interfaces
=
inventory
.
load_interfaces
(
config
[
'
inventory
'
])
result
=
interfaces
.
refresh
(
config
[
'
sensu
'
],
state
)
statsd_config
=
config
.
get
(
'
statsd
'
,
None
)
if
statsd_config
:
statsd
=
StatsClient
(
host
=
statsd_config
[
'
hostname
'
],
port
=
statsd_config
[
'
port
'
],
prefix
=
f
'
{
statsd_config
[
"
prefix
"
]
}
_interfaces
'
)
statsd
.
gauge
(
'
checks
'
,
result
[
'
checks
'
])
statsd
.
gauge
(
'
input
'
,
result
[
'
input
'
])
statsd
.
gauge
(
'
created
'
,
result
[
'
created
'
])
statsd
.
gauge
(
'
updated
'
,
result
[
'
updated
'
])
statsd
.
gauge
(
'
deleted
'
,
result
[
'
deleted
'
])
return
statsd_config
def
_validate_config
(
_ctx
,
_param
,
file
):
"""
loads, validates and returns configuration parameters
...
...
@@ -65,23 +95,7 @@ def cli(config, force):
"""
Update BRIAN snmp checks based on Inventory Provider data.
"""
state
=
configuration
.
State
(
config
[
'
statedir
'
])
last
=
inventory
.
last_update_timestamp
(
config
[
'
inventory
'
])
if
force
or
not
last
or
last
!=
state
.
last
:
state
.
last
=
last
state
.
interfaces
=
inventory
.
load_interfaces
(
config
[
'
inventory
'
])
statsd_config
=
config
.
get
(
'
statsd
'
,
None
)
if
statsd_config
:
statsd
=
StatsClient
(
host
=
statsd_config
[
'
hostname
'
],
port
=
statsd_config
[
'
port
'
],
prefix
=
statsd_config
[
'
prefix
'
])
else
:
statsd
=
None
interfaces
.
refresh
(
config
[
'
sensu
'
],
state
,
statsd
=
statsd
)
refresh
(
config
,
force
)
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment