Prometheus配置解析小結(jié)
1.Prometheus整體架構(gòu)圖
2.配置文件
# 全局配置 global: scrape_interval: 15s # 多久 收集 一次數(shù)據(jù) evaluation_interval: 30s # 多久評(píng)估一次 規(guī)則 scrape_timeout: 10s # 每次 收集數(shù)據(jù)的 超時(shí)時(shí)間 # 當(dāng)Prometheus和外部系統(tǒng)(聯(lián)邦, 遠(yuǎn)程存儲(chǔ), Alertmanager)通信的時(shí)候,添加標(biāo)簽到任意的時(shí)間序列或者報(bào)警 external_labels: monitor: codelab foo: bar # 規(guī)則文件, 可以使用通配符 rule_files: - "first.rules" - "my/*.rules" # 遠(yuǎn)程寫入功能相關(guān)的設(shè)置 remote_write: - url: http://remote1/push write_relabel_configs: - source_labels: [__name__] regex: expensive.* action: drop - url: http://remote2/push # 遠(yuǎn)程讀取相關(guān)功能的設(shè)置 remote_read: - url: http://remote1/read read_recent: true - url: http://remote3/read read_recent: false required_matchers: job: special # 收集數(shù)據(jù) 配置 列表 scrape_configs: - job_name: prometheus # 必須配置, 自動(dòng)附加的job labels, 必須唯一 honor_labels: true # 標(biāo)簽沖突, true 為以抓取的數(shù)據(jù)為準(zhǔn) 并 忽略 服務(wù)器中的, false 為 通過(guò)重命名來(lái)解決沖突 # scrape_interval is defined by the configured global (15s). # scrape_timeout is defined by the global default (10s). metrics_path: '/metrics' # scheme defaults to 'http'. # 文件服務(wù)發(fā)現(xiàn)配置 列表 file_sd_configs: - files: # 從這些文件中提取目標(biāo) - foo/*.slow.json - foo/*.slow.yml - single/file.yml refresh_interval: 10m # 刷新文件的 時(shí)間間隔 - files: - bar/*.yaml # 使用job名作為label的 靜態(tài)配置目錄 的 列表 static_configs: - targets: ['localhost:9090', 'localhost:9191'] labels: my: label your: label # 目標(biāo)節(jié)點(diǎn) 重新打標(biāo)簽 的配置 列表. 重新標(biāo)記是一個(gè)功能強(qiáng)大的工具,可以在抓取目標(biāo)之前動(dòng)態(tài)重寫目標(biāo)的標(biāo)簽集。 可以配置多個(gè),按照先后順序應(yīng)用 relabel_configs: - source_labels: [job, __meta_dns_name] # 從現(xiàn)有的標(biāo)簽中選擇源標(biāo)簽, 最后會(huì)被 替換, 保持, 丟棄 regex: (.*)some-[regex] # 正則表達(dá)式, 將會(huì)提取source_labels中匹配的值 target_label: job # 在替換動(dòng)作中將結(jié)果值寫入的標(biāo)簽. replacement: foo-${1} # 如果正則表達(dá)匹配, 那么替換值. 可以使用正則表達(dá)中的 捕獲組 # action defaults to 'replace' - source_labels: [abc] # 將abc標(biāo)簽的內(nèi)容復(fù)制到cde標(biāo)簽中 target_label: cde - replacement: static target_label: abc - regex: replacement: static target_label: abc bearer_token_file: valid_token_file # 可選的, bearer token 文件的信息 - job_name: service-x # HTTP basic 認(rèn)證信息 basic_auth: username: admin_name password: "multiline\nmysecret\ntest" scrape_interval: 50s # 對(duì)于該job, 多久收集一次數(shù)據(jù) scrape_timeout: 5s sample_limit: 1000 # 每次 收集 樣本數(shù)據(jù)的限制. 0 為不限制 metrics_path: /my_path # 從目標(biāo) 獲取數(shù)據(jù)的 HTTP 路徑 scheme: https # 配置用于請(qǐng)求的協(xié)議方案 # DNS 服務(wù)發(fā)現(xiàn) 配置列表 dns_sd_configs: - refresh_interval: 15s names: # 要查詢的DNS域名列表 - first.dns.address.domain.com - second.dns.address.domain.com - names: - first.dns.address.domain.com # refresh_interval defaults to 30s. # 目標(biāo)節(jié)點(diǎn) 重新打標(biāo)簽 的配置 列表 relabel_configs: - source_labels: [job] regex: (.*)some-[regex] action: drop - source_labels: [__address__] modulus: 8 target_label: __tmp_hash action: hashmod - source_labels: [__tmp_hash] regex: 1 action: keep - action: labelmap regex: 1 - action: labeldrop regex: d - action: labelkeep regex: k # metric 重新打標(biāo)簽的 配置列表 metric_relabel_configs: - source_labels: [__name__] regex: expensive_metric.* action: drop - job_name: service-y # consul 服務(wù)發(fā)現(xiàn) 配置列表 consul_sd_configs: - server: 'localhost:1234' # consul API 地址 token: mysecret services: ['nginx', 'cache', 'mysql'] # 被檢索目標(biāo)的 服務(wù) 列表. 如果不定義那么 所有 服務(wù) 都會(huì)被 收集 scheme: https tls_config: ca_file: valid_ca_file cert_file: valid_cert_file key_file: valid_key_file insecure_skip_verify: false relabel_configs: - source_labels: [__meta_sd_consul_tags] separator: ',' regex: label:([^=]+)=([^,]+) target_label: ${1} replacement: ${2} - job_name: service-z # 收集 數(shù)據(jù)的 TLS 設(shè)置 tls_config: cert_file: valid_cert_file key_file: valid_key_file bearer_token: mysecret - job_name: service-kubernetes # kubernetes 服務(wù) 發(fā)現(xiàn) 列表 kubernetes_sd_configs: - role: endpoints # 必須寫, 必須是endpoints, service, pod, node, 或者 ingress api_server: 'https://localhost:1234' basic_auth: # HTTP basic 認(rèn)證信息 username: 'myusername' password: 'mysecret' - job_name: service-kubernetes-namespaces kubernetes_sd_configs: - role: endpoints # 應(yīng)該被發(fā)現(xiàn)的 kubernetes 對(duì)象 實(shí)體 api_server: 'https://localhost:1234' # API Server的地址 namespaces: # 可選的命名空間發(fā)現(xiàn), 如果省略 那么所有的命名空間都會(huì)被使用 names: - default - job_name: service-marathon # Marathon 服務(wù)發(fā)現(xiàn) 列表 marathon_sd_configs: - servers: - 'https://marathon.example.com:443' tls_config: cert_file: valid_cert_file key_file: valid_key_file - job_name: service-ec2 ec2_sd_configs: - region: us-east-1 access_key: access secret_key: mysecret profile: profile - job_name: service-azure azure_sd_configs: - subscription_id: 11AAAA11-A11A-111A-A111-1111A1111A11 tenant_id: BBBB222B-B2B2-2B22-B222-2BB2222BB2B2 client_id: 333333CC-3C33-3333-CCC3-33C3CCCCC33C client_secret: mysecret port: 9100 - job_name: service-nerve nerve_sd_configs: - servers: - localhost paths: - /monitoring - job_name: 0123service-xxx metrics_path: /metrics static_configs: - targets: - localhost:9090 - job_name: 測(cè)試 metrics_path: /metrics static_configs: - targets: - localhost:9090 - job_name: service-triton triton_sd_configs: - account: 'testAccount' dns_suffix: 'triton.example.com' endpoint: 'triton.example.com' port: 9163 refresh_interval: 1m version: 1 tls_config: cert_file: testdata/valid_cert_file key_file: testdata/valid_key_file # Alertmanager相關(guān)的配置 alerting: alertmanagers: - scheme: https static_configs: - targets: - "1.2.3.4:9093" - "1.2.3.5:9093" - "1.2.3.6:9093"
3.基于consul的服務(wù)發(fā)現(xiàn)
注意: Prometheus的consul_sd_config
使用的是catalog的API。
使用http接口注冊(cè)consul
# curl -X PUT -d '{"ID": "node_exporter", "Name": "node_exporter", "Address": "10.6.28.37", "Port": 9100, "Tags": ["lock"], "EnableTagOverride": false}' http://10.6.28.37:8500/v1/agent/service/register
# curl -s http://10.6.28.37:8500/v1/agent/services|jq { "node_exporter": { "ID": "node_exporter", "Service": "node_exporter", "Tags": [ "lock" ], "Address": "10.6.28.37", "Port": 9100, "EnableTagOverride": false, "CreateIndex": 0, "ModifyIndex": 0 } }
4.prometheus配置詳解
當(dāng)查詢的時(shí)候存在十分復(fù)雜的表達(dá)式,這樣會(huì)降低prometheus的性能可以使用Recording rules
允許您預(yù)先計(jì)算經(jīng)常需要的或計(jì)算上昂貴的表達(dá)式,并將其結(jié)果保存為新的 time series。這對(duì)于儀表板尤其有用,每次刷新時(shí)它都需要重復(fù)查詢相同的表達(dá)式。 將復(fù)雜的計(jì)算后臺(tái)計(jì)算 放到一個(gè)新的時(shí)序里
二元算術(shù)運(yùn)算符 應(yīng)用于 應(yīng)用于 即時(shí)向量/即時(shí)向量 時(shí),運(yùn)算符將應(yīng)用于左側(cè)向量中的元素及其在右側(cè)向量中的匹配到的元素.
運(yùn)算結(jié)果被傳播到結(jié)果向量中,并且度量名稱被丟棄.那些在右側(cè)向量中沒(méi)有匹配條目的條目 不是結(jié)果的一部分。
例如:
employee_age_bucket_bucket{le=~"20|30|40"} + employee_age_bucket_bucket{le=~"30|40|50"}
返回的結(jié)果是:
{instance="10.0.86.71:8080",job="prometheus",le="30"} 6000
{instance="10.0.86.71:8080",job="prometheus",le="40"} 8000
到此這篇關(guān)于Prometheus配置解析小姐的文章就介紹到這了,更多相關(guān)Prometheus配置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
鴻蒙(HarmonyOS)實(shí)現(xiàn)隱私政策彈窗效果
但在HarmonyOS中,由于系統(tǒng)彈窗的顯示優(yōu)先級(jí)高于其他組件,即使跳轉(zhuǎn)到Web頁(yè)面,彈窗依然會(huì)顯示在最上層,下面給大家分享鴻蒙(HarmonyOS)實(shí)現(xiàn)隱私政策彈窗,感興趣的朋友跟隨小編一起看看吧2024-08-08centos搭建code-server配置HTTPS登錄頁(yè)自定義實(shí)現(xiàn)步驟
這篇文章主要為大家介紹了centos搭建code-server及配置HTTPS、登錄頁(yè)自定義實(shí)現(xiàn)步驟詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05在C#和Java語(yǔ)言中for和foreach的區(qū)別詳解
這篇文章主要介紹了在C#和Java語(yǔ)言中for和foreach的區(qū)別詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-09-09遠(yuǎn)程過(guò)程調(diào)用RPC基本概念及實(shí)現(xiàn)原理
這篇文章介紹了遠(yuǎn)程過(guò)程調(diào)用RPC基本概念及實(shí)現(xiàn)原理,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-01-01WebStorm打開(kāi)多個(gè)項(xiàng)目的三種方法總結(jié)
WebStorm支持多項(xiàng)目管理,本文介紹了三種方法:使用項(xiàng)目導(dǎo)航面板、窗口分割和多個(gè)WebStorm實(shí)例,項(xiàng)目導(dǎo)航面板可以在同一窗口內(nèi)管理多個(gè)項(xiàng)目,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-09-09MobaXterm遠(yuǎn)程登錄工具功能與應(yīng)用小結(jié)
MobaXterm是一款功能強(qiáng)大的遠(yuǎn)程終端軟件,主要支持SSH登錄,擁有多種遠(yuǎn)程協(xié)議,實(shí)現(xiàn)跨平臺(tái)訪問(wèn),它包括多會(huì)話管理、本地命令行執(zhí)行、圖形化界面集成和文件傳輸?shù)裙δ?提供豐富的自定義選項(xiàng)和安全特性,感興趣的朋友一起看看吧2025-02-02Gateway網(wǎng)關(guān)工作原理及使用方法
本文詳細(xì)講解了Gateway網(wǎng)關(guān)工作原理及使用方法,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-12-12