Esempio n. 1
0
func setGlobalConfigs(config *HekadConfig) (*pipeline.GlobalConfigStruct, string, string) {
	maxprocs := config.Maxprocs
	poolSize := config.PoolSize
	chanSize := config.ChanSize
	cpuProfName := config.CpuProfName
	memProfName := config.MemProfName
	maxMsgLoops := config.MaxMsgLoops
	maxMsgProcessInject := config.MaxMsgProcessInject
	maxMsgProcessDuration := config.MaxMsgProcessDuration
	maxMsgTimerInject := config.MaxMsgTimerInject

	runtime.GOMAXPROCS(maxprocs)

	globals := pipeline.DefaultGlobals()
	globals.PoolSize = poolSize
	globals.PluginChanSize = chanSize
	globals.MaxMsgLoops = maxMsgLoops
	if globals.MaxMsgLoops == 0 {
		globals.MaxMsgLoops = 1
	}
	globals.MaxMsgProcessInject = maxMsgProcessInject
	globals.MaxMsgProcessDuration = maxMsgProcessDuration
	globals.MaxMsgTimerInject = maxMsgTimerInject
	globals.BaseDir = config.BaseDir
	globals.ShareDir = config.ShareDir
	globals.SampleDenominator = config.SampleDenominator
	globals.Hostname = config.Hostname

	return globals, cpuProfName, memProfName
}
Esempio n. 2
0
func main() {
	configFile := flag.String("config", "/etc/hekad.toml", "Config file")
	maxprocs := flag.Int("maxprocs", 1, "Go runtime MAXPROCS value")
	poolSize := flag.Int("poolsize", 100, "Pipeline pool size")
	decoderPoolSize := flag.Int("decoder_poolsize", 4, "Decoder pool size")
	chanSize := flag.Int("plugin_chansize", 50, "Plugin input channel buffer size")
	cpuProfName := flag.String("cpuprof", "", "Go CPU profiler output file")
	memProfName := flag.String("memprof", "", "Go memory profiler output file")
	version := flag.Bool("version", false, "Output version and exit")
	maxMsgLoops := flag.Uint("max_message_loops", 4, "Maximum number of times a message can pass thru the system")
	flag.Parse()

	if *version {
		fmt.Println(VERSION)
		os.Exit(0)
	}

	runtime.GOMAXPROCS(*maxprocs)

	if *cpuProfName != "" {
		profFile, err := os.Create(*cpuProfName)
		if err != nil {
			log.Fatalln(err)
		}
		pprof.StartCPUProfile(profFile)
		defer pprof.StopCPUProfile()
	}

	if *memProfName != "" {
		defer func() {
			profFile, err := os.Create(*memProfName)
			if err != nil {
				log.Fatalln(err)
			}
			pprof.WriteHeapProfile(profFile)
			profFile.Close()
		}()
	}

	// Set up and load the pipeline configuration and start the daemon.
	globals := pipeline.DefaultGlobals()
	globals.PoolSize = *poolSize
	globals.DecoderPoolSize = *decoderPoolSize
	globals.PluginChanSize = *chanSize
	globals.MaxMsgLoops = *maxMsgLoops
	if globals.MaxMsgLoops == 0 {
		globals.MaxMsgLoops = 1
	}
	pipeconf := pipeline.NewPipelineConfig(globals)
	err := pipeconf.LoadFromConfigFile(*configFile)
	if err != nil {
		log.Fatal("Error reading config: ", err)
	}
	pipeline.Run(pipeconf)
}
Esempio n. 3
0
func main() {
	configFile := flag.String("config", "/etc/hekad.toml", "Config file")
	version := flag.Bool("version", false, "Output version and exit")
	flag.Parse()

	if flag.NFlag() == 0 {
		flag.PrintDefaults()
		os.Exit(0)
	}

	if *version {
		fmt.Println(VERSION)
		os.Exit(0)
	}

	config, err := LoadHekadConfig(*configFile)
	if err != nil {
		log.Fatal("Error reading config: ", err)
	}

	maxprocs := config.Maxprocs
	poolSize := config.PoolSize
	decoderPoolSize := config.DecoderPoolSize
	chanSize := config.ChanSize
	cpuProfName := config.CpuProfName
	memProfName := config.MemProfName
	maxMsgLoops := config.MaxMsgLoops
	maxMsgProcessInject := config.MaxMsgProcessInject
	maxMsgTimerInject := config.MaxMsgTimerInject

	runtime.GOMAXPROCS(maxprocs)

	if cpuProfName != "" {
		profFile, err := os.Create(cpuProfName)
		if err != nil {
			log.Fatalln(err)
		}
		profFile.Close()
		pprof.StartCPUProfile(profFile)
		defer pprof.StopCPUProfile()
	}

	if memProfName != "" {
		defer func() {
			profFile, err := os.Create(memProfName)
			if err != nil {
				log.Fatalln(err)
			}
			pprof.WriteHeapProfile(profFile)
			profFile.Close()
		}()
	}

	// Set up and load the pipeline configuration and start the daemon.
	globals := pipeline.DefaultGlobals()
	globals.PoolSize = poolSize
	globals.DecoderPoolSize = decoderPoolSize
	globals.PluginChanSize = chanSize
	globals.MaxMsgLoops = maxMsgLoops
	if globals.MaxMsgLoops == 0 {
		globals.MaxMsgLoops = 1
	}
	globals.MaxMsgProcessInject = maxMsgProcessInject
	globals.MaxMsgTimerInject = maxMsgTimerInject
	pipeconf := pipeline.NewPipelineConfig(globals)

	err = pipeconf.LoadFromConfigFile(*configFile)
	if err != nil {
		log.Fatal("Error reading config: ", err)
	}
	pipeline.Run(pipeconf)
}
Esempio n. 4
0
func TestWriteMessage(t *testing.T) {
	pipeline.NewPipelineConfig(pipeline.DefaultGlobals()) // Set up globals :P
	var sbc SandboxConfig
	sbc.ScriptFilename = "./testsupport/field_scribble.lua"
	sbc.MemoryLimit = 32767
	sbc.InstructionLimit = 1000
	pack := getTestPack()
	sb, err := lua.CreateLuaSandbox(&sbc)
	if err != nil {
		t.Errorf("%s", err)
	}
	err = sb.Init("", "decoder")
	if err != nil {
		t.Errorf("%s", err)
	}
	r := sb.ProcessMessage(pack)
	if r != 0 {
		t.Errorf("ProcessMessage should return 0, received %d", r)
	}
	if pack.Message.GetType() != "MyType" {
		t.Error("Type not set")
	}
	if pack.Message.GetLogger() != "MyLogger" {
		t.Error("Logger not set")
	}
	packTime := time.Unix(0, pack.Message.GetTimestamp())
	cmpTime := time.Unix(0, 1385968914904958136)
	d, _ := time.ParseDuration("500ns")
	packTime = packTime.Round(d)
	cmpTime = cmpTime.Round(d)
	if !packTime.Equal(cmpTime) {
		t.Errorf("Timestamp not set: %d", pack.Message.GetTimestamp())
	}
	if pack.Message.GetPayload() != "MyPayload" {
		t.Error("Payload not set")
	}
	if pack.Message.GetEnvVersion() != "000" {
		t.Error("EnvVersion not set")
	}
	if pack.Message.GetHostname() != "MyHostname" {
		t.Error("Hostname not set")
	}
	if pack.Message.GetSeverity() != 4 {
		t.Error("Severity not set")
	}
	if pack.Message.GetPid() != 12345 {
		t.Error("Pid not set")
	}
	var f []*message.Field
	f = pack.Message.FindAllFields("String")
	if len(f) != 1 || len(f[0].GetValueString()) != 1 || f[0].GetValueString()[0] != "foo" {
		t.Errorf("String field not set")
	}
	f = pack.Message.FindAllFields("Float")
	if len(f) != 1 || len(f[0].GetValueDouble()) != 1 || f[0].GetValueDouble()[0] != 1.2345 {
		t.Error("Float field not set")
	}
	f = pack.Message.FindAllFields("Int")
	if len(f) != 1 {
		t.Error("Int field not set")
	} else {
		if len(f[0].GetValueDouble()) != 2 || f[0].GetValueDouble()[0] != 123 ||
			f[0].GetValueDouble()[1] != 456 {
			t.Error("Int field set incorrectly")
		}
		if f[0].GetRepresentation() != "count" {
			t.Error("Int field representation not set")
		}
	}
	f = pack.Message.FindAllFields("Bool")
	if len(f) != 2 {
		t.Error("Bool fields not set")
	} else {
		if len(f[0].GetValueBool()) != 1 || !f[0].GetValueBool()[0] {
			t.Error("Bool field 0 not set")
		}
		if len(f[1].GetValueBool()) != 1 || f[1].GetValueBool()[0] {
			t.Error("Bool field 1 not set")
		}
	}
	if f = pack.Message.FindAllFields(""); len(f) != 1 {
		t.Error("No-name field not set")
	} else {
		if len(f[0].GetValueString()) != 1 || f[0].GetValueString()[0] != "bad idea" {
			t.Error("No-name field set incorrectly")
		}
	}
	if pack.Message.GetUuidString() != "550d19b9-58c7-49d8-b0dd-b48cd1c5b305" {
		t.Errorf("Uuid not set: %s", pack.Message.GetUuidString())
	}
}