gorma

package module
v2.0.6+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2018 License: MIT Imports: 8 Imported by: 11

README

Redis memory analysis

🔎 Analyzing memory of redis is to find the keys(prefix) which used a lot of memory, export the analysis result into csv file.

Binary File Usage

  1. Download the appropriate binary file from Releases

  2. Run

# help
./redis-memory-analysis-linux-amd64 -h
Usage of ./redis-memory-analysis-darwin-amd64:
  -ip string
    	The host of redis (default "127.0.0.1")
  -password string
    	The password of redis (default "")
  -port uint
    	The port of redis (default 6379)
  -rdb string
    	The rdb file of redis (default "")
  -prefixes string
    	The prefixes list of redis key, be split by '//', special pattern characters need to escape by '\' (default "#//:")
  -reportPath string
    	The csv file path of analysis result (default "./reports")

# run by connecting to redis
./redis-memory-analysis-linux-amd64 -ip="127.0.0.1" -port=6380 -password="abc" -prefixes="#//:"

# run by redis rdb file
./redis-memory-analysis-linux-amd64 -rdb="./6379_dump.rdb" -prefixes="#//:"

Source Code Usage

  1. Install
//cd your-root-folder-of-project
// dep init
dep ensure -add github.com/hhxsv5/go-redis-memory-analysis@~2.0.0
  1. Run
  • Analyze keys by connecting to redis directly.
analysis := NewAnalysis()
//Open redis: 127.0.0.1:6379 without password
err := analysis.Open("127.0.0.1", 6379, "")
defer analysis.Close()
if err != nil {
    fmt.Println("something wrong:", err)
    return
}

//Scan the keys which can be split by '#' ':'
//Special pattern characters need to escape by '\'
analysis.Start([]string{"#", ":"})

//Find the csv file in default target folder: ./reports
//CSV file name format: redis-analysis-{host:port}-{db}.csv
//The keys order by count desc
err = analysis.SaveReports("./reports")
if err == nil {
    fmt.Println("done")
} else {
    fmt.Println("error:", err)
}
  • Analyze keys by redis RDB file, but cannot work out the size of key.
analysis := NewAnalysis()
//Open redis rdb file: ./6379_dump.rdb
err := analysis.OpenRDB("./6379_dump.rdb")
defer analysis.CloseRDB()
if err != nil {
    fmt.Println("something wrong:", err)
    return
}

//Scan the keys which can be split by '#' ':'
//Special pattern characters need to escape by '\'
analysis.StartRDB([]string{"#", ":"})

//Find the csv file in default target folder: ./reports
//CSV file name format: redis-analysis-{host:port}-{db}.csv
//The keys order by count desc
err = analysis.SaveReports("./reports")
if err == nil {
    fmt.Println("done")
} else {
    fmt.Println("error:", err)
}

CSV

Another tool implemented by PHP

redis-memory-analysis

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HumanSize

func HumanSize(byte uint64) (float64, string)

Types

type AnalysisConnection

type AnalysisConnection struct {
	Reports DBReports
	// contains filtered or unexported fields
}

func NewAnalysisConnection

func NewAnalysisConnection(host string, port uint16, password string) (*AnalysisConnection, error)

func (*AnalysisConnection) Close

func (analysis *AnalysisConnection) Close()

func (AnalysisConnection) SaveReports

func (analysis AnalysisConnection) SaveReports(folder string) error

func (AnalysisConnection) Start

func (analysis AnalysisConnection) Start(delimiters []string)

type AnalysisInterface

type AnalysisInterface interface {
	Start(delimiters []string)
	SaveReports(folder string) error
	Close()
}

type AnalysisRDB

type AnalysisRDB struct {
	Reports DBReports
	// contains filtered or unexported fields
}

func NewAnalysisRDB

func NewAnalysisRDB(rdb string) (*AnalysisRDB, error)

func (*AnalysisRDB) Close

func (analysis *AnalysisRDB) Close()

func (AnalysisRDB) SaveReports

func (analysis AnalysisRDB) SaveReports(folder string) error

func (AnalysisRDB) Start

func (analysis AnalysisRDB) Start(delimiters []string)

type DBReports added in v1.1.5

type DBReports map[uint64][]Report

type KeyReports added in v1.1.5

type KeyReports map[string]Report

type Report

type Report struct {
	Key         string
	Count       uint64
	Size        uint64
	NeverExpire uint64
	AvgTtl      uint64
}

type SortByCountReports

type SortByCountReports []Report

func (SortByCountReports) Len

func (sr SortByCountReports) Len() int

func (SortByCountReports) Less

func (sr SortByCountReports) Less(i, j int) bool

func (SortByCountReports) Swap

func (sr SortByCountReports) Swap(i, j int)

type SortBySizeReports

type SortBySizeReports []Report

func (SortBySizeReports) Len

func (sr SortBySizeReports) Len() int

func (SortBySizeReports) Less

func (sr SortBySizeReports) Less(i, j int) bool

func (SortBySizeReports) Swap

func (sr SortBySizeReports) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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