{"id":327903,"date":"2022-01-12T21:00:34","date_gmt":"2022-01-12T21:00:34","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=327903"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=327903","title":{"rendered":"<span>\u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Rust \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Prometheus \u0438 Grafana<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043a\u0430\u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Rust. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0430\u0440\u0443\u0436\u0443 Prometheus \u043c\u0435\u0442\u0440\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Grafana. \u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/tree\/master\/mongodb-redis\" rel=\"nofollow noopener noreferrer\">mongodb-redis demo<\/a>, \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u043e\u0433\u043e <a href=\"https:\/\/romankudryashov.com\/blog\/2021\/06\/mongodb-redis-rust\/\" rel=\"nofollow noopener noreferrer\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u0412 \u0438\u0442\u043e\u0433\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"\/img\/image-loader.svg\" alt=\"architecture\" data-src=\"https:\/\/habrastorage.org\/webt\/el\/wh\/nr\/elwhnrdquzf52csouhe9z3khgis.png\"\/><\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442:<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/prometheus.io\/\" rel=\"nofollow noopener noreferrer\">Prometheus<\/a> \u2014 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430 \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u0443\u0435\u0442 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0438\u0445 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Time_series_database\" rel=\"nofollow noopener noreferrer\">time series database<\/a>).<\/li>\n<li><a href=\"https:\/\/grafana.com\/\" rel=\"nofollow noopener noreferrer\">Grafana<\/a> \u2014 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u0440\u0438\u043a<\/li>\n<li><a href=\"https:\/\/prometheus.io\/docs\/alerting\/latest\/alertmanager\/\" rel=\"nofollow noopener noreferrer\">AlertManager<\/a> \u2014 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f (alerts), \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 Prometheus \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u0432 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0447\u0442\u043e-\u0442\u043e \u0438\u0434\u0451\u0442 \u043d\u0435 \u0442\u0430\u043a), \u0438 \u043e\u043f\u043e\u0432\u0435\u0449\u0430\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b, Slack, Telegram \u0438 \u0442. \u0434.<\/li>\n<li><a href=\"https:\/\/github.com\/google\/cadvisor\" rel=\"nofollow noopener noreferrer\">cAdvisor<\/a> \u2014 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0445 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432. (\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 cAdvisor \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043e \u0432\u0441\u0435\u0445 Docker \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432 \u043d\u0430 \u0441\u0445\u0435\u043c\u0435)<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0432\u0441\u0435\u0445 \u044d\u0442\u0438\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c:<\/p>\n<p>  <\/p>\n<p><em><a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/docker-compose.override.yml\" rel=\"nofollow noopener noreferrer\">Docker Compose \u0444\u0430\u0439\u043b<\/a><\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">version: '3.8' services:    prometheus:     image: prom\/prometheus:latest     container_name: prometheus     restart: always     ports:       - '9090:9090'     volumes:       - .\/monitoring\/prometheus:\/etc\/prometheus     command:       - '--config.file=\/etc\/prometheus\/prometheus.yml'       - '--web.external-url=http:\/\/localhost:9090'    grafana:     image: grafana\/grafana:latest     container_name: grafana     restart: always     ports:       - '3000:3000'     volumes:       - .\/monitoring\/grafana\/data:\/var\/lib\/grafana       - .\/monitoring\/grafana\/provisioning:\/etc\/grafana\/provisioning     environment:       GF_SECURITY_ADMIN_USER: admin       GF_SECURITY_ADMIN_PASSWORD: admin    alertmanager:     image: prom\/alertmanager:latest     container_name: alertmanager     ports:       - '9093:9093'     volumes:       - .\/monitoring\/alertmanager:\/etc\/alertmanager     command:       - '--config.file=\/etc\/alertmanager\/alertmanager.yml'       - '--web.external-url=http:\/\/localhost:9093'    cadvisor:     image: gcr.io\/cadvisor\/cadvisor:latest     container_name: cadvisor     restart: always     ports:       - '8080:8080'     volumes:       - \/:\/rootfs:ro       - \/var\/run:\/var\/run:rw       - \/sys:\/sys:ro       - \/var\/lib\/docker\/:\/var\/lib\/docker:ro<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"otdacha-prometheus-metrik-rust-prilozheniem\">\u041e\u0442\u0434\u0430\u0447\u0430 Prometheus \u043c\u0435\u0442\u0440\u0438\u043a Rust \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c<\/h2>\n<p>  <\/p>\n<p>\u041e\u0442\u0434\u0430\u0447\u0430 \u043c\u0435\u0442\u0440\u0438\u043a \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/github.com\/tikv\/rust-prometheus\" rel=\"nofollow noopener noreferrer\">\u043a\u0440\u0435\u0439\u0442\u0430<\/a> <code>prometheus<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 <a href=\"https:\/\/prometheus.io\/docs\/concepts\/metric_types\/\" rel=\"nofollow noopener noreferrer\">\u0447\u0435\u0442\u044b\u0440\u0435 \u0442\u0438\u043f\u0430<\/a> Prometheus \u043c\u0435\u0442\u0440\u0438\u043a: \u0441\u0447\u0451\u0442\u0447\u0438\u043a, \u0434\u0430\u0442\u0447\u0438\u043a\/\u0438\u0437\u043c\u0435\u0440\u0438\u0442\u0435\u043b\u044c\/\u0448\u043a\u0430\u043b\u0430, \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u0441\u0432\u043e\u0434\u043a\u0430 (summary). \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0432\u044b\u0445 \u0442\u0440\u0451\u0445 \u0438\u0437 \u043d\u0438\u0445 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 (\u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043a\u0440\u0435\u0439\u0442 <a href=\"https:\/\/github.com\/tikv\/rust-prometheus\/issues\/5\" rel=\"nofollow noopener noreferrer\">\u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442<\/a> \u0441\u0432\u043e\u0434\u043a\u0438).<\/p>\n<p>  <\/p>\n<h3 id=\"sozdanie-metrik\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u0440\u0438\u043a<\/h3>\n<p>  <\/p>\n<p>\u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0438 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<p><em><a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/src\/metrics.rs\" rel=\"nofollow noopener noreferrer\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u0440\u0438\u043a<\/a><\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">lazy_static! {     pub static ref HTTP_REQUESTS_TOTAL: IntCounterVec = register_int_counter_vec!(         opts!(\"http_requests_total\", \"HTTP requests total\"),         &amp;[\"method\", \"path\"]     )     .expect(\"Can't create a metric\");     pub static ref HTTP_CONNECTED_SSE_CLIENTS: IntGauge =         register_int_gauge!(opts!(\"http_connected_sse_clients\", \"Connected SSE clients\"))             .expect(\"Can't create a metric\");     pub static ref HTTP_RESPONSE_TIME_SECONDS: HistogramVec = register_histogram_vec!(         \"http_response_time_seconds\",         \"HTTP response times\",         &amp;[\"method\", \"path\"],         HTTP_RESPONSE_TIME_CUSTOM_BUCKETS.to_vec()     )     .expect(\"Can't create a metric\"); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043a\u043e\u0434\u0430 \u0432\u044b\u0448\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u0440\u0435\u0435\u0441\u0442\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u0422\u0430\u043a\u0436\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u043c \u0440\u0435\u0435\u0441\u0442\u0440\u0435 (<a href=\"https:\/\/github.com\/tikv\/rust-prometheus\/blob\/master\/examples\/example_custom_registry.rs\" rel=\"nofollow noopener noreferrer\">\u043f\u0440\u0438\u043c\u0435\u0440<\/a>).<\/p>\n<p>  <\/p>\n<h3 id=\"schyotchik\">\u0421\u0447\u0451\u0442\u0447\u0438\u043a<\/h3>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u0441\u0435 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 HTTP \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f <a href=\"https:\/\/docs.rs\/prometheus\/latest\/prometheus\/type.IntCounter.html\" rel=\"nofollow noopener noreferrer\">IntCounter<\/a>. \u041d\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a path \u0438 HTTP \u043c\u0435\u0442\u043e\u0434. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/docs.rs\/prometheus\/latest\/prometheus\/type.IntCounterVec.html\" rel=\"nofollow noopener noreferrer\">IntCounterVec<\/a>; \u043c\u0435\u0442\u0440\u0438\u043a\u0430 <code>HTTP_REQUESTS_TOTAL<\/code> \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u043c Actix middleware \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<p><em><a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/src\/main.rs\" rel=\"nofollow noopener noreferrer\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/a> \u043c\u0435\u0442\u0440\u0438\u043a\u0438 HTTP_REQUESTS_TOTAL<\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">let request_path = req.path(); let is_registered_resource = req.resource_map().has_resource(request_path); \/\/ this check prevents possible DoS attacks that can be done by flooding the application \/\/ using requests to different unregistered paths. That can cause high memory consumption \/\/ of the application and Prometheus server and also overflow Prometheus's TSDB if is_registered_resource {     let request_method = req.method().to_string();     metrics::HTTP_REQUESTS_TOTAL         .with_label_values(&amp;[&amp;request_method, request_path])         .inc(); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a API, \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u043d\u0430:<\/p>\n<p>  <\/p>\n<p><em>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 HTTP_REQUESTS_TOTAL<\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\"># HELP http_requests_total HTTP requests total # TYPE http_requests_total counter http_requests_total{method=\"GET\",path=\"\/\"} 1 http_requests_total{method=\"GET\",path=\"\/events\"} 1 http_requests_total{method=\"GET\",path=\"\/metrics\"} 22 http_requests_total{method=\"GET\",path=\"\/planets\"} 20634<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 <em>\u043b\u0435\u0439\u0431\u043b\u044b<\/em> (\u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b \u043c\u0435\u0442\u0440\u0438\u043a\u0438) <code>method<\/code> \u0438 <code>path<\/code>, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 Prometheus \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0438.<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0435 \u0432\u044b\u0448\u0435, \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a <code>GET \/metrics<\/code> (\u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e Prometheus \u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f) \u0442\u0430\u043a\u0436\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<h3 id=\"datchik\">\u0414\u0430\u0442\u0447\u0438\u043a<\/h3>\n<p>  <\/p>\n<p>\u0414\u0430\u0442\u0447\u0438\u043a \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0430 \u0442\u0435\u043c, \u0447\u0442\u043e \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0442\u044c\u0441\u044f. \u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0430\u0442\u0447\u0438\u043a\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e SSE. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<p><em><a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/src\/broadcaster.rs\" rel=\"nofollow noopener noreferrer\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/a> \u043c\u0435\u0442\u0440\u0438\u043a\u0438 HTTP_CONNECTED_SSE_CLIENTS<\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">crate::metrics::HTTP_CONNECTED_SSE_CLIENTS.inc();  crate::metrics::HTTP_CONNECTED_SSE_CLIENTS.set(broadcaster_mutex.clients.len() as i64)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043d\u0430 <code>http:\/\/localhost:9000<\/code> \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e SSE \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0438\u043d\u043a\u0440\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0442\u0430\u043d\u0443\u0442 \u0442\u0430\u043a\u0438\u043c\u0438:<\/p>\n<p>  <\/p>\n<p><em>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 HTTP_CONNECTED_SSE_CLIENTS<\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\"># HELP http_connected_sse_clients Connected SSE clients # TYPE http_connected_sse_clients gauge http_connected_sse_clients 1<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"broadcaster\">Broadcaster<\/h4>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0434\u0430\u0442\u0447\u0438\u043a\u0430 \u0447\u0438\u0441\u043b\u0430 SSE \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0441\u044f \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u043a\u043e\u0434\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 <a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/src\/broadcaster.rs\" rel=\"nofollow noopener noreferrer\">\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/a> broadcaster&#8217;\u0430. \u041e\u043d \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0432\u0441\u0435\u0445 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u044b\u0445 (\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/src\/handlers.rs\" rel=\"nofollow noopener noreferrer\">\u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/a> <code>sse<\/code>) \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440 \u0438 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0445 \u043f\u0438\u043d\u0433\u0443\u0435\u0442 (\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/src\/broadcaster.rs\" rel=\"nofollow noopener noreferrer\">\u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/a> <code>remove_stale_clients<\/code>), \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0430\u043a\u0442\u0438\u0432\u043d\u043e, \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u043e\u0442\u0441\u043e\u0435\u0434\u0438\u043d\u0451\u043d\u043d\u044b\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0438\u0437 \u0432\u0435\u043a\u0442\u043e\u0440\u0430. Broadcaster \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043e\u0434\u043d\u043e Redis Pub\/Sub <a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/src\/redis.rs\" rel=\"nofollow noopener noreferrer\">\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435<\/a>; \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0438\u0437 \u043d\u0435\u0433\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f (broadcasted) \u0432\u0441\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c.<\/p>\n<p>  <\/p>\n<h3 id=\"gistogramma\">\u0413\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u0430<\/h3>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0433\u0430\u0439\u0434\u0435 <a href=\"https:\/\/prometheus.io\/docs\/practices\/histograms\/\" rel=\"nofollow noopener noreferrer\">\u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u0430<\/a> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0442\u0432\u0435\u0442\u0430. \u041a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043e \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0442\u0440\u0435\u043a\u0438\u043d\u0433 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 Actix middleware; \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<p>  <\/p>\n<p><em><a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/src\/main.rs\" rel=\"nofollow noopener noreferrer\">\u0422\u0440\u0435\u043a\u0438\u043d\u0433 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0442\u0432\u0435\u0442\u0430<\/a><\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">...  histogram_timer = Some(     metrics::HTTP_RESPONSE_TIME_SECONDS         .with_label_values(&amp;[&amp;request_method, request_path])         .start_timer(), );  ...  if let Some(histogram_timer) = histogram_timer {     histogram_timer.observe_duration(); };<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0430\u0433\u0430\u044e, \u044d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0442\u043e\u0447\u043d\u044b\u0439 (\u0432\u043e\u043f\u0440\u043e\u0441 \u0432 \u0442\u043e\u043c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043c\u0435\u043d\u044c\u0448\u0435 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e), \u043d\u043e \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u044b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438 \u0434\u043b\u044f \u0435\u0451 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 Grafana.<\/p>\n<p>  <\/p>\n<p>\u0413\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u0438 \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0438\u0445 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0445 bucket&#8217;\u0430\u0445 (\u0435\u0441\u0442\u044c bucket&#8217;\u044b \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u043d\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 bucket&#8217;\u044b, \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043a \u0432\u0430\u0448\u0435\u043c\u0443 use case); \u0447\u0442\u043e\u0431\u044b \u0438\u0445 \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0431\u044b\u043b\u043e \u0431\u044b \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0437\u043d\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e\u0435 \u0440\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0439 \u043c\u0435\u0442\u0440\u0438\u043a\u0438. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0432\u0440\u0435\u043c\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043d\u0435\u0432\u0435\u043b\u0438\u043a\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f:<\/p>\n<p>  <\/p>\n<p><em><a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/src\/metrics.rs\" rel=\"nofollow noopener noreferrer\">Bucket&#8217;\u044b \u0434\u043b\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0442\u0432\u0435\u0442\u0430<\/a><\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">const HTTP_RESPONSE_TIME_CUSTOM_BUCKETS: &amp;[f64; 14] = &amp;[     0.0005, 0.0008, 0.00085, 0.0009, 0.00095, 0.001, 0.00105, 0.0011, 0.00115, 0.0012, 0.0015,     0.002, 0.003, 1.0, ];<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a (\u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0430\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445):<\/p>\n<p>  <\/p>\n<p><em>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 HTTP_RESPONSE_TIME_SECONDS<\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\"># HELP http_response_time_seconds HTTP response times # TYPE http_response_time_seconds histogram http_response_time_seconds_bucket{method=\"GET\",path=\"\/planets\",le=\"0.0005\"} 0 http_response_time_seconds_bucket{method=\"GET\",path=\"\/planets\",le=\"0.0008\"} 6 http_response_time_seconds_bucket{method=\"GET\",path=\"\/planets\",le=\"0.00085\"} 1307 http_response_time_seconds_bucket{method=\"GET\",path=\"\/planets\",le=\"0.0009\"} 10848 http_response_time_seconds_bucket{method=\"GET\",path=\"\/planets\",le=\"0.00095\"} 22334 http_response_time_seconds_bucket{method=\"GET\",path=\"\/planets\",le=\"0.001\"} 31698 http_response_time_seconds_bucket{method=\"GET\",path=\"\/planets\",le=\"0.00105\"} 38973 http_response_time_seconds_bucket{method=\"GET\",path=\"\/planets\",le=\"0.0011\"} 44619 http_response_time_seconds_bucket{method=\"GET\",path=\"\/planets\",le=\"0.00115\"} 48707 http_response_time_seconds_bucket{method=\"GET\",path=\"\/planets\",le=\"0.0012\"} 51495 http_response_time_seconds_bucket{method=\"GET\",path=\"\/planets\",le=\"0.0015\"} 57066 http_response_time_seconds_bucket{method=\"GET\",path=\"\/planets\",le=\"0.002\"} 59542 http_response_time_seconds_bucket{method=\"GET\",path=\"\/planets\",le=\"0.003\"} 60532 http_response_time_seconds_bucket{method=\"GET\",path=\"\/planets\",le=\"1\"} 60901 http_response_time_seconds_bucket{method=\"GET\",path=\"\/planets\",le=\"+Inf\"} 60901 http_response_time_seconds_sum{method=\"GET\",path=\"\/planets\"} 66.43133770000004 http_response_time_seconds_count{method=\"GET\",path=\"\/planets\"} 60901<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0447\u0438\u0441\u043b\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439, \u043f\u043e\u043f\u0430\u0432\u0448\u0438\u0445 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 bucket&#8217;\u044b. \u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043e\u0431\u0449\u0435\u043c\u0443 \u0447\u0438\u0441\u043b\u0443 \u0438 \u0441\u0443\u043c\u043c\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439.<\/p>\n<p>  <\/p>\n<h3 id=\"sistemnye-metriki\">\u0421\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438<\/h3>\n<p>  <\/p>\n<p><code>process<\/code> \u0444\u0438\u0447\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/prometheus.io\/docs\/instrumenting\/writing_clientlibs\/#process-metrics\" rel=\"nofollow noopener noreferrer\">\u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430<\/a>, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0438\u043b\u0438 \u043f\u0430\u043c\u044f\u0442\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0444\u0438\u0447\u0443 \u0432 <code>Cargo.toml<\/code>. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435:<\/p>\n<p>  <\/p>\n<p><em>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430<\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\"># HELP process_cpu_seconds_total Total user and system CPU time spent in seconds. # TYPE process_cpu_seconds_total counter process_cpu_seconds_total 134.49 # HELP process_max_fds Maximum number of open file descriptors. # TYPE process_max_fds gauge process_max_fds 1048576 # HELP process_open_fds Number of open file descriptors. # TYPE process_open_fds gauge process_open_fds 37 # HELP process_resident_memory_bytes Resident memory size in bytes. # TYPE process_resident_memory_bytes gauge process_resident_memory_bytes 15601664 # HELP process_start_time_seconds Start time of the process since unix epoch in seconds. # TYPE process_start_time_seconds gauge process_start_time_seconds 1636309802.38 # HELP process_threads Number of OS threads in the process. # TYPE process_threads gauge process_threads 6 # HELP process_virtual_memory_bytes Virtual memory size in bytes. # TYPE process_virtual_memory_bytes gauge process_virtual_memory_bytes 439435264<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043a\u0440\u0435\u0439\u0442 <code>prometheus<\/code> \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u043c\u0435\u0442\u0440\u0438\u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0445 \u043d\u0430 Linux (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 <a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/Dockerfile\" rel=\"nofollow noopener noreferrer\">\u0442\u0430\u043a\u043e\u043c<\/a> Docker \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435).<\/p>\n<p>  <\/p>\n<h3 id=\"endpoint-dlya-otdachi-metrik\">\u042d\u043d\u0434\u043f\u043e\u0438\u043d\u0442 \u0434\u043b\u044f \u043e\u0442\u0434\u0430\u0447\u0438 \u043c\u0435\u0442\u0440\u0438\u043a<\/h3>\n<p>  <\/p>\n<p>Actix \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043a <code>GET \/metrics<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0445\u044d\u043d\u0434\u043b\u0435\u0440\u0430:<\/p>\n<p>  <\/p>\n<p><em><a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/src\/handlers.rs\" rel=\"nofollow noopener noreferrer\">\u0425\u044d\u043d\u0434\u043b\u0435\u0440 \u0434\u043b\u044f \u043c\u0435\u0442\u0440\u0438\u043a<\/a><\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"rust\">pub async fn metrics() -> Result&lt;HttpResponse, CustomError> {     let encoder = TextEncoder::new();     let mut buffer = vec![];     encoder         .encode(&amp;prometheus::gather(), &amp;mut buffer)         .expect(\"Failed to encode metrics\");      let response = String::from_utf8(buffer.clone()).expect(\"Failed to convert bytes to string\");     buffer.clear();      Ok(HttpResponse::Ok()         .insert_header(header::ContentType(mime::TEXT_PLAIN))         .body(response)) }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043f\u043e\u0441\u043b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0440\u0430\u043d\u0435\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u0437\u0430\u043f\u0440\u043e\u0441 <code>GET http:\/\/localhost:9000\/metrics<\/code>. \u042d\u0442\u043e\u0442 \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f Prometheus \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u0440\u0438\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u043e\u0442\u0434\u0430\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u043c <a href=\"https:\/\/github.com\/prometheus\/docs\/blob\/main\/content\/docs\/instrumenting\/exposition_formats.md\" rel=\"nofollow noopener noreferrer\">\u0444\u043e\u0440\u043c\u0430\u0442\u0435<\/a>.<\/p>\n<p>  <\/p>\n<h2 id=\"nastroyka-prometheus-dlya-sbora-metrik\">\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 Prometheus \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u043c\u0435\u0442\u0440\u0438\u043a<\/h2>\n<p>  <\/p>\n<p>Prometheus \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043d\u0444\u0438\u0433:<\/p>\n<p>  <\/p>\n<p><em><a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/monitoring\/prometheus\/prometheus.yml\" rel=\"nofollow noopener noreferrer\">\u041a\u043e\u043d\u0444\u0438\u0433<\/a> Prometheus \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u043c\u0435\u0442\u0440\u0438\u043a<\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">scrape_configs:    - job_name: mongodb_redis_web_app     scrape_interval: 5s     static_configs:       - targets: ['host.docker.internal:9000']    - job_name: cadvisor     scrape_interval: 5s     static_configs:       - targets: ['cadvisor:8080']<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043a\u043e\u043d\u0444\u0438\u0433\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0434\u0432\u0435 job&#8217;\u044b. \u041f\u0435\u0440\u0432\u0430\u044f \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0440\u0430\u043d\u0435\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0432\u0442\u043e\u0440\u0430\u044f \u2014 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0445 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432 (\u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043e \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 cAdvisor). <code>scrape_interval<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u043e \u0437\u0430\u0431\u0438\u0440\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 target. \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>metrics_path<\/code> \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 Prometheus \u043e\u0436\u0438\u0434\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043d\u0430 target&#8217;\u0430\u0445 \u043f\u043e \u043f\u0443\u0442\u0438 <code>\/metrics<\/code>.<\/p>\n<p>  <\/p>\n<h3 id=\"expression-browser-i-graficheskiy-interfeys\">Expression browser \u0438 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441<\/h3>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e Prometheus expression browser \u043f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u043d\u0430 <code>http:\/\/localhost:9090\/graph<\/code> \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0438\u0442\u044c \u043b\u044e\u0431\u0443\u044e \u0438\u0437 \u0440\u0430\u043d\u0435\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u0440\u0438\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>http_requests_total<\/code>. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0432\u043a\u043b\u0430\u0434\u043a\u0443 &#171;Graph&#187; \u0434\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/prometheus.io\/docs\/prometheus\/latest\/querying\/basics\/\" rel=\"nofollow noopener noreferrer\">PromQL<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b; \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0430\u0440\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432.<\/p>\n<p>  <\/p>\n<ul>\n<li>\n<p>\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0432\u0441\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0440\u044f\u0434\u044b \u0434\u043b\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0438 <code>http_requests_total<\/code> \u0438 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439 job&#8217;\u044b:<\/p>\n<p>  <\/p>\n<p><code>http_requests_total{job=\"mongodb_redis_web_app\"}<\/code><\/p>\n<p>  <\/p>\n<p>\u041b\u0435\u0439\u0431\u043b\u044b <code>job<\/code> \u0438 <code>instance<\/code> <a href=\"https:\/\/prometheus.io\/docs\/concepts\/jobs_instances\/\" rel=\"nofollow noopener noreferrer\">\u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f<\/a> \u043a \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u044b\u043c Prometheus \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u0440\u044f\u0434\u0430\u043c.<\/p>\n<p>  <\/li>\n<li>\n<p>\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <a href=\"https:\/\/prometheus.io\/docs\/prometheus\/latest\/querying\/functions\/#rate\" rel=\"nofollow noopener noreferrer\">rate<\/a> \u0447\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u0439 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 5 \u043c\u0438\u043d\u0443\u0442:<\/p>\n<p>  <\/p>\n<p><code>rate(http_requests_total[5m])<\/code><\/p>\n<p>  <\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 <a href=\"https:\/\/prometheus.io\/docs\/prometheus\/latest\/querying\/examples\/\" rel=\"nofollow noopener noreferrer\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  <\/p>\n<h2 id=\"nastroyka-grafana-dlya-vizualizacii-metrik\">\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 Grafana \u0434\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u0440\u0438\u043a<\/h2>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 Grafana \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432:<\/p>\n<p>  <\/p>\n<ul>\n<li>\n<p>\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043e\u0442\u043a\u0443\u0434\u0430 Grafana \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435)<\/p>\n<p>  <\/p>\n<p><em><a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/monitoring\/grafana\/provisioning\/datasources\/datasources.yml\" rel=\"nofollow noopener noreferrer\">\u041a\u043e\u043d\u0444\u0438\u0433 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445<\/a> \u0434\u043b\u044f Grafana<\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">apiVersion: 1  datasources:   - name: Prometheus     type: prometheus     access: proxy     url: prometheus:9090     isDefault: true<\/code><\/pre>\n<p>  <\/li>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u043e\u0432 (\u043e\u0442\u043a\u0443\u0434\u0430 Grafana \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442 \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u044b)<\/p>\n<p>  <\/p>\n<p><em><a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/monitoring\/grafana\/provisioning\/dashboards\/providers.yml\" rel=\"nofollow noopener noreferrer\">\u041a\u043e\u043d\u0444\u0438\u0433 \u0434\u0430\u0448\u0431\u043e\u0440\u0434\u043e\u0432<\/a> \u0434\u043b\u044f Grafana<\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">apiVersion: 1  providers:   - name: 'default'     folder: 'default'     type: file     allowUiUpdates: true     updateIntervalSeconds: 30     options:       path: \/etc\/grafana\/provisioning\/dashboards       foldersFromFilesStructure: true<\/code><\/pre>\n<p>  <\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/docker-compose.override.yml\" rel=\"nofollow noopener noreferrer\">\u0444\u0430\u0439\u043b\u0430 Docker Compose<\/a> \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 <code>http:\/\/localhost:3000\/<\/code>, \u0432\u043e\u0439\u0442\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>admin\/admin<\/code> \u0438 \u043d\u0430\u0439\u0442\u0438 \u0434\u0430\u0448\u0431\u043e\u0440\u0434 <code>webapp_metrics<\/code>. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0441\u043f\u0443\u0441\u0442\u044f \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"\/img\/image-loader.svg\" alt=\"grafana\" data-src=\"https:\/\/habrastorage.org\/webt\/mv\/ww\/eq\/mvwweqo3fvjxgm6ef7bo3uhbzvc.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0448\u0431\u043e\u0440\u0434 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u0434 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u044b\u043c \u0442\u0435\u0441\u0442\u043e\u043c. (\u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u044b\u0439 \u0442\u0435\u0441\u0442, \u0442\u043e \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438 \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432 (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u044b) \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c <a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/src\/services.rs\" rel=\"nofollow noopener noreferrer\">\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435<\/a> <code>MAX_REQUESTS_PER_MINUTE<\/code>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0443\u0442\u0451\u043c \u0440\u0435\u0437\u043a\u043e\u0433\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430.)<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 <a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/monitoring\/grafana\/provisioning\/dashboards\/webapp_metrics.json\" rel=\"nofollow noopener noreferrer\">\u0434\u0430\u0448\u0431\u043e\u0440\u0434\u0435<\/a> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f PromQL \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0438\u0435 \u0440\u0430\u043d\u0435\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<ul>\n<li>\n<p><code>rate(http_response_time_seconds_sum[5m]) \/ rate(http_response_time_seconds_count[5m])<\/code><\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 5 \u043c\u0438\u043d\u0443\u0442<\/p>\n<p>  <\/li>\n<li>\n<p><code>sum(increase(http_response_time_seconds_bucket{path=\"\/planets\"}[30s])) by (le)<\/code><\/p>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u0432 \u0444\u043e\u0440\u043c\u0435 <a href=\"https:\/\/grafana.com\/docs\/grafana\/latest\/basics\/intro-histograms\/\" rel=\"nofollow noopener noreferrer\">\u0442\u0435\u043f\u043b\u043e\u0432\u043e\u0439 \u043a\u0430\u0440\u0442\u044b<\/a>. \u0422\u0435\u043f\u043b\u043e\u0432\u0430\u044f \u043a\u0430\u0440\u0442\u0430 \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043d\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438; \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u0443:<\/p>\n<p>  <\/li>\n<li>\n<p><code>rate(process_cpu_seconds_total{job=\"mongodb_redis_web_app\"}[1m])<\/code>, <code>sum(rate(container_cpu_usage_seconds_total{name='mongodb-redis'}[1m])) by (name)<\/code><\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 5 \u043c\u0438\u043d\u0443\u0442. \u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0438 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c \u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \u0414\u0432\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0430 \u043f\u043e\u0447\u0442\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b. (<code>sum<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>container_cpu_usage_seconds_total<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044f\u0434\u0440\u0430.)<\/p>\n<p>  <\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u0413\u0440\u0430\u0444\u0438\u043a &#171;Memory usage&#187; \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0443\u044e:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c (<code>process_resident_memory_bytes{job=\"mongodb_redis_web_app\"} \/ 1024 \/ 1024<\/code>)<\/li>\n<li>\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c (<code>container_memory_usage_bytes{name=\"mongodb-redis\"} \/ 1024 \/ 1024<\/code>)<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u043e \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 \u043c\u043d\u0435 \u043f\u0440\u0438\u0447\u0438\u043d\u0435 \u0433\u0440\u0430\u0444\u0438\u043a \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0435\u0442 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0430\u043c\u044f\u0442\u0438, \u0447\u0435\u043c \u0432\u0435\u0441\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440. \u042f \u0441\u043e\u0437\u0434\u0430\u043b <a href=\"https:\/\/github.com\/tikv\/rust-prometheus\/issues\/424\" rel=\"nofollow noopener noreferrer\">issue<\/a> \u043f\u043e \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u0443. \u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435, \u0435\u0441\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043d\u0435 \u0442\u0430\u043a \u0432 \u044d\u0442\u043e\u043c \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0438\u043b\u0438 \u0437\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u044d\u0442\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<h2 id=\"monitoring-metrik-konteynera-prilozheniya-s-pomoschyu-cadvisor\">\u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u043c\u0435\u0442\u0440\u0438\u043a \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e cAdvisor<\/h2>\n<p>  <\/p>\n<p>\u0412 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u043c \u043c\u0435\u0442\u0440\u0438\u043a\u0430\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 (\u0431\u044b\u043b\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0440\u0430\u043d\u0435\u0435) \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 Docker \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e cAdvisor.<\/p>\n<p>  <\/p>\n<p>\u0412\u0435\u0431-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 cAdvisor \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043f\u043e <code>http:\/\/localhost:8080\/<\/code>. \u0412\u0441\u0435 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 Docker \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u043d\u0430 <code>http:\/\/localhost:8080\/docker\/<\/code>:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"\/img\/image-loader.svg\" alt=\"cadvisor docker containers\" data-src=\"https:\/\/habrastorage.org\/webt\/gs\/0t\/gt\/gs0tgtrlklukxhui5nq-v1dgtka.png\"\/><\/p>\n<p>  <\/p>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043b\u044e\u0431\u044b\u043c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u043c:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"\/img\/image-loader.svg\" alt=\"cadvisor container info\" data-src=\"https:\/\/habrastorage.org\/webt\/g4\/gj\/0j\/g4gj0jywg1_9ocpwcnrz-gpsv9o.png\"\/><\/p>\n<p>  <\/p>\n<p>\u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f Prometheus \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u0441 <code>http:\/\/localhost:8080\/metrics<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041c\u0435\u0442\u0440\u0438\u043a\u0438, \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0435 cAdvisor&#8217;\u043e\u043c, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u044b <a href=\"https:\/\/github.com\/google\/cadvisor\/blob\/master\/docs\/storage\/prometheus.md\" rel=\"nofollow noopener noreferrer\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0421\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/github.com\/prometheus\/node_exporter\" rel=\"nofollow noopener noreferrer\">Node exporter<\/a> \u0438\u043b\u0438 <a href=\"https:\/\/github.com\/prometheus-community\/windows_exporter\" rel=\"nofollow noopener noreferrer\">Windows exporter<\/a>.<\/p>\n<p>  <\/p>\n<h2 id=\"nastroyka-uvedomleniy-s-pomoschyu-pravil-i-alertmanager\">\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u0430\u0432\u0438\u043b \u0438 AlertManager<\/h2>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0430 Prometheus \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<p><em><a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/monitoring\/prometheus\/prometheus.yml\" rel=\"nofollow noopener noreferrer\">\u041a\u043e\u043d\u0444\u0438\u0433<\/a> Prometheus \u0434\u043b\u044f \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439<\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">rule_files:   - 'rules.yml'  alerting:   alertmanagers:     - static_configs:         - targets: ['alertmanager:9093']<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 <code>alerting<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u0438\u043d\u0441\u0442\u0430\u043d\u0441 AlertManager, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0435\u0442 Prometheus \u0441\u0435\u0440\u0432\u0435\u0440.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/prometheus.io\/docs\/prometheus\/latest\/configuration\/alerting_rules\/\" rel=\"nofollow noopener noreferrer\">\u041f\u0440\u0430\u0432\u0438\u043b\u0430 \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u0439<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 PromQL \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439:<\/p>\n<p>  <\/p>\n<p><em><a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/monitoring\/prometheus\/rules.yml\" rel=\"nofollow noopener noreferrer\">\u041f\u0440\u0438\u043c\u0435\u0440<\/a> \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u044f \u0432 <code>rules.yml<\/code><\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">groups: - name: default   rules:   - alert: SseClients     expr:  http_connected_sse_clients > 0     for: 1m     labels:       severity: high     annotations:       summary: Too many SSE clients<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>alert \u2013 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u044f<\/li>\n<li>expr \u2013 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0432 \u0432\u0438\u0434\u0435 Prometheus \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/li>\n<li>for \u2013 \u043a\u0430\u043a \u0434\u043e\u043b\u0433\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u043e \u043f\u0435\u0440\u0435\u0434 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u044f. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u0447\u0438\u0441\u043b\u043e SSE \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 0 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 1 \u043c\u0438\u043d\u0443\u0442\u044b, \u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043e \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u0435<\/li>\n<li>labels \u2013 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u043a \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u044e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/li>\n<li>annotations \u2013 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u043a \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u044e<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0423\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0447\u0442\u043e \u0447\u0438\u0441\u043b\u043e SSE \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 \u0431\u043e\u043b\u044c\u0448\u0435 0, \u2014 \u044d\u0442\u043e \u043d\u0435 \u0442\u043e, \u0447\u0442\u043e \u0432\u044b \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0435 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u041e\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u0435\u0433\u043e \u043d\u0430\u0440\u0443\u0448\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u043d\u0430\u0440\u0443\u0448\u0435\u043d\u043e, Prometheus \u0441\u0435\u0440\u0432\u0435\u0440 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442 \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u0435 \u043d\u0430 \u0438\u043d\u0441\u0442\u0430\u043d\u0441 AlertManager, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0444\u0438\u0447, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0434\u0435\u0434\u0443\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044f \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u0439, \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0430, \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u0440\u043e\u0443\u0442\u0438\u043d\u0433 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u043e\u0443\u0442\u0438\u043d\u0433: \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u043b\u0435\u0442 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043e \u043d\u0430 email.<\/p>\n<p>  <\/p>\n<p>AlertManager \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<p><em><a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/blob\/master\/mongodb-redis\/monitoring\/alertmanager\/alertmanager.yml\" rel=\"nofollow noopener noreferrer\">\u041a\u043e\u043d\u0444\u0438\u0433 AlertManager<\/a><\/em><\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">route:   receiver: gmail  receivers: - name: gmail   email_configs:   - to: recipient@gmail.com     from: email_id@gmail.com     smarthost: smtp.gmail.com:587     auth_username: email_id@gmail.com     auth_identity: email_id@gmail.com     auth_password: password<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 AlertManager \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Gmail \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430. \u0427\u0442\u043e\u0431\u044b \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c app password, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/support.google.com\/accounts\/answer\/185833?hl=en\" rel=\"nofollow noopener noreferrer\">\u044d\u0442\u043e\u0442 \u0433\u0430\u0439\u0434<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u044f <code>SseClients<\/code> \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 <code>http:\/\/localhost:9000<\/code> \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435. \u042d\u0442\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 <code>http_connected_sse_clients<\/code> \u043d\u0430 1. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0438\u0434\u0435\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u044f <code>SseClients<\/code> \u043d\u0430 <code>http:\/\/localhost:9090\/alerts<\/code>. \u041f\u043e\u0441\u043b\u0435 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u0442 \u0432 \u0441\u0442\u0430\u0442\u0443\u0441 <code>Pending<\/code>. \u041f\u043e \u043f\u0440\u043e\u0448\u0435\u0441\u0442\u0432\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0430 <code>for<\/code>, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u0432 <code>rules.yml<\/code> (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e 1 \u043c\u0438\u043d\u0443\u0442\u0430), \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u0442 \u0432 \u0441\u0442\u0430\u0442\u0443\u0441 <code>Firing<\/code>.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"\/img\/image-loader.svg\" alt=\"prometheus alert\" data-src=\"https:\/\/habrastorage.org\/webt\/mu\/k8\/m7\/muk8m7qj_poo6_khfmh3ad8lrpu.png\"\/><\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u0442 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e Prometheus \u0441\u0435\u0440\u0432\u0435\u0440 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442 \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u0435 \u0432 AlertManager, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442 \u0447\u0442\u043e \u0441 \u043d\u0438\u043c \u0434\u0435\u043b\u0430\u0442\u044c. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d email:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"\/img\/image-loader.svg\" alt=\"gmail alert\" data-src=\"https:\/\/habrastorage.org\/webt\/5y\/fp\/ei\/5yfpein8ao3hdr6v-cugkvn3nxu.png\"\/><\/p>\n<p>  <\/p>\n<h2 id=\"monitoring-third-party-sistem-s-pomoschyu-prometheus-exporters\">\u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 third-party \u0441\u0438\u0441\u0442\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Prometheus exporters<\/h2>\n<p>  <\/p>\n<p>\u0414\u043b\u044f third-party \u0442\u0443\u043b\u043e\u0432, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a MongoDB, Redis \u0438 \u043c\u043d\u043e\u0433\u0438\u0445 \u0434\u0440\u0443\u0433\u0438\u0445, \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Prometheus <a href=\"https:\/\/prometheus.io\/docs\/instrumenting\/exporters\/\" rel=\"nofollow noopener noreferrer\">exporters<\/a>.<\/p>\n<p>  <\/p>\n<h2 id=\"zapusk\">\u0417\u0430\u043f\u0443\u0441\u043a<\/h2>\n<p>  <\/p>\n<p><code>docker compose up --build<\/code><\/p>\n<p>  <\/p>\n<h2 id=\"zaklyuchenie\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u044b\u043b\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043a\u0430\u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043e\u0442\u0434\u0430\u0447\u0443 \u043c\u0435\u0442\u0440\u0438\u043a \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Rust, \u0438\u0445 \u0441\u0431\u043e\u0440 Prometheus&#8217;\u043e\u043c \u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Grafana. \u0422\u0430\u043a\u0436\u0435 \u0431\u044b\u043b\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043a\u0430\u043a \u043d\u0430\u0447\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 cAdvisor \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u043c\u0435\u0442\u0440\u0438\u043a \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432 \u0438 \u0441 \u043d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f\u043c\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e AlertManager. \u041d\u0435 \u0441\u0442\u0435\u0441\u043d\u044f\u0439\u0442\u0435\u0441\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u043d\u0435, \u0435\u0441\u043b\u0438 \u043d\u0430\u0448\u043b\u0438 \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0438\u043b\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043a\u043e\u0434\u0435. \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<\/p>\n<p>  <\/p>\n<h2 id=\"poleznye-ssylki\">\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/h2>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/prometheus.io\/docs\/introduction\/overview\/\" rel=\"nofollow noopener noreferrer\">Introduction to Prometheus<\/a><\/li>\n<li><a href=\"https:\/\/prometheus.io\/docs\/practices\/naming\/\" rel=\"nofollow noopener noreferrer\">Prometheus\u2019s naming convention<\/a><\/li>\n<li><a href=\"https:\/\/grafana.com\/docs\/grafana\/latest\/basics\/intro-histograms\/\" rel=\"nofollow noopener noreferrer\">Introduction to histograms and heatmaps<\/a><\/li>\n<li><a href=\"https:\/\/grafana.com\/blog\/2020\/06\/23\/how-to-visualize-prometheus-histograms-in-grafana\/\" rel=\"nofollow noopener noreferrer\">How to visualize Prometheus histograms in Grafana<\/a><\/li>\n<li><a href=\"https:\/\/tomgregory.com\/monitoring-a-spring-boot-application-part-3-rules-and-alerting\/\" rel=\"nofollow noopener noreferrer\">Setup of an alerting system for Spring Boot application<\/a><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/645231\/\"> https:\/\/habr.com\/ru\/post\/645231\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043a\u0430\u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 Rust. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0430\u0440\u0443\u0436\u0443 Prometheus \u043c\u0435\u0442\u0440\u0438\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Grafana. \u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f <a href=\"https:\/\/github.com\/rkudryashov\/exploring-rust-ecosystem\/tree\/master\/mongodb-redis\" rel=\"nofollow noopener noreferrer\">mongodb-redis demo<\/a>, \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u043e\u0433\u043e <a href=\"https:\/\/romankudryashov.com\/blog\/2021\/06\/mongodb-redis-rust\/\" rel=\"nofollow noopener noreferrer\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u0412 \u0438\u0442\u043e\u0433\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"\/img\/image-loader.svg\" alt=\"architecture\" data-src=\"https:\/\/habrastorage.org\/webt\/el\/wh\/nr\/elwhnrdquzf52csouhe9z3khgis.png\"\/><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-327903","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/327903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=327903"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/327903\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=327903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=327903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=327903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}