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


Golang promql.ParseStmts函數代碼示例

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


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

示例1: loadRuleFiles

// loadRuleFiles loads alerting and recording rules from the given files.
func (m *Manager) loadRuleFiles(filenames ...string) error {
	for _, fn := range filenames {
		content, err := ioutil.ReadFile(fn)
		if err != nil {
			return err
		}
		stmts, err := promql.ParseStmts(string(content))
		if err != nil {
			return fmt.Errorf("error parsing %s: %s", fn, err)
		}

		for _, stmt := range stmts {
			switch r := stmt.(type) {
			case *promql.AlertStmt:
				rule := NewAlertingRule(r.Name, r.Expr, r.Duration, r.Labels, r.Summary, r.Description, r.Runbook)
				m.rules = append(m.rules, rule)
			case *promql.RecordStmt:
				rule := NewRecordingRule(r.Name, r.Expr, r.Labels)
				m.rules = append(m.rules, rule)
			default:
				panic("retrieval.Manager.LoadRuleFiles: unknown statement type")
			}
		}
	}
	return nil
}
開發者ID:bitemyapp,項目名稱:prometheus,代碼行數:27,代碼來源:manager.go

示例2: loadGroups

// loadGroups reads groups from a list of files.
// As there's currently no group syntax a single group named "default" containing
// all rules will be returned.
func (m *Manager) loadGroups(interval time.Duration, filenames ...string) (map[string]*Group, error) {
	rules := []Rule{}
	for _, fn := range filenames {
		content, err := ioutil.ReadFile(fn)
		if err != nil {
			return nil, err
		}
		stmts, err := promql.ParseStmts(string(content))
		if err != nil {
			return nil, fmt.Errorf("error parsing %s: %s", fn, err)
		}

		for _, stmt := range stmts {
			var rule Rule

			switch r := stmt.(type) {
			case *promql.AlertStmt:
				rule = NewAlertingRule(r.Name, r.Expr, r.Duration, r.Labels, r.Annotations)

			case *promql.RecordStmt:
				rule = NewRecordingRule(r.Name, r.Expr, r.Labels)

			default:
				panic("retrieval.Manager.LoadRuleFiles: unknown statement type")
			}
			rules = append(rules, rule)
		}
	}

	// Currently there is no group syntax implemented. Thus all rules
	// are read into a single default group.
	g := NewGroup("default", interval, rules, m.opts)
	groups := map[string]*Group{g.name: g}
	return groups, nil
}
開發者ID:prometheus,項目名稱:prometheus,代碼行數:38,代碼來源:manager.go

示例3: checkRules

// checkRules reads rules from in. Sucessfully read rules
// are printed to out.
func checkRules(filename string, in io.Reader, out io.Writer) error {
	content, err := ioutil.ReadAll(in)
	if err != nil {
		return err
	}

	rules, err := promql.ParseStmts(string(content))
	if err != nil {
		return err
	}

	fmt.Fprintf(os.Stderr, "%s: successfully loaded %d rules:\n", filename, len(rules))
	for _, rule := range rules {
		fmt.Fprint(out, rule.String())
		fmt.Fprint(out, "\n")
	}
	return nil
}
開發者ID:gitter-badger,項目名稱:prometheus,代碼行數:20,代碼來源:main.go

示例4: checkRules

func checkRules(t cli.Term, filename string) (int, error) {
	t.Infof("Checking %s", filename)

	if stat, err := os.Stat(filename); err != nil {
		return 0, fmt.Errorf("cannot get file info")
	} else if stat.IsDir() {
		return 0, fmt.Errorf("is a directory")
	}

	content, err := ioutil.ReadFile(filename)
	if err != nil {
		return 0, err
	}

	rules, err := promql.ParseStmts(string(content))
	if err != nil {
		return 0, err
	}
	return len(rules), nil
}
開發者ID:yershalom,項目名稱:prometheus,代碼行數:20,代碼來源:main.go


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