使用 Prometheus 和 Grafana 監(jiān)控 Rust Web 應(yīng)用程序
項(xiàng)目不能裸奔,監(jiān)控必不可少。本文介紹如何對(duì) Rust Web 應(yīng)用進(jìn)行監(jiān)控。
01 概述
在本文中,我將向你展示如何設(shè)置 Rust Web 應(yīng)用程序的監(jiān)控。該應(yīng)用程序?qū)⒐_ Prometheus 指標(biāo),這些指標(biāo)將使用 Grafana 進(jìn)行可視化。監(jiān)控的應(yīng)用是 mongodb-redis demo[1],這里[2]有詳細(xì)介紹 。最終架構(gòu)如下:

監(jiān)控系統(tǒng)包括:
Prometheus[3] — 收集實(shí)時(shí)指標(biāo)并將其記錄在時(shí)間序列數(shù)據(jù)庫中的監(jiān)控平臺(tái) Grafana[4] — 可觀察性和數(shù)據(jù)可視化平臺(tái) AlertManager[5] — 處理 Prometheus 服務(wù)器發(fā)送的警報(bào)(例如,當(dāng)你的應(yīng)用程序出現(xiàn)問題時(shí))并通過電子郵件、Slack、Telegram 或其他渠道通知最終用戶的應(yīng)用程序 cAdvisor[6] — 一個(gè)平臺(tái),可讓容器用戶了解其正在運(yùn)行的容器的資源使用情況和性能特征。(實(shí)際上,它收集有關(guān)方案中所有 Docker 容器的信息
要一次啟動(dòng)所有工具,你可以使用以下命令:
清單 1. Docker Compose 文件[7]
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
02 在 Rust 應(yīng)用程序中公開 Prometheus 指標(biāo)
指標(biāo)展示是用prometheus crate[8] 實(shí)現(xiàn)的。
Prometheus 指標(biāo)有四種核心類型[9]:計(jì)數(shù)器、儀表、直方圖和摘要。前三個(gè)將在文章中介紹(該 crate 目前不支持[10] 摘要類型)。
指標(biāo)定義
可以通過以下方式創(chuàng)建和注冊(cè)指標(biāo):
清單 2.指標(biāo)創(chuàng)建和注冊(cè)[11]
lazy_static!?{
????pub?static?ref?HTTP_REQUESTS_TOTAL:?IntCounterVec?=?register_int_counter_vec!(
????????opts!("http_requests_total",?"HTTP?requests?total"),
????????&["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",
????????&["method",?"path"],
????????HTTP_RESPONSE_TIME_CUSTOM_BUCKETS.to_vec()
????)
????.expect("Can't?create?a?metric");
}
在上面的代碼片段中,自定義指標(biāo)被添加到默認(rèn)注冊(cè)表中;也可以在自定義注冊(cè)表中注冊(cè)它們(參見 示例[12])。
此外,將詳細(xì)描述度量的目的和用途。
計(jì)數(shù)器
如果我們想統(tǒng)計(jì)所有傳入的 HTTP 請(qǐng)求,可以使用 IntCounter[13] 類型。但是不僅可以查看請(qǐng)求的總數(shù),還可以查看其他一些維度,例如請(qǐng)求的路徑和方法,這會(huì)更有用。這可以通過 IntCounterVec[14] 完成;HTTP_REQUESTS_TOTAL該類型用于自定義 Actix 中間件,如下所示:
清單3.使用[15] HTTP_REQUESTS_TOTAL 度量
let?request_method?=?req.method().to_string();
let?request_path?=?req.path();
metrics::HTTP_REQUESTS_TOTAL
????.with_label_values(&[&request_method,?request_path])
????.inc();
向 API 發(fā)出一些請(qǐng)求后,將產(chǎn)生如下內(nèi)容:
清單 4. HTTP_REQUESTS_TOTAL 指標(biāo)的輸出
#?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="/favicon.ico"}?3
http_requests_total{method="GET",path="/metrics"}?22
http_requests_total{method="GET",path="/planets"}?20634
度量的每個(gè)樣本都有method和path 標(biāo)簽(度量的屬性),因此 Prometheus 可以區(qū)分樣本。
如上一個(gè)片段所示,還觀察到對(duì) GET /metrics(Prometheus 服務(wù)器從中收集應(yīng)用程序指標(biāo)的端點(diǎn))的請(qǐng)求。
計(jì)量器
Gauge 與計(jì)數(shù)器的不同之處在于它的值可以下降。儀表示例顯示了當(dāng)前使用 SSE 連接的客戶端數(shù)量。儀表的使用方法如下:
清單5.使用[16] HTTP_CONNECTED_SSE_CLIENTS度量
crate::metrics::HTTP_CONNECTED_SSE_CLIENTS.inc();
crate::metrics::HTTP_CONNECTED_SSE_CLIENTS.set(broadcaster_mutex.clients.len()?as?i64)
訪問 http://localhost:9000,將建立通過 SSE 的連接,并且指標(biāo)將增加。之后,它的輸出將如下所示:
清單 6. HTTP_CONNECTED_SSE_CLIENTS 指標(biāo)的輸出
#?HELP?http_connected_sse_clients?Connected?SSE?clients
#?TYPE?http_connected_sse_clients?gauge
http_connected_sse_clients?1
廣播器
為了實(shí)現(xiàn) SSE 客戶端規(guī)范,需要重構(gòu)應(yīng)用程序的代碼并 實(shí)現(xiàn)[17] 廣播器。它將所有連接的(使用sse function[18])客戶端存儲(chǔ)在一個(gè)向量中,并定期 ping 每個(gè)客戶端(在remove_stale_clients function 中[19])以確保連接仍然有效,否則從向量中刪除斷開連接的客戶端。廣播器只允許打開一個(gè) Redis Pub/Sub 連接[20];來自它的消息被發(fā)送(廣播)到所有客戶端。
直方圖
在本指南中,直方圖[21]用于收集有關(guān)響應(yīng)時(shí)間的數(shù)據(jù)。與請(qǐng)求計(jì)數(shù)器的情況一樣,跟蹤是在 Actix 中間件中完成的;它是使用以下代碼實(shí)現(xiàn)的:
清單 7.響應(yīng)時(shí)間觀察[22]
let?request_method?=?req.method().to_string();
let?request_path?=?req.path();
let?histogram_timer?=?metrics::HTTP_RESPONSE_TIME_SECONDS
????.with_label_values(&[&request_method,?request_path])
????.start_timer();
histogram_timer.observe_duration();
我認(rèn)為這種方法并不精確(問題是這一時(shí)間比實(shí)際響應(yīng)時(shí)間少多少),但觀察數(shù)據(jù)將有助于作為直方圖的示例,并在 Grafana 進(jìn)一步可視化。
直方圖采樣觀察并在可配置的桶中對(duì)它們進(jìn)行計(jì)數(shù)(有默認(rèn)的桶,但很可能你需要定義為你的用例定制的桶);要配置它們,很高興知道度量值的大致分布。在此應(yīng)用程序中,響應(yīng)時(shí)間非常小,因此使用以下配置:
清單 8.響應(yīng)時(shí)間段[23]
const?HTTP_RESPONSE_TIME_CUSTOM_BUCKETS:?&[f64;?14]?=?&[
????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,
];
輸出如下所示(僅顯示部分?jǐn)?shù)據(jù)以節(jié)省空間):
清單 9. HTTP_RESPONSE_TIME_SECONDS 指標(biāo)的輸出
#?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
數(shù)據(jù)顯示落入特定觀察值桶中的觀察值數(shù)量。輸出還提供有關(guān)總計(jì)數(shù)和觀測(cè)值總和的信息。
系統(tǒng)指標(biāo)
process功能支持導(dǎo)出進(jìn)程指標(biāo)[24],例如 CPU 或內(nèi)存使用情況。你所需要的只是在Cargo.toml 之后,你會(huì)得到這樣的東西:
清單 10. process 度量的輸出
#?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
請(qǐng)注意,prometheuscrate 支持導(dǎo)出在 Linux 上運(yùn)行的應(yīng)用程序的進(jìn)程指標(biāo)(例如在 這樣[25] 的 Docker 容器中)。
指標(biāo)展示的端點(diǎn)
Actix 配置為使用此處理程序處理 GET/metrics 請(qǐng)求:
清單 11.指標(biāo)處理程序[26]
pub?async?fn?metrics()?->?Result?{
????let?encoder?=?TextEncoder::new();
????let?mut?buffer?=?vec![];
????encoder
????????.encode(&prometheus::gather(),?&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))
}
現(xiàn)在,在成功配置應(yīng)用程序后,你可以通過執(zhí)行 GET http://localhost:9000/metrics 請(qǐng)求來獲取之前描述的所有指標(biāo)。Prometheus 服務(wù)器使用端點(diǎn)來收集應(yīng)用程序的指標(biāo)。
指標(biāo)以簡單的基于文本的格式[27]公開。
03 用于指標(biāo)收集的 Prometheus 設(shè)置
Prometheus 使用以下配置收集(抓?。┲笜?biāo):
清單 12.用于度量收集的 Prometheus 配置[28]
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']
在配置中,指定了兩個(gè)作業(yè)(jobs)。前者收集應(yīng)用程序之前描述的指標(biāo),后者收集運(yùn)行容器的資源使用和性能指標(biāo)(將在關(guān)于 cAdvisor 的部分詳細(xì)描述)。scrape_interval 指定抓取目標(biāo)的頻率。metrics_path參數(shù)未指定,因此 Prometheus 期望指標(biāo)可用于路徑上的目標(biāo)/metrics。
表達(dá)式瀏覽器和圖形界面
要使用 Prometheus 的內(nèi)置表達(dá)式瀏覽器,請(qǐng)打開 http://localhost:9090/graph 并嘗試查詢前面描述的任何指標(biāo),例如,http_requests_total。使用 “Graph” 選項(xiàng)卡可視化數(shù)據(jù)。
PromQL[29] 允許你進(jìn)行更復(fù)雜的查詢;讓我們考慮幾個(gè)例子。
返回帶有指標(biāo)
http_requests_total和給定作業(yè)的所有時(shí)間序列:
http_requests_total{job="mongodb_redis_web_app"}
`job`和`instance`標(biāo)簽[會(huì)自動(dòng)連接](https://prometheus.io/docs/concepts/jobs_instances/?"會(huì)自動(dòng)連接")到由 Prometheus 服務(wù)器記下的時(shí)間序列。
-?在最近 5 分鐘內(nèi)測(cè)量的傳入請(qǐng)求的每秒返回率:
```rust
rate(http_requests_total[5m])
你可以在此處[30]找到更多示例。
04 用于度量可視化的 Grafana 設(shè)置
在這個(gè)項(xiàng)目中,Grafana 配置如下:
數(shù)據(jù)源(Grafana 將從那里請(qǐng)求數(shù)據(jù))
清單 13. Grafana 的數(shù)據(jù)源配置[31]
apiVersion:?1
datasources:
??-?name:?Prometheus
????type:?prometheus
????access:?proxy
????url:?prometheus:9090
????isDefault:?true儀表板提供程序(Grafana 將從那里加載儀表板)
清單 14. Grafana 的儀表板配置[32]
apiVersion:?1
providers:
??-?name:?'default'
????folder:?'default'
????type:?file
????allowUiUpdates:?true
????updateIntervalSeconds:?30
????options:
??????path:?/etc/grafana/provisioning/dashboards
??????foldersFromFilesStructure:?true
啟動(dòng) Docker Compose[33] 文件中指定的項(xiàng)目后,打開 http://localhost:3000/,使用admin/admin 憑據(jù)登錄,然后找到webapp_metrics儀表板。稍后,它看起來像這樣:

儀表板顯示應(yīng)用程序在簡單負(fù)載測(cè)試下的狀態(tài)。(如果你啟動(dòng)一些負(fù)載測(cè)試,為了更好地查看圖形(特別是直方圖),你需要以某種方式禁用MAX_REQUESTS_PER_MINUTE 限制[34],例如,通過該數(shù)字的急劇增加。)
為了可視化數(shù)據(jù),儀表板[35] 使用 PromQL 查詢,這些查詢利用了之前描述的指標(biāo),例如:
rate(http_response_time_seconds_sum[5m]) / rate(http_response_time_seconds_count[5m])顯示過去五分鐘的平均響應(yīng)時(shí)間
sum(increase(http_response_time_seconds_bucket{path="/planets"}[30s])) by (le)用于以熱圖[36]的形式可視化響應(yīng)時(shí)間分布。熱圖就像直方圖,但隨著時(shí)間的推移,每個(gè)時(shí)間片代表自己的直方圖
rate(process_cpu_seconds_total{job="mongodb_redis_web_app"}[1m]),sum(rate(container_cpu_usage_seconds_total{name='mongodb-redis'}[1m])) by (name)
顯示過去五分鐘的 CPU 使用率。請(qǐng)求的數(shù)據(jù)來自兩個(gè)不同的來源,分別顯示進(jìn)程和容器的 CPU 使用率。兩張圖幾乎一模一樣。(sum使用是因?yàn)?code style="font-size: 14px;padding: 2px 4px;border-radius: 4px;margin-right: 2px;margin-left: 2px;background-color: rgba(27, 31, 35, 0.05);font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace;word-break: break-all;color: rgb(60, 112, 198);">container_cpu_usage_seconds_total提供了有關(guān)每個(gè)內(nèi)核使用情況的信息。
05 使用 cAdvisor 監(jiān)控應(yīng)用容器的指標(biāo)
除了進(jìn)程的系統(tǒng)指標(biāo)(如之前所示),還可以導(dǎo)出 Docker 容器的系統(tǒng)指標(biāo)。這可以使用 cAdvisor 來完成。
cAdvisor 的 Web UI 可通過 http://localhost:8080/。所有正在運(yùn)行的 Docker 容器都顯示在 http://localhost:8080/docker/:

你可以獲取有關(guān)任何容器的資源使用情況的信息:

Prometheus 服務(wù)器從http://localhost:8080/metrics 收集指標(biāo)。
此處[37]列出了 cAdvisor 導(dǎo)出的指標(biāo)。
機(jī)器的系統(tǒng)指標(biāo)可以使用 Node exporter[38] 或 Windows exporter[39] 導(dǎo)出。
06 使用規(guī)則和 AlertManager 設(shè)置警報(bào)通知
在這個(gè)項(xiàng)目中,Prometheus 配置的以下部分負(fù)責(zé)警報(bào):
清單 15.用于警報(bào)的 Prometheus 配置[40]
rule_files:
??-?'rules.yml'
alerting:
??alertmanagers:
????-?static_configs:
????????-?targets:?['alertmanager:9093']
該alerting部分定義了 Prometheus 服務(wù)器與之通信的 AlertManager 實(shí)例。
警報(bào)規(guī)則[41]允許你根據(jù) PromQL 表達(dá)式定義一些條件:
清單 16. rules.yml 中的警報(bào)規(guī)則示例[42]
groups:
-?name:?default
??rules:
??-?alert:?SseClients
????expr:??http_connected_sse_clients?>?0
????for:?1m
????labels:
??????severity:?high
????annotations:
??????summary:?Too?many?SSE?clients
alert - 警報(bào)的名稱 expr – Prometheus 表達(dá)式形式的實(shí)際規(guī)則定義 for – 在發(fā)出警報(bào)之前需要打破規(guī)則多長時(shí)間。在我們的例子中,如果 SSE 客戶端的數(shù)量在 1 分鐘內(nèi)保持大于 0,則會(huì)發(fā)出警報(bào) labels - 可以附加到警報(bào)的額外信息,例如嚴(yán)重性 annotations - 可以附加到警報(bào)的額外描述,例如摘要
SSE 客戶端編號(hào)大于 0 的規(guī)則不是通常為應(yīng)用程序設(shè)置的規(guī)則。它被用作示例,因?yàn)槲覀冎灰岢鲆粋€(gè)請(qǐng)求就很容易違反規(guī)則。
如果規(guī)則被破壞,Prometheus 服務(wù)器將向 AlertManager 實(shí)例發(fā)送警報(bào)。它提供了許多功能,例如警報(bào)重復(fù)數(shù)據(jù)刪除、分組、靜音和向最終用戶發(fā)送通知。我們將只考慮路由能力:警報(bào)將發(fā)送到電子郵件。
AlertManager 配置如下:
清單 17. AlertManager 配置[43]
route:
??receiver:?gmail
receivers:
-?name:?gmail
??email_configs:
??-?to:?[email protected]
????from:?[email protected]
????smarthost:?smtp.gmail.com:587
????auth_username:?[email protected]
????auth_identity:?[email protected]
????auth_password:?password
在這個(gè)項(xiàng)目中,AlertManager 配置了一個(gè) Gmail 帳戶。要生成應(yīng)用密碼,你可以使用本指南[44]。
要觸發(fā)SseClients警報(bào)規(guī)則,你只需http://localhost:9000。這會(huì)將http_connected_sse_clients指標(biāo)增加 1。你可以在http://localhost:9090/alerts 上跟蹤SseClients警報(bào)的狀態(tài)。觸發(fā)后,警報(bào)將轉(zhuǎn)到Pending狀態(tài)。在rules.yml中定義的for間隔過后(在本例中為1分鐘),警報(bào)將進(jìn)入Firing狀態(tài)。

這將導(dǎo)致 Prometheus 服務(wù)器向 AlertManager 發(fā)送警報(bào)。它將決定如何處理警報(bào),在我們的例子中發(fā)送電子郵件:

07 使用 Prometheus 導(dǎo)出器監(jiān)控第三方系統(tǒng)
對(duì)于 MongoDB、Redis 等第三方工具,可以使用 Prometheus 導(dǎo)出器[45]設(shè)置監(jiān)控 。
08 啟動(dòng)
docker?compose?up?--build
09 結(jié)論
在本文中,我展示了如何在 Rust Web 應(yīng)用程序中設(shè)置指標(biāo)展示、使用 Prometheus 收集它們以及使用 Grafana 進(jìn)行數(shù)據(jù)可視化。此外,還展示了如何開始使用 cAdvisor 收集容器的指標(biāo)以及使用 AlertManager 發(fā)出警報(bào)。
原文鏈接:https://romankudryashov.com/blog/2021/11/monitoring-rust-web-application/
參考資料
mongodb-redis demo: https://github.com/rkudryashov/exploring-rust-ecosystem/tree/master/mongodb-redis
[2]這里: https://romankudryashov.com/blog/2021/06/mongodb-redis-rust/
[3]Prometheus: https://prometheus.io/
[4]Grafana: https://grafana.com/
[5]AlertManager: https://prometheus.io/docs/alerting/latest/alertmanager/
[6]cAdvisor: https://github.com/google/cadvisor
[7]Docker Compose 文件: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/docker-compose.override.yml
[8]crate: https://github.com/tikv/rust-prometheus
[9]四種核心類型: https://prometheus.io/docs/concepts/metric_types/
[10]不支持: https://github.com/tikv/rust-prometheus/issues/5
[11]指標(biāo)創(chuàng)建和注冊(cè): https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/src/metrics.rs
[12]示例: https://github.com/tikv/rust-prometheus/blob/master/examples/example_custom_registry.rs
[13]IntCounter: https://docs.rs/prometheus/latest/prometheus/type.IntCounter.html
[14]IntCounterVec: https://docs.rs/prometheus/latest/prometheus/type.IntCounterVec.html
[15]使用: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/src/main.rs
[16]使用: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/src/broadcaster.rs
[17]實(shí)現(xiàn): https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/src/broadcaster.rs
[18]function: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/src/handlers.rs
[19]function 中: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/src/broadcaster.rs
[20]連接: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/src/redis.rs
[21]直方圖: https://prometheus.io/docs/practices/histograms/
[22]響應(yīng)時(shí)間觀察: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/src/main.rs
[23]響應(yīng)時(shí)間段: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/src/metrics.rs
[24]進(jìn)程指標(biāo): https://prometheus.io/docs/instrumenting/writing_clientlibs/#process-metrics
[25]這樣: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/Dockerfile
[26]指標(biāo)處理程序: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/src/handlers.rs
[27]格式: https://github.com/prometheus/docs/blob/main/content/docs/instrumenting/exposition_formats.md
[28]配置: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/monitoring/prometheus/prometheus.yml
[29]PromQL: https://prometheus.io/docs/prometheus/latest/querying/basics/
[30]在此處: https://prometheus.io/docs/prometheus/latest/querying/examples/
[31]數(shù)據(jù)源配置: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/monitoring/grafana/provisioning/datasources/datasources.yml
[32]儀表板配置: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/monitoring/grafana/provisioning/dashboards/providers.yml
[33]Docker Compose: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/docker-compose.override.yml
[34]限制: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/src/services.rs
[35]儀表板: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/monitoring/grafana/provisioning/dashboards/webapp_metrics.json
[36]熱圖: https://grafana.com/docs/grafana/latest/basics/intro-histograms/
[37]此處: https://github.com/google/cadvisor/blob/master/docs/storage/prometheus.md
[38]Node exporter: https://github.com/prometheus/node_exporter
[39]Windows exporter: https://github.com/prometheus-community/windows_exporter
[40]配置: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/monitoring/prometheus/prometheus.yml
[41]警報(bào)規(guī)則: https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/
[42]示例: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/monitoring/prometheus/rules.yml
[43]AlertManager 配置: https://github.com/rkudryashov/exploring-rust-ecosystem/blob/master/mongodb-redis/monitoring/alertmanager/alertmanager.yml
[44]本指南: https://support.google.com/accounts/answer/185833?hl=en
[45]導(dǎo)出器: https://prometheus.io/docs/instrumenting/exporters/
推薦閱讀
我是 polarisxu,北大碩士畢業(yè),曾在 360 等知名互聯(lián)網(wǎng)公司工作,10多年技術(shù)研發(fā)與架構(gòu)經(jīng)驗(yàn)!2012 年接觸 Go 語言并創(chuàng)建了 Go 語言中文網(wǎng)!著有《Go語言編程之旅》、開源圖書《Go語言標(biāo)準(zhǔn)庫》等。
堅(jiān)持輸出技術(shù)(包括 Go、Rust 等技術(shù))、職場(chǎng)心得和創(chuàng)業(yè)感悟!歡迎關(guān)注「polarisxu」一起成長!也歡迎加我微信好友交流:gopherstudio
