Istio自定义指标
环境说明
namespace:default,test
pod: proxy
查看EnvoyFilter
~# kubectl -n istio-system get envoyfilter
NAME AGE
stats-filter-1.13 6d1h
stats-filter-1.14 6d1h
stats-filter-1.15 6d1h
tcp-stats-filter-1.13 6d1h
tcp-stats-filter-1.14 6d1h
tcp-stats-filter-1.15 6d1h
创建EnvoyFilter 配置副本
~# kubectl -n istio-system get envoyfilter stats-filter-1.15 -o yaml > stats-filter-1.15.yaml
DefaultStatTags 列表
查看标准指标
添加DefaultStatTags
istio-operator.yaml
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
spec:
profile: demo # profile=default为生成环境
values:
telemetry:
v2:
prometheus:
configOverride:
inboundSidecar:
metrics:
- name: requests_total
dimensions:
destination_port: string(destination.port)
request_host: request.host
outboundSidecar:
metrics:
- name: requests_total
dimensions:
destination_port: string(destination.port)
request_host: request.host
gateway:
metrics:
- name: requests_total
dimensions:
destination_port: string(destination.port)
request_host: request.host
应用指标
# istioctl install -f istio-operator.yaml -y
请求访问
# while true;do curl `kubectl get svc -l app=svc-proxy -o jsonpath='{.items[0].spec.clusterIP}'`;done
查看指标
还原默认指标
# istioctl install --set profile=demo -y
添加extraStatTags
istio-operator.yaml
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
spec:
profile: demo
values:
telemetry:
v2:
prometheus:
configOverride:
inboundSidecar:
metrics:
- name: requests_total
dimensions:
destination_port: string(destination.port)
request_host: request.host
request_method: request.method
tags_to_remove:
- request_protocol
outboundSidecar:
metrics:
- name: requests_total
dimensions:
destination_port: string(destination.port)
request_host: request.host
request_method: request.method
tags_to_remove:
- request_protocol
gateway:
metrics:
- name: requests_total
dimensions:
destination_port: string(destination.port)
request_host: request.host
request_method: request.method
tags_to_remove:
- request_protocol
meshConfig:
defaultConfig:
extraStatTags:
- request_method
应用指标
# istioctl install -f istio-operator.yaml -y
重新创建pod
# kubectl apply -f deploy-demoapp-v10.yaml
请求访问
# while true;do curl `kubectl get svc -n default -l app=svc-proxy -o jsonpath='{.items[0].spec.clusterIP}'`; sleep 0.$RANDOM;done
# while true;do curl `kubectl get svc -n test -l app=svc-proxy -o jsonpath='{.items[0].spec.clusterIP}'`; sleep 0.$RANDOM;done
查看指标
namespace级别自定义
istio-operator.yaml
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
spec:
profile: demo
values:
telemetry:
v2:
prometheus:
configOverride:
inboundSidecar:
metrics:
- name: requests_total
dimensions:
destination_port: string(destination.port)
request_host: request.host
request_method: request.method
tags_to_remove:
- request_protocol
outboundSidecar:
metrics:
- name: requests_total
dimensions:
destination_port: string(destination.port)
request_host: request.host
request_method: request.method
tags_to_remove:
- request_protocol
gateway:
metrics:
- name: requests_total
dimensions:
destination_port: string(destination.port)
request_host: request.host
request_method: request.method
tags_to_remove:
- request_protocol
meshConfig:
defaultConfig:
extraStatTags:
- request_method
应用指标
# istioctl install -f istio-operator.yaml -y
namespace-metrics.yaml
apiVersion: telemetry.istio.io/v1alpha1
kind: Telemetry
metadata:
name: namespace-metrics
namespace: test
spec:
selector:
matchLabels:
app: proxy
# no selector specified, applies to all workloads in the namespace
metrics:
- providers:
- name: prometheus
overrides:
# match clause left off matches all istio metrics, client and server
- tagOverrides: # 在标准指标上修改
request_method:
value: "request.method"
request_host:
value: "request.host"
response_code:
operation: REMOVE
应用Telemetry
# kubectl -n test apply -f prometh.yaml
重新创建pod
# kubectl apply -f deploy-demoapp-v10.yaml
请求访问
# while true;do curl `kubectl get svc -n default -l app=svc-proxy -o jsonpath='{.items[0].spec.clusterIP}'`; sleep 0.$RANDOM;done
# while true;do curl `kubectl get svc -n test -l app=svc-proxy -o jsonpath='{.items[0].spec.clusterIP}'`; sleep 0.$RANDOM;done
查看指标
标准指标 namespace:default namespace: test namespace: test
app: proxy app: proxy app: proxy app: demoapp
在工作负载级自定义
istio-operator.yaml
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
spec:
profile: demo # profile=default为生成环境
values:
telemetry:
v2:
prometheus:
configOverride:
inboundSidecar:
metrics:
- name: requests_total
dimensions:
destination_port: string(destination.port)
request_host: request.host
outboundSidecar:
metrics:
- name: requests_total
dimensions:
destination_port: string(destination.port)
request_host: request.host
gateway:
metrics:
- name: requests_total
dimensions:
destination_port: string(destination.port)
request_host: request.host
应用指标
# istioctl install -f istio-operator.yaml -y
deploy-proxy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: proxy
spec:
progressDeadlineSeconds: 600
replicas: 1
selector:
matchLabels:
app: proxy
template:
metadata:
annotations:
sidecar.istio.io/extraStatTags: destination_port,request_host,request_method
labels:
app: proxy
重新创建pod
# kubectl apply -f deploy-proxy.yaml -f deploy-demoapp-v10.yaml
请求访问
# while true;do curl `kubectl get svc -l app=svc-proxy -o jsonpath='{.items[0].spec.clusterIP}'`;done
查看指标
app=proxy
~# kubectl exec "$(kubectl get pod -l app=proxy -o jsonpath='{.items[0].metadata.name}')" -c istio-proxy -- curl -sS 'localhost:15000/stats/prometheus' | grep istio_requests_total
app=demoapp
~# kubectl exec "$(kubectl get pod -l app=demoapp -o jsonpath='{.items[0].metadata.name}')" -c istio-proxy -- curl -sS 'localhost:15000/stats/prometheus' | grep istio_requests_total
移除指标
remove-response-code.yaml
apiVersion: telemetry.istio.io/v1alpha1
kind: Telemetry
metadata:
name: remove-response-code
namespace: foo
spec:
selector:
matchLabels:
service.istio.io/canonical-name: bar
metrics:
- providers:
- name: prometheus
overrides:
- match:
metric: REQUEST_COUNT
tagOverrides:
response_code:
operation: REMOVE
- match:
metric: REQUEST_DURATION
tagOverrides:
response_code:
operation: REMOVE
- match:
metric: REQUEST_SIZE
tagOverrides:
response_code:
operation: REMOVE
- match:
metric: RESPONSE_SIZE
tagOverrides:
response_code:
operation: REMOVE
应用资源
# kubectl apply -f remove-response-code.yaml
参考文档
https://istio.io/latest/docs/reference/config/telemetry/