zoon/pyrospy

从 phpspy 到 pyroscope 的适配器

维护者

详细信息

github.com/zoonru/pyrospy

源代码

问题

安装: 42

依赖项: 0

建议者: 0

安全: 0

星标: 17

关注者: 3

分支: 3

开放问题: 0

类型:项目

v2.2.0 2024-08-16 15:27 UTC

This package is auto-updated.

Last update: 2024-09-16 15:38:58 UTC


README

phpspy 适配到 pyroscope.io

关于我们

Phpspy 要求

  • apt install binutils 用于 Ubuntu/Debian
  • 要在 docker 容器中使用,它必须是 privileged 或具有能力 SYS_PTRACE

参数

Usage:
  php pyrospy.php run [options]

Options:
  -s, --pyroscope=STRING     Url of the pyroscope server. 
                             Example: https://your-pyroscope-sever.com
                             
  -auth, --pyroscopeAuthToken=STRING     
                             Pyroscope Auth Token. 
                             Example: psx-BWlqy_dW1Wxg6oBjuCWD28HxGCkB1Jfzt-jjtqHzrkzI
                             
  -a, --app=STRING           Name of app. 
                             All samples will be saved under given app name.
                             Example: app
                             
  -r, --rateHz=INT           Sample rate in Hz. 
                             Used to convert number of samples to CPU time 
                             [default: 100]
                             
  -i, --interval=INT         Maximum time between requests to pyroscope server 
                             [default: 10]
                             
  -b, --batch=INT            Maximum number of traces in request to pyroscope server 
                             [default: 250]
                             
  -t, --tags=STRING=STRING   Add tags to samples. Use to filter data inside one app.
                             Example: host=server1; role=cli 
                             (multiple values allowed)
                             
  -p, --plugins=STRING       Load custom class to modify trace and phpspy comments/tags. Can be class or folder with classes.
                             Example: /zoon/pyrospy/app/Plugins/ClearEmptyTags.php
                             (multiple values allowed)
                             
  -h, --help                 Display help for the given command. 
                             When no command is given display help for the list command

用法

phpspy --max-depth=-1 --time-limit-ms=59000 --threads=1024 --rate-hz=4 --buffer-size=65536 -J m -P '-x "php|php[0-9]\.[0-9]" | shuf' 2> error_log.log | php pyrospy.php run --pyroscope=https://pyroscope.yourdomain.com --rateHz=4 --app=testApp --tags=host=server39 --tags=role=cli

phpspy --max-depth=-1 --time-limit-ms=59000 --threads=100 --rate-hz=25 --buffer-size=65536 -J m -P '-x "php-fpm|php-fpm[0-9]\.[0-9]" | shuf' 2> error_log.log | php pyrospy.php run --pyroscope=https://pyroscope.yourdomain.com --rateHz=25 --app=testApp --tags=host=server39 --tags=role=web

插件

  1. 创建 .php 插件类。将其放置在任何位置。确保它具有 namespace Zoon\PyroSpy\Plugins; 并且类名与文件名匹配。
<?php

namespace Zoon\PyroSpy\Plugins;

class MyAwesomePlugin implements PluginInterface {

    public function process(array $tags, array $trace): array {
        //Modify tags and/or trace

        return [$tags, $trace];
    }
}

可以提供多个插件。每个插件将获取来自之前结果的标签和追踪。

  1. --request-info=QCuP 添加到 phpspy 参数中,以将 uri 字符串添加到标签中。
  2. 在 pyrospy 参数中提供其完整路径。
  3. 要忽略追踪,返回空追踪。

示例

phpspy --max-depth=-1 --time-limit-ms=59000 --threads=100 --rate-hz=25 --buffer-size=65536 -J m -P '-x "php-fpm|php-fpm[0-9]\.[0-9]" | shuf' --request-info=QCuP 2> error_log.log | php pyrospy.php run --pyroscope=https://pyroscope.yourdomain.com --rateHz=25 --app=testApp --tags=host=server39 --tags=role=web --plugins=/zoon/pyrospy/app/Plugins/ClearEmptyTags.php