Pyroscope 是一个持续调优的工具,可以检查程序代码在运行时,检查 CPU 的使用率和内存内存的使用率,本文将介绍如何搭建和使用
安装
Pyroscope 的安装将在 k8s 上进行,并使用 helm 进行部署。分为 server 的安装和 agent 的安装:
server 的安装,命令如下:
kubectl create namespace pyroscope-test
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
helm -n pyroscope-test upgrade --install pyroscope grafana/pyroscope --set pyroscope.service.type=NodePort
agent 的安装,安装时需要将下面的 yaml 文件保存为 values.yaml 执行如下命令:
agent:
mode: 'flow'
configMap:
create: true
content: |
discovery.kubernetes "local_pods" {
selectors {
field = "spec.nodeName=" + env("HOSTNAME")
role = "pod"
}
role = "pod"
}
pyroscope.ebpf "instance" {
forward_to = [pyroscope.write.endpoint.receiver]
targets = discovery.kubernetes.local_pods.targets
}
pyroscope.write "endpoint" {
endpoint {
url = "http://pyroscope.pyroscope-test.svc.cluster.local.:4040/"
}
}
securityContext:
privileged: true
runAsGroup: 0
runAsUser: 0
controller:
hostPID: true
helm install pyroscope-ebpf grafana/grafana-agent -f values.yaml
这个文档中使用的 agent 的模式为 ebpf ,这个模式要求内核要在 4.9 以上。
查看
安装完成之后,执行 kubectl port-forward -n pyroscope-test service/grafana 3000:80
即可在浏览器访问 http://127.0.0.1 查看调用信息。