Skip to content

Instantly share code, notes, and snippets.

@wuub
Created October 8, 2015 08:42
Show Gist options
  • Save wuub/e71f8176caf1ab106743 to your computer and use it in GitHub Desktop.
Save wuub/e71f8176caf1ab106743 to your computer and use it in GitHub Desktop.
Find out which services generate workload in your consul raft log
package main
import (
"fmt"
"github.com/hashicorp/raft"
"github.com/hashicorp/raft-boltdb"
"regexp"
)
func main() {
bs, err := raftboltdb.NewBoltStore("raft.db")
if err != nil {
panic(err)
}
defer bs.Close()
lastIndex, _ := bs.LastIndex()
firstIndex, _ := bs.FirstIndex()
var log raft.Log
var count map[string]int
count = make(map[string]int)
re := regexp.MustCompile("service:[\\w-]+")
for i := firstIndex; i < lastIndex; i++ {
if err = bs.GetLog(i, &log); err != nil {
panic(err)
}
checkName := re.FindString(string(log.Data))
count[checkName] += 1
}
fmt.Printf("TOTAL: %d\n", lastIndex-firstIndex)
for k, v := range count {
fmt.Printf("%09d\t%s\n", v, k)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment