MCPcopy
hub / github.com/crowdsecurity/crowdsec / dumpPprof

Method dumpPprof

cmd/crowdsec-cli/clisupport/support.go:365–400  ·  view source on GitHub ↗
(ctx context.Context, zw *zip.Writer, prometheusCfg csconfig.PrometheusCfg, endpoint string)

Source from the content-addressed store, hash-verified

363}
364
365func (cli *cliSupport) dumpPprof(ctx context.Context, zw *zip.Writer, prometheusCfg csconfig.PrometheusCfg, endpoint string) error {
366 fmt.Fprintf(os.Stdout, "Collecting pprof/%s data\n", endpoint)
367
368 ctx, cancel := context.WithTimeout(ctx, 120*time.Second)
369 defer cancel()
370
371 req, err := http.NewRequestWithContext(
372 ctx,
373 http.MethodGet,
374 fmt.Sprintf(
375 "http://%s/debug/pprof/%s",
376 net.JoinHostPort(
377 prometheusCfg.ListenAddr,
378 strconv.Itoa(prometheusCfg.ListenPort),
379 ),
380 endpoint,
381 ),
382 http.NoBody,
383 )
384 if err != nil {
385 return fmt.Errorf("could not create request to pprof endpoint: %w", err)
386 }
387
388 client := &http.Client{}
389
390 resp, err := client.Do(req)
391 if err != nil {
392 return fmt.Errorf("could not get pprof data from endpoint: %w", err)
393 }
394
395 defer resp.Body.Close()
396
397 cli.writeToZip(zw, SUPPORT_PPROF_DIR+endpoint+".pprof", time.Now(), resp.Body)
398
399 return nil
400}
401
402func (cli *cliSupport) dumpProfiles(zw *zip.Writer) {
403 fmt.Fprintln(os.Stdout, "Collecting crowdsec profile")

Callers 1

dumpMethod · 0.95

Calls 3

writeToZipMethod · 0.95
DoMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected