Skip to content

Commit 8af49b9

Browse files
gregsparrowOleksandr Kaluhin
andauthored
Add pgrep pattern as a configurable argument for phpspy (#2) (#4)
* Update printWelcomeBanner to include pgrepPattern * Modify phpspy command to use the new pgrep configuration * Add PhpspyPgrep field to Config struct with default value Co-authored-by: Oleksandr Kaluhin <aleksandr.kaluhyn@perfsol.tech>
1 parent ec65c55 commit 8af49b9

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

collector/phpspy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ func New(cfg *config.Config) *PhpSpy {
2525
// Returns a channel that will receive parsed traces and any error that occurred
2626
func (ps *PhpSpy) Start() (<-chan *Trace, error) {
2727
// Construct phpspy command with configuration parameters
28-
cmd := exec.Command("sh", "-c", fmt.Sprintf("phpspy --rate-hz=%d --pgrep='-x \"(php-fpm.*|^php$)\"' --buffer-size=%d --max-depth=%d --threads=%d --request-info=%s",
28+
cmd := exec.Command("sh", "-c", fmt.Sprintf("phpspy --rate-hz=%d --pgrep='%s' --buffer-size=%d --max-depth=%d --threads=%d --request-info=%s",
2929
ps.config.RateHz,
30+
ps.config.PhpspyPgrep,
3031
ps.config.PhpspyBufferSize,
3132
ps.config.PhpspyMaxDepth,
3233
ps.config.PhpspyThreads,

config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Config struct {
2121
PhpspyMaxDepth int
2222
PhpspyThreads int
2323
PhpspyRequestInfo string
24+
PhpspyPgrep string
2425
}
2526

2627
// NewDefault returns a new default config
@@ -34,5 +35,6 @@ func NewDefault() *Config {
3435
PhpspyMaxDepth: -1,
3536
PhpspyThreads: 64,
3637
PhpspyRequestInfo: "qcup",
38+
PhpspyPgrep: `-x "(php-fpm.*|^php$)"`,
3739
}
3840
}

main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"strings"
1111
)
1212

13-
func printWelcomeBanner(pyroscopeURL, appName string, rateHz int, interval float64, batchLimit int, concurrentLimit int, tags map[string]string, excludePattern string, debug bool) {
13+
func printWelcomeBanner(pyroscopeURL, appName string, rateHz int, interval float64, batchLimit int, concurrentLimit int, tags map[string]string, excludePattern string, pgrepPattern string, debug bool) {
1414

1515
bannerLines := []string{
1616
" ____ __ ______ _____ ",
@@ -36,6 +36,7 @@ func printWelcomeBanner(pyroscopeURL, appName string, rateHz int, interval float
3636
fmt.Printf("⏱️ Update Interval: %.2f sec\n", interval)
3737
fmt.Printf("📦 Batch Limit: %d\n", batchLimit)
3838
fmt.Printf("🔄 Concurrent Limit: %d\n", concurrentLimit)
39+
fmt.Printf("🔍 Process Filter: %s\n", pgrepPattern)
3940
if excludePattern != "" {
4041
fmt.Printf("🚫 Exclude Pattern: %s\n", excludePattern)
4142
}
@@ -72,6 +73,7 @@ func main() {
7273
flag.IntVar(&cfg.PhpspyMaxDepth, "phpspyMaxDepth", cfg.PhpspyMaxDepth, "Maximum stack trace depth")
7374
flag.IntVar(&cfg.PhpspyThreads, "phpspyThreads", cfg.PhpspyThreads, "Number of phpspy worker threads")
7475
flag.StringVar(&cfg.PhpspyRequestInfo, "phpspyRequestInfo", cfg.PhpspyRequestInfo, "Request info to include in traces")
76+
flag.StringVar(&cfg.PhpspyPgrep, "pgrep", cfg.PhpspyPgrep, "pgrep pattern for finding PHP processes")
7577

7678
flag.BoolVar(&cfg.Debug, "debug", false, "Enable debug logging")
7779

@@ -96,7 +98,7 @@ func main() {
9698
}
9799

98100
// Print welcome banner
99-
printWelcomeBanner(cfg.PyroscopeURL, cfg.AppName, cfg.RateHz, cfg.Interval, cfg.BatchLimit, cfg.ConcurrentLimit, cfg.Tags, cfg.ExcludePattern, cfg.Debug)
101+
printWelcomeBanner(cfg.PyroscopeURL, cfg.AppName, cfg.RateHz, cfg.Interval, cfg.BatchLimit, cfg.ConcurrentLimit, cfg.Tags, cfg.ExcludePattern, cfg.PhpspyPgrep, cfg.Debug)
100102

101103
// Initialize components
102104
s := sender.New(cfg)

0 commit comments

Comments
 (0)