wip: lab_4 до дашборда в Prometheus
Этот коммит содержится в:
@@ -1,7 +1,9 @@
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
from itertools import chain
|
||||
from pandas import DataFrame
|
||||
from pickle import load
|
||||
from prometheus_client import Counter, Histogram
|
||||
|
||||
|
||||
def open_model_file(file, *, buffering=-1, opener=None, **kwargs_extra):
|
||||
@@ -61,6 +63,27 @@ class PricePredictionFeatures:
|
||||
transmission_type: TransmissionType
|
||||
|
||||
|
||||
metric_prediction_latency = Histogram(
|
||||
'model_prediction_seconds', 'Время вычислений в модели',
|
||||
buckets=(
|
||||
list(chain.from_iterable((v * (10 ** p) for v in (1, 2, 5)) for p in range(-4, (1 + 1))))
|
||||
+ [float('+inf')]
|
||||
),
|
||||
)
|
||||
|
||||
metric_prediction_errors = Counter(
|
||||
'model_prediction_errors_total', 'Ошибки вычислений в модели по типу', ('error_type',),
|
||||
)
|
||||
|
||||
metric_prediction_value = Histogram(
|
||||
'model_prediction_value', 'Предсказанное значение цены',
|
||||
buckets=(
|
||||
list(chain.from_iterable((v * (10 ** p) for v in (1, 2, 5)) for p in range(-1, (2 + 1))))
|
||||
+ [float('+inf')]
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class PricePredictor:
|
||||
|
||||
def __init__(self, model_path):
|
||||
@@ -76,6 +99,13 @@ class PricePredictor:
|
||||
'transmission': features.transmission_type.value,
|
||||
'age': features.age,
|
||||
}])
|
||||
predictions = self._model.predict(features_df)
|
||||
try:
|
||||
with metric_prediction_latency.time():
|
||||
predictions = self._model.predict(features_df)
|
||||
except Exception as err:
|
||||
metric_prediction_errors.labels(error_type=type(err).__name__).inc()
|
||||
raise
|
||||
assert len(predictions) == 1
|
||||
return float(predictions[0])
|
||||
value = float(predictions[0])
|
||||
metric_prediction_value.observe(value)
|
||||
return value
|
||||
|
||||
Ссылка в новой задаче
Block a user