-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmetrics.py
More file actions
109 lines (91 loc) · 2.78 KB
/
metrics.py
File metadata and controls
109 lines (91 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import enum
import prometheus_client
class Metrics(enum.Enum):
VIDEO_COUNT = (
"video_count",
"Number of videos played",
prometheus_client.Counter,
)
STREAMS_COUNT = (
"streams_count",
"Number of streams created",
prometheus_client.Counter,
["video_type"], # playing, interlude
)
SUBPROCESS_COUNT = (
"subprocess_count",
"Number of subprocesses ended",
prometheus_client.Counter,
["exit_code"], # 0, 137, 1 etc
)
DOWNLOAD_TIME = (
"download_time",
"Total time spent downloading videos in seconds",
prometheus_client.Summary,
)
DOWNLOAD_RATE = (
"download_rate",
"The rate of downloading videos in bytes per seconds",
prometheus_client.Histogram,
)
DATA_DOWNLOADED = (
"data_downloaded",
"Total video data downloaded in bytes",
prometheus_client.Counter,
)
VIDEO_DOWNLOAD_COUNT = (
"video_download_count",
"Number of videos downloaded",
prometheus_client.Counter,
)
CACHE_SIZE = (
"cache_size",
"Total entries in cache",
prometheus_client.Gauge,
)
CACHE_SIZE_BYTES = (
"cache_size_bytes",
"Current cache size in bytes",
prometheus_client.Gauge,
)
CACHE_HIT_COUNT = (
"cache_hit_count",
"Number of successful cache retrievals",
prometheus_client.Counter,
)
CACHE_MISS_COUNT = (
"cache_miss_count",
"Number of failed cache retrievals",
prometheus_client.Counter,
)
HTTP_REQUEST_COUNT = (
"http_request_count",
"Number of requests received for each endpoint",
prometheus_client.Counter,
["endpoint"],
)
STREAM_STATE = (
"stream_state",
"Indicates whether the given stream type is running (1=running, 0=stopped)",
prometheus_client.Gauge,
["video_type"],
)
def __init__(self, title, description, prometheus_type, labels=()):
# we use the above default value for labels because it matches what's used
# in the prometheus_client library's metrics constructor, see
# https://github.com/prometheus/client_python/blob/fd4da6cde36a1c278070cf18b4b9f72956774b05/prometheus_client/metrics.py#L115
self.title = title
self.description = description
self.prometheus_type = prometheus_type
self.labels = labels
class MetricsHandler:
@classmethod
def init(self) -> None:
for metric in Metrics:
setattr(
self,
metric.title,
metric.prometheus_type(
metric.title, metric.description, labelnames=metric.labels
),
)