Example #1
0
func main() {
	flag.Parse()
	common.SetupLogger()

	config := common.LoadConfig()

	ruleset, err := internal.LoadRules(config.API.ConversionRulesPath)
	if err != nil {
		common.ExitWithMessage(fmt.Sprintf("Error while reading rules: %s", err.Error()))
	}
	metricFile, err := os.Open(*metricsFile)
	if err != nil {
		common.ExitWithMessage("No metric file.")
	}
	scanner := bufio.NewScanner(metricFile)
	apiInstance := common.NewAPI(config.API)
	var output *os.File
	if *unmatchedFile != "" {
		output, err = os.Create(*unmatchedFile)
		if err != nil {
			common.ExitWithMessage(fmt.Sprintf("Error creating the output file: %s", err.Error()))
		}
	}
	stat := run(ruleset, scanner, apiInstance, output)
	report(stat)
}
Example #2
0
func readRule(filename string) *internal.RuleSet {
	file, err := os.Open(filename)
	if err != nil {
		common.ExitWithMessage("No rule file")
	}
	bytes, err := ioutil.ReadAll(file)
	if err != nil {
		common.ExitWithMessage("Cannot read the rule YAML")
	}
	rule, err := internal.LoadYAML(bytes)
	if err != nil {
		common.ExitWithMessage("Cannot parse Rule file")
	}
	return &rule
}
Example #3
0
func main() {
	if os.Getenv("GOMAXPROCS") == "" {
		runtime.GOMAXPROCS(runtime.NumCPU())
	}
	flag.Parse()
	common.SetupLogger()

	if *metricsFile == "" {
		common.ExitWithMessage("No metric file specified. Use '-metrics-file'")
	}

	if *rulePath == "" {
		common.ExitWithMessage("No rule path specified. Use '-rule-path'")
	}

	//TODO(cchandler): Make a constructor for a graphite converter so we don't
	//have to stich everything together outside of the package.

	ruleset, err := util.LoadRules(*rulePath)
	if err != nil {
		common.ExitWithMessage(fmt.Sprintf("Error while reading rules: %s", err.Error()))
	}

	graphiteConverter := util.RuleBasedGraphiteConverter{Ruleset: ruleset}

	metrics, err := ReadMetricsFile(*metricsFile)
	if err != nil {
		fmt.Printf("Fatal error reading metrics file %s\n", err)
		os.Exit(1)
	}

	classifiedMetrics := DoAnalysis(metrics, graphiteConverter)
	fmt.Printf("Generating report files...\n")
	GenerateReport(classifiedMetrics[Unmatched], graphiteConverter)

	fmt.Printf("Total metric count %d\n", len(metrics))
}