美文网首页
可观测性之profile

可观测性之profile

作者: wwq2020 | 来源:发表于2026-02-09 13:33 被阅读0次

背景

使用pyroscope可以对应用程序进行profile,从而了解应用程序的性能问题。

操作步骤

安装pyroscope和grafana

helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
kubectl create namespace pyroscope-test
helm -n pyroscope-test install pyroscope grafana/pyroscope
helm install grafana grafana/grafana -n pyroscope-test

部署测试服务

创建demo.go内容如下

package main

import (
    "io"
    "net/http"
    _ "net/http/pprof"
)

func main() {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        io.WriteString(w, "hello world")
    })
    if err := http.ListenAndServe(":80", nil); err != nil {
        panic(err)
    }
}

创建Dockerfile内容如下

from golang:1.25 as builder
workdir /app
copy demo.go .
copy go.mod .
run CGO_ENABLED=0 go build -o demo .

from alpine
workdir /app
copy --from=builder /app/demo .
cmd ["/app/demo"]

构建测试镜像

docker build -t demo:v0.1 .

部署测试,yaml如下

apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo
  namespace: pyroscope-test
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: demo
  template:
    metadata:
      annotations:
        profiles.grafana.com/cpu.port_name: http
        profiles.grafana.com/cpu.scrape: "true"
      labels:
        app.kubernetes.io/name: demo
        name: demo
    spec:
      containers:
      - image: demo:v0.1
        imagePullPolicy: IfNotPresent
        name: demo
        ports:
        - containerPort: 80
          name: http
          protocol: TCP
      restartPolicy: Always

查看profile

端口映射出来

kubectl port-forward svc/grafana 3000:3000

打开

http://localhost:3000

选择Drilldown,选择Profiles,选择profile type为cpu,如下


image.png

选择flamegraph,得到如下


image.png
image.png

相关文章

  • OpenTelemetry 简析

    OpenTelemetry 是 CNCF 的一个可观测性项目,旨在提供可观测性领域的标准化方案,解决观测数据的数据...

  • 第三十六章 使用 ^PROFILE 监控例程性能 - Using

    第三十六章 使用 ^PROFILE 监控例程性能 - Using ^PROFILE ^PROFILE 实用程序可帮...

  • Mac下iTerm2的显示文件件颜色

    方案① 修改 .bash_profile, 添加如下内容: source .bash_profile 使之生效。再...

  • 习水之性,有容乃大

    水可柔可刚,可直可曲。人若欲行之远,须习水之性,有容乃大。 习水之性,容己而致远。人立于世,时常遇...

  • maven profile多环境配置

    使用maven profile实现多环境配置(代码) maven profile 实现多环境可移植构建 在开发过程...

  • 参数估计(二)最大似然估计

    概率p(x|θ)是在已知参数θ的情况下,发生观测结果x可能性大小; 似然性L(θ|x)是从观测结果x出发,分布系数...

  • 可观测性的历史

    这方面要跟进新动向 https://jimmysong.io/docs/opentelemetry-obervab...

  • 什么是可观测性

    可观测性有许多名称,如监测、审计、遥测、仪器。忽略这些细微差别,所有这些词本质上的意思都是一样的:度量您的基础设施...

  • 可观测性的意义

    差不多在五年前,分布式系统已经成熟,微服务架构尚未普及,可观测问题就已经在桎梏技术团队的工作效率。 一个To C的...

  • 隐马尔可夫模型

    隐马尔可夫模型(HMM) 设 表示隐状态序列, 表示观测状态序列, 表示观测状态集, 表示隐状态集合。定义 ...

网友评论

      本文标题:可观测性之profile

      本文链接:https://www.haomeiwen.com/subject/bexurstx.html