當前位置: 首頁>>代碼示例>>Golang>>正文


Golang util.Info函數代碼示例

本文整理匯總了Golang中github.com/mperham/inspeqtor/util.Info函數的典型用法代碼示例。如果您正苦於以下問題:Golang Info函數的具體用法?Golang Info怎麽用?Golang Info使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Info函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: LookupService

func (i *Initd) LookupService(serviceName string) (*ProcessStatus, error) {
	path := i.ctlPath + serviceName
	result, _ := util.FileExists(path)
	if !result {
		// service script does not exist in etc/init.d, not under
		// init.d control
		return nil, &ServiceError{i.Name(), serviceName, ErrServiceNotFound}
	}

	// First try to find the PID file with same name in /var/run.
	paths := []string{
		i.varrunPath + serviceName + ".pid",
		i.varrunPath + serviceName + "/" + serviceName + ".pid",
	}

	for _, pidpath := range paths {
		st, err := i.readPidFile(pidpath)
		if err != nil {
			util.Info("Error processing PID file %s: %s", pidpath, err.Error())
			continue
		} else if st != nil {
			return st, nil
		} else {
			util.Info("No such pidfile %s", pidpath)
		}
	}

	return &ProcessStatus{0, Down}, nil
}
開發者ID:rquelle,項目名稱:inspeqtor,代碼行數:29,代碼來源:initd.go

示例2: detectInitd

func detectInitd(root string) (InitSystem, error) {
	ctlpath := root + "etc/init.d/"
	result, err := util.FileExists(ctlpath)
	if err != nil {
		return nil, err
	}

	if !result {
		util.Debug("init.d not detected in " + ctlpath)
		return nil, nil
	}

	matches, err := filepath.Glob(ctlpath + "*")
	if err != nil {
		return nil, err
	}

	if !result {
		util.Debug("init.d not detected in " + ctlpath)
		return nil, nil
	}

	if len(matches) > 0 {
		util.Info("Detected init.d in " + ctlpath)
		return &Initd{ctlpath, root + "var/run/", pidForString}, nil
	}

	util.Info(ctlpath + " exists but appears to be empty")
	return nil, nil
}
開發者ID:rquelle,項目名稱:inspeqtor,代碼行數:30,代碼來源:initd.go

示例3: AddSource

func (ps *processStorage) AddSource(name string, config map[string]string) (Source, error) {
	for _, x := range ps.daemonSpecific {
		if x.Name() == name {
			return x, nil
		}
	}
	builder := Sources[name]
	if builder == nil {
		return nil, nil
	}
	util.Info("Activating metrics for %s", name)
	src, err := builder(config)
	if err != nil {
		return nil, err
	}

	m, ok := src.(MandatorySource)
	if ok && m.Mandatory() {
		util.Debug("Registering all metrics for %s", name)
		descs := src.ValidMetrics()
		for _, d := range descs {
			if d.MetricType == Counter {
				ps.DeclareCounter(name, d.Name, nil, d.Display)
			} else {
				ps.DeclareGauge(name, d.Name, d.Display)
			}
		}
	}

	ps.daemonSpecific = append(ps.daemonSpecific, src)
	return src, nil
}
開發者ID:rquelle,項目名稱:inspeqtor,代碼行數:32,代碼來源:process.go

示例4: reload

func reload(i *Inspeqtor) {
	util.Info(Name + " reloading")
	newi, err := New(i.RootDir, i.SocketPath)
	if err != nil {
		util.Warn("Unable to reload: %s", err.Error())
		return
	}

	err = newi.Parse()
	if err != nil {
		util.Warn("Unable to reload: %s", err.Error())
		return
	}

	// we're reloading and newcopy will become the new
	// singleton.  Pro hooks into this to reload its features too.
	for _, callback := range Reloaders {
		err := callback(i, newi)
		if err != nil {
			util.Warn("Unable to reload: %s", err.Error())
			return
		}
	}

	// TODO proper reloading would not throw away the existing metric data
	// in i but defining new metrics can change the storage tree.  Implement
	// deep metric tree ring buffer sync if possible in basicReloader?
	i.Shutdown()
	newi.Start()
}
開發者ID:jmptrader,項目名稱:inspeqtor,代碼行數:30,代碼來源:inspeqtor.go

示例5: main

func main() {
	cli.SetupLogging()
	options := cli.ParseArguments()

	ins, err := inspeqtor.New(options.ConfigDirectory, options.SocketPath)
	if err != nil {
		log.Fatalln(err)
	}
	err = ins.Parse()
	if err != nil {
		log.Fatalln(err)
	}

	if options.TestConfig {
		util.Info("Configuration parsed ok.")
		os.Exit(0)
	} else if options.TestAlertRoutes {
		ins.TestAlertRoutes()
	} else {
		// Fire up the Inspeqtor singleton
		ins.Start()

		// Install the global signal handlers
		// This method never returns.
		inspeqtor.HandleSignals()
	}
}
開發者ID:rquelle,項目名稱:inspeqtor,代碼行數:27,代碼來源:main.go

示例6: check

func check(jobs map[string]*Job) time.Duration {
	min := time.Hour

	for _, j := range jobs {
		now := time.Now()
		due := j.LastRun.Add(j.Interval)
		if due.After(now) && min > due.Sub(now) {
			// calculate the delay time until the next job check
			min = due.Sub(now)
		}

		if due.Before(now) && j.state == inspeqtor.Ok {
			util.Warn("Recurring job \"%s\" is overdue", j.JobName)
			j.state = inspeqtor.Triggered
			err := j.alert(JobOverdue)
			if err != nil {
				util.Warn(fmt.Sprintf("Error firing cron job alert: %s", err.Error()))
			}
		}
		if !due.Before(now) && j.state == inspeqtor.Triggered {
			util.Info("Recurring job \"%s\" has recovered", j.JobName)
			err := j.alert(JobRan)
			if err != nil {
				util.Warn(fmt.Sprintf("Error firing cron job alert: %s", err.Error()))
			}
			j.state = inspeqtor.Ok
		}
	}
	return min
}
開發者ID:jmptrader,項目名稱:inspeqtor-pro,代碼行數:30,代碼來源:types.go

示例7: Resolve

/*
  Resolve each defined service to its managing init system.  Called only
  at startup, this is what maps services to init and fires ProcessDoesNotExist events.
*/
func (svc *Service) Resolve(mgrs []services.InitSystem) error {
	for _, sm := range mgrs {
		// TODO There's a bizarre race condition here. Figure out
		// why this is necessary.  We shouldn't be multi-threaded yet.
		if sm == nil {
			continue
		}

		ps, err := sm.LookupService(svc.Name())
		if err != nil {
			serr := err.(*services.ServiceError)
			if serr.Err == services.ErrServiceNotFound {
				util.Debug(sm.Name() + " doesn't have " + svc.Name())
				continue
			}
			return err
		}
		util.Info("Found %s/%s with status %s", sm.Name(), svc.Name(), ps)
		svc.Manager = sm
		svc.Transition(ps, func(et EventType) {
			counters.Add("events", 1)
			err = svc.EventHandler.Trigger(&Event{et, svc, nil})
			if err != nil {
				util.Warn("Error firing event: %s", err.Error())
			}
		})
		break
	}
	if svc.Manager == nil {
		return fmt.Errorf("Could not find service %s, did you misspell it?", svc.Name())
	}
	return nil
}
開發者ID:rquelle,項目名稱:inspeqtor,代碼行數:37,代碼來源:types.go

示例8: startDeploy

func startDeploy(i *Inspeqtor, args []string, resp io.Writer) {
	length := time.Duration(i.GlobalConfig.DeployLength) * time.Second
	i.SilenceUntil = time.Now().Add(length)

	counters.Get("deploy").(*expvar.Int).Set(1)
	util.Info("Starting deploy")
	io.WriteString(resp, "Starting deploy, now silenced\n")
}
開發者ID:jmptrader,項目名稱:inspeqtor,代碼行數:8,代碼來源:commands.go

示例9: triggeredHandler

func triggeredHandler(rule *Rule, tripped bool) *Event {
	if !tripped {
		util.Info("%s[%s] recovered.", rule.EntityName(), rule.Metric())
		rule.State = Recovered
		return nil
	}
	util.Debug("%s[%s] still triggered. Current: %.1f, Threshold: %.1f", rule.EntityName(), rule.Metric(), rule.CurrentValue, rule.Threshold)
	return nil
}
開發者ID:rquelle,項目名稱:inspeqtor,代碼行數:9,代碼來源:rules.go

示例10: finishDeploy

func finishDeploy(i *Inspeqtor, args []string, resp io.Writer) {
	// silence for a cycle, give processes a little time to
	// settle before alerting again. We don't want a restart
	// during a deploy to send email for those events.
	i.SilenceUntil = time.Now().Add(time.Duration(i.GlobalConfig.CycleTime) * time.Second)

	counters.Get("deploy").(*expvar.Int).Set(0)
	util.Info("Finished deploy")
	io.WriteString(resp, "Finished deploy, volume turned to 11\n")
}
開發者ID:jmptrader,項目名稱:inspeqtor,代碼行數:10,代碼來源:commands.go

示例11: main

func main() {
	inspeqtor.Name = "Inspeqtor Pro"

	cli.StartupInfo = func() {
	}

	cli.SetupLogging()
	options := cli.ParseArguments()

	_, err := verifyLicense(options.ConfigDirectory)
	if err != nil {
		util.Warn("Error verifying license file: %s", err)
		os.Exit(127)
	}

	ins, err := inspeqtor.New(options.ConfigDirectory, options.SocketPath)
	if err != nil {
		log.Fatalln(err)
	}
	err = ins.Parse()
	if err != nil {
		log.Fatalln(err)
	}

	err = bootstrapJobs(ins, options.ConfigDirectory)
	if err != nil {
		log.Fatalln(err)
	}

	err = bootstrapStatsd(ins, options.ConfigDirectory)
	if err != nil {
		log.Fatalln(err)
	}

	err = expose.Bootstrap(ins)
	if err != nil {
		log.Fatalln(err)
	}

	if options.TestConfig {
		util.Info("Configuration parsed ok.")
		os.Exit(0)
	} else if options.TestAlertRoutes {
		ins.TestAlertRoutes()
	} else {
		ins.Start()
		inspeqtor.HandleSignals()
	}
}
開發者ID:jmptrader,項目名稱:inspeqtor-pro,代碼行數:49,代碼來源:main.go

示例12: Parse

func Parse(global *inspeqtor.ConfigFile, confDir string) (map[string]*Job, error) {
	inspeqtor.CommandHandlers["job_done"] = jobDone

	parsedJobs, err := parseJobs(global, confDir)
	if err != nil {
		return nil, err
	}
	if len(parsedJobs) == 0 {
		return nil, nil
	}
	jobs = parsedJobs

	util.Info("Watching for %d recurring jobs", len(parsedJobs))
	return parsedJobs, nil
}
開發者ID:jmptrader,項目名稱:inspeqtor-pro,代碼行數:15,代碼來源:types.go

示例13: ParseGlobal

func ParseGlobal(rootDir string) (*ConfigFile, error) {
	path := rootDir + "/inspeqtor.conf"
	exists, err := util.FileExists(path)
	if err != nil {
		return nil, err
	}

	if exists {
		util.Debug("Parsing " + path)
		data, err := ioutil.ReadFile(path)
		if err != nil {
			return nil, err
		}

		s := lexer.NewLexer([]byte(data))
		p := parser.NewParser()
		obj, err := p.Parse(s)
		if err != nil {
			return nil, err
		}
		ast := obj.(ast.Config)

		config := ConfigFile{Defaults, map[string]*AlertRoute{}}

		config.Variables = ast.Variables
		if val, has := ast.Variables["log_level"]; has {
			util.SetLogLevel(val)
		}
		parseValue(ast, &config.CycleTime, "cycle_time", 15)
		parseValue(ast, &config.DeployLength, "deploy_length", 300)
		parseValue(ast, &config.ExposePort, "expose_port", 4677)

		for _, v := range ast.Routes {
			ar, err := ValidateChannel(v.Name, v.Channel, v.Config)
			if err != nil {
				return nil, err
			}
			if _, ok := config.AlertRoutes[v.Name]; ok {
				return nil, fmt.Errorf("Duplicate alert config for '%s'", v.Name)
			}
			config.AlertRoutes[v.Name] = ar
		}
		return &config, nil
	}

	util.Info("No configuration file found at " + rootDir + "/inspector.conf")
	return &ConfigFile{Defaults, nil}, nil
}
開發者ID:rquelle,項目名稱:inspeqtor,代碼行數:48,代碼來源:global_parser.go

示例14: detectLaunchd

func detectLaunchd(rootDir string) (InitSystem, error) {
	if !util.Darwin() {
		return nil, nil
	}
	util.Info("Detected OSX, using launchd")

	usr, err := user.Current()
	if err != nil {
		return nil, err
	}

	dir := usr.HomeDir
	paths := []string{
		dir + "/Library/LaunchAgents",
		"/Library/LaunchAgents",
		"/Library/LaunchDaemons",
		"/System/Library/LaunchDaemons",
	}
	return &Launchd{paths}, nil
}
開發者ID:rquelle,項目名稱:inspeqtor,代碼行數:20,代碼來源:launchd.go

示例15: Start

func (i *Inspeqtor) Start() {
	util.Debug("Starting command socket")
	err := i.openSocket(i.SocketPath)
	if err != nil {
		util.Warn("Could not create Unix socket: %s", err.Error())
		exit(i)
	}

	go func() {
		for {
			if !i.safelyAccept() {
				util.Debug("Shutting down command socket")
				return
			}
		}
	}()

	// if expose_port is 0, disable the feature altogether
	if i.GlobalConfig.ExposePort != 0 {
		sock, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", i.GlobalConfig.ExposePort))
		if err != nil {
			util.Warn("Could not listen on port %d: %s", i.GlobalConfig.ExposePort, err.Error())
			exit(i)
		}
		i.Expose = sock
		go func() {
			// TODO How do we error handling here?
			util.Info("Expose now available at port %d", i.GlobalConfig.ExposePort)
			err := http.Serve(i.Expose, nil)
			// Don't log an "error" when we shut down normally and close the socket
			if err != nil && !strings.Contains(err.Error(), "use of closed network") {
				util.Warn("HTTP server error: %s", err.Error())
			}
		}()
	}

	util.Debug("Starting main run loop")
	go i.runLoop()

	Singleton = i
}
開發者ID:jmptrader,項目名稱:inspeqtor,代碼行數:41,代碼來源:inspeqtor.go


注:本文中的github.com/mperham/inspeqtor/util.Info函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。