[TOC]html
prometheus这个后端组件涉及到数据存储问题(levleDB,代码里面添加SDK,直接存储在本地磁盘),并且咱们有本身的prometheus集群,所以不太建议直接使用官方自带的镜像,而是采用本身的prometheus集群。git
先看看原理,mixer组件中遥测相关的对外提供的Kubernetes的Service的服务名是istio-telemetry
,mixer对外开放的exporter的数据查询接口是/metrics;istio-telemetry
开放了42422端口,用来采集istio-mesh指标,开放了9093端口,用来采集mixer自己的指标。查看istio-telemetry这个Service,能够看到以下配置:github
- name: http-monitoring
port: 9093
- name: prometheus
port: 42422
复制代码
另外就是还有一个envoy的指标,是经过statsd 转换为 prometheus 的,关于statsd exporter的更多信息查看这里,大致流程以下:json
+----------+ +-------------------+ +--------------+
| StatsD |---(UDP/TCP repeater)--->| statsd_exporter |<---(scrape /metrics)---| Prometheus |
+----------+ +-------------------+ +--------------+
复制代码
在Istio中,这个对外提供的服务名是Istio-statsd-prom-bridge
,经过9102端口对外提供服务,经过kubectl get svc -n istio-system istio-statsd-prom-bridge
能够查看到详细信息:后端
apiVersion: v1
kind: Service
metadata:
name: Istio-statsd-prom-bridge
namespace: Istio-system
labels:
chart: mixer-1.0.0
release: RELEASE-NAME
Istio: statsd-prom-bridge
spec:
ports:
- name: statsd-prom
port: 9102
- name: statsd-udp
port: 9125
protocol: UDP
selector:
Istio: statsd-prom-bridge
复制代码
这里,若是修改istio-statsd-prom-bridge这个服务的Service type类型,则可能致使ingressgateway失败,由于istio-statsd-prom-bridge的IP失效异常了。查看ingressgateway的日志能够发现:api
error initializing configuration '/etc/istio/proxy/envoy-rev0.json': malformed IP address: istio-statsd-prom-bridge
复制代码
这个时候,能够经过删除ingressgateway这个pod,重启便可生效bash
默认监控指标指的是使用初始配置时,Istio 收集的监控指标(metrics)的详细信息,能够经过更改配置来添加和删除指标,具体配置指标能够查看config.yaml配置文件中的kind: metric
,这些指标都是经过metric 模板来定义的。微信
prometheus须要采用本身的服务,所以须要禁用,而后配置好相应的,注意服务要打通,能够采用NodePort方式,也能够采用ClusterIP(prometheus的Server端要打通网络),最优的姿式固然就是服务发现。须要将本身的prometheus集群里面的配置(scrape_config)的数据采集配置上mixer的地址和采集的端口(共三个端口),而后接口API是/metrics,这样本身的集群就可以采集到mixer的数据了:网络
istio-mesh (istio-mixer.istio-system:42422): 全部 Mixer 生成的网格指标运维
mixer (istio-mixer.istio-system:9093): 全部特定于 Mixer 的指标, 用于监控 Mixer 自己
envoy (istio-mixer.istio-system:9102): envoy 生成的原始统计数据(并从 statsd 转换为 prometheus )
pre环境验证中能够将istio-telemetry和istio-statsd-prom-bridge的Service的Type的类型改成NodePort,而后经过端口映射查看;须要注意的是若是修改istio-statsd-prom-bridge的Service的Type的类型改成NodePort,则会致使ingressgateway失败,须要删除ingressgateway的pod进行重启生效。
而后能够经过各自的 /metrics 接口查看数据
上述的方案都是经过NodePort的方式,这样的话,须要手动配置要采集的目标地址(ip:port/URI),可是线上应用应该要采用prometheus的服务发现功能,自动发现节点并采集,后面这个须要和运维同窗沟通,如何实现自动发现服务
新增Istio组件的采集指标,须要作相关配置,能够详见收集指标和日志
现有Istio默认的监控指标有这些
Istio默认有grafana服务,而且已经有相关面板配置ok,只须要查看,可是由于咱们公司本身已有一套成熟的prometheus+grafana方案,运维配套、权限管理、组织管理等比较成熟,而且运维还须要兼顾容器内的服务和容器外的服务,所以Istio中,更适合采用外部已有的grafana服务。
只是咱们须要将现有Istio提供的这些面板都经过模板方式转移到运维的grafana中
两个服务都采用二进制安装部署
启动prometheus:./prometheus;访问prometheus
启动grafana:/grafana-server ; 访问grafana
配置prometheus的scrape_configs,新增Istio相关的采集
- job_name: 'Istio'
metrics_path: '/metrics'
static_configs:
- targets: ['172.31.2.2:32398']
labels:
group: 'Istio-mesh'
- targets: ['172.31.2.2:32697']
labels:
group: 'mixer'
- targets: ['172.31.2.2:32744']
labels:
group: 'envoy'
复制代码
而后重启prometheus,经过http://172.31.36.68:9090/config
查看
而后查看采集指标,搜索isito,发现有了数据
先add data source,设置默认的数据源,在setting中的type中选择prometheus,url选择地址http://172.31.2.2:9090,而后save and test
在原有grafana系统中,Share dashboard,而后Export到文件,而后再在新的grafana中import Json file,而后选定prometheus便可。这样默认获得是DashBoard是没法编辑的,以下两个方式能够调整为可编辑状态:
导出的Json File,须要修改editable为true,不然不能修改只能查看
或者新版能够经过admin帐号来Make dashboard editable
【"欢迎关注个人微信公众号:Linux 服务端系统研发,后面会大力经过微信公众号发送优质文章"】