This repository was archived by the owner on Aug 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/grafana/metrictank/mdata" | ||
"github.com/raintank/schema" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type PrintNotifierHandler struct{} | ||
|
||
func NewPrintNotifierHandler() PrintNotifierHandler { | ||
return PrintNotifierHandler{} | ||
} | ||
|
||
func (dn PrintNotifierHandler) PartitionOf(key schema.MKey) (int32, bool) { | ||
return 0, false | ||
} | ||
|
||
func (dn PrintNotifierHandler) Handle(data []byte) { | ||
version := uint8(data[0]) | ||
if version == uint8(mdata.PersistMessageBatchV1) { | ||
batch := mdata.PersistMessageBatch{} | ||
err := json.Unmarshal(data[1:], &batch) | ||
if err != nil { | ||
log.Errorf("failed to unmarsh batch message: %s -- skipping", err) | ||
return | ||
} | ||
for _, c := range batch.SavedChunks { | ||
fmt.Printf("%s %d %s\n", batch.Instance, c.T0, c.Key) | ||
} | ||
} else { | ||
log.Errorf("unknown message version %d", version) | ||
} | ||
return | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"math/rand" | ||
"os" | ||
"os/signal" | ||
"strconv" | ||
"syscall" | ||
|
||
"github.com/grafana/metrictank/logger" | ||
"github.com/grafana/metrictank/mdata/notifierKafka" | ||
"github.com/grafana/metrictank/stats" | ||
"github.com/rakyll/globalconf" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
var confFile = flag.String("config", "/etc/metrictank/metrictank.ini", "configuration file path") | ||
|
||
func main() { | ||
flag.Usage = func() { | ||
fmt.Fprintln(os.Stderr, "mt-kafka-persist-sniff") | ||
fmt.Fprintln(os.Stderr, "Print what's flowing through kafka metric persist topic") | ||
fmt.Fprintf(os.Stderr, "\nFlags:\n\n") | ||
flag.PrintDefaults() | ||
} | ||
flag.Parse() | ||
formatter := &logger.TextFormatter{} | ||
formatter.TimestampFormat = "2006-01-02 15:04:05.000" | ||
log.SetFormatter(formatter) | ||
log.SetLevel(log.InfoLevel) | ||
instance := "mt-kafka-persist-sniff" + strconv.Itoa(rand.Int()) | ||
|
||
// Only try and parse the conf file if it exists | ||
path := "" | ||
if _, err := os.Stat(*confFile); err == nil { | ||
path = *confFile | ||
} | ||
conf, err := globalconf.NewWithOptions(&globalconf.Options{ | ||
Filename: path, | ||
EnvPrefix: "MT_", | ||
}) | ||
if err != nil { | ||
log.Fatalf("error with configuration file: %s", err.Error()) | ||
os.Exit(1) | ||
} | ||
conf.ParseAll() | ||
|
||
// config may have had it disabled | ||
notifierKafka.Enabled = true | ||
|
||
stats.NewDevnull() // make sure metrics don't pile up without getting discarded | ||
|
||
notifierKafka.ConfigProcess(instance) | ||
notifierKafka.New(instance, NewPrintNotifierHandler()) | ||
sigChan := make(chan os.Signal, 1) | ||
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) | ||
sig := <-sigChan | ||
log.Infof("Received signal %q. Shutting down", sig) | ||
// notifierKafka.Stop() | ||
} |
This file contains 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
This file contains 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