本文整理汇总了Golang中github.com/prometheus/prometheus/util/cli.Term类的典型用法代码示例。如果您正苦于以下问题:Golang Term类的具体用法?Golang Term怎么用?Golang Term使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Term类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: checkConfig
func checkConfig(t cli.Term, filename string) ([]string, error) {
t.Infof("Checking %s", filename)
if stat, err := os.Stat(filename); err != nil {
return nil, fmt.Errorf("cannot get file info")
} else if stat.IsDir() {
return nil, fmt.Errorf("is a directory")
}
content, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
var cfg config.Config
if err := yaml.Unmarshal(content, &cfg); err != nil {
return nil, err
}
var ruleFiles []string
for _, rf := range cfg.RuleFiles {
rfs, err := filepath.Glob(rf)
if err != nil {
return nil, err
}
// If an explicit file was given, error if it doesn't exist.
if !strings.Contains(rf, "*") && len(rfs) == 0 {
return nil, fmt.Errorf("%q does not point to an existing file", rf)
}
ruleFiles = append(ruleFiles, rfs...)
}
return ruleFiles, nil
}
开发者ID:bluecmd,项目名称:prometheus,代码行数:33,代码来源:main.go
示例2: checkConfig
func checkConfig(t cli.Term, filename string) ([]string, error) {
t.Infof("Checking %s", filename)
if stat, err := os.Stat(filename); err != nil {
return nil, fmt.Errorf("cannot get file info")
} else if stat.IsDir() {
return nil, fmt.Errorf("is a directory")
}
cfg, err := config.LoadFile(filename)
if err != nil {
return nil, err
}
check := func(fn string) error {
// Nothing set, nothing to error on.
if fn == "" {
return nil
}
_, err := os.Stat(fn)
return err
}
var ruleFiles []string
for _, rf := range cfg.RuleFiles {
rfs, err := filepath.Glob(rf)
if err != nil {
return nil, err
}
// If an explicit file was given, error if it is not accessible.
if !strings.Contains(rf, "*") {
if len(rfs) == 0 {
return nil, fmt.Errorf("%q does not point to an existing file", rf)
}
if err := check(rfs[0]); err != nil {
return nil, fmt.Errorf("error checking rule file %q: %s", rfs[0], err)
}
}
ruleFiles = append(ruleFiles, rfs...)
}
for _, scfg := range cfg.ScrapeConfigs {
if err := check(scfg.BearerTokenFile); err != nil {
return nil, fmt.Errorf("error checking bearer token file %q: %s", scfg.BearerTokenFile, err)
}
if scfg.ClientCert != nil {
if err := check(scfg.ClientCert.Cert); err != nil {
return nil, fmt.Errorf("error checking client cert file %q: %s", scfg.ClientCert.Cert, err)
}
if err := check(scfg.ClientCert.Key); err != nil {
return nil, fmt.Errorf("error checking client key file %q: %s", scfg.ClientCert.Key, err)
}
}
}
return ruleFiles, nil
}
开发者ID:robert-zaremba,项目名称:prometheus,代码行数:58,代码来源:main.go
示例3: VersionCmd
// VersionCmd prints the binaries version information.
func VersionCmd(t cli.Term, _ ...string) int {
tmpl := template.Must(template.New("version").Parse(versionInfoTmpl))
var buf bytes.Buffer
if err := tmpl.ExecuteTemplate(&buf, "version", version.Map); err != nil {
panic(err)
}
fmt.Fprintln(t.Out(), strings.TrimSpace(buf.String()))
return 0
}
开发者ID:yershalom,项目名称:prometheus,代码行数:11,代码来源:main.go
示例4: checkConfig
func checkConfig(t cli.Term, filename string) ([]string, error) {
t.Infof("Checking %s", filename)
if stat, err := os.Stat(filename); err != nil {
return nil, fmt.Errorf("cannot get file info")
} else if stat.IsDir() {
return nil, fmt.Errorf("is a directory")
}
cfg, err := config.LoadFile(filename)
if err != nil {
return nil, err
}
var ruleFiles []string
for _, rf := range cfg.RuleFiles {
rfs, err := filepath.Glob(rf)
if err != nil {
return nil, err
}
// If an explicit file was given, error if it is not accessible.
if !strings.Contains(rf, "*") {
if len(rfs) == 0 {
return nil, fmt.Errorf("%q does not point to an existing file", rf)
}
if err := checkFileExists(rfs[0]); err != nil {
return nil, fmt.Errorf("error checking rule file %q: %s", rfs[0], err)
}
}
ruleFiles = append(ruleFiles, rfs...)
}
for _, scfg := range cfg.ScrapeConfigs {
if err := checkFileExists(scfg.BearerTokenFile); err != nil {
return nil, fmt.Errorf("error checking bearer token file %q: %s", scfg.BearerTokenFile, err)
}
if err := checkTLSConfig(scfg.TLSConfig); err != nil {
return nil, err
}
for _, kd := range scfg.KubernetesSDConfigs {
if err := checkTLSConfig(kd.TLSConfig); err != nil {
return nil, err
}
}
}
return ruleFiles, nil
}
开发者ID:yershalom,项目名称:prometheus,代码行数:50,代码来源:main.go
示例5: 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
示例6: DumpHeadsCmd
// DumpHeadsCmd dumps metadata of a heads.db file.
func DumpHeadsCmd(t cli.Term, args ...string) int {
if len(args) != 1 {
t.Infof("usage: storagetool dump-heads <file>")
return 2
}
if err := local.DumpHeads(args[0], t.Out()); err != nil {
t.Errorf(" FAILED: %s", err)
return 1
}
return 0
}
开发者ID:PrFalken,项目名称:prometheus,代码行数:12,代码来源:main.go
示例7: CheckRulesCmd
// CheckRulesCmd validates rule files.
func CheckRulesCmd(t cli.Term, args ...string) int {
if len(args) == 0 {
t.Infof("usage: promtool check-rules <files>")
return 2
}
failed := false
for _, arg := range args {
if n, err := checkRules(t, arg); err != nil {
t.Errorf(" FAILED: %s", err)
failed = true
} else {
t.Infof(" SUCCESS: %d rules found", n)
}
t.Infof("")
}
if failed {
return 1
}
return 0
}
开发者ID:yershalom,项目名称:prometheus,代码行数:22,代码来源:main.go
示例8: CheckConfigCmd
// CheckConfigCmd validates configuration files.
func CheckConfigCmd(t cli.Term, args ...string) int {
if len(args) == 0 {
t.Infof("usage: promtool check-config <files>")
return 2
}
failed := false
for _, arg := range args {
ruleFiles, err := checkConfig(t, arg)
if err != nil {
t.Errorf(" FAILED: %s", err)
failed = true
} else {
t.Infof(" SUCCESS: %d rule files found", len(ruleFiles))
}
t.Infof("")
for _, rf := range ruleFiles {
if n, err := checkRules(t, rf); err != nil {
t.Errorf(" FAILED: %s", err)
failed = true
} else {
t.Infof(" SUCCESS: %d rules found", n)
}
t.Infof("")
}
}
if failed {
return 1
}
return 0
}
开发者ID:yershalom,项目名称:prometheus,代码行数:33,代码来源:main.go
注:本文中的github.com/prometheus/prometheus/util/cli.Term类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论