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
0164cd2e
Commit
0164cd2e
authored
1 year ago
by
Pelle Koster
Browse files
Options
Downloads
Patches
Plain Diff
more wip on error report
parent
65987a67
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/error_report/cli.py
+15
-21
15 additions, 21 deletions
brian_polling_manager/error_report/cli.py
with
15 additions
and
21 deletions
brian_polling_manager/error_report/cli.py
+
15
−
21
View file @
0164cd2e
import
logging
import
logging
import
pathlib
import
pathlib
import
pprint
from
typing
import
Sequence
from
typing
import
Sequence
,
Set
,
Tuple
from
brian_polling_manager.interface_stats.services
import
influx_client
from
brian_polling_manager.interface_stats.services
import
influx_client
from
brian_polling_manager.inventory
import
load_interfaces
from
brian_polling_manager.inventory
import
load_interfaces
from
influxdb
import
InfluxDBClient
from
influxdb
import
InfluxDBClient
...
@@ -126,7 +125,7 @@ def get_error_points(client: InfluxDBClient, time_window: str):
...
@@ -126,7 +125,7 @@ def get_error_points(client: InfluxDBClient, time_window: str):
def
interface_errors
(
def
interface_errors
(
client
:
InfluxDBClient
,
interface_info
,
errors
,
raise_on_errors
=
False
client
:
InfluxDBClient
,
interface_info
,
errors
,
exclusions
,
raise_on_errors
=
False
):
):
"""
"""
Retrieves error counters from influx
Retrieves error counters from influx
...
@@ -144,16 +143,15 @@ def interface_errors(
...
@@ -144,16 +143,15 @@ def interface_errors(
yesterdays_data
=
get_error_points
(
client
,
TIME_WINDOW_YESTERDAY
)
yesterdays_data
=
get_error_points
(
client
,
TIME_WINDOW_YESTERDAY
)
result
=
{
"
interfaces
"
:
[],
"
excluded_interfaces
"
:
[]}
result
=
{
"
interfaces
"
:
[],
"
excluded_interfaces
"
:
[]}
exception_count
=
0
for
(
router
,
ifc
),
info
in
interface_info
.
items
():
for
(
router
,
ifc
),
today
in
todays_data
.
items
():
yesterday
=
yesterdays_data
.
get
((
router
,
ifc
),
{})
try
:
try
:
info
=
interface_info
[(
router
,
ifc
)]
today
=
todays_data
[(
router
,
ifc
)]
except
KeyError
:
except
KeyError
:
logger
.
exception
(
f
"
{
router
}
-
{
ifc
}
not found in inventory provider
"
)
logger
.
error
(
f
"
{
router
}
-
{
ifc
}
not found in influx data
"
)
exception_count
+=
1
if
raise_on_errors
:
if
raise_on_errors
:
raise
raise
continue
yesterday
=
yesterdays_data
.
get
((
router
,
ifc
),
{})
counters
=
{
counters
=
{
"
error_counters
"
:
{
err
[
0
]:
(
today
[
err
[
1
]]
or
0
)
for
(
err
)
in
errors
},
"
error_counters
"
:
{
err
[
0
]:
(
today
[
err
[
1
]]
or
0
)
for
(
err
)
in
errors
},
...
@@ -162,7 +160,7 @@ def interface_errors(
...
@@ -162,7 +160,7 @@ def interface_errors(
"
description
"
:
info
[
"
description
"
],
"
description
"
:
info
[
"
description
"
],
}
}
if
not
is_excluded_interface
(
info
[
"
description
"
]):
if
not
is_excluded_interface
(
info
[
"
description
"
]
,
exclusions
):
counters
[
"
diff
"
]
=
{
counters
[
"
diff
"
]
=
{
err
[
0
]:
(
today
[
err
[
1
]]
or
0
)
-
(
yesterday
.
get
(
err
[
1
],
0
)
or
0
)
err
[
0
]:
(
today
[
err
[
1
]]
or
0
)
-
(
yesterday
.
get
(
err
[
1
],
0
)
or
0
)
for
err
in
errors
for
err
in
errors
...
@@ -177,7 +175,7 @@ def interface_errors(
...
@@ -177,7 +175,7 @@ def interface_errors(
else
:
else
:
result
[
"
excluded_interfaces
"
].
append
(
counters
)
result
[
"
excluded_interfaces
"
].
append
(
counters
)
return
result
,
exception_count
return
result
def
is_excluded_interface
(
description
:
str
,
exclusions
:
Sequence
[
str
]):
def
is_excluded_interface
(
description
:
str
,
exclusions
:
Sequence
[
str
]):
...
@@ -212,16 +210,12 @@ def main():
...
@@ -212,16 +210,12 @@ def main():
client
=
influx_client
(
config
[
"
influx
"
])
client
=
influx_client
(
config
[
"
influx
"
])
all_interfaces
=
get_relevant_interfaces
(
config
[
"
inventory
"
])
all_interfaces
=
get_relevant_interfaces
(
config
[
"
inventory
"
])
with
client
:
with
client
:
all_error_counters
=
interface_errors
(
client
,
errors
=
ERROR_FIELDS
)
all_error_counters
=
interface_errors
(
for
key
in
sorted
(
all_interfaces
):
client
,
if
key
not
in
all_error_counters
:
interface_info
=
all_interfaces
,
print
(
f
"
interface
{
key
}
not found in influx data
"
)
errors
=
ERROR_FIELDS
,
continue
exclusions
=
config
[
"
exclude-interfaces
"
],
)
errors
=
all_error_counters
[
key
]
if
any
(
v
>
0
for
v
in
errors
.
values
()):
print
(
*
key
,
"
,
"
.
join
(
str
(
c
)
for
c
in
errors
.
values
()))
# TODO: ensure data is from the day that we're interested in (today or yesterday)
# TODO: ensure data is from the day that we're interested in (today or yesterday)
# TODO: send script failures to admin email
# TODO: send script failures to admin email
...
...
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