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
06f3a23d
Commit
06f3a23d
authored
4 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
send some guages
parent
10112aa7
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/cli.py
+29
-3
29 additions, 3 deletions
brian_polling_manager/cli.py
brian_polling_manager/interfaces.py
+16
-1
16 additions, 1 deletion
brian_polling_manager/interfaces.py
with
45 additions
and
4 deletions
brian_polling_manager/cli.py
+
29
−
3
View file @
06f3a23d
...
@@ -29,6 +29,7 @@ from typing import Union
...
@@ -29,6 +29,7 @@ from typing import Union
import
click
import
click
import
jsonschema
import
jsonschema
from
statsd
import
StatsClient
from
brian_polling_manager
import
inventory
,
interfaces
,
environment
from
brian_polling_manager
import
inventory
,
interfaces
,
environment
...
@@ -60,7 +61,12 @@ _DEFAULT_CONFIG = {
...
@@ -60,7 +61,12 @@ _DEFAULT_CONFIG = {
}
}
},
},
'
statedir
'
:
'
/tmp/
'
,
'
statedir
'
:
'
/tmp/
'
,
'
logging
'
:
environment
.
DEFAULT_LOGGING_FILENAME
'
logging
'
:
environment
.
DEFAULT_LOGGING_FILENAME
,
'
statsd
'
:
{
'
hostname
'
:
'
localhost
'
,
'
port
'
:
8125
,
'
prefix
'
:
'
brian_polling
'
}
}
}
CONFIG_SCHEMA
=
{
CONFIG_SCHEMA
=
{
...
@@ -102,6 +108,16 @@ CONFIG_SCHEMA = {
...
@@ -102,6 +108,16 @@ CONFIG_SCHEMA = {
},
},
'
required
'
:
[
'
api-base
'
,
'
token
'
,
'
interface-check
'
],
'
required
'
:
[
'
api-base
'
,
'
token
'
,
'
interface-check
'
],
'
additionalProperties
'
:
False
'
additionalProperties
'
:
False
},
'
statsd
'
:
{
'
type
'
:
'
object
'
,
'
properties
'
:
{
'
hostname
'
:
{
'
type
'
:
'
string
'
},
'
port
'
:
{
'
type
'
:
'
integer
'
},
'
prefix
'
:
{
'
type
'
:
'
string
'
}
},
'
required
'
:
[
'
hostname
'
,
'
port
'
,
'
prefix
'
],
'
additionalProperties
'
:
False
}
}
},
},
'
type
'
:
'
object
'
,
'
type
'
:
'
object
'
,
...
@@ -113,7 +129,8 @@ CONFIG_SCHEMA = {
...
@@ -113,7 +129,8 @@ CONFIG_SCHEMA = {
},
},
'
sensu
'
:
{
'
$ref
'
:
'
#/definitions/sensu
'
},
'
sensu
'
:
{
'
$ref
'
:
'
#/definitions/sensu
'
},
'
statedir
'
:
{
'
type
'
:
'
string
'
},
'
statedir
'
:
{
'
type
'
:
'
string
'
},
'
logging
'
:
{
'
type
'
:
'
string
'
}
'
logging
'
:
{
'
type
'
:
'
string
'
},
'
statsd
'
:
{
'
$ref
'
:
'
#/definitions/statsd
'
}
},
},
'
required
'
:
[
'
inventory
'
,
'
sensu
'
,
'
statedir
'
],
'
required
'
:
[
'
inventory
'
,
'
sensu
'
,
'
statedir
'
],
'
additionalProperties
'
:
False
'
additionalProperties
'
:
False
...
@@ -237,7 +254,16 @@ def main(config, force):
...
@@ -237,7 +254,16 @@ def main(config, force):
state
.
last
=
last
state
.
last
=
last
state
.
interfaces
=
inventory
.
load_interfaces
(
config
[
'
inventory
'
])
state
.
interfaces
=
inventory
.
load_interfaces
(
config
[
'
inventory
'
])
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
=
statsd_config
[
'
prefix
'
])
else
:
statsd
=
None
interfaces
.
refresh
(
config
[
'
sensu
'
],
state
,
statsd
=
statsd
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
brian_polling_manager/interfaces.py
+
16
−
1
View file @
06f3a23d
...
@@ -68,22 +68,37 @@ def _checks_match(a, b) -> bool:
...
@@ -68,22 +68,37 @@ def _checks_match(a, b) -> bool:
return
True
return
True
def
refresh
(
sensu_params
,
state
):
def
refresh
(
sensu_params
,
state
,
statsd
=
None
):
ifc_checks
=
load_ifc_checks
(
sensu_params
)
ifc_checks
=
load_ifc_checks
(
sensu_params
)
created
=
0
updated
=
0
interfaces
=
0
for
interface
in
state
.
interfaces
:
for
interface
in
state
.
interfaces
:
interfaces
+=
1
expected_check
=
_make_check
(
expected_check
=
_make_check
(
sensu_params
[
'
interface-check
'
],
interface
)
sensu_params
[
'
interface-check
'
],
interface
)
expected_name
=
_check_name
(
interface
)
expected_name
=
_check_name
(
interface
)
if
expected_name
not
in
ifc_checks
:
if
expected_name
not
in
ifc_checks
:
created
+=
1
sensu
.
create_check
(
sensu_params
,
expected_check
)
sensu
.
create_check
(
sensu_params
,
expected_check
)
elif
not
_checks_match
(
ifc_checks
[
expected_name
],
expected_check
):
elif
not
_checks_match
(
ifc_checks
[
expected_name
],
expected_check
):
updated
+=
1
sensu
.
update_check
(
sensu_params
,
expected_check
)
sensu
.
update_check
(
sensu_params
,
expected_check
)
wanted_checks
=
{
_check_name
(
ifc
)
for
ifc
in
state
.
interfaces
}
wanted_checks
=
{
_check_name
(
ifc
)
for
ifc
in
state
.
interfaces
}
extra_checks
=
set
(
ifc_checks
.
keys
())
-
wanted_checks
extra_checks
=
set
(
ifc_checks
.
keys
())
-
wanted_checks
for
name
in
extra_checks
:
for
name
in
extra_checks
:
sensu
.
delete_check
(
sensu_params
,
name
)
sensu
.
delete_check
(
sensu_params
,
name
)
if
statsd
:
statsd
.
guage
(
'
checks
'
,
len
(
ifc_checks
))
statsd
.
guage
(
'
interfaces
'
,
interfaces
)
statsd
.
guage
(
'
created
'
,
created
)
statsd
.
guage
(
'
updated
'
,
updated
)
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