Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
prozorro-sale
Prozorro metrics
Commits
5409bb38
Commit
5409bb38
authored
Jun 14, 2021
by
Pavel Kuzmenko
Browse files
Epic/lre
parent
d5a8ed39
Changes
2
Hide whitespace changes
Inline
Side-by-side
.flake8
View file @
5409bb38
[flake8]
max-line-length = 120
ignore = D
\ No newline at end of file
src/prozorro_sale/metrics/__init__.py
View file @
5409bb38
import
asyncio
import
logging
import
signal
from
typing
import
Any
from
aiohttp
import
web
import
prometheus_client
import
logging
from
aiohttp
import
web
from
aiohttp.web_runner
import
_raise_graceful_exit
LOG
=
logging
.
getLogger
(
'application_wrapper'
)
...
...
@@ -72,12 +71,27 @@ class CoroutineWrapper:
class
ApplicationWrapper
:
"""Application wrapper for exporting metrics on prometheus
"""
Application wrapper for exporting metrics on prometheus
Args:
_loop (:obj:, optional): Event loop
**kwargs: Arbitrary keyword arguments.
Returns:
None
Examples:
kwargs[prometheus] - for setup prometheus client
prometheus={
'_port': 9091,
'tcp_params': {
'backlog': 256,
'reuse_address': True,
'reuse_port': True
}
}
"""
def
__init__
(
self
,
_loop
=
None
):
def
__init__
(
self
,
_loop
=
None
,
**
kwargs
:
Any
):
self
.
loop
=
_loop
self
.
apps
=
[]
if
_loop
is
None
:
...
...
@@ -85,10 +99,20 @@ class ApplicationWrapper:
else
:
self
.
loop
=
_loop
self
.
add_web_app
(
init_mertics_app
(),
_port
=
9091
)
prometheus
=
kwargs
.
get
(
'prometheus'
,
{
'_port'
:
9091
,
'tcp_params'
:
{
'reuse_address'
:
True
,
'reuse_port'
:
True
}
})
if
isinstance
(
prometheus
,
dict
):
self
.
add_web_app
(
init_mertics_app
(),
**
prometheus
)
def
add_web_app
(
self
,
_app
:
web
.
Application
,
_port
:
int
,
**
kwargs
:
Any
)
->
None
:
"""Add Application for start list
"""
Add Application for start list
Args:
_app (obj): Application
_port (int): Application PORT to listed
...
...
@@ -122,8 +146,8 @@ class ApplicationWrapper:
try
:
LOG
.
info
(
'Start serving'
)
self
.
loop
.
run_until_complete
(
asyncio
.
gather
(
*
[
app
.
initialize
()
for
app
in
self
.
apps
]))
except
KeyboardInterrupt
:
pass
except
(
KeyboardInterrupt
,
asyncio
.
exceptions
.
CancelledError
)
:
...
finally
:
for
app
in
self
.
apps
:
app
.
shutdown
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment