Documentation
¶
Index ¶
- Variables
- func APIKeyMiddleware(apiKey string) func(http.Handler) http.Handler
- func BasicAuthMiddleware(username, password string) func(http.Handler) http.Handler
- func GetAPIHandlers(customBaseAPIPath ...string) map[string]http.HandlerFunc
- func GetFiberHandler(customBaseAPIPath ...string) func(*fiber.Ctx) error
- func GetSecuredAPIHandlers(m *Monigo, customBaseAPIPath ...string) map[string]http.HandlerFunc
- func GetSecuredStaticHandler(m *Monigo) http.HandlerFunc
- func GetSecuredUnifiedHandler(m *Monigo, customBaseAPIPath ...string) http.HandlerFunc
- func GetStaticHandler() http.HandlerFunc
- func GetUnifiedHandler(customBaseAPIPath ...string) http.HandlerFunc
- func IPWhitelistMiddleware(allowedIPs []string) func(http.Handler) http.Handler
- func LoggingMiddleware() func(http.Handler) http.Handler
- func RateLimitMiddleware(requests int, window time.Duration) (mw func(http.Handler) http.Handler, stop func())
- func RegisterAPIHandlers(mux *http.ServeMux, customBaseAPIPath ...string)
- func RegisterDashboardHandlers(mux *http.ServeMux, customBaseAPIPath ...string)
- func RegisterSecuredAPIHandlers(mux *http.ServeMux, m *Monigo, customBaseAPIPath ...string)
- func RegisterSecuredDashboardHandlers(mux *http.ServeMux, m *Monigo, customBaseAPIPath ...string)
- func RegisterSecuredStaticHandlers(mux *http.ServeMux, m *Monigo)
- func RegisterStaticHandlers(mux *http.ServeMux)
- func SetSamplingRate(rate int)
- func StartDashboard(port int) error
- func StartDashboardWithCustomPath(port int, customBaseAPIPath string) error
- func StartSecuredDashboard(m *Monigo) error
- func TraceFunction(ctx context.Context, f func())
- func TraceFunctionWithArgs(ctx context.Context, f interface{}, args ...interface{})
- func TraceFunctionWithReturn(ctx context.Context, f interface{}, args ...interface{}) interface{}
- func TraceFunctionWithReturns(ctx context.Context, f interface{}, args ...interface{}) []interface{}
- type Cache
- type Monigo
- func (m *Monigo) GetGoRoutinesStats() models.GoRoutinesStatistic
- func (m *Monigo) GetRunningPort() int
- func (m *Monigo) Initialize() error
- func (m *Monigo) MonigoInstanceConstructor() error
- func (m *Monigo) MonigoInstanceConstructorWithoutPort()
- func (m *Monigo) Shutdown(ctx context.Context) error
- func (m *Monigo) Start() error
- type MonigoBuilder
- func (b *MonigoBuilder) Build() *Monigo
- func (b *MonigoBuilder) WithAPIMiddleware(middleware ...func(http.Handler) http.Handler) *MonigoBuilder
- func (b *MonigoBuilder) WithAlertWebhook(url string) *MonigoBuilder
- func (b *MonigoBuilder) WithAuthFunction(authFunc func(*http.Request) bool) *MonigoBuilder
- func (b *MonigoBuilder) WithCustomBaseAPIPath(path string) *MonigoBuilder
- func (b *MonigoBuilder) WithDashboardMiddleware(middleware ...func(http.Handler) http.Handler) *MonigoBuilder
- func (b *MonigoBuilder) WithDataPointsSyncFrequency(frequency string) *MonigoBuilder
- func (b *MonigoBuilder) WithHeadless(headless bool) *MonigoBuilder
- func (b *MonigoBuilder) WithLogLevel(level slog.Level) *MonigoBuilder
- func (b *MonigoBuilder) WithLogger(l *slog.Logger) *MonigoBuilder
- func (b *MonigoBuilder) WithMaxCPUUsage(usage float64) *MonigoBuilder
- func (b *MonigoBuilder) WithMaxGoRoutines(routines int) *MonigoBuilder
- func (b *MonigoBuilder) WithMaxMemoryUsage(usage float64) *MonigoBuilder
- func (b *MonigoBuilder) WithOTelEndpoint(endpoint string) *MonigoBuilder
- func (b *MonigoBuilder) WithOTelHeaders(headers map[string]string) *MonigoBuilder
- func (b *MonigoBuilder) WithPort(port int) *MonigoBuilder
- func (b *MonigoBuilder) WithRetentionPeriod(period string) *MonigoBuilder
- func (b *MonigoBuilder) WithSamplingRate(rate int) *MonigoBuilder
- func (b *MonigoBuilder) WithServiceName(serviceName string) *MonigoBuilder
- func (b *MonigoBuilder) WithStaleGoroutineThreshold(d time.Duration) *MonigoBuilder
- func (b *MonigoBuilder) WithStorageType(storageType string) *MonigoBuilder
- func (b *MonigoBuilder) WithTimeZone(timeZone string) *MonigoBuilder
- type MonigoInt
Constants ¶
This section is empty.
Variables ¶
var (
BasePath string
)
Functions ¶
func APIKeyMiddleware ¶ added in v1.1.0
APIKeyMiddleware creates an API key authentication middleware
func BasicAuthMiddleware ¶ added in v1.1.0
BasicAuthMiddleware creates a basic authentication middleware
func GetAPIHandlers ¶ added in v1.1.0
func GetAPIHandlers(customBaseAPIPath ...string) map[string]http.HandlerFunc
GetAPIHandlers returns a map of API handlers for any HTTP router
func GetFiberHandler ¶ added in v1.1.0
GetFiberHandler returns a Fiber-compatible handler
func GetSecuredAPIHandlers ¶ added in v1.1.0
func GetSecuredAPIHandlers(m *Monigo, customBaseAPIPath ...string) map[string]http.HandlerFunc
GetSecuredAPIHandlers returns secured API handlers
func GetSecuredStaticHandler ¶ added in v1.1.0
func GetSecuredStaticHandler(m *Monigo) http.HandlerFunc
GetSecuredStaticHandler returns the static file handler with middleware
func GetSecuredUnifiedHandler ¶ added in v1.1.0
func GetSecuredUnifiedHandler(m *Monigo, customBaseAPIPath ...string) http.HandlerFunc
GetSecuredUnifiedHandler returns a unified handler with middleware
func GetStaticHandler ¶ added in v1.1.0
func GetStaticHandler() http.HandlerFunc
GetStaticHandler returns the static file handler function
func GetUnifiedHandler ¶ added in v1.1.0
func GetUnifiedHandler(customBaseAPIPath ...string) http.HandlerFunc
GetUnifiedHandler returns a unified handler that handles both API and static files
func IPWhitelistMiddleware ¶ added in v1.1.0
IPWhitelistMiddleware creates an IP whitelist middleware
func LoggingMiddleware ¶ added in v1.1.0
LoggingMiddleware creates a request logging middleware
func RateLimitMiddleware ¶ added in v1.1.0
func RateLimitMiddleware(requests int, window time.Duration) (mw func(http.Handler) http.Handler, stop func())
RateLimitMiddleware creates a simple rate limiting middleware. The returned stop function should be called during shutdown to release the cleanup goroutine.
func RegisterAPIHandlers ¶ added in v1.1.0
RegisterAPIHandlers registers only the API handlers
func RegisterDashboardHandlers ¶ added in v1.1.0
RegisterDashboardHandlers registers all dashboard handlers to the provided HTTP mux
func RegisterSecuredAPIHandlers ¶ added in v1.1.0
RegisterSecuredAPIHandlers registers only the API handlers with middleware support
func RegisterSecuredDashboardHandlers ¶ added in v1.1.0
RegisterSecuredDashboardHandlers registers all dashboard handlers with middleware support
func RegisterSecuredStaticHandlers ¶ added in v1.1.0
RegisterSecuredStaticHandlers registers only the static file handlers with middleware
func RegisterStaticHandlers ¶ added in v1.1.0
RegisterStaticHandlers registers only the static file handlers
func SetSamplingRate ¶ added in v1.3.0
func SetSamplingRate(rate int)
SetSamplingRate sets the sampling rate for function tracing
func StartDashboard ¶
StartDashboard starts the dashboard on the specified port
func StartDashboardWithCustomPath ¶ added in v1.1.0
StartDashboardWithCustomPath starts the dashboard on the specified port with a custom API path
func StartSecuredDashboard ¶ added in v1.1.0
StartSecuredDashboard starts the dashboard with middleware support
func TraceFunction ¶ added in v0.0.2
TraceFunction traces the function
func TraceFunctionWithArgs ¶ added in v1.1.0
TraceFunctionWithArgs traces a function with parameters and captures the metrics
func TraceFunctionWithReturn ¶ added in v1.1.0
TraceFunctionWithReturn traces a function with parameters and return values
func TraceFunctionWithReturns ¶ added in v1.1.0
func TraceFunctionWithReturns(ctx context.Context, f interface{}, args ...interface{}) []interface{}
TraceFunctionWithReturns traces a function with parameters and returns all results
Types ¶
type Monigo ¶
type Monigo struct {
ServiceName string `json:"service_name"`
DashboardPort int `json:"dashboard_port"`
DataPointsSyncFrequency string `json:"db_sync_frequency"`
DataRetentionPeriod string `json:"retention_period"`
TimeZone string `json:"time_zone"`
GoVersion string `json:"go_version"`
ServiceStartTime time.Time `json:"service_start_time"`
ProcessId int32 `json:"process_id"`
MaxCPUUsage float64 `json:"max_cpu_usage"`
MaxMemoryUsage float64 `json:"max_memory_usage"`
MaxGoRoutines int `json:"max_go_routines"`
CustomBaseAPIPath string `json:"custom_base_api_path"`
Headless bool `json:"headless"`
SamplingRate int `json:"sampling_rate"`
StorageType string `json:"storage_type"`
AlertWebhookURL string `json:"alert_webhook_url,omitempty"`
// StaleGoroutineThreshold is how long a goroutine must stay blocked before
// leak detection reports it as stale. Zero means the 24h default.
StaleGoroutineThreshold time.Duration `json:"stale_goroutine_threshold,omitempty"`
// OpenTelemetry Configuration
OTelEndpoint string `json:"otel_endpoint,omitempty"`
OTelHeaders map[string]string `json:"-"`
// Security and Middleware Configuration
DashboardMiddleware []func(http.Handler) http.Handler `json:"-"`
APIMiddleware []func(http.Handler) http.Handler `json:"-"`
AuthFunction func(*http.Request) bool `json:"-"`
// contains filtered or unexported fields
}
Monigo is the main struct to start the monigo service
func (*Monigo) GetGoRoutinesStats ¶ added in v0.0.2
func (m *Monigo) GetGoRoutinesStats() models.GoRoutinesStatistic
GetGoRoutinesStats returns Go routines statistics.
func (*Monigo) GetRunningPort ¶ added in v1.3.0
GetRunningPort returns the running port
func (*Monigo) Initialize ¶ added in v1.1.0
Initialize initializes the monigo service without starting the dashboard
func (*Monigo) MonigoInstanceConstructor ¶ added in v0.0.2
MonigoInstanceConstructor validates the port then initialises common fields.
func (*Monigo) MonigoInstanceConstructorWithoutPort ¶ added in v1.1.0
func (m *Monigo) MonigoInstanceConstructorWithoutPort()
MonigoInstanceConstructorWithoutPort initialises common fields without port binding.
type MonigoBuilder ¶ added in v1.2.0
type MonigoBuilder struct {
// contains filtered or unexported fields
}
MonigoBuilder is the builder for the Monigo struct
func NewBuilder ¶ added in v1.2.0
func NewBuilder() *MonigoBuilder
NewBuilder creates a new instance of the MonigoBuilder
func (*MonigoBuilder) Build ¶ added in v1.2.0
func (b *MonigoBuilder) Build() *Monigo
Build validates the configuration and returns the Monigo struct. Panics if ServiceName is empty since it is a required field.
func (*MonigoBuilder) WithAPIMiddleware ¶ added in v1.2.0
func (b *MonigoBuilder) WithAPIMiddleware(middleware ...func(http.Handler) http.Handler) *MonigoBuilder
WithAPIMiddleware sets the API middleware
func (*MonigoBuilder) WithAlertWebhook ¶ added in v1.3.0
func (b *MonigoBuilder) WithAlertWebhook(url string) *MonigoBuilder
WithAlertWebhook sets the health breach alert webhook URL
func (*MonigoBuilder) WithAuthFunction ¶ added in v1.2.0
func (b *MonigoBuilder) WithAuthFunction(authFunc func(*http.Request) bool) *MonigoBuilder
WithAuthFunction sets the custom authentication function
func (*MonigoBuilder) WithCustomBaseAPIPath ¶ added in v1.2.0
func (b *MonigoBuilder) WithCustomBaseAPIPath(path string) *MonigoBuilder
WithCustomBaseAPIPath sets the custom base API path
func (*MonigoBuilder) WithDashboardMiddleware ¶ added in v1.2.0
func (b *MonigoBuilder) WithDashboardMiddleware(middleware ...func(http.Handler) http.Handler) *MonigoBuilder
WithDashboardMiddleware sets the dashboard middleware
func (*MonigoBuilder) WithDataPointsSyncFrequency ¶ added in v1.2.0
func (b *MonigoBuilder) WithDataPointsSyncFrequency(frequency string) *MonigoBuilder
WithDataPointsSyncFrequency sets the data points sync frequency
func (*MonigoBuilder) WithHeadless ¶ added in v1.3.0
func (b *MonigoBuilder) WithHeadless(headless bool) *MonigoBuilder
WithHeadless sets whether the dashboard should be started
func (*MonigoBuilder) WithLogLevel ¶ added in v1.3.0
func (b *MonigoBuilder) WithLogLevel(level slog.Level) *MonigoBuilder
WithLogLevel sets the log level for monigo's structured logger
func (*MonigoBuilder) WithLogger ¶ added in v1.3.0
func (b *MonigoBuilder) WithLogger(l *slog.Logger) *MonigoBuilder
WithLogger sets a custom slog.Logger for monigo
func (*MonigoBuilder) WithMaxCPUUsage ¶ added in v1.2.0
func (b *MonigoBuilder) WithMaxCPUUsage(usage float64) *MonigoBuilder
WithMaxCPUUsage sets the max CPU usage
func (*MonigoBuilder) WithMaxGoRoutines ¶ added in v1.2.0
func (b *MonigoBuilder) WithMaxGoRoutines(routines int) *MonigoBuilder
WithMaxGoRoutines sets the max Go routines
func (*MonigoBuilder) WithMaxMemoryUsage ¶ added in v1.2.0
func (b *MonigoBuilder) WithMaxMemoryUsage(usage float64) *MonigoBuilder
WithMaxMemoryUsage sets the max memory usage
func (*MonigoBuilder) WithOTelEndpoint ¶ added in v1.3.0
func (b *MonigoBuilder) WithOTelEndpoint(endpoint string) *MonigoBuilder
WithOTelEndpoint sets the OTLP gRPC endpoint for OpenTelemetry export (e.g. "localhost:4317")
func (*MonigoBuilder) WithOTelHeaders ¶ added in v1.3.0
func (b *MonigoBuilder) WithOTelHeaders(headers map[string]string) *MonigoBuilder
WithOTelHeaders sets optional headers for the OTel exporter
func (*MonigoBuilder) WithPort ¶ added in v1.2.0
func (b *MonigoBuilder) WithPort(port int) *MonigoBuilder
WithPort sets the dashboard port
func (*MonigoBuilder) WithRetentionPeriod ¶ added in v1.2.0
func (b *MonigoBuilder) WithRetentionPeriod(period string) *MonigoBuilder
WithRetentionPeriod sets the data retention period
func (*MonigoBuilder) WithSamplingRate ¶ added in v1.3.0
func (b *MonigoBuilder) WithSamplingRate(rate int) *MonigoBuilder
WithSamplingRate sets the sampling rate for function tracing: one call in every `rate` is profiled. The default is 100.
The sampled call pays a roughly constant ~200ms, independent of how long the function itself runs, because pprof.StopCPUProfile blocks on the runtime's buffer flush -- and because the CPU profiler samples at 100Hz, a call shorter than ~10ms usually captures nothing for that cost. See core.SetSamplingRate for the measurements and what to do about it.
func (*MonigoBuilder) WithServiceName ¶ added in v1.2.0
func (b *MonigoBuilder) WithServiceName(serviceName string) *MonigoBuilder
WithServiceName sets the service name
func (*MonigoBuilder) WithStaleGoroutineThreshold ¶ added in v1.3.0
func (b *MonigoBuilder) WithStaleGoroutineThreshold(d time.Duration) *MonigoBuilder
WithStaleGoroutineThreshold sets how long a goroutine must stay blocked before leak detection reports it as stale. Defaults to 24h when unset.
The Go runtime reports block duration in whole minutes, so a threshold below one minute cannot be represented and is rejected by Build().
func (*MonigoBuilder) WithStorageType ¶ added in v1.3.0
func (b *MonigoBuilder) WithStorageType(storageType string) *MonigoBuilder
WithStorageType sets the storage type ("disk" or "memory")
func (*MonigoBuilder) WithTimeZone ¶ added in v1.2.0
func (b *MonigoBuilder) WithTimeZone(timeZone string) *MonigoBuilder
WithTimeZone sets the time zone