Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

add indexdump rules analyzer #1840

Merged
merged 4 commits into from
Dec 1, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
WIP / add indexdump rules analyzer
Dieterbe committed Jun 1, 2020

Verified

This commit was signed with the committer’s verified signature.
micahmo Micah Morrison
commit 5c1179b67b0e21f20759572659cc3906e6583a75
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
/cmd/mt-index-cat/mt-index-cat
/cmd/mt-index-migrate/mt-index-migrate
/cmd/mt-index-prune/mt-index-prune
/cmd/mt-indexdump-rules-analyzer/mt-indexdump-rules-analyzer
/cmd/mt-kafka-mdm-sniff-out-of-order/mt-kafka-mdm-sniff-out-of-order
/cmd/mt-kafka-mdm-sniff/mt-kafka-mdm-sniff
/cmd/mt-kafka-persist-sniff/mt-kafka-persist-sniff
69 changes: 69 additions & 0 deletions cmd/mt-indexdump-rules-analyzer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package main

import (
"bufio"
"flag"
"fmt"
"os"
"sync/atomic"
"time"

"github.com/gosuri/uilive"
"github.com/grafana/metrictank/conf"
"github.com/grafana/metrictank/logger"
log "github.com/sirupsen/logrus"
)

func init() {
formatter := &logger.TextFormatter{}
formatter.TimestampFormat = "2006-01-02 15:04:05.000"
log.SetFormatter(formatter)
log.SetLevel(log.InfoLevel)
}

func perror(err error) {
if err != nil {
log.Fatal(err.Error())
}
}

func main() {
var indexRulesFile string
flag.StringVar(&indexRulesFile, "index-rules-file", "/etc/metrictank/index-rules.conf", "name of file which defines the max-stale times")
flag.Parse()

indexRules, err := conf.ReadIndexRules(indexRulesFile)
if os.IsNotExist(err) {
log.Fatalf("Index-rules.conf file %s does not exist; exiting", indexRulesFile)
os.Exit(1)
}
scanner := bufio.NewScanner(os.Stdin)

counts := make([]uint64, len(indexRules.Rules)+1)

writer := uilive.New()
writer.Start()

go func() {
tick := time.NewTicker(100 * time.Millisecond)
for range tick.C {
for i := range counts {
fmt.Fprintf(writer, "Patt [%d]: %s -- %d\n", i, indexRules.Get(uint16(i)), atomic.LoadUint64(&counts[i]))
}
writer.Flush()
}

}()

for scanner.Scan() {
word := scanner.Text()
ruleID, _ := indexRules.Match(word)
atomic.AddUint64(&counts[ruleID], 1)
}
writer.Stop()

if err := scanner.Err(); err != nil {
log.Println(err)
}

}
9 changes: 9 additions & 0 deletions docs/tools.md
Original file line number Diff line number Diff line change
@@ -305,6 +305,15 @@ mt-index-cat cass -hosts localhost:9042 -schema-file ../../scripts/config/schema
```


## mt-indexdump-rules-analyzer

```
Usage of ./mt-indexdump-rules-analyzer:
-index-rules-file string
name of file which defines the max-stale times (default "/etc/metrictank/index-rules.conf")
```


## mt-index-migrate

```