当前位置: 首页>>代码示例>>Golang>>正文


Golang checkers.NewChecker函数代码示例

本文整理汇总了Golang中github.com/mackerelio/checkers.NewChecker函数的典型用法代码示例。如果您正苦于以下问题:Golang NewChecker函数的具体用法?Golang NewChecker怎么用?Golang NewChecker使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewChecker函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: run

func run(args []string) *checkers.Checker {
	_, err := flags.ParseArgs(&opts, args)
	if err != nil {
		os.Exit(1)
	}

	size, err := getSqsQueueSize(opts.Region, opts.AccessKeyID, opts.SecretAccessKey, opts.QueueName)
	if err != nil {
		return checkers.NewChecker(checkers.UNKNOWN, err.Error())
	}

	var chkSt checkers.Status
	var msg string
	if opts.Crit < size {
		msg = fmt.Sprintf("size %d > %d in %s", size, opts.Crit, opts.QueueName)
		chkSt = checkers.CRITICAL
	} else if opts.Warn < size {
		msg = fmt.Sprintf("size %d > %d in %s", size, opts.Warn, opts.QueueName)
		chkSt = checkers.WARNING
	} else {
		msg = fmt.Sprintf("size %d < warning %d, critical %d in %s", size, opts.Warn, opts.Crit, opts.QueueName)
		chkSt = checkers.OK
	}

	return checkers.NewChecker(chkSt, msg)
}
开发者ID:hiroakis,项目名称:go-check-plugins,代码行数:26,代码来源:check-aws-sqs-queue-size.go

示例2: checkConnection

func checkConnection(args []string) *checkers.Checker {
	opts := connectionOpts{}
	psr := flags.NewParser(&opts, flags.Default)
	psr.Usage = "connection [OPTIONS]"
	_, err := psr.ParseArgs(args)
	if err != nil {
		os.Exit(1)
	}

	db, err := sql.Open(opts.getDriverAndDataSourceName())
	if err != nil {
		return checkers.Unknown(err.Error())
	}
	defer db.Close()

	statActivityCount := 0
	err = db.QueryRow("SELECT COUNT(*) AS cnt FROM pg_stat_activity").Scan(&statActivityCount)
	if err != nil {
		return checkers.Unknown(err.Error())
	}

	checkSt := checkers.OK
	msg := fmt.Sprintf("%d connections", statActivityCount)
	if statActivityCount > opts.Crit {
		checkSt = checkers.CRITICAL
	} else if statActivityCount > opts.Warn {
		checkSt = checkers.WARNING
	}
	return checkers.NewChecker(checkSt, msg)
}
开发者ID:hfm,项目名称:go-check-plugins,代码行数:30,代码来源:connection.go

示例3: checkPing

func checkPing(opts solrOpts) *checkers.Checker {
	uri := opts.createBaseURL() + "/admin/ping?wt=json"
	resp, err := http.Get(uri)
	if err != nil {
		return checkers.Unknown("couldn't get access to " + uri)
	}
	defer resp.Body.Close()

	dec := json.NewDecoder(resp.Body)
	var stats map[string]interface{}
	err = dec.Decode(&stats)
	if err != nil {
		return checkers.Unknown("couldn't parse JSON at " + uri)
	}

	status, ok := stats["status"].(string)
	if !ok {
		return checkers.Unknown("couldn't find status in JSON at " + uri)
	}

	checkSt := checkers.OK
	msg := fmt.Sprintf("%s %s", opts.Core, status)
	if status != "OK" {
		checkSt = checkers.CRITICAL
	}
	return checkers.NewChecker(checkSt, msg)
}
开发者ID:hiroakis,项目名称:go-check-plugins,代码行数:27,代码来源:ping.go

示例4: run

func run(args []string) *checkers.Checker {
	_, err := flags.ParseArgs(&opts, args)
	if err != nil {
		os.Exit(1)
	}

	stTime := time.Now()
	resp, err := http.Get(opts.URL)
	if err != nil {
		return checkers.Critical(err.Error())
	}
	elapsed := time.Since(stTime)
	defer resp.Body.Close()

	cLength := resp.ContentLength
	if cLength == -1 {
		byt, _ := ioutil.ReadAll(resp.Body)
		cLength = int64(len(byt))
	}

	checkSt := checkers.UNKNOWN
	switch st := resp.StatusCode; true {
	case st < 400:
		checkSt = checkers.OK
	case st < 500:
		checkSt = checkers.WARNING
	default:
		checkSt = checkers.CRITICAL
	}

	msg := fmt.Sprintf("%s %s - %d bytes in %f second respons time",
		resp.Proto, resp.Status, cLength, elapsed.Seconds())

	return checkers.NewChecker(checkSt, msg)
}
开发者ID:editnuki,项目名称:go-check-plugins,代码行数:35,代码来源:check_http.go

示例5: run

func run(args []string) *checkers.Checker {
	_, err := flags.ParseArgs(&opts, args)
	if err != nil {
		os.Exit(1)
	}
	ut, err := uptime.Get()
	if err != nil {
		return checkers.Unknown(fmt.Sprintf("Faild to fetch uptime metrics: %s", err))
	}
	checkSt := checkers.OK
	if opts.WarnUnder != nil && *opts.WarnUnder > ut {
		checkSt = checkers.WARNING
	}
	if opts.WarnOver != nil && *opts.WarnOver < ut {
		checkSt = checkers.WARNING
	}
	if opts.CritUnder != nil && *opts.CritUnder > ut {
		checkSt = checkers.CRITICAL
	}
	if opts.CritOver != nil && *opts.CritOver < ut {
		checkSt = checkers.CRITICAL
	}
	dur := time.Duration(ut * float64(time.Second))
	hours := int64(dur.Hours())
	days := hours / 24
	hours = hours % 24
	mins := int64(dur.Minutes()) % 60
	msg := fmt.Sprintf("%d day(s) %d hour(s) %d minute(s) (%d second(s))\n", days, hours, mins, int64(dur.Seconds()))

	return checkers.NewChecker(checkSt, msg)
}
开发者ID:matsuzj,项目名称:go-check-plugins,代码行数:31,代码来源:check-uptime.go

示例6: checkUptime

func checkUptime(args []string) *checkers.Checker {
	opts := uptimeOpts{}
	psr := flags.NewParser(&opts, flags.Default)
	psr.Usage = "uptime [OPTIONS]"
	_, err := psr.ParseArgs(args)
	if err != nil {
		os.Exit(1)
	}
	db := newMySQL(opts.mysqlSetting)
	err = db.Connect()
	if err != nil {
		return checkers.Unknown("couldn't connect DB")
	}
	defer db.Close()

	rows, res, err := db.Query("SHOW GLOBAL STATUS LIKE 'Uptime'")
	if err != nil {
		return checkers.Unknown("couldn't execute query")
	}

	idxValue := res.Map("Value")
	upTime := rows[0].Int64(idxValue)

	checkSt := checkers.OK
	msg := fmt.Sprintf("up %s", uptime2str(upTime))
	if opts.Crit > 0 && upTime < opts.Crit {
		checkSt = checkers.CRITICAL
	} else if opts.Warn > 0 && upTime < opts.Warn {
		checkSt = checkers.WARNING
	}
	return checkers.NewChecker(checkSt, msg)
}
开发者ID:hiroakis,项目名称:go-check-plugins,代码行数:32,代码来源:uptime.go

示例7: run

func run(args []string) *checkers.Checker {
	_, err := flags.ParseArgs(&opts, args)
	if err != nil {
		os.Exit(1)
	}

	stat, err := os.Stat(opts.File)
	if err != nil {
		if opts.IgnoreMissing {
			return checkers.Ok("No such file, but ignore missing is set.")
		}
		return checkers.Unknown(err.Error())
	}

	monitor := newMonitor(opts.WarningAge, opts.WarningSize, opts.CriticalAge, opts.CriticalSize)

	result := checkers.OK

	mtime := stat.ModTime()
	age := time.Now().Unix() - mtime.Unix()
	size := stat.Size()

	if monitor.CheckWarning(age, size) {
		result = checkers.WARNING
	}

	if monitor.CheckCritical(age, size) {
		result = checkers.CRITICAL
	}

	msg := fmt.Sprintf("%s is %d seconds old (%02d:%02d:%02d) and %d bytes.\n", opts.File, age, mtime.Hour(), mtime.Minute(), mtime.Second(), size)
	return checkers.NewChecker(result, msg)
}
开发者ID:hfm,项目名称:go-check-plugins,代码行数:33,代码来源:check_file_age.go

示例8: checkCertExpiration

func checkCertExpiration() *checkers.Checker {
	opts := certOpts{}
	psr := flags.NewParser(&opts, flags.Default)
	_, err := psr.Parse()
	if err != nil {
		psr.WriteHelp(os.Stdout)
		os.Exit(1)
	}

	cfByte, err := ioutil.ReadFile(opts.CertFile)
	if err != nil {
		return checkers.Critical(err.Error())
	}
	cfBlock, _ := pem.Decode(cfByte)
	cfCrt, err := x509.ParseCertificate(cfBlock.Bytes)

	if err != nil {
		return checkers.Critical(err.Error())
	}

	cfDaysRemaining := int64(cfCrt.NotAfter.Sub(time.Now().UTC()).Hours() / 24)
	checkSt := checkers.OK
	msg := fmt.Sprintf("%d days remaining", cfDaysRemaining)

	if cfDaysRemaining < opts.Crit {
		checkSt = checkers.CRITICAL
	} else if cfDaysRemaining < opts.Warn {
		checkSt = checkers.WARNING
	}
	return checkers.NewChecker(checkSt, msg)
}
开发者ID:hiroakis,项目名称:go-check-plugins,代码行数:31,代码来源:check-cert-file.go

示例9: run

func run(args []string) *checkers.Checker {
	_, err := flags.ParseArgs(&opts, args)
	if err != nil {
		return checkers.Critical(err.Error())
	}

	offset, err := getNtpOffset()
	if err != nil {
		return checkers.Unknown(err.Error())
	}

	var chkSt checkers.Status
	var msg string
	if opts.Crit < math.Abs(offset) {
		msg = fmt.Sprintf("ntp offset is over %f(actual) > %f(threshold)", math.Abs(offset), opts.Crit)
		chkSt = checkers.CRITICAL
	} else if opts.Warn < math.Abs(offset) {
		msg = fmt.Sprintf("ntp offset is over %f(actual) > %f(threshold)", math.Abs(offset), opts.Warn)
		chkSt = checkers.WARNING
	} else {
		msg = fmt.Sprintf("ntp offset is %f(actual) < %f(warning threshold), %f(critial threshold)", offset, opts.Warn, opts.Crit)
		chkSt = checkers.OK
	}

	return checkers.NewChecker(chkSt, msg)
}
开发者ID:kentokento,项目名称:go-check-plugins,代码行数:26,代码来源:check-ntpoffset.go

示例10: run

func run(args []string) *checkers.Checker {
	_, err := flags.ParseArgs(&opts, args)
	if err != nil {
		os.Exit(1)
	}

	ws, err := sizeValue(opts.Warn)
	if err != nil {
		return checkers.NewChecker(checkers.UNKNOWN, err.Error())
	}

	cs, err := sizeValue(opts.Crit)
	if err != nil {
		return checkers.NewChecker(checkers.UNKNOWN, err.Error())
	}

	var stat os.FileInfo
	var size int64
	files, err := listFiles(opts.Base, opts.Depth)
	if err != nil {
		// file not found
		return checkers.NewChecker(checkers.OK, err.Error())
	}

	for _, v := range files {
		stat, err = os.Stat(v)
		if err != nil {
			continue
		}
		size = size + stat.Size()
	}

	var chkSt checkers.Status
	var msg string
	if cs < float64(size) {
		msg = fmt.Sprintf("size %d Byte > %s Byte in %s", size, opts.Crit, opts.Base)
		chkSt = checkers.CRITICAL
	} else if ws < float64(size) {
		msg = fmt.Sprintf("size %d Byte > %s Byte in %s", size, opts.Warn, opts.Base)
		chkSt = checkers.WARNING
	} else {
		msg = fmt.Sprintf("size %d Byte < warning %s Byte, critical %s Byte in %s", size, opts.Warn, opts.Crit, opts.Base)
		chkSt = checkers.OK
	}

	return checkers.NewChecker(chkSt, msg)
}
开发者ID:hiroakis,项目名称:go-check-plugins,代码行数:47,代码来源:check_file_size.go

示例11: run

func run(args []string) *checkers.Checker {
	_, err := flags.ParseArgs(&opts, args)
	if err != nil {
		os.Exit(1)
	}

	var queue int64
	queueStr := "0"
	monitor := newMonitor(opts.Warning, opts.Critical)

	result := checkers.OK

	if opts.Mta == "postfix" {
		out, err := exec.Command("mailq").Output()

		if err != nil {
			return checkers.Unknown(err.Error())
		}

		outs := strings.Split(string(out), "\n")
		line := outs[len(outs)-2]

		re := regexp.MustCompile(`-- \d+ Kbytes in (\d+) Requests.`)
		if re.MatchString(line) {
			queueStr = re.ReplaceAllString(line, "$1")
			queue, err = strconv.ParseInt(queueStr, 10, 64)
		}
	} else if opts.Mta == "qmail" {
		out, err := exec.Command("qmail-qstat").Output()

		if err != nil {
			return checkers.Unknown(err.Error())
		}

		outs := strings.Split(string(out), "\n")
		line := outs[0]

		re := regexp.MustCompile(`^messages in queue: (\d+)`)
		if re.MatchString(line) {
			queueStr = re.ReplaceAllString(line, "$1")
			queue, err = strconv.ParseInt(queueStr, 10, 64)
		}
	} else {
		return checkers.Unknown(fmt.Sprintf("%s: specified mta's check is not implemented.", opts.Mta))
	}

	if monitor.checkWarning(queue) {
		result = checkers.WARNING
	}

	if monitor.checkCritical(queue) {
		result = checkers.CRITICAL
	}

	msg := fmt.Sprintf(queueStr)
	return checkers.NewChecker(result, msg)
}
开发者ID:hiroakis,项目名称:go-check-plugins,代码行数:57,代码来源:check_mailq.go

示例12: run

func run(args []string) *checkers.Checker {
	_, err := flags.ParseArgs(&opts, args)
	if err != nil {
		os.Exit(1)
	}
	psformat := "user,pid,vsz,rss,pcpu,nlwp,state,etime,time,command"
	if threadsUnknown {
		psformat = "user,pid,vsz,rss,pcpu,state,etime,time,command"
	}
	output, err := exec.Command("ps", "axwwo", psformat).Output()
	var procs []procState
	for _, line := range strings.Split(string(output), "\n")[1:] {
		proc, err := parseProcState(line)
		if err != nil {
			continue
		}
		procs = append(procs, proc)
	}
	cmdPatRegexp := regexp.MustCompile(".*")
	if opts.CmdPat != "" {
		r, err := regexp.Compile(opts.CmdPat)
		if err != nil {
			os.Exit(1)
		}
		cmdPatRegexp = r
	}
	cmdExcludePatRegexp := regexp.MustCompile(".*")
	if opts.CmdExcludePat != "" {
		r, err := regexp.Compile(opts.CmdExcludePat)
		if err != nil {
			os.Exit(1)
		}
		cmdExcludePatRegexp = r
	}
	var resultrocStates []procState
	for _, proc := range procs {
		if matchProc(proc, cmdPatRegexp, cmdExcludePatRegexp) {
			resultrocStates = append(resultrocStates, proc)
		}
	}
	count := int64(len(resultrocStates))
	msg := gatherMsg(count)
	result := checkers.OK
	if opts.CritUnder != 0 && count < opts.CritUnder ||
		opts.CritOver != 0 && count > opts.CritOver {
		result = checkers.CRITICAL
	} else if opts.WarnUnder != 0 && count < opts.WarnUnder ||
		opts.WarnOver != 0 && count > opts.WarnOver {
		result = checkers.WARNING
	}
	return checkers.NewChecker(result, msg)
}
开发者ID:editnuki,项目名称:go-check-plugins,代码行数:52,代码来源:check_procs.go

示例13: run

func run(args []string) *checkers.Checker {
	_, err := flags.ParseArgs(&opts, args)
	if err != nil {
		os.Exit(1)
	}

	// for backward compatibility
	if opts.WarnUnder != 1 && opts.WarningUnder == 1 {
		opts.WarningUnder = opts.WarnUnder
	}
	if opts.WarnOver != nil && opts.WarningOver == nil {
		opts.WarningOver = opts.WarnOver
	}

	procs, err := getProcs()
	cmdPatRegexp := regexp.MustCompile(".*")
	if opts.CmdPat != "" {
		r, err := regexp.Compile(opts.CmdPat)
		if err != nil {
			os.Exit(1)
		}
		cmdPatRegexp = r
	}
	cmdExcludePatRegexp := regexp.MustCompile(".*")
	if opts.CmdExcludePat != "" {
		r, err := regexp.Compile(opts.CmdExcludePat)
		if err != nil {
			os.Exit(1)
		}
		cmdExcludePatRegexp = r
	}
	var resultrocStates []procState
	for _, proc := range procs {
		if matchProc(proc, cmdPatRegexp, cmdExcludePatRegexp) {
			resultrocStates = append(resultrocStates, proc)
		}
	}
	count := int64(len(resultrocStates))
	msg := gatherMsg(count)
	result := checkers.OK
	if opts.CritUnder != 0 && count < opts.CritUnder ||
		opts.CritOver != nil && count > *opts.CritOver {
		result = checkers.CRITICAL
	} else if opts.WarningUnder != 0 && count < opts.WarningUnder ||
		opts.WarningOver != nil && count > *opts.WarningOver {
		result = checkers.WARNING
	}
	return checkers.NewChecker(result, msg)
}
开发者ID:hiroakis,项目名称:go-check-plugins,代码行数:49,代码来源:check_procs.go

示例14: checkTimeout

func (opts *sshOpts) checkTimeout(elapsed time.Duration) *checkers.Checker {
	chkSt := checkers.OK
	if opts.Warning > 0 && elapsed > time.Duration(opts.Warning)*time.Second {
		chkSt = checkers.WARNING
	}
	if opts.Critical > 0 && elapsed > time.Duration(opts.Critical)*time.Second {
		chkSt = checkers.CRITICAL
	}
	msg := fmt.Sprintf("%.3f seconds response time on", float64(elapsed)/float64(time.Second))
	if opts.Hostname != "" {
		msg += " " + opts.Hostname
	}
	if opts.Port > 0 {
		msg += fmt.Sprintf(" port %d", opts.Port)
	}
	return checkers.NewChecker(chkSt, msg)
}
开发者ID:hiroakis,项目名称:go-check-plugins,代码行数:17,代码来源:check-ssh.go

示例15: checkReplication

func checkReplication(args []string) *checkers.Checker {
	opts := replicationOpts{}
	psr := flags.NewParser(&opts, flags.Default)
	psr.Usage = "replication [OPTIONS]"
	_, err := psr.ParseArgs(args)
	if err != nil {
		os.Exit(1)
	}
	db := newMySQL(opts.mysqlSetting)
	err = db.Connect()
	if err != nil {
		return checkers.Unknown("couldn't connect DB")
	}
	defer db.Close()

	rows, res, err := db.Query("SHOW SLAVE STATUS")
	if err != nil {
		return checkers.Unknown("couldn't execute query")
	}

	if len(rows) == 0 {
		return checkers.Ok("MySQL is not slave")
	}

	idxIoThreadRunning := res.Map("Slave_IO_Running")
	idxSQLThreadRunning := res.Map("Slave_SQL_Running")
	idxSecondsBehindMaster := res.Map("Seconds_Behind_Master")
	ioThreadStatus := rows[0].Str(idxIoThreadRunning)
	sqlThreadStatus := rows[0].Str(idxSQLThreadRunning)
	secondsBehindMaster := rows[0].Int64(idxSecondsBehindMaster)

	if !(ioThreadStatus == "Yes" && sqlThreadStatus == "Yes") {
		return checkers.Critical("MySQL replication has been stopped")
	}

	checkSt := checkers.OK
	msg := fmt.Sprintf("MySQL replication behind master %d seconds", secondsBehindMaster)
	if secondsBehindMaster > opts.Crit {
		checkSt = checkers.CRITICAL
	} else if secondsBehindMaster > opts.Warn {
		checkSt = checkers.WARNING
	}
	return checkers.NewChecker(checkSt, msg)
}
开发者ID:hiroakis,项目名称:go-check-plugins,代码行数:44,代码来源:replication.go


注:本文中的github.com/mackerelio/checkers.NewChecker函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。