...
 
Commits (2)
......@@ -15,6 +15,7 @@ type Config struct {
SendInterval string `default:"1h" yaml:"send_interval"`
Verbose bool `default:"false" yaml:"verbose"`
Debug bool `default:"false" yaml:"debug"`
AllowWrite bool
Database string `default:"data.db" yaml:"database"`
......
......@@ -56,7 +56,7 @@ func (a *App) Send() error {
tags, fields := ev.Point()
p := influxdb.NewPoint(string(evt), tags, fields, ev.GetTime())
if a.config.Verbose {
if a.config.Debug {
log.Printf("writing point: %s", ev.String())
}
......
......@@ -49,7 +49,7 @@ func (a *App) SaveEvent(evt event.Type, ev event.Event) error {
return err
}
if a.config.Verbose {
if a.config.Debug {
go func(ev event.Event) {
log.Printf("saving event: %s", ev.String())
}(ev)
......
package cmd
import (
"log"
"os"
"runtime"
"runtime/pprof"
"github.com/spf13/cobra"
)
......@@ -11,10 +16,14 @@ var rootCmd = &cobra.Command{
var (
configPath string
profileCPU string
profileMem string
)
func init() {
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "jetstats.yml", "configuration file")
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "jetstats.yml", "configuration `file`")
rootCmd.PersistentFlags().StringVar(&profileCPU, "cpuprofile", "", "write cpu profile to `file`")
rootCmd.PersistentFlags().StringVar(&profileMem, "memprofile", "", "write memory profile to `file`")
rootCmd.AddCommand(serverCmd)
rootCmd.AddCommand(webhooksCmd)
rootCmd.AddCommand(sendCmd)
......@@ -22,5 +31,32 @@ func init() {
// Execute root command
func Execute() error {
return rootCmd.Execute()
if profileCPU != "" {
f, err := os.Create(profileCPU)
if err != nil {
log.Fatal("could not create CPU profile: ", err)
}
defer f.Close()
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal("could not start CPU profile: ", err)
}
defer pprof.StopCPUProfile()
}
err := rootCmd.Execute()
if profileMem != "" {
f, err := os.Create(profileMem)
if err != nil {
log.Fatal("could not create memory profile: ", err)
}
defer f.Close()
runtime.GC()
if err := pprof.WriteHeapProfile(f); err != nil {
log.Fatal("could not write memory profile: ", err)
}
}
return err
}