From e76b663ed22d36acebd8120a20727405059dbdc3 Mon Sep 17 00:00:00 2001 From: Al Lefebvre Date: Fri, 2 Oct 2015 13:59:24 -0400 Subject: [PATCH] Bug fixes and improvements for v0.1.1 --- CHANGELOG.md | 15 +++++++++++++++ build.sh | 3 ++- collector.go | 38 ++++++++++++++------------------------ custom_metric.go | 2 +- version.go | 6 +++--- 5 files changed, 35 insertions(+), 29 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..0789fc3 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,15 @@ +stats_ag CHANGELOG +=========================== + + +0.1.1 +----- +- Fixed syslog date format and example +- Added debug option `-d` +- Updated how flag default options are printed +- Added `-v` option to print version info +- Updated build script so that build version is automatically included as well as the build date and the commit hash + +0.1.0 +----- +- Initial version. diff --git a/build.sh b/build.sh index 99d7f37..9fcaac1 100755 --- a/build.sh +++ b/build.sh @@ -1,3 +1,4 @@ #!/bin/bash -go build -o bin/stats-ag +echo "Building v$1" +go build -o bin/stats-ag -ldflags "-X main.BUILD_DATE `date +%Y-%m-%d` -X main.VERSION $1 -X main.COMMIT_SHA `git rev-parse --verify HEAD`" diff --git a/collector.go b/collector.go index 4e0cfb1..ebcdcff 100644 --- a/collector.go +++ b/collector.go @@ -9,41 +9,31 @@ import ( ) var metrics_dir, scripts_dir, time_prefix string -var enable_scripts int +var enable_scripts, debug int var core_stats map[string]interface{} -var debug bool func main() { + flag.IntVar(&enable_scripts, "e", 0, "Enable custom scripts execution") + flag.StringVar(&metrics_dir, "m", "/var/log/stats-ag", "Location where metrics log files are written") + flag.StringVar(&scripts_dir, "s", "/opt/stats-ag/scripts", "Location where custom metrics scripts are located") + flag.StringVar(&time_prefix, "p", "SYSLOG", "Date prefix format for metric entries (RFC822Z, ISO8601, RFC3339, SYSLOG)") + flag.IntVar(&debug, "d", 0, "Enable verbose debug mode") + if len(os.Args) >= 2 && os.Args[1] == "-v" { - fmt.Printf("Stats-ag Version %s\n", VERSION) + fmt.Printf("Stats-ag Version %s (Build date: %s)\nCommit SHA: %s\n", VERSION, BUILD_DATE, COMMIT_SHA) os.Exit(0) } - flag.IntVar(&enable_scripts, "e", 0, "Enable custom scripts execution") - flag.StringVar(&metrics_dir, "m", "/var/log/stats_collector", "Location where metrics log files are written") - flag.StringVar(&scripts_dir, "s", "/opt/stats_collector", "Location where custom metrics scripts are located") - flag.StringVar(&time_prefix, "p", "SYSLOG", "Date prefix format for metric entries (RFC822Z, ISO8601, RFC3339, SYSLOG)") - flag.BoolVar(&debug, "d", false, "Enable verbose debug mode") flag.Parse() - if flag.NArg() == 0 { - usage := ` -Usage: stats-ag [OPTIONS] -Options: - -e [ENABLE_CUSTOM_SCRIPTS] (default = 0) - -m [METRICS_DIR] (default = /var/log/stats_collector) - -s [CUSTOM_SCRIPTS_DIR] (default = /opt/stats_collector) - -p [TIME_PREFIX_FORMAT] (default = SYSLOG) - -d [DEBUG] (default = false) - ` - fmt.Printf("%s\n", usage) - os.Exit(0) + if flag.NFlag() == 0 { + flag.PrintDefaults() } - if debug { + if debug == 1 { fmt.Printf( - "\nstats-ag config values:\n---------------------------\nenable_scripts = %d\nmetrics_dir = %s\nscripts_dir = %s\ntime_prefix = %s\ndebug = %t\n\n", + "\nstats-ag config values:\n---------------------------\nenable_scripts = %d\nmetrics_dir = %s\nscripts_dir = %s\ntime_prefix = %s\ndebug = %d\n\n", enable_scripts, metrics_dir, scripts_dir, @@ -69,7 +59,7 @@ Options: for k, _ := range core_stats { go func(wg *sync.WaitGroup, core_stats map[string]interface{}, method string) { mw := NewMetricsWriter(method, time_prefix) - if debug { + if debug == 1 { fmt.Printf("%s [DEBUG] fetching core stat: %s\n", getDateStamp(time_prefix), method) } res, _ := Call(core_stats, method) @@ -85,7 +75,7 @@ Options: go func(wg *sync.WaitGroup, script_name string) { - if debug { + if debug == 1 { fmt.Printf("%s [DEBUG] calling custom stat: %s\n", getDateStamp(time_prefix), script_name) } cm, err := NewCustomMetric(script_name) diff --git a/custom_metric.go b/custom_metric.go index 8e9a8a3..d4ca98e 100644 --- a/custom_metric.go +++ b/custom_metric.go @@ -16,7 +16,7 @@ type CustomMetric struct { func NewCustomMetric(script_path string) (*CustomMetric, error) { - if debug { + if debug == 1 { fmt.Println(getDateStamp(time_prefix), "[DEBUG] custom metric file:", script_path) } diff --git a/version.go b/version.go index 4762549..eadce73 100644 --- a/version.go +++ b/version.go @@ -1,5 +1,5 @@ package main -const ( - VERSION = "0.1.1" -) +var VERSION string = "0.0.0" +var BUILD_DATE string = "" +var COMMIT_SHA string = ""