羣裏問的比較多,正好我看到這塊。閒話不表。版本8.1.0
skywalking 支持遙測技術(telemetry), 這就比較好了,既可以分析別人,又可以自身被分析,所以我們需要開啓配置:編輯config/application.yml文件,改爲如下,端口這裏用了1543,當然可以自定義。
telemetry:
selector: ${SW_TELEMETRY:prometheus}
none:
prometheus:
host: ${SW_TELEMETRY_PROMETHEUS_HOST:0.0.0.0}
port: ${SW_TELEMETRY_PROMETHEUS_PORT:1543}
Skywalking 支持 prometheus fetcher,所以可以去採集指標,這裏採用拉取模式,這裏是有別於receiver收取模式的。同樣編輯config/application.yml, 將active設爲true
prometheus-fetcher:
selector: ${SW_PROMETHEUS_FETCHER:default}
default:
active: ${SW_PROMETHEUS_FETCHER_ACTIVE:true}
config/fetcher-prom-rules/self.yaml 文件是skywalking官方文件,修改:
target 改爲你的ip和上面定義的端口,這裏主要是爲了在UI上顯示實例。kill 掉skywalking server, 重啓服務。
可以在本地驗證:curl localhost:1543/metrics會列出很多指標:
skywalking fetcher會定時拉取這個指標存儲你使用的底層存儲裏,我這裏用elasticsearch7, 存儲的索引是:[namespace]_meter_*開頭的索引裏,這裏namespace是你在存儲配置裏配置的namespace。
過一段時間Skywalking UI裏就可以看到了,如下圖:
當然我們照着葫蘆畫瓢從其他prometheus拉取數據,我們在config/fetcher-prom-rules/ 新建yaml文件,名稱隨意,這裏就用host_pro.yaml做名字吧。內容格式如下:
(https://github.com/apache/skywalking/blob/master/docs/en/setup/backend/backend-fetcher.md)
<duration>
: 時間間隔. 基於 ISO-8601 格式(24小時制):PnDTnHnMn.nS
,如下例-
"PT20.345S" -- parses as "20.345 seconds" "PT15M" -- parses as "15 minutes" (where a minute is 60 seconds) "PT10H" -- parses as "10 hours" (where an hour is 3600 seconds) "P2D" -- parses as "2 days" (where a day is 24 hours or 86400 seconds) "P2DT3H4M" -- parses as "2 days, 3 hours and 4 minutes" "P-6H3M" -- parses as "-6 hours and +3 minutes" "-P6H3M" -- parses as "-6 hours and -3 minutes" "-P-6H+3M" -- parses as "+6 hours and -3 minutes"
<labelname>
: 字符串,需要滿足正則 [a-zA-Z_][a-zA-Z0-9_]*<labelvalue>
:unicode字符串<host>
: 主機名或ip地址和端口號<path>
: URL路徑<string>
: 正常字符串
# 採集頻率. fetcherInterval: <duration> #每次採集的超時時間. fetcherTimeout: <duration> # The HTTP resource path on which to fetch metrics from targets. metricsPath: <path> #Statically configured targets. staticConfig: targets: #獲取來源 [ - <host> ] labels: [ <labelname>: <labelvalue> ... ] # Metrics rule allow you to recompute queries. metricsRules: [ - <metric_rules> ]
然後可以在skywalking 新建dashboard去展示了