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
6f9850a3
Commit
6f9850a3
authored
1 year ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
set timestamp when netconf doc is queried
parent
f1976945
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/interface_stats/cli.py
+20
-14
20 additions, 14 deletions
brian_polling_manager/interface_stats/cli.py
test/test_interface_stats.py
+3
-0
3 additions, 0 deletions
test/test_interface_stats.py
with
23 additions
and
14 deletions
brian_polling_manager/interface_stats/cli.py
+
20
−
14
View file @
6f9850a3
...
...
@@ -70,7 +70,7 @@ def setup_logging():
logging
.
config
.
dictConfig
(
logging_config
)
def
ctr2point
(
measurement
,
counters
):
def
ctr2point
(
measurement
,
timestamp
,
counters
):
"""
:param measurement: the measurement where the point will be written
...
...
@@ -83,12 +83,10 @@ def ctr2point(measurement, counters):
fields
=
dict
([
_k
,
_v
]
for
_k
,
_v
in
counters
.
items
()
if
not
_is_tag
(
_k
))
tags
=
dict
([
_k
,
_v
]
for
_k
,
_v
in
counters
.
items
()
if
_is_tag
(
_k
))
return
{
'
time
'
:
timestamp
.
strftime
(
'
%Y-%m-%dT%H:%M:%SZ
'
),
'
measurement
'
:
measurement
,
'
tags
'
:
tags
,
'
fields
'
:
fields
,
# TODO: let's set this at neconf query/response time
'
time
'
:
datetime
.
now
().
strftime
(
'
%Y-%m-%dT%H:%M:%SZ
'
),
}
...
...
@@ -108,29 +106,35 @@ def _managed_routers(inventory_base_urls):
def
fqdn_netconf_doc_map
(
app_config_params
):
_result
=
{}
for
fqdn
in
_managed_routers
(
inventory_base_urls
=
app_config_params
[
'
inventory
'
]):
_result
[
fqdn
]
=
juniper
.
get_interface_info_ncrpc
(
fqdn
)
_result
[
fqdn
]
=
{
'
timestamp
'
:
datetime
.
now
(),
'
doc
'
:
juniper
.
get_interface_info_ncrpc
(
fqdn
)
}
return
_result
def
_brian_points
(
router_fqdn
,
netconf_doc
,
measurement_name
):
def
_brian_points
(
router_fqdn
,
netconf_doc
,
timestamp
,
measurement_name
):
_ctr2point
=
partial
(
ctr2point
,
measurement_name
,
timestamp
)
interfaces
=
juniper
.
physical_interface_counters
(
netconf_doc
)
counters
=
brian
.
counters
(
router_fqdn
=
router_fqdn
,
interface_counters
=
interfaces
)
yield
from
map
(
partial
(
ctr2point
,
measurement_name
),
counters
)
yield
from
map
(
_
ctr2point
,
counters
)
interfaces
=
juniper
.
logical_interface_counters
(
netconf_doc
)
counters
=
brian
.
counters
(
router_fqdn
=
router_fqdn
,
interface_counters
=
interfaces
)
yield
from
map
(
partial
(
ctr2point
,
measurement_name
),
counters
)
yield
from
map
(
_ctr2point
,
counters
)
def
_error_points
(
router_fqdn
,
netconf_doc
,
timestamp
,
measurement_name
):
_ctr2point
=
partial
(
ctr2point
,
measurement_name
,
timestamp
)
def
_error_points
(
router_fqdn
,
netconf_doc
,
measurement_name
):
interfaces
=
juniper
.
physical_interface_counters
(
netconf_doc
)
counters
=
errors
.
counters
(
router_fqdn
=
router_fqdn
,
interface_counters
=
interfaces
)
yield
from
map
(
partial
(
ctr2point
,
measurement_name
),
counters
)
yield
from
map
(
_
ctr2point
,
counters
)
interfaces
=
juniper
.
logical_interface_counters
(
netconf_doc
)
counters
=
errors
.
counters
(
router_fqdn
=
router_fqdn
,
interface_counters
=
interfaces
)
yield
from
map
(
partial
(
ctr2point
,
measurement_name
),
counters
)
yield
from
map
(
_
ctr2point
,
counters
)
def
_main
(
app_config_params
:
dict
):
...
...
@@ -150,7 +154,8 @@ def _main(app_config_params: dict):
for
_fqdn
,
_ncdoc
in
nc_doc_map
.
items
():
points
=
_brian_points
(
router_fqdn
=
_fqdn
,
netconf_doc
=
_ncdoc
,
netconf_doc
=
_ncdoc
[
'
doc
'
],
timestamp
=
_ncdoc
[
'
timestamp
'
],
measurement_name
=
influx_params
[
'
measurement
'
])
with
contextlib
.
closing
(
influx
.
influx_client
(
influx_params
))
as
client
:
...
...
@@ -160,7 +165,8 @@ def _main(app_config_params: dict):
for
_fqdn
,
_ncdoc
in
nc_doc_map
.
items
():
points
=
_error_points
(
router_fqdn
=
_fqdn
,
netconf_doc
=
_ncdoc
,
netconf_doc
=
_ncdoc
[
'
doc
'
],
timestamp
=
_ncdoc
[
'
timestamp
'
],
measurement_name
=
influx_params
[
'
measurement
'
])
with
contextlib
.
closing
(
influx
.
influx_client
(
influx_params
))
as
client
:
...
...
This diff is collapsed.
Click to expand it.
test/test_interface_stats.py
+
3
−
0
View file @
6f9850a3
import
concurrent.futures
import
contextlib
import
datetime
import
itertools
import
json
import
logging
...
...
@@ -173,6 +174,7 @@ def test_brian_points(router_fqdn, ifc_netconf_rpc):
for
_p
in
cli
.
_brian_points
(
router_fqdn
=
router_fqdn
,
netconf_doc
=
juniper
.
get_interface_info_ncrpc
(
router_fqdn
),
timestamp
=
datetime
.
datetime
.
now
(),
measurement_name
=
'
blah
'
):
jsonschema
.
validate
(
_p
,
influx
.
INFLUX_POINT
)
assert
_p
[
'
fields
'
]
# any trivial points should already be filtered
...
...
@@ -183,6 +185,7 @@ def test_error_points(router_fqdn, ifc_netconf_rpc):
for
_p
in
cli
.
_error_points
(
router_fqdn
=
router_fqdn
,
netconf_doc
=
juniper
.
get_interface_info_ncrpc
(
router_fqdn
),
timestamp
=
datetime
.
datetime
.
now
(),
measurement_name
=
'
blah
'
):
jsonschema
.
validate
(
_p
,
influx
.
INFLUX_POINT
)
assert
_p
[
'
fields
'
]
# any trivial points should already be filtered
...
...
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