ExUtcp.Monitoring (ex_utcp v0.3.2)

Copy Markdown View Source

Monitoring and metrics system for ExUtcp.

Provides comprehensive monitoring capabilities including:

  • Telemetry events for all UTCP operations
  • Prometheus metrics integration
  • Health checks for transports and providers
  • Performance monitoring and alerting
  • Custom metrics and dashboards

Summary

Functions

Emits a telemetry event for connection operations.

Emits a telemetry event for provider registration.

Emits a telemetry event for search operations.

Gets health status for all components.

Gets current system metrics.

Starts the monitoring system.

Stops the monitoring system.

Functions

emit_connection_event(provider_name, transport_type, event, duration_ms \\ 0)

@spec emit_connection_event(
  String.t(),
  atom(),
  :connect | :disconnect | :error,
  integer()
) :: :ok

Emits a telemetry event for connection operations.

emit_provider_event(provider_name, transport_type, action, tool_count)

@spec emit_provider_event(String.t(), atom(), :register | :deregister, integer()) ::
  :ok

Emits a telemetry event for provider registration.

emit_search_event(query, algorithm, filters, duration_ms, result_count)

@spec emit_search_event(String.t(), atom(), map(), integer(), integer()) :: :ok

Emits a telemetry event for search operations.

emit_tool_call_event(tool_name, provider_name, args, duration_ms, status, result_or_error)

@spec emit_tool_call_event(
  String.t(),
  String.t(),
  map(),
  integer(),
  :success | :error,
  any()
) :: :ok

Emits a telemetry event for tool call operations.

get_health_status()

@spec get_health_status() :: %{
  overall: :healthy,
  components: %{
    prometheus: :healthy | :unhealthy,
    telemetry: :healthy | :unhealthy,
    transports: %{overall: :degraded | :healthy, transports: map()}
  },
  timestamp: integer()
}

Gets health status for all components.

get_metrics()

@spec get_metrics() :: %{
  system: %{
    memory: %{
      atom: non_neg_integer(),
      binary: non_neg_integer(),
      ets: non_neg_integer(),
      processes: non_neg_integer(),
      system: non_neg_integer(),
      total: non_neg_integer()
    },
    processes: %{count: non_neg_integer(), limit: non_neg_integer()},
    schedulers: %{online: pos_integer(), total: pos_integer()}
  },
  timestamp: integer(),
  utcp: %{
    connections: %{active: 0, failed: 0, total: 0},
    providers: %{by_transport: map(), total: 0},
    searches: %{by_algorithm: map(), total: 0},
    tool_calls: %{avg_duration: float(), error: 0, success: 0, total: 0}
  }
}

Gets current system metrics.

start()

@spec start() :: :ok

Starts the monitoring system.

stop()

@spec stop() :: :ok

Stops the monitoring system.