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
ae803b41
Commit
ae803b41
authored
1 year ago
by
Pelle Koster
Browse files
Options
Downloads
Patches
Plain Diff
improve and prettify logging for get-^Cterface-stats
parent
c8a84f9e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
brian_polling_manager/interface_stats/cli.py
+53
-20
53 additions, 20 deletions
brian_polling_manager/interface_stats/cli.py
with
53 additions
and
20 deletions
brian_polling_manager/interface_stats/cli.py
+
53
−
20
View file @
ae803b41
...
...
@@ -3,7 +3,7 @@ import logging.config
import
os
import
socket
from
datetime
import
datetime
from
typing
import
Iterable
,
List
from
typing
import
Iterable
,
List
,
Sequence
import
click
import
jsonschema
...
...
@@ -22,23 +22,18 @@ logger = logging.getLogger(__file__)
LOGGING_DEFAULT_CONFIG
=
{
"
version
"
:
1
,
"
disable_existing_loggers
"
:
False
,
"
formatters
"
:
{
"
simple
"
:
{
"
format
"
:
"
%(asctime)s - %(name)s
"
"
(%(lineno)d) - %(levelname)s - %(message)s
"
}
},
"
formatters
"
:
{
"
simple
"
:
{
"
format
"
:
"
%(asctime)s - %(levelname)s - %(message)s
"
}},
"
handlers
"
:
{
"
console
"
:
{
"
class
"
:
"
logging.StreamHandler
"
,
"
level
"
:
"
DEBUG
"
,
"
level
"
:
"
INFO
"
,
"
formatter
"
:
"
simple
"
,
"
stream
"
:
"
ext://sys.stdout
"
,
},
},
"
loggers
"
:
{
"
brian_polling_manager
"
:
{
"
level
"
:
"
DEBUG
"
,
"
level
"
:
"
INFO
"
,
"
handlers
"
:
[
"
console
"
],
"
propagate
"
:
False
,
}
...
...
@@ -62,6 +57,17 @@ def setup_logging():
if LOGGING_CONFIG is defined in the environment, use this for
the filename, otherwise use LOGGING_DEFAULT_CONFIG
"""
# demote ncclient logs
def
changeLevel
(
record
):
if
record
.
levelno
==
logging
.
INFO
:
record
.
levelno
=
logging
.
DEBUG
record
.
levelname
=
"
DEBUG
"
return
record
logging
.
getLogger
(
"
ncclient.transport.ssh
"
).
addFilter
(
changeLevel
)
logging
.
getLogger
(
"
ncclient.operations.rpc
"
).
addFilter
(
changeLevel
)
logging_config
=
LOGGING_DEFAULT_CONFIG
if
"
LOGGING_CONFIG
"
in
os
.
environ
:
filename
=
os
.
environ
[
"
LOGGING_CONFIG
"
]
...
...
@@ -141,31 +147,58 @@ def process_juniper_router(
router_fqdn
:
str
,
all_influx_params
:
dict
,
):
logger
.
info
(
f
"
p
rocessing Juniper router
{
router_fqdn
}
"
)
logger
.
info
(
f
"
P
rocessing Juniper router
{
router_fqdn
}
"
)
document
=
get_netconf
(
router_fqdn
,
vendor
=
Vendor
.
JUNIPER
)
timestamp
=
datetime
.
now
()
influx_params
=
all_influx_params
[
"
brian-counters
"
]
points
=
_juniper_brian_points
(
router_fqdn
=
router_fqdn
,
netconf_doc
=
document
,
timestamp
=
timestamp
,
measurement_name
=
influx_params
[
"
measurement
"
],
logger
.
info
(
"
Processing Brian points...
"
)
points
=
list
(
_juniper_brian_points
(
router_fqdn
=
router_fqdn
,
netconf_doc
=
document
,
timestamp
=
timestamp
,
measurement_name
=
influx_params
[
"
measurement
"
],
)
)
_log_interface_points_sorted
(
points
)
write_points
(
points
,
influx_params
=
influx_params
)
influx_params
=
all_influx_params
[
"
error-counters
"
]
points
=
_juniper_error_points
(
router_fqdn
=
router_fqdn
,
netconf_doc
=
document
,
timestamp
=
timestamp
,
measurement_name
=
influx_params
[
"
measurement
"
],
logger
.
info
(
"
Processing Error points...
"
)
points
=
list
(
_juniper_error_points
(
router_fqdn
=
router_fqdn
,
netconf_doc
=
document
,
timestamp
=
timestamp
,
measurement_name
=
influx_params
[
"
measurement
"
],
)
)
_log_interface_points_sorted
(
points
,
point_kind
=
'
error
'
)
write_points
(
points
,
influx_params
=
influx_params
)
def
_log_interface_points_sorted
(
points
:
Sequence
[
dict
],
point_kind
=
""
):
N_COLUMNS
=
5
num_points
=
len
(
points
)
point_kind
=
point_kind
+
"
"
if
point_kind
else
""
semicolon
=
'
:
'
if
num_points
else
''
logger
.
info
(
f
"
Found
{
point_kind
}
points for
{
num_points
}
interfaces
{
semicolon
}
"
)
if
not
points
:
return
interfaces
=
sorted
(
p
[
"
tags
"
][
"
interface_name
"
]
for
p
in
points
)
longest_ifc
=
max
(
len
(
i
)
for
i
in
interfaces
)
for
n
in
range
(
len
(
interfaces
)
//
N_COLUMNS
+
1
):
ifc_slice
=
interfaces
[
n
*
N_COLUMNS
:
(
n
+
1
)
*
N_COLUMNS
]
logger
.
info
(
"
"
.
join
(
i
.
ljust
(
longest_ifc
)
for
i
in
ifc_slice
))
def
_juniper_brian_points
(
router_fqdn
,
netconf_doc
,
timestamp
,
measurement_name
):
interfaces
=
juniper
.
interface_counters
(
netconf_doc
)
yield
from
vendors
.
brian_points
(
...
...
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