Skip to content

Commit

Permalink
Merge pull request oliver006#64 from oliver006/oh_get_maxmemory_from_…
Browse files Browse the repository at this point in the history
…INFO

Get maxmemory from INFO command
  • Loading branch information
oliver006 authored Apr 22, 2017
2 parents 012673f + 700c0ed commit 77c9cdc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 25 deletions.
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ machine:
SRC_LOCATION: "/home/ubuntu/.go_workspace/src/github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME"
COVERAGE_PROFILE: "/home/ubuntu/coverage.out"
GO_LDFLAGS: '-extldflags "-static" -X main.VERSION=$CIRCLE_TAG -X main.COMMIT_SHA1=$CIRCLE_SHA1 -X main.BUILD_DATE=$(date +%F-%T)'
MY_GO_VERSION: "1.8"
MY_GO_VERSION: "1.8.1"

dependencies:
pre:
Expand Down
23 changes: 1 addition & 22 deletions exporter/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var (
"used_memory_rss": "memory_used_rss_bytes",
"used_memory_peak": "memory_used_peak_bytes",
"used_memory_lua": "memory_used_lua_bytes",
"max_memory": "memory_max_bytes",
"maxmemory": "memory_max_bytes",
"mem_fragmentation_ratio": "memory_fragmentation_ratio",

// # Persistence
Expand Down Expand Up @@ -386,23 +386,6 @@ func (e *Exporter) extractInfoMetrics(info, addr string, alias string, scrapes c
return nil
}

func extractConfigMetrics(config []string, addr string, alias string, scrapes chan<- scrapeResult) error {

if len(config)%2 != 0 {
return fmt.Errorf("invalid config: %#v", config)
}

for pos := 0; pos < len(config)/2; pos++ {
val, err := strconv.ParseFloat(config[pos*2+1], 64)
if err != nil {
log.Debugf("couldn't parse %s, err: %s", config[pos*2+1], err)
continue
}
scrapes <- scrapeResult{Name: fmt.Sprintf("config_%s", config[pos*2]), Addr: addr, Alias: alias, Value: val}
}
return nil
}

func (e *Exporter) scrape(scrapes chan<- scrapeResult) {

defer close(scrapes)
Expand Down Expand Up @@ -465,10 +448,6 @@ func (e *Exporter) scrape(scrapes chan<- scrapeResult) {

scrapes <- scrapeResult{Name: "up", Addr: addr, Alias: alias, Value: 1}

if config, err := redis.Strings(c.Do("CONFIG", "GET", "maxmemory")); err == nil {
extractConfigMetrics(config, addr, alias, scrapes)
}

for _, k := range e.keys {
if _, err := c.Do("SELECT", k.db); err != nil {
continue
Expand Down
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
logFormat = flag.String("log-format", "txt", "Log format, valid options are txt and json")
showVersion = flag.Bool("version", false, "Show version information and exit")

// VERSION, BUILD_DATE, GIT_COMMIT are filled in by the CircleCI build
// VERSION, BUILD_DATE, GIT_COMMIT are filled in by the build script
VERSION = "<<< filled in by build >>>"
BUILD_DATE = "<<< filled in by build >>>"
COMMIT_SHA1 = "<<< filled in by build >>>"
Expand All @@ -39,7 +39,10 @@ func main() {
default:
log.SetFormatter(&log.TextFormatter{})
}
log.Printf("Redis Metrics Exporter %s build date: %s sha1: %s\n", VERSION, BUILD_DATE, COMMIT_SHA1)
log.Printf("Redis Metrics Exporter %s build date: %s sha1: %s Go: %s\n",
VERSION, BUILD_DATE, COMMIT_SHA1,
runtime.Version(),
)
if *isDebug {
log.SetLevel(log.DebugLevel)
log.Debugln("Enabling debug output")
Expand Down

0 comments on commit 77c9cdc

Please sign in to comment.