Class: Mammoth::ObservabilityServer

Inherits:
Object
  • Object
show all
Defined in:
lib/mammoth/observability_server.rb

Overview

Small HTTP server exposing Mammoth health, readiness, and metrics endpoints.

The server is intentionally independent from the replication loop. Operators may run it as a sidecar-like process or in a separate process that points at the same SQLite operational database.

Constant Summary collapse

DEFAULT_HOST =

Default bind host for the observability server.

"0.0.0.0"
DEFAULT_PORT =

Default TCP port for the observability server.

9393

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, host: nil, port: nil, sqlite_store: nil, logger: nil) ⇒ ObservabilityServer

Returns a new instance of ObservabilityServer.

Parameters:

  • config (Mammoth::Configuration)

    loaded configuration

  • host (String, nil) (defaults to: nil)

    bind host override

  • port (Integer, nil) (defaults to: nil)

    bind port override

  • sqlite_store (Mammoth::SQLiteStore, nil) (defaults to: nil)

    optional operational store

  • logger (WEBrick::Log, nil) (defaults to: nil)

    optional WEBrick logger



25
26
27
28
29
30
31
32
33
# File 'lib/mammoth/observability_server.rb', line 25

def initialize(config, host: nil, port: nil, sqlite_store: nil, logger: nil)
  @config = config
  @host = host || config.dig("observability", "host") || DEFAULT_HOST
  @port = port || config.dig("observability", "port") || DEFAULT_PORT
  @sqlite_store = sqlite_store
  @logger = logger || WEBrick::Log.new($stderr, WEBrick::Log::WARN)
  @server = build_server
  mount_endpoints
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



18
19
20
# File 'lib/mammoth/observability_server.rb', line 18

def config
  @config
end

#hostObject (readonly)

Returns the value of attribute host.



18
19
20
# File 'lib/mammoth/observability_server.rb', line 18

def host
  @host
end

#loggerObject (readonly)

Returns the value of attribute logger.



18
19
20
# File 'lib/mammoth/observability_server.rb', line 18

def logger
  @logger
end

#portObject (readonly)

Returns the value of attribute port.



18
19
20
# File 'lib/mammoth/observability_server.rb', line 18

def port
  @port
end

#serverObject (readonly)

Returns the value of attribute server.



18
19
20
# File 'lib/mammoth/observability_server.rb', line 18

def server
  @server
end

#sqlite_storeObject (readonly)

Returns the value of attribute sqlite_store.



18
19
20
# File 'lib/mammoth/observability_server.rb', line 18

def sqlite_store
  @sqlite_store
end

Instance Method Details

#shutdownvoid

This method returns an undefined value.

Stop the HTTP server.



45
46
47
# File 'lib/mammoth/observability_server.rb', line 45

def shutdown
  server.shutdown
end

#startvoid

This method returns an undefined value.

Start the blocking HTTP server.



38
39
40
# File 'lib/mammoth/observability_server.rb', line 38

def start
  server.start
end