Skip to content
This repository has been archived by the owner on Jul 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from lightspeedretail/bugfix-flags
Browse files Browse the repository at this point in the history
Bug fixes and improvements for v0.1.1
  • Loading branch information
hartfordfive committed Oct 2, 2015
2 parents f0685db + e76b663 commit 92c2fc0
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 29 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -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`"
38 changes: 14 additions & 24 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion custom_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 3 additions & 3 deletions version.go
Original file line number Diff line number Diff line change
@@ -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 = ""

0 comments on commit 92c2fc0

Please sign in to comment.