From c490032bb261d5375d7f9b13c12a9287c22d77a2 Mon Sep 17 00:00:00 2001 From: hunterlong Date: Fri, 8 May 2020 21:33:04 -0700 Subject: [PATCH 1/3] service dropdown for chart timeframe and interval --- Makefile | 21 ++- frontend/src/assets/scss/base.scss | 12 ++ .../src/components/Service/ServiceBlock.vue | 125 +++++++++++++----- .../src/components/Service/ServiceChart.vue | 35 ++--- frontend/src/store.js | 6 +- 5 files changed, 138 insertions(+), 61 deletions(-) diff --git a/Makefile b/Makefile index 71f1d085..fc786c0c 100644 --- a/Makefile +++ b/Makefile @@ -156,14 +156,11 @@ build-linux: export PWD=`pwd` @for arch in $(ARCHS);\ do \ - for os in $(OS);\ - do \ - echo "Building v$$VERSION for $$os-$$arch"; \ - mkdir -p releases/statping-$$os-$$arch/; \ - GO111MODULE="on" GOOS=$$os GOARCH=$$arch go build -a -ldflags "-X main.VERSION=${VERSION} -X main.COMMIT=$(TRAVIS_COMMIT)" -o releases/statping-$$os-$$arch/statping ${PWD}/cmd || true; \ - chmod +x releases/statping-$$os-$$arch/statping || true; \ - tar -czf releases/statping-$$os-$$arch.tar.gz -C releases/statping-$$os-$$arch statping || true; \ - done \ + echo "Building v${VERSION} for linux-$$arch"; \ + mkdir -p releases/statping-$$os-$$arch/; \ + GO111MODULE="on" GOOS=$$os GOARCH=$$arch go build -a -ldflags "-s -w -extldflags -static -X main.VERSION=${VERSION}" -o releases/statping-$$os-$$arch/statping ${PWD}/cmd || true; \ + chmod +x releases/statping-$$os-$$arch/statping || true; \ + tar -czf releases/statping-$$os-$$arch.tar.gz -C releases/statping-$$os-$$arch statping || true; \ done find ./releases/ -name "*.tar.gz" -type f -size +1M -exec mv "{}" build/ \; @@ -172,9 +169,9 @@ build-mac: export PWD=`pwd` @for arch in $(ARCHS);\ do \ - echo "Building v$$VERSION for darwin-$$arch"; \ + echo "Building v${VERSION} for darwin-$$arch"; \ mkdir -p releases/statping-darwin-$$arch/; \ - GO111MODULE="on" GOOS=darwin GOARCH=$$arch go build -a -ldflags "-X main.VERSION=${VERSION} -X main.COMMIT=$(TRAVIS_COMMIT)" -o releases/statping-darwin-$$arch/statping ${PWD}/cmd || true; \ + GO111MODULE="on" GOOS=darwin GOARCH=$$arch go build -a -ldflags "-s -w -extldflags -static -X main.VERSION=${VERSION}" -o releases/statping-darwin-$$arch/statping ${PWD}/cmd || true; \ chmod +x releases/statping-darwin-$$arch/statping || true; \ tar -czf releases/statping-darwin-$$arch.tar.gz -C releases/statping-darwin-$$arch statping || true; \ done @@ -185,9 +182,9 @@ build-win: export PWD=`pwd` @for arch in $(ARCHS);\ do \ - echo "Building v$$VERSION for windows-$$arch"; \ + echo "Building v${VERSION} for windows-$$arch"; \ mkdir -p releases/statping-windows-$$arch/; \ - GO111MODULE="on" GOOS=windows GOARCH=$$arch go build -a -ldflags "-X main.VERSION=${VERSION} -X main.COMMIT=$(TRAVIS_COMMIT)" -o releases/statping-windows-$$arch/statping.exe ${PWD}/cmd || true; \ + GO111MODULE="on" GOOS=windows GOARCH=$$arch go build -a -ldflags "-s -w -extldflags -static -X main.VERSION=${VERSION}" -o releases/statping-windows-$$arch/statping.exe ${PWD}/cmd || true; \ chmod +x releases/statping-windows-$$arch/statping.exe || true; \ zip -j releases/statping-windows-$$arch.zip releases/statping-windows-$$arch/statping.exe || true; \ done diff --git a/frontend/src/assets/scss/base.scss b/frontend/src/assets/scss/base.scss index c9e6b98e..ae4cca9e 100644 --- a/frontend/src/assets/scss/base.scss +++ b/frontend/src/assets/scss/base.scss @@ -14,6 +14,18 @@ HTML,BODY { transition: height 0.3s ease; } +.service-tm-menu { + width: 210px; + height: 355px; + bottom: 15px; + left: -25px; + position: absolute; + background-color: #ffffffd4; + border: 0; + border-radius: 0; + box-shadow: 0px 3px 6px 1px rgba(0,0,0,0.08); +} + .copy-btn { position: absolute; right: 0; diff --git a/frontend/src/components/Service/ServiceBlock.vue b/frontend/src/components/Service/ServiceBlock.vue index 3015b7eb..77da239e 100644 --- a/frontend/src/components/Service/ServiceBlock.vue +++ b/frontend/src/components/Service/ServiceBlock.vue @@ -19,35 +19,45 @@
- - View More Details - + + View More Details +
-
- +
-
- - - - - {{smallText(service)}} - +
+ + +
+ +
+ + + + + {{smallText(service)}} + +
+
+
@@ -47,7 +47,7 @@ {{intervalpick.text}} @@ -89,7 +89,7 @@ export default { service() { return this.track_service }, - timepick() { + timeframepick() { return this.timeframes.find(s => s.value === this.timeframe_val) }, intervalpick() { @@ -109,30 +109,30 @@ export default { interval_val: "60m", timeframe_val: this.timeset(259200), timeframes: [ - {value: this.timeset(1800), text: "30 Minutes"}, - {value: this.timeset(3600), text: "1 Hour"}, - {value: this.timeset(21600), text: "6 Hours"}, - {value: this.timeset(43200), text: "12 Hours"}, - {value: this.timeset(86400), text: "1 Day"}, - {value: this.timeset(259200), text: "3 Days"}, - {value: this.timeset(604800), text: "7 Days"}, - {value: this.timeset(1209600), text: "14 Days"}, - {value: this.timeset(2592000), text: "1 Month"}, - {value: this.timeset(7776000), text: "3 Months"}, + {value: this.timeset(1800), text: "30 Minutes", set: 1}, + {value: this.timeset(3600), text: "1 Hour", set: 2}, + {value: this.timeset(21600), text: "6 Hours", set: 3}, + {value: this.timeset(43200), text: "12 Hours", set: 4}, + {value: this.timeset(86400), text: "1 Day", set: 5}, + {value: this.timeset(259200), text: "3 Days", set: 6}, + {value: this.timeset(604800), text: "7 Days", set: 7}, + {value: this.timeset(1209600), text: "14 Days", set: 8}, + {value: this.timeset(2592000), text: "1 Month", set: 9}, + {value: this.timeset(7776000), text: "3 Months", set: 10}, {value: 0, text: "All Records"}, ], intervals: [ - {value: "1m", text: "1/min"}, - {value: "5m", text: "5/min"}, - {value: "15m", text: "15/min"}, - {value: "30m", text: "30/min" }, - {value: "60m", text: "1/hr" }, - {value: "180m", text: "3/hr" }, - {value: "360m", text: "6/hr" }, - {value: "720m", text: "12/hr" }, - {value: "1440m", text: "1/day" }, - {value: "4320m", text: "3/day" }, - {value: "10080m", text: "7/day" }, + {value: "1m", text: "1/min", set: 1}, + {value: "5m", text: "5/min", set: 2}, + {value: "15m", text: "15/min", set: 3}, + {value: "30m", text: "30/min", set: 4 }, + {value: "60m", text: "1/hr", set: 5 }, + {value: "180m", text: "3/hr", set: 6 }, + {value: "360m", text: "6/hr", set: 7 }, + {value: "720m", text: "12/hr", set: 8 }, + {value: "1440m", text: "1/day", set: 9 }, + {value: "4320m", text: "3/day", set: 10 }, + {value: "10080m", text: "7/day", set: 11 }, ], stats: { total_failures: { @@ -171,6 +171,10 @@ export default { this.track_service = this.in_service }, methods: { + disabled_interval(interval) { + let min = this.timeframepick.set - interval.set - 1; + return min >= interval.set; + }, timeset (seconds) { return this.toUnix(this.nowSubtract(seconds)) }, @@ -228,10 +232,7 @@ export default { if (last) { return `Offline, last error: ${last} ${this.ago(last.created_at)}` } - if (!s.online) { - return `Service is offline` - } - return `Offline` + return `Service is offline for ${this.ago(s.last_success)}` } }, visibleChart(isVisible, entry) { diff --git a/frontend/src/forms/Setup.vue b/frontend/src/forms/Setup.vue index 26b99c6e..d360a15a 100644 --- a/frontend/src/forms/Setup.vue +++ b/frontend/src/forms/Setup.vue @@ -137,7 +137,7 @@ return } } - if (!s.project || !s.description || !s.domain || !s.username || !s.password || !s.confirm_password) { + if (!s.project || !s.domain || !s.username || !s.password || !s.confirm_password) { this.disabled = true return } From 1bd9e981630bb82d43f3e5d8e988dbfad651cc68 Mon Sep 17 00:00:00 2001 From: hunterlong Date: Sun, 10 May 2020 14:40:45 -0700 Subject: [PATCH 3/3] added --config flag to specify config.yml file --- README.md | 2 +- cmd/cli.go | 6 +++--- cmd/flags.go | 11 ++++++++++ cmd/main.go | 12 ++++------- .../components/Index/GroupServiceFailures.vue | 7 ++++--- .../src/components/Service/ServiceBlock.vue | 2 +- frontend/src/pages/Settings.vue | 20 +++++++++++++------ types/configs/file.go | 4 ++-- types/configs/load.go | 10 +++++----- 9 files changed, 45 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index c6089fb5..c3854821 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@

Statping - Web and App Status Monitoring for Any Type of Project
-View Wiki | Demo | iPhone | Android
API | Docker | EC2 | Mac | Linux | Windows +View Wiki | Demo | iPhone | Android
API | Docker | EC2 | Mac | Linux | Windows

# Statping - Status Page & Monitoring Server diff --git a/cmd/cli.go b/cmd/cli.go index 2af7da54..ffbed998 100644 --- a/cmd/cli.go +++ b/cmd/cli.go @@ -46,7 +46,7 @@ func exportCli(args []string) error { if err := source.Assets(); err != nil { return err } - config, err := configs.LoadConfigs() + config, err := configs.LoadConfigs(configFile) if err != nil { return err } @@ -168,7 +168,7 @@ func importCli(args []string) error { log.Printf("Messages: %d\n", len(exportData.Messages)) log.Printf("Users: %d\n", len(exportData.Users)) - config, err := configs.LoadConfigs() + config, err := configs.LoadConfigs(configFile) if err != nil { return err } @@ -258,7 +258,7 @@ func updateDisplay() error { // runOnce will initialize the Statping application and check each service 1 time, will not run HTTP server func runOnce() error { - config, err := configs.LoadConfigs() + config, err := configs.LoadConfigs(configFile) if err != nil { return errors.Wrap(err, "config.yml file not found") } diff --git a/cmd/flags.go b/cmd/flags.go index 85ba871d..130a958e 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -3,6 +3,14 @@ package main import ( "github.com/spf13/cobra" "github.com/spf13/viper" + "github.com/statping/statping/utils" +) + +var ( + ipAddress string + configFile string + verboseMode int + port int ) func parseFlags(cmd *cobra.Command) { @@ -14,4 +22,7 @@ func parseFlags(cmd *cobra.Command) { cmd.PersistentFlags().IntVarP(&verboseMode, "verbose", "v", 2, "verbose logging") viper.BindPFlag("verbose", cmd.PersistentFlags().Lookup("verbose")) + + cmd.PersistentFlags().StringVarP(&configFile, "config", "c", utils.Directory+"/config.yml", "path to config.yml file") + viper.BindPFlag("config", cmd.PersistentFlags().Lookup("config")) } diff --git a/cmd/main.go b/cmd/main.go index 01416ce7..14f98f0a 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -20,13 +20,9 @@ var ( // VERSION stores the current version of Statping VERSION string // COMMIT stores the git commit hash for this version of Statping - COMMIT string - ipAddress string - //grpcPort int - verboseMode int - port int - log = utils.Log.WithField("type", "cmd") - confgs *configs.DbConfig + COMMIT string + log = utils.Log.WithField("type", "cmd") + confgs *configs.DbConfig ) func init() { @@ -83,7 +79,7 @@ func start() { // log.Warnln(err) //} - confgs, err = configs.LoadConfigs() + confgs, err = configs.LoadConfigs(configFile) if err != nil { log.Infoln("Starting in Setup Mode") if err := SetupMode(); err != nil { diff --git a/frontend/src/components/Index/GroupServiceFailures.vue b/frontend/src/components/Index/GroupServiceFailures.vue index a18926fb..96c5d2ab 100644 --- a/frontend/src/components/Index/GroupServiceFailures.vue +++ b/frontend/src/components/Index/GroupServiceFailures.vue @@ -34,11 +34,12 @@ export default { }, computed: { service_txt() { - if (!this.service.online) { - if (!this.toUnix(this.service.last_success)) { + const s = this.service + if (!s.online) { + if (!this.toUnix(this.parseISO(s.last_success))) { return `Always Offline` } - return `Offline for ${this.ago(this.service.last_success)}` + return `Offline for ${this.ago(s.last_success)}` } return `${this.service.online_24_hours}% Uptime` } diff --git a/frontend/src/components/Service/ServiceBlock.vue b/frontend/src/components/Service/ServiceBlock.vue index 66703423..88264a69 100644 --- a/frontend/src/components/Service/ServiceBlock.vue +++ b/frontend/src/components/Service/ServiceBlock.vue @@ -232,7 +232,7 @@ export default { if (last) { return `Offline, last error: ${last} ${this.ago(last.created_at)}` } - return `Service is offline for ${this.ago(s.last_success)}` + return `Service has been offline for ${this.ago(s.last_success)}` } }, visibleChart(isVisible, entry) { diff --git a/frontend/src/pages/Settings.vue b/frontend/src/pages/Settings.vue index 3de2739d..0801519f 100644 --- a/frontend/src/pages/Settings.vue +++ b/frontend/src/pages/Settings.vue @@ -295,15 +295,23 @@ return this.$store.getters.notifiers } }, - async mounted() { - this.cache = await Api.cache() + mounted() { + this.update() }, - async created() { - const c = this.core - this.qrurl = `statping://setup?domain=${c.domain}&api=${c.api_secret}` - this.qrcode = "https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=" + encodeURI(this.qrurl) + created() { + this.update() }, methods: { + async update() { + const c = await Api.core() + this.$store.commit('setCore', c) + const n = await Api.notifiers() + this.$store.commit('setNotifiers', n) + + this.qrurl = `statping://setup?domain=${c.domain}&api=${c.api_secret}` + this.qrcode = "https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=" + encodeURI(this.qrurl) + this.cache = await Api.cache() + }, changeTab(e) { this.tab = e.target.id }, diff --git a/types/configs/file.go b/types/configs/file.go index ed44173e..f336e62f 100644 --- a/types/configs/file.go +++ b/types/configs/file.go @@ -21,7 +21,7 @@ func ConnectConfigs(configs *DbConfig, retry bool) error { return nil } -func LoadConfigs() (*DbConfig, error) { +func LoadConfigs(cfgFile string) (*DbConfig, error) { writeAble, err := utils.DirWritable(utils.Directory) if err != nil { return nil, err @@ -30,7 +30,7 @@ func LoadConfigs() (*DbConfig, error) { return nil, errors.Errorf("Directory %s is not writable!", utils.Directory) } - return LoadConfigFile(utils.Directory) + return LoadConfigFile(cfgFile) } func findDbFile(configs *DbConfig) (string, error) { diff --git a/types/configs/load.go b/types/configs/load.go index 9fd8be1f..6bb6d79d 100644 --- a/types/configs/load.go +++ b/types/configs/load.go @@ -7,15 +7,15 @@ import ( "os" ) -func LoadConfigFile(directory string) (*DbConfig, error) { +func LoadConfigFile(configFile string) (*DbConfig, error) { p := utils.Params - log.Infof("Attempting to read config file at: %s/config.yml ", directory) - p.SetConfigFile(directory + "/config.yml") + log.Infof("Attempting to read config file at: %s", configFile) + p.SetConfigFile(configFile) p.SetConfigType("yaml") p.ReadInConfig() db := new(DbConfig) - content, err := utils.OpenFile(directory + "/config.yml") + content, err := utils.OpenFile(configFile) if err == nil { if err := yaml.Unmarshal([]byte(content), &db); err != nil { return nil, err @@ -66,7 +66,7 @@ func LoadConfigFile(directory string) (*DbConfig, error) { Location: utils.Directory, SqlFile: p.GetString("SQL_FILE"), } - log.WithFields(utils.ToFields(configs)).Debugln("read config file: " + directory + "/config.yml") + log.WithFields(utils.ToFields(configs)).Debugln("read config file: " + configFile) if configs.DbConn == "" { return configs, errors.New("Starting in setup mode")