代码拉取完成,页面将自动刷新
package keyspace
import (
"strings"
"github.com/elastic/beats/libbeat/common"
s "github.com/elastic/beats/libbeat/common/schema"
c "github.com/elastic/beats/libbeat/common/schema/mapstrstr"
"github.com/elastic/beats/metricbeat/module/redis"
)
// Map data to MapStr
func eventsMapping(info map[string]string) []common.MapStr {
events := []common.MapStr{}
for key, space := range getKeyspaceStats(info) {
space["id"] = key
events = append(events, space)
}
return events
}
func getKeyspaceStats(info map[string]string) map[string]common.MapStr {
keyspaceMap := findKeyspaceStats(info)
return parseKeyspaceStats(keyspaceMap)
}
// findKeyspaceStats will grep for keyspace ("^db" keys) and return the resulting map
func findKeyspaceStats(info map[string]string) map[string]string {
keyspace := map[string]string{}
for k, v := range info {
if strings.HasPrefix(k, "db") {
keyspace[k] = v
}
}
return keyspace
}
var schema = s.Schema{
"keys": c.Int("keys"),
"expires": c.Int("expires"),
"avg_ttl": c.Int("avg_ttl"),
}
// parseKeyspaceStats resolves the overloaded value string that Redis returns for keyspace
func parseKeyspaceStats(keyspaceMap map[string]string) map[string]common.MapStr {
keyspace := map[string]common.MapStr{}
for k, v := range keyspaceMap {
// Extract out the overloaded values for db keyspace
// fmt: info[db0] = keys=795341,expires=0,avg_ttl=0
dbInfo := redis.ParseRedisLine(v, ",")
if len(dbInfo) == 3 {
db := map[string]interface{}{}
for _, dbEntry := range dbInfo {
stats := redis.ParseRedisLine(dbEntry, "=")
if len(stats) == 2 {
db[stats[0]] = stats[1]
}
}
data, _ := schema.Apply(db)
keyspace[k] = data
}
}
return keyspace
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。