caddy_profiling

package module
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

README

Continuous Profiling for Caddy

The package contains 3 Caddy modules for push-mode continuous profiling support in Caddy.

Go Reference

Modules

profiling

The module can only serve as an app that is the host for multiple other profilers to configure and propagate common profiling parameters, i.e. CPU profile rate, block profile rate, mutex profile fraction, and the enabled profile types.

Documentation: https://caddyserver.com/docs/json/apps/profiling/

Sample config
{
	"apps": {
		"profiling": {
			"cpu_profile_rate": 2,
			"block_profile_rate": 2,
			"mutex_profile_fraction": 2,
			"profile_types": ["cpu","heap","allocs","goroutine"],
			"profilers": [
				{
					"profiler": "pyroscope",
					"server_address": "http://localhost:4040"
				},
				{
					"profiler": "pyroscope",
					"server_address": "http://another-instance.local:4040",
					"profile_types": ["heap"]
				},
				{
					"profiler": "profefe",
					// rest of config
				}
			]
		}
	}
}
pyroscope

Configures and enables the push-mode Pyroscope agent. May serve as an app or a child module of the profiling app. It may be configured as a child profiler of the profilig app or as first-level app within Caddy. Configuring the pyroscope app may look like this:

{
	"apps": {
		"pyroscope": {
			"server_address": "http://localhost:4040",
			"application_name": "my_cool_app",
			"auth_token": "{env.PYROSCOPE_AUTH_TOKEN}",
			"parameters": {
				"cpu_profile_rate": 2,
				"block_profile_rate": 2,
				"mutex_profile_fraction": 2,
				"profile_types": ["cpu","heap","allocs","goroutine"]
			}
		}
	}
}

Documentation: https://caddyserver.com/docs/json/apps/pyroscope/

profefe

Similar to the pyroscope module, the profefe module configures and pushes data to Profefe server. May serve as an app or a child module of the profiling app. It may be configured as a child profiler of the profilig app or as first-level app within Caddy. Configuring the profefe app may look like this:

{
	"apps": {
		"profefe": {
			"address": "http://localhost:4040",
			"service": "my_cool_app",
			"timeout": "10m",
			"parameters": {
				"cpu_profile_rate": 2,
				"block_profile_rate": 2,
				"mutex_profile_fraction": 2,
				"profile_types": ["cpu","heap","allocs","goroutine"]
			}
		}
	}
}

Documentation: https://caddyserver.com/docs/json/apps/profefe/

Available Profile Types

The ProfileTypes field in Parameters accepts the following values:

  • goroutine: stack traces of all current goroutines
  • heap: a sampling of memory allocations of live objects
  • allocs: a sampling of all past memory allocations
  • threadcreate: stack traces that led to the creation of new OS threads
  • block: stack traces that led to blocking on synchronization primitives
  • mutex: stack traces of holders of contended mutexes

They may be overridden by the individual guest profilers, if the guest module chooses to do so. The guest modules may not support the same types and they may have different names for the same types. The guest profilers own the translation logic.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parameters

type Parameters struct {
	// The hertz rate for CPU profiling, as accepted by the [`SetCPUProfileRate`](https://pkg.go.dev/runtime#SetCPUProfileRate) function.
	CPUProfileRate int `json:"cpu_profile_rate,omitempty"`

	// The hertz rate for CPU profiling, as accepted by the [`SetBlockProfileRate`](https://pkg.go.dev/runtime#SetBlockProfileRate) function.
	BlockProfileRate int `json:"block_profile_rate,omitempty"`

	// The the fraction of mutex contention events, as accepted by the [`SetMutexProfileFraction`](https://pkg.go.dev/runtime#SetMutexProfileFraction) function.
	MutexProfileFraction int `json:"mutex_profile_fraction,omitempty"`

	// The enabled runtime profile types. The accepted values are: cpu, goroutine, heap, allocs, threadcreate, block, mutex.
	ProfileTypes []ProfileType `json:"profile_types,omitempty"`
}

Common profiling paramters

type ProfileType

type ProfileType string
const (
	CPU          ProfileType = "cpu"
	Goroutine    ProfileType = "goroutine"
	Heap         ProfileType = "heap"
	Allocs       ProfileType = "allocs"
	Threadcreate ProfileType = "threadcreate"
	Block        ProfileType = "block"
	Mutex        ProfileType = "mutex"
)

type Profiler

type Profiler interface {
	Start() error
	Stop() error
}

Guest moduels of the `profiling` app are expected to implement this interface and be registered in the `profiling.profiler` caddy namespace

type ProfilingParameterSetter

type ProfilingParameterSetter interface {
	SetProfilingParameter(Parameters)
}

Signals whether a guest profiling module accepts inheriting the profiling parameters

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL