当前位置: 首页>>代码示例>>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;未经允许,请勿转载。