mirror of https://github.com/statping/statping
better text for Service UI, add core if SAMPLE_DATA is set to false, start service if added from services.yml
parent
c40437a124
commit
94485e3a9e
|
@ -121,6 +121,10 @@ func start() {
|
|||
if err := configs.TriggerSamples(); err != nil {
|
||||
exit(errors.Wrap(err, "error creating database"))
|
||||
}
|
||||
} else {
|
||||
if err := core.Samples(); err != nil {
|
||||
exit(errors.Wrap(err, "error added core details"))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,6 +35,9 @@ export default {
|
|||
computed: {
|
||||
service_txt() {
|
||||
if (!this.service.online) {
|
||||
if (!this.toUnix(this.service.last_success)) {
|
||||
return `Always Offline`
|
||||
}
|
||||
return `Offline for ${this.ago(this.service.last_success)}`
|
||||
}
|
||||
return `${this.service.online_24_hours}% Uptime`
|
||||
|
|
|
@ -159,12 +159,15 @@ export default {
|
|||
smallText(s) {
|
||||
const incidents = s.incidents
|
||||
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 {
|
||||
const last = s.last_failure
|
||||
if (last) {
|
||||
return `Offline, last error: ${last} ${this.ago(last.created_at)}`
|
||||
}
|
||||
if (!this.toUnix(s.last_success)) {
|
||||
return `Service has never been online`
|
||||
}
|
||||
return `Offline`
|
||||
}
|
||||
},
|
||||
|
|
|
@ -169,11 +169,16 @@
|
|||
},
|
||||
methods: {
|
||||
async chartHits(group) {
|
||||
const start = this.nowSubtract(84600 * 3)
|
||||
this.data = await Api.service_hits(this.service.id, this.toUnix(start), this.toUnix(new Date()), group, false)
|
||||
const start = this.toUnix(this.nowSubtract(84600 * 3))
|
||||
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") {
|
||||
await this.chartHits("1h")
|
||||
window.console.log(this.data === null && group !== "5m")
|
||||
if (this.data === null && group !== "5m") {
|
||||
await this.chartHits("10m")
|
||||
}
|
||||
this.series = [{
|
||||
name: this.service.name,
|
||||
|
|
|
@ -73,11 +73,11 @@ export default Vue.mixin({
|
|||
});
|
||||
},
|
||||
serviceLink(service) {
|
||||
if (!service) {
|
||||
return ""
|
||||
if (service.permalink) {
|
||||
service = this.$store.getters.serviceByPermalink(service)
|
||||
}
|
||||
if (!service.id) {
|
||||
service = this.$store.getters.serviceById(service)
|
||||
if (service===undefined) {
|
||||
return `/service/0`
|
||||
}
|
||||
let link = service.permalink ? service.permalink : service.id
|
||||
return `/service/${link}`
|
||||
|
|
|
@ -6,11 +6,9 @@ import (
|
|||
)
|
||||
|
||||
func Samples() error {
|
||||
apiKey := utils.Params.GetString("API_KEY")
|
||||
apiSecret := utils.Params.GetString("API_SECRET")
|
||||
|
||||
if apiKey == "" || apiSecret == "" {
|
||||
apiKey = utils.RandomString(32)
|
||||
if apiSecret == "" {
|
||||
apiSecret = utils.RandomString(32)
|
||||
}
|
||||
|
||||
|
|
|
@ -72,13 +72,17 @@ type IntResult struct {
|
|||
|
||||
func (h Hitters) Avg() int64 {
|
||||
var r IntResult
|
||||
var q database.Database
|
||||
switch h.db.DbType() {
|
||||
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":
|
||||
h.db.Select("CAST(AVG(latency) as bigint) as amount").Scan(&r)
|
||||
q = h.db.Select("CAST(AVG(latency) as bigint) as amount")
|
||||
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
|
||||
}
|
||||
|
|
|
@ -6,30 +6,35 @@ import (
|
|||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type ServicesYaml struct {
|
||||
Services []Service `yaml:"services,flow"`
|
||||
type yamlFile struct {
|
||||
Services []*Service `yaml:"services,flow"`
|
||||
}
|
||||
|
||||
// LoadServicesYaml will attempt to load the 'services.yml' file for Service Auto Creation on startup.
|
||||
func LoadServicesYaml() (*ServicesYaml, error) {
|
||||
f, err := utils.OpenFile("services.yml")
|
||||
func LoadServicesYaml() (*yamlFile, error) {
|
||||
f, err := utils.OpenFile(utils.Directory + "/services.yml")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var svrs *ServicesYaml
|
||||
var svrs *yamlFile
|
||||
if err := yaml.Unmarshal([]byte(f), &svrs); err != nil {
|
||||
log.Errorln("Unable to parse the services.yml file", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Infof("Found %d services inside services.yml file", len(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 err := svr.Create(); err != nil {
|
||||
return nil, errors.Wrapf(err, "could not create service %s", svr.Name)
|
||||
}
|
||||
log.Infof("Automatically created service '%s' checking %s", svr.Name, svr.Domain)
|
||||
}
|
||||
|
||||
go ServiceCheckQueue(svr, true)
|
||||
}
|
||||
}
|
||||
|
||||
return svrs, nil
|
||||
|
|
Loading…
Reference in New Issue