Generating a Service Graph

本文介绍如何在Istio服务网格中生成服务图,包括安装Servicegraph插件、查看服务图及清理过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这个task向你展示如何为Istio网格中的服务生成一个图。在这个task中,你将安装Servicegraph 插件并使用基于web的界面来查看服务网格的服务图。

这个task使用 Bookinfo 作为示例应用。

Before you begin

  • 在你的集群安装Istio并部署一个应用
  • 安装Prometheus 插件。这个插件的安装指南在 Querying Metrics 中。

service graph必须使用Prometheus 插件。

Generating a Service Graph

1.为了在你的服务网格中查看图像表示,安装Servicegraph 插件。
在k8s环境中,执行:

kubectl apply -f install/kubernetes/addons/servicegraph.yaml

2.确认你的集群中服务正在运行
在k8s环境中,执行:

kubectl -n istio-system get svc servicegraph

输出类似:

NAME           CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
servicegraph   10.59.253.165   <none>        8088/TCP   30s

3.向网格发送流量。
对于Bookinfo ,在你的浏览器访问 http://$GATEWAY_URL/productpage 或执行命令:

curl http://$GATEWAY_URL/productpage

刷新几次页面(或发送几次命令)来生成一些流量。

注意: $GATEWAY_URL 是 Bookinfo 指南中设置的。

4.打开Servicegraph UI
在k8s环境中,执行:

kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=servicegraph -o jsonpath='{.items[0].metadata.name}') 8088:8088 &   

在你的浏览器访问 http://localhost:8088/force/forcegraph.html 。试着点击一个服务来查看细节。实时流量数据在下面的面板上展示。
结果类似:
这里写图片描述

1.尝试带查询参数
在浏览器访问 http://localhost:8088/force/forcegraph.html?time_horizon=15s&filter_empty=true 。注意提供的查询参数。
filter_empty=true 将只展示在这个时间范围内当前接受流量的服务。
time_horizon=15s 影响上面的过滤,同时影响点击一个服务时报告的流量信息。流量信息将会在这个特定的时间范围进行聚合。

默认行为是不过滤空服务,并使用一个5分钟的时间范围。

About the Servicegraph Add-on

Servicegraph 服务提供一个端点来生成和可视化网格中的服务到一张图中。它暴露了如下端点:

  • /force/forcegraph.html 。如上所述,这是一个交互的 D3.js 可视化。
  • /dotviz 是一个标准的Graphviz 可视化。
  • /dotgraph 提供了一个 DOT 序列化
  • /d3graph 为D3可视化提供了一个JSON 序列化。
  • /graph 提供了一个通用JSON 序列化

所有端点采用如上所述的查询参数。

Servicegraph 例子建立在Prometheus 查询的顶部,并依赖Istio metric的标准配置。

Cleanup

  • 在k8s环境中,执行如下命令移除Servicegraph 插件:
kubectl delete -f install/kubernetes/addons/servicegraph.yaml
  • 如果你不打算探索接下来地任何课题,参考 Bookinfo cleanup 指南来关闭应用。
from __future__ import print_function, with_statement import sys, time import os import string import re import subprocess import distutils.version from optparse import OptionParser import rospy from tf.srv import * import tf def listen(duration): rospy.init_node("view_frames", anonymous=True) tf_listener = tf.TransformListener() print("Listening to /tf for {} seconds".format(duration)) time.sleep(duration) print("Done Listening") return tf_listener.allFramesAsDot(rospy.Time.now()) def poll(node_name): print("Waiting for service {}/tf_frames".format(node_name)) rospy.wait_for_service('{}/tf_frames'.format(node_name)) try: print("Polling service") tf_frames_proxy = rospy.ServiceProxy('{}/tf_frames'.format(node_name), FrameGraph) output = tf_frames_proxy.call(FrameGraphRequest()) except rospy.ServiceException as e: print("Service call failed: {}".format(e)) return output.dot_graph def generate(dot_graph): with open('frames.gv', 'w') as outfile: outfile.write(dot_graph) try: # Check version, make postscript if too old to make pdf args = ["dot", "-V"] try: vstr = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[1] except OSError as ex: print("Warning: Could not execute `dot -V`. Is graphviz installed?") sys.exit(-1) v = distutils.version.StrictVersion('2.16') r = re.compile(".*version (\d+\.?\d*)") print(vstr) vstr = str(vstr) m = r.search(vstr.decode('utf-8') if not m or not m.group(1): print('Warning: failed to determine your version of dot. Assuming v2.16') else: version = distutils.version.StrictVersion(m.group(1)) print('Detected dot version {}'.format(version)) if version > distutils.version.StrictVersion('2.8'): subprocess.check_call(["dot", "-Tpdf", "frames.gv", "-o", "frames.pdf"]) else: subprocess.check_call(["dot", "-Tps2", "frames.gv", "-o", "frames.ps"]) print("frames.ps generated") except subprocess.CalledProcessError: print("failed to generate frames.pdf", file=sys.stderr) if __name__ == '__main__': parser = OptionParser(usage="usage: %prog [options]", prog='viewFrames.py') parser.add_option("--node", metavar="node name", type="string", help="Node to get frames from", dest="node") options, args = parser.parse_args() dot_graph = '' if not options.node: dot_graph = listen(5.0) else: print("Generating graph for node: ", options.node) dot_graph = poll(options.node) generate(dot_graph) 什么问题
最新发布
07-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值