查询普罗米修斯的指标
基于已经搭建好的istio环境和bookinfo应用
- 创建配置
[root@k8-master-1 ~]# cat new_telemetry.yaml
apiVersion: "config.istio.io/v1alpha2"
kind: metric
metadata:
name: doublerequestcount
namespace: istio-system
spec:
value: "2" # count each request twice
dimensions:
reporter: conditional((context.reporter.kind | "inbound") == "outbound", "client", "server")
source: source.workload.name | "unknown"
destination: destination.workload.name | "unknown"
message: '"twice the fun!"'
monitored_resource_type: '"UNSPECIFIED"'
---
# Configuration for a Prometheus handler
apiVersion: "config.istio.io/v1alpha2"
kind: prometheus
metadata:
name: doublehandler
namespace: istio-system
spec:
metrics:
- name: double_request_count # Prometheus metric name
instance_name: doublerequestcount.metric.istio-system # Mixer instance name (fully-qualified)
kind: COUNTER
label_names:
- reporter
- source
- destination
- message
---
# Rule to send metric instances to a Prometheus handler
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: doubleprom
namespace: istio-system
spec:
actions:
- handler: doublehandler.prometheus
instances:
- doublerequestcount.metric
---
# Configuration for logentry instances
apiVersion: "config.istio.io/v1alpha2"
kind: logentry
metadata:
name: newlog
namespace: istio-system
spec:
severity: '"warning"'
timestamp: request.time
variables:
source: source.labels["app"] | source.workload.name | "unknown"
user: source.user | "unknown"
destination: destination.labels["app"] | destination.workload.name | "unknown"
responseCode: response.code | 0
responseSize: response.size | 0
latency: response.duration | "0ms"
monitored_resource_type: '"UNSPECIFIED"'
---
# Configuration for a stdio handler
apiVersion: "config.istio.io/v1alpha2"
kind: stdio
metadata:
name: newhandler
namespace: istio-system
spec:
severity_levels:
warning: 1 # Params.Level.WARNING
outputAsJson: true
---
# Rule to send logentry instances to a stdio handler
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: newlogstdio
namespace: istio-system
spec:
match: "true" # match for all requests
actions:
- handler: newhandler.stdio
instances:
- newlog.logentry
---
- 生成配置
kubectl apply -f new_telemetry.yaml
- 测试
1.向bookinfo应用发送流量
curl 192.168.233.101:31380/productpage
2.将Prometheus暴露访问
修改为NodePort
kubectl edit svc prometheus -n istio-system
3.访问Prometheus查看数据
http://192.168.233.101:30090/graph
4.其他查询
#对productpage服务的所有请求的总数
istio_requests_total{destination_service="productpage.default.svc.cluster.local"}
#所有的请求的总数v3的的reviews服务
istio_requests_total{destination_service="reviews.default.svc.cluster.local", destination_version="v3"}
#过去5分钟内对所有productpage服务实例的请求率
rate(istio_requests_total{destination_service=~"productpage.*", response_code="200"}[5m])
TCP
- 创建yaml文件以保存Istio将自动生成和手机的新指标的配置
[root@k8-master-1 ~]# cat tcp_telemetry.yaml
# Configuration for a metric measuring bytes sent from a server
# to a client
apiVersion: "config.istio.io/v1alpha2"
kind: metric
metadata:
name: mongosentbytes
namespace: default
spec:
value: connection.sent.bytes | 0 # uses a TCP-specific attribute
dimensions:
source_service: source.workload.name | "unknown"
source_version: source.labels["version"] | "unknown"
destination_version: destination.labels["version"] | "unknown"
monitoredResourceType: '"UNSPECIFIED"'
---
# Configuration for a metric measuring bytes sent from a client
# to a server
apiVersion: "config.istio.io/v1alpha2"
kind: metric
metadata:
name: mongoreceivedbytes
namespace: default
spec:
value: connection.received.bytes | 0 # uses a TCP-specific attribute
dimensions:
source_service: source.workload.name | "unknown"
source_version: source.labels["version"] | "unknown"
destination_version: destination.labels["version"] | "unknown"
monitoredResourceType: '"UNSPECIFIED"'
---
# Configuration for a Prometheus handler
apiVersion: "config.istio.io/v1alpha2"
kind: prometheus
metadata:
name: mongohandler
namespace: default
spec:
metrics:
- name: mongo_sent_bytes # Prometheus metric name
instance_name: mongosentbytes.metric.default # Mixer instance name (fully-qualified)
kind: COUNTER
label_names:
- source_service
- source_version
- destination_version
- name: mongo_received_bytes # Prometheus metric name
instance_name: mongoreceivedbytes.metric.default # Mixer instance name (fully-qualified)
kind: COUNTER
label_names:
- source_service
- source_version
- destination_version
---
# Rule to send metric instances to a Prometheus handler
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
name: mongoprom
namespace: default
spec:
match: context.protocol == "tcp"
&& destination.service == "mongodb.default.svc.cluster.local"
actions:
- handler: mongohandler.prometheus
instances:
- mongoreceivedbytes.metric
- mongosentbytes.metric
- 根据配置创建
kubectl apply -f tcp_telemetry.yaml
- 安装服务
1.安装v2的ratings服务
#自动注入
kubectl apply -f istio-1.0.0/samples/bookinfo/platform/kube/bookinfo-ratings-v2.yaml
#手动注入
kubectl apply -f <(istioctl kube-inject -f istio-1.0.0/samples/bookinfo/platform/kube/bookinfo-ratings-v2.yaml)
2.安装mongodb服务
#自动注入
kubectl apply -f istio-1.0.0/samples/bookinfo/platform/kube/bookinfo-db.yaml
#手动注入
kubectl apply -f <(istioctl kube-inject -f istio-1.0.0/samples/bookinfo/platform/kube/bookinfo-db.yaml)
3.创建规则
kubectl apply -f samples/bookinfo/networking/destination-rule-all.yaml
#启动了双向TLS认证
kubectl apply -f samples/bookinfo/networking/destination-rule-all-mtls.yaml
#查看目标规则
kubectl get destinationrules -o yaml
4.创建ratings和reviews虚拟服务
kubectl apply -f istio-1.0.0/samples/bookinfo/networking/virtual-service-ratings-db.yaml
5.测试
#发送流量
curl http://192.168.233.101:32380/productpage
执行istio_mongo_received_bytes查询
使用Grafana可视化
- 将Grafana暴露访问
kubectl edit svc grafana -n istio-system
- 访问查看测试
1.访问
http://192.168.233.101:30091
2.测试
3.查看