Skywalking 8: 如何启用自监控(SelfObservability)

群里问的比较多,正好我看到这块。闲话不表。版本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去展示了

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章