better text for Service UI, add core if SAMPLE_DATA is set to false, start service if added from services.yml

pull/554/head
hunterlong 2020-05-01 02:26:57 -07:00
parent c40437a124
commit 94485e3a9e
8 changed files with 43 additions and 21 deletions

View File

@ -121,6 +121,10 @@ func start() {
if err := configs.TriggerSamples(); err != nil { if err := configs.TriggerSamples(); err != nil {
exit(errors.Wrap(err, "error creating database")) exit(errors.Wrap(err, "error creating database"))
} }
} else {
if err := core.Samples(); err != nil {
exit(errors.Wrap(err, "error added core details"))
}
} }
} }

View File

@ -35,6 +35,9 @@ export default {
computed: { computed: {
service_txt() { service_txt() {
if (!this.service.online) { if (!this.service.online) {
if (!this.toUnix(this.service.last_success)) {
return `Always Offline`
}
return `Offline for ${this.ago(this.service.last_success)}` return `Offline for ${this.ago(this.service.last_success)}`
} }
return `${this.service.online_24_hours}% Uptime` return `${this.service.online_24_hours}% Uptime`

View File

@ -159,12 +159,15 @@ export default {
smallText(s) { smallText(s) {
const incidents = s.incidents const incidents = s.incidents
if (s.online) { if (s.online) {
return `Online, last checked ${this.ago(s.last_success)}` return `Checked ${this.ago(s.last_success)} ago and responded in ${this.humanTime(s.latency)}`
} else { } else {
const last = s.last_failure const last = s.last_failure
if (last) { if (last) {
return `Offline, last error: ${last} ${this.ago(last.created_at)}` return `Offline, last error: ${last} ${this.ago(last.created_at)}`
} }
if (!this.toUnix(s.last_success)) {
return `Service has never been online`
}
return `Offline` return `Offline`
} }
}, },

View File

@ -169,11 +169,16 @@
}, },
methods: { methods: {
async chartHits(group) { async chartHits(group) {
const start = this.nowSubtract(84600 * 3) const start = this.toUnix(this.nowSubtract(84600 * 3))
this.data = await Api.service_hits(this.service.id, this.toUnix(start), this.toUnix(new Date()), group, false) const end = this.toUnix(new Date())
if (end-start < 283800) {
group = "5m"
}
this.data = await Api.service_hits(this.service.id, start, end, group, false)
if (this.data.length === 0 && group !== "1h") { window.console.log(this.data === null && group !== "5m")
await this.chartHits("1h") if (this.data === null && group !== "5m") {
await this.chartHits("10m")
} }
this.series = [{ this.series = [{
name: this.service.name, name: this.service.name,

View File

@ -73,11 +73,11 @@ export default Vue.mixin({
}); });
}, },
serviceLink(service) { serviceLink(service) {
if (!service) { if (service.permalink) {
return "" service = this.$store.getters.serviceByPermalink(service)
} }
if (!service.id) { if (service===undefined) {
service = this.$store.getters.serviceById(service) return `/service/0`
} }
let link = service.permalink ? service.permalink : service.id let link = service.permalink ? service.permalink : service.id
return `/service/${link}` return `/service/${link}`

View File

@ -6,11 +6,9 @@ import (
) )
func Samples() error { func Samples() error {
apiKey := utils.Params.GetString("API_KEY")
apiSecret := utils.Params.GetString("API_SECRET") apiSecret := utils.Params.GetString("API_SECRET")
if apiKey == "" || apiSecret == "" { if apiSecret == "" {
apiKey = utils.RandomString(32)
apiSecret = utils.RandomString(32) apiSecret = utils.RandomString(32)
} }

View File

@ -72,13 +72,17 @@ type IntResult struct {
func (h Hitters) Avg() int64 { func (h Hitters) Avg() int64 {
var r IntResult var r IntResult
var q database.Database
switch h.db.DbType() { switch h.db.DbType() {
case "mysql": case "mysql":
h.db.Select("CAST(AVG(latency) as UNSIGNED INTEGER) as amount").Scan(&r) q = h.db.Select("CAST(AVG(latency) as UNSIGNED INTEGER) as amount")
case "postgres": case "postgres":
h.db.Select("CAST(AVG(latency) as bigint) as amount").Scan(&r) q = h.db.Select("CAST(AVG(latency) as bigint) as amount")
default: default:
h.db.Select("CAST(AVG(latency) as INT) as amount").Scan(&r) q = h.db.Select("CAST(AVG(latency) as INT) as amount")
}
if err := q.Scan(&r).Error(); err != nil {
log.Errorln(err)
} }
return r.Amount return r.Amount
} }

View File

@ -6,30 +6,35 @@ import (
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
type ServicesYaml struct { type yamlFile struct {
Services []Service `yaml:"services,flow"` Services []*Service `yaml:"services,flow"`
} }
// LoadServicesYaml will attempt to load the 'services.yml' file for Service Auto Creation on startup. // LoadServicesYaml will attempt to load the 'services.yml' file for Service Auto Creation on startup.
func LoadServicesYaml() (*ServicesYaml, error) { func LoadServicesYaml() (*yamlFile, error) {
f, err := utils.OpenFile("services.yml") f, err := utils.OpenFile(utils.Directory + "/services.yml")
if err != nil { if err != nil {
return nil, err return nil, err
} }
var svrs *ServicesYaml var svrs *yamlFile
if err := yaml.Unmarshal([]byte(f), &svrs); err != nil { if err := yaml.Unmarshal([]byte(f), &svrs); err != nil {
log.Errorln("Unable to parse the services.yml file", err)
return nil, err return nil, err
} }
log.Infof("Found %d services inside services.yml file", len(svrs.Services))
for _, svr := range svrs.Services { for _, svr := range svrs.Services {
log.Infof("Service %s %d, hash: %s", svr.Name, svr.Id, svr.Hash())
if findServiceByHash(svr.Hash()) == nil { if findServiceByHash(svr.Hash()) == nil {
if err := svr.Create(); err != nil { if err := svr.Create(); err != nil {
return nil, errors.Wrapf(err, "could not create service %s", svr.Name) return nil, errors.Wrapf(err, "could not create service %s", svr.Name)
} }
log.Infof("Automatically created service '%s' checking %s", svr.Name, svr.Domain) log.Infof("Automatically created service '%s' checking %s", svr.Name, svr.Domain)
}
go ServiceCheckQueue(svr, true)
}
} }
return svrs, nil return svrs, nil