models

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package models defines the data structures used throughout memtui.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidMetadumpLine = errors.New("invalid metadump line")

ErrInvalidMetadumpLine is returned when a metadump line cannot be parsed

Functions

func FormatBytes

func FormatBytes(bytes int64) string

FormatBytes formats bytes in human-readable units.

Types

type Item

type Item struct {
	Key   string
	Value []byte
	Flags uint32
	CAS   uint64

	// TTL-related fields (from metadump)
	Expiration int64 // Unix timestamp (0 = permanent)
	LastAccess int64 // Last access time

	// Computed fields
	TTLRemaining int64 // Remaining TTL in seconds (calculated in real-time)
	IsExpired    bool  // Expiration flag
}

Item represents an item stored in Memcached.

func (*Item) UpdateTTL

func (i *Item) UpdateTTL()

UpdateTTL updates TTL-related fields based on the current time.

type KeyInfo

type KeyInfo struct {
	Key        string // Key name
	Expiration int64  // Unix timestamp (0 = permanent)
	LastAccess int64  // Last access timestamp
	CAS        uint64 // CAS value
	Fetch      bool   // Whether fetch has been performed
	SlabClass  int    // Slab class ID
	Size       int    // Size in bytes
}

KeyInfo represents metadata for a Memcached key from lru_crawler metadump

func FilterKeyInfos

func FilterKeyInfos(keys []KeyInfo, pattern string) []KeyInfo

FilterKeyInfos returns keys that contain the given pattern

func ParseMetadumpLine

func ParseMetadumpLine(line string) (KeyInfo, error)

ParseMetadumpLine parses a single line from lru_crawler metadump output Format: key=<key> exp=<exp> la=<la> cas=<cas> fetch=<yes|no> cls=<cls> size=<size>

func SortKeyInfos

func SortKeyInfos(keys []KeyInfo, order SortOrder) []KeyInfo

SortKeyInfos returns a sorted copy of the KeyInfo slice

func (KeyInfo) IsExpiredAt

func (ki KeyInfo) IsExpiredAt(now int64) bool

IsExpiredAt checks if the key is expired at the given timestamp Returns false for permanent keys (Expiration == 0)

type SlabItemStats

type SlabItemStats struct {
	SlabID    int   // Slab class ID
	Number    int64 // Number of items in this slab class
	Age       int64 // Age of oldest item in seconds
	Evicted   int64 // Items evicted from this slab class
	EvictedNZ int64 // Items evicted with non-zero TTL
	Outofmem  int64 // Times memory allocation failed
}

SlabItemStats represents stats for items in a slab class (from 'stats items').

type SlabStats

type SlabStats struct {
	SlabID     int   // Slab class ID
	ChunkSize  int64 // Bytes per chunk
	Chunks     int64 // Total chunks in this slab class
	UsedChunks int64 // Chunks currently in use
	FreeChunks int64 // Chunks not in use
	MemReq     int64 // Memory requested for this slab class
}

SlabStats represents stats for a slab class (from 'stats slabs').

type SlabsStats

type SlabsStats struct {
	ActiveSlabs   int                // Number of active slab classes
	TotalMalloced int64              // Total memory allocated for slabs
	Slabs         map[int]*SlabStats // Per-slab statistics
}

SlabsStats represents overall slab statistics.

type SortOrder

type SortOrder int

SortOrder represents the sort order for KeyInfo slices

const (
	// SortByKey sorts alphabetically by key name
	SortByKey SortOrder = iota
	// SortBySize sorts by size (ascending)
	SortBySize
)

Sort order options

type Stats

type Stats struct {
	// Process info
	PID    int   // Process ID
	Uptime int64 // Seconds since server start

	// Version
	Version string // Memcached version string

	// Connections
	CurrentConnections int   // Current open connections
	TotalConnections   int64 // Total connections since start

	// Items
	CurrentItems int64 // Current number of items stored
	TotalItems   int64 // Total items stored since start

	// Memory
	Bytes         int64 // Current bytes used for storage
	LimitMaxBytes int64 // Maximum bytes allowed (limit_maxbytes)

	// Cache performance
	GetHits   int64   // Cache hits
	GetMisses int64   // Cache misses
	Evictions int64   // Items evicted to free memory
	HitRate   float64 // Calculated hit rate percentage

	// Network I/O
	BytesRead    int64 // Total bytes read from network
	BytesWritten int64 // Total bytes written to network

	// Raw contains all STAT key-value pairs
	Raw map[string]string
}

Stats represents Memcached server statistics from the 'stats' command.

func ParseStatsResponse

func ParseStatsResponse(response string) (*Stats, error)

ParseStatsResponse parses the response from a Memcached 'stats' command. The response format is:

STAT <key> <value>\r\n
...
END\r\n

func (*Stats) BytesFormatted

func (s *Stats) BytesFormatted() string

BytesFormatted returns the bytes used in a human-readable format.

func (*Stats) MemoryUsagePercent

func (s *Stats) MemoryUsagePercent() float64

MemoryUsagePercent returns the percentage of memory used.

func (*Stats) UptimeFormatted

func (s *Stats) UptimeFormatted() string

UptimeFormatted returns the uptime in a human-readable format.

Jump to

Keyboard shortcuts

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