Created
October 8, 2015 08:42
-
-
Save wuub/e71f8176caf1ab106743 to your computer and use it in GitHub Desktop.
Find out which services generate workload in your consul raft log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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