mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 17:28:54 +00:00
0bb9d69ece
Adds endpoints and fleetctl commands to retrieve various debug profiles from the Fleet server. The best summary is from the help text: ``` fleetctl debug NAME: fleetctl debug - Tools for debugging Fleet USAGE: fleetctl debug command [command options] [arguments...] COMMANDS: profile Record a CPU profile from the Fleet server. cmdline Get the command line used to invoke the Fleet server. heap Report the allocated memory in the Fleet server. goroutine Get stack traces of all goroutines (threads) in the Fleet server. trace Record an execution trace on the Fleet server. archive Create an archive with the entire suite of debug profiles. OPTIONS: --config value Path to the Fleet config file (default: "/Users/zwass/.fleet/config") [$CONFIG] --context value Name of Fleet config context to use (default: "default") [$CONTEXT] --help, -h show help ```
33 lines
671 B
Go
33 lines
671 B
Go
package service
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"net/http"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// DebugPprof calls the /debug/pprof/ endpoints.
|
|
func (c *Client) DebugPprof(name string) ([]byte, error) {
|
|
endpoint := "/debug/pprof/" + name
|
|
response, err := c.AuthenticatedDo("GET", endpoint, "", nil)
|
|
if err != nil {
|
|
return nil, errors.Wrapf(err, "GET %s", endpoint)
|
|
}
|
|
defer response.Body.Close()
|
|
|
|
if response.StatusCode != http.StatusOK {
|
|
return nil, errors.Errorf(
|
|
"get pprof received status %d",
|
|
response.StatusCode,
|
|
)
|
|
}
|
|
|
|
body, err := ioutil.ReadAll(response.Body)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "read pprof response body")
|
|
}
|
|
|
|
return body, nil
|
|
}
|