-
Notifications
You must be signed in to change notification settings - Fork 6
/
rocks_srvs.go
98 lines (88 loc) · 3.39 KB
/
rocks_srvs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"fmt"
"os"
"runtime"
"strings"
"time"
)
// Server and Connection Command
func (rh *RocksDBHandler) RedisSelect(db int) error {
if rh.db == nil {
return ErrRocksIsDead
}
return nil
}
func (rh *RocksDBHandler) RedisPing() (*StatusReply, error) {
if rh.db == nil {
return nil, ErrRocksIsDead
}
return &StatusReply{"PONG"}, nil
}
func (rh *RocksDBHandler) RedisInfo() ([]byte, error) {
if rh.db == nil {
return nil, ErrRocksIsDead
}
data := make([]string, 0)
// server section
qpsStart := globalStat.qpsStart.Get()
qps := float64(globalStat.qpsCommands.Get()) / float64(time.Now().Unix()-qpsStart)
serverSection := []string{
"# Server",
"version: " + globalStat.version,
"os: " + runtime.GOOS,
fmt.Sprintf("process_id: %d", os.Getpid()),
fmt.Sprintf("tcp_port: %d", globalStat.config.Server.Port),
"config_file: " + globalStat.configFile,
fmt.Sprintf("uptime: %s", time.Since(globalStat.startTime)),
fmt.Sprintf("connected_clients: %d", globalStat.clients.Get()),
fmt.Sprintf("total_connections_received: %d", globalStat.totalConnections.Get()),
fmt.Sprintf("total_commands_processed: %d", globalStat.totalCommands.Get()),
fmt.Sprintf("instantaneous_ops_per_sec: %v", qps),
fmt.Sprintf("keyspace_hits: %d", globalStat.keyHits.Get()),
fmt.Sprintf("keyspace_misses: %d", globalStat.keyMisses.Get()),
"",
}
data = append(data, serverSection...)
// Runtime Section
var memStats runtime.MemStats
runtime.ReadMemStats(&memStats)
runtimeSection := []string{
"# Runtime",
fmt.Sprintf("cpu_count: %d", runtime.NumCPU()),
fmt.Sprintf("cgo_calls: %d", runtime.NumCgoCall()),
fmt.Sprintf("goroutine_count: %d", runtime.NumGoroutine()),
fmt.Sprintf("mem_alloc: %d", memStats.Alloc),
fmt.Sprintf("mem_sys: %d", memStats.Sys),
fmt.Sprintf("mem_total: %d", memStats.TotalAlloc),
fmt.Sprintf("mem_stack: %d", memStats.StackInuse),
fmt.Sprintf("mem_heap_alloc: %d", memStats.HeapAlloc),
fmt.Sprintf("mem_heap_sys: %d", memStats.HeapSys),
fmt.Sprintf("mem_heap_objects: %d", memStats.HeapObjects),
fmt.Sprintf("mem_gc_count: %d", memStats.NumGC),
fmt.Sprintf("mem_gc_total_pause: %v", float64(memStats.PauseTotalNs)/float64(time.Millisecond)),
"",
}
data = append(data, runtimeSection...)
// rocksdb section
rocksSection := []string{
"# Rocksdb Config",
"rocksdb_directory: " + globalStat.config.Database.DbDir,
"max_memory: " + globalStat.config.Database.MaxMemory,
"block_size: " + globalStat.config.Database.BlockSize,
"compression: " + globalStat.config.Database.Compression,
"compaction_style: " + globalStat.config.Database.CompactionStyle,
fmt.Sprintf("max_memtable_merge: %d", globalStat.config.Database.MaxMerge),
"",
"# Rocksdb Stats",
}
rocksStats := strings.Split(rh.db.GetProperty("rocksdb.stats"), "\n")
rocksStats = rocksStats[len(rocksStats)-14:]
for _, rockStat := range rocksStats {
rocksSection = append(rocksSection, rockStat)
}
rocksSection = append(rocksSection, "")
data = append(data, rocksSection...)
return []byte(strings.Join(data, "\r\n")), nil
}
var _ = fmt.Println