api

package
v0.50.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultSockPath

func DefaultSockPath() string

DefaultSockPath returns the preferred socket path under a 0700 runtime directory.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client connects to the xtop daemon Unix socket API.

func NewClient

func NewClient(sockPath string) *Client

NewClient creates a new API client for the given socket path.

func TryConnect

func TryConnect() *Client

TryConnect attempts to connect to the daemon socket. Returns the client if successful, nil otherwise.

func (*Client) Incidents

func (c *Client) Incidents(limit int) ([]store.IncidentRecord, error)

Incidents returns stored incidents.

func (*Client) Ping

func (c *Client) Ping() error

Ping checks if the daemon is reachable.

func (*Client) Status

func (c *Client) Status() (*StatusResponse, error)

Status returns the current health status.

func (*Client) Top

func (c *Client) Top(limit int) ([]model.ImpactScore, error)

Top returns impact-scored process list.

type DaemonSnapshotProvider

type DaemonSnapshotProvider struct {
	// contains filtered or unexported fields
}

DaemonSnapshotProvider wraps engine state for the API.

func NewDaemonSnapshotProvider

func NewDaemonSnapshotProvider() *DaemonSnapshotProvider

func (*DaemonSnapshotProvider) ImpactScores

func (p *DaemonSnapshotProvider) ImpactScores() []model.ImpactScore

func (*DaemonSnapshotProvider) Latest

func (*DaemonSnapshotProvider) Update

func (p *DaemonSnapshotProvider) Update(snap *model.Snapshot, rates *model.RateSnapshot, result *model.AnalysisResult, scores []model.ImpactScore)

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is a Unix socket HTTP API server for xtop.

func NewServer

func NewServer(sockPath string, provider SnapshotProvider, st *store.Store) (*Server, error)

NewServer creates a new API server. sockPath: path to Unix socket (/run/xtop.sock or ~/.xtop/xtop.sock).

func (*Server) Close

func (s *Server) Close() error

Close closes the listener and removes the socket file.

func (*Server) Serve

func (s *Server) Serve() error

Serve starts accepting connections. Blocks until error or Close(). When the server is stopped via Close(), Serve returns http.ErrServerClosed so callers can distinguish a clean shutdown from a genuine failure.

func (*Server) SockPath

func (s *Server) SockPath() string

SockPath returns the socket path.

type SnapshotProvider

type SnapshotProvider interface {
	Latest() (*model.Snapshot, *model.RateSnapshot, *model.AnalysisResult)
	ImpactScores() []model.ImpactScore
}

SnapshotProvider gives access to the latest snapshot data.

type StatusResponse

type StatusResponse struct {
	Timestamp      interface{} `json:"timestamp"`
	Health         string      `json:"health"`
	Confidence     int         `json:"confidence"`
	Bottleneck     string      `json:"bottleneck,omitempty"`
	Score          int         `json:"score"`
	RootCause      string      `json:"root_cause,omitempty"`
	Pattern        string      `json:"pattern,omitempty"`
	CausalChain    string      `json:"causal_chain,omitempty"`
	TopOffender    string      `json:"top_offender,omitempty"`
	TopOffenderPID int         `json:"top_offender_pid,omitempty"`
	CPUBusy        float64     `json:"cpu_busy"`
	MemPct         float64     `json:"mem_pct"`
}

StatusResponse is the /v1/status endpoint response.

Jump to

Keyboard shortcuts

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