mirror of https://github.com/statping/statping
notifier endpoint fixes, timeframe rounding chart data
parent
5bc10fcc85
commit
1c57f5af53
|
@ -8,7 +8,7 @@ const tokenKey = "statping_auth";
|
||||||
class Api {
|
class Api {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.version = "0.90.65";
|
this.version = "0.90.65";
|
||||||
this.commit = "3051206a7a843b97c92462a536f1c54ee92fbab8";
|
this.commit = "5bc10fcc8536a08ce7a099a0b4cbceb2dc9fc35b";
|
||||||
}
|
}
|
||||||
|
|
||||||
async oauth() {
|
async oauth() {
|
||||||
|
|
|
@ -121,13 +121,14 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async getUptime() {
|
async getUptime() {
|
||||||
const start = this.nowSubtract(3 * 86400)
|
const end = this.endOf("day", this.now())
|
||||||
this.uptime = await Api.service_uptime(this.service.id, this.toUnix(start), this.toUnix(this.now()))
|
const start = this.beginningOf("day", this.nowSubtract(3 * 86400))
|
||||||
|
this.uptime = await Api.service_uptime(this.service.id, this.toUnix(start), this.toUnix(end))
|
||||||
},
|
},
|
||||||
async loadInfo() {
|
async loadInfo() {
|
||||||
this.set1 = await this.getHits(24 * 7, "720m")
|
this.set1 = await this.getHits(86400 * 7, "12h")
|
||||||
this.set1_name = this.calc(this.set1)
|
this.set1_name = this.calc(this.set1)
|
||||||
this.set2 = await this.getHits(24, "60m")
|
this.set2 = await this.getHits(86400, "60m")
|
||||||
this.set2_name = this.calc(this.set2)
|
this.set2_name = this.calc(this.set2)
|
||||||
this.loaded = true
|
this.loaded = true
|
||||||
},
|
},
|
||||||
|
@ -145,14 +146,13 @@
|
||||||
});
|
});
|
||||||
total = total / data.length
|
total = total / data.length
|
||||||
},
|
},
|
||||||
async getHits(hours, group) {
|
async getHits(seconds, group) {
|
||||||
const start = this.nowSubtract(3600 * hours)
|
let start = this.nowSubtract(seconds)
|
||||||
const fetched = await Api.service_hits(this.service.id, this.toUnix(start), this.toUnix(this.now()), group, true)
|
let end = this.endOf("today")
|
||||||
|
const startEnd = this.startEndParams(start, end, group)
|
||||||
|
const fetched = await Api.service_hits(this.service.id, startEnd.start, startEnd.end, group, true)
|
||||||
const data = this.convertToChartData(fetched, 0.001, true)
|
const data = this.convertToChartData(fetched, 0.001, true)
|
||||||
|
|
||||||
return [{name: "Latency", ...data}]
|
return [{name: "Latency", ...data}]
|
||||||
|
|
||||||
},
|
},
|
||||||
calc(s) {
|
calc(s) {
|
||||||
let data = s[0].data
|
let data = s[0].data
|
||||||
|
|
|
@ -157,7 +157,8 @@ export default {
|
||||||
},
|
},
|
||||||
async loadFailures() {
|
async loadFailures() {
|
||||||
this.loaded = false
|
this.loaded = false
|
||||||
const data = await Api.service_failures_data(this.service.id, this.toUnix(this.parseISO(this.start)), this.toUnix(this.parseISO(this.end)), this.group, true)
|
const startEnd = this.startEndParams(this.parseISO(this.start), this.parseISO(this.end), this.group)
|
||||||
|
const data = await Api.service_failures_data(this.service.id, startEnd.start, startEnd.end, this.group, true)
|
||||||
this.loaded = true
|
this.loaded = true
|
||||||
this.data = [{data: this.convertChartData(data)}]
|
this.data = [{data: this.convertChartData(data)}]
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,6 @@
|
||||||
const Analytics = () => import(/* webpackChunkName: "service" */ './Analytics');
|
const Analytics = () => import(/* webpackChunkName: "service" */ './Analytics');
|
||||||
const ServiceChart = () => import(/* webpackChunkName: "service" */ "./ServiceChart");
|
const ServiceChart = () => import(/* webpackChunkName: "service" */ "./ServiceChart");
|
||||||
const ServiceTopStats = () => import(/* webpackChunkName: "service" */ "@/components/Service/ServiceTopStats");
|
const ServiceTopStats = () => import(/* webpackChunkName: "service" */ "@/components/Service/ServiceTopStats");
|
||||||
const Graphing = () => import(/* webpackChunkName: "service" */ '../../graphing');
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ServiceBlock',
|
name: 'ServiceBlock',
|
||||||
|
|
|
@ -195,17 +195,14 @@
|
||||||
methods: {
|
methods: {
|
||||||
async chartHits(val) {
|
async chartHits(val) {
|
||||||
this.ready = false
|
this.ready = false
|
||||||
const start = val.start_time
|
const end = this.endOf("hour", this.now())
|
||||||
const end = this.toUnix(new Date())
|
const start = this.beginningOf("hour", this.fromUnix(val.start_time))
|
||||||
this.data = await Api.service_hits(this.service.id, start, end, val.interval, false)
|
this.data = await Api.service_hits(this.service.id, this.toUnix(start), this.toUnix(end), val.interval, false)
|
||||||
if (this.data === null && val.interval !== "5m") {
|
this.ping_data = await Api.service_ping(this.service.id, this.toUnix(start), this.toUnix(end), val.interval, false)
|
||||||
await this.chartHits({start_time: val.start_time, interval: "5m"})
|
|
||||||
}
|
|
||||||
this.ping_data = await Api.service_ping(this.service.id, start, end, val.interval, false)
|
|
||||||
|
|
||||||
this.series = [
|
this.series = [
|
||||||
{name: "Latency", ...this.convertToChartData(this.data)},
|
{name: "Latency", ...this.convertToChartData(this.data)},
|
||||||
{name: "Ping", ...this.convertToChartData(this.ping_data)},
|
{name: "Ping", ...this.convertToChartData(this.ping_data)},
|
||||||
]
|
]
|
||||||
this.ready = true
|
this.ready = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import Vue from "vue";
|
import Vue from "vue";
|
||||||
const { startOfDay, startOfWeek, endOfMonth, startOfToday, startOfTomorrow, startOfYesterday, endOfYesterday, endOfTomorrow, endOfToday, endOfDay, startOfMonth, lastDayOfMonth, subSeconds, getUnixTime, fromUnixTime, differenceInSeconds, formatDistance, addMonths, addSeconds, isWithinInterval } = require('date-fns')
|
const { startOfDay, startOfHour, startOfWeek, endOfMonth, endOfHour, startOfToday, startOfTomorrow, startOfYesterday, endOfYesterday, endOfTomorrow, endOfToday, endOfDay, startOfMonth, lastDayOfMonth, subSeconds, getUnixTime, fromUnixTime, differenceInSeconds, formatDistance, addMonths, addSeconds, isWithinInterval } = require('date-fns')
|
||||||
import formatDistanceToNow from 'date-fns/formatDistanceToNow'
|
import formatDistanceToNow from 'date-fns/formatDistanceToNow'
|
||||||
import format from 'date-fns/format'
|
import format from 'date-fns/format'
|
||||||
import parseISO from 'date-fns/parseISO'
|
import parseISO from 'date-fns/parseISO'
|
||||||
|
@ -59,6 +59,8 @@ export default Vue.mixin({
|
||||||
},
|
},
|
||||||
endOf(method, val) {
|
endOf(method, val) {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
|
case "hour":
|
||||||
|
return endOfHour(val)
|
||||||
case "day":
|
case "day":
|
||||||
return endOfDay(val)
|
return endOfDay(val)
|
||||||
case "today":
|
case "today":
|
||||||
|
@ -70,10 +72,17 @@ export default Vue.mixin({
|
||||||
case "month":
|
case "month":
|
||||||
return endOfMonth(val)
|
return endOfMonth(val)
|
||||||
}
|
}
|
||||||
return roundToNearestMinutes(val)
|
return val
|
||||||
|
},
|
||||||
|
startEndParams(start, end, group) {
|
||||||
|
start = this.beginningOf("hour", start)
|
||||||
|
end = this.endOf("hour", end)
|
||||||
|
return {start: this.toUnix(start), end: this.toUnix(end), group: group}
|
||||||
},
|
},
|
||||||
beginningOf(method, val) {
|
beginningOf(method, val) {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
|
case "hour":
|
||||||
|
return startOfHour(val)
|
||||||
case "day":
|
case "day":
|
||||||
return startOfDay(val)
|
return startOfDay(val)
|
||||||
case "today":
|
case "today":
|
||||||
|
@ -83,11 +92,11 @@ export default Vue.mixin({
|
||||||
case "yesterday":
|
case "yesterday":
|
||||||
return startOfYesterday()
|
return startOfYesterday()
|
||||||
case "week":
|
case "week":
|
||||||
return startOfWeek()
|
return startOfWeek(val)
|
||||||
case "month":
|
case "month":
|
||||||
return startOfMonth(val)
|
return startOfMonth(val)
|
||||||
}
|
}
|
||||||
return roundToNearestMinutes(val)
|
return val
|
||||||
},
|
},
|
||||||
isZero(val) {
|
isZero(val) {
|
||||||
return getUnixTime(parseISO(val)) <= 0
|
return getUnixTime(parseISO(val)) <= 0
|
||||||
|
|
|
@ -2275,7 +2275,7 @@ OluFxewsEO0QNDrfFb+0gnjYlnGqOFcZjUMXbDdY5oLSPtXohynuTK1qyQ==
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="text-center small text-dim" v-pre>
|
<div class="text-center small text-dim" v-pre>
|
||||||
Automatically generated from Statping's Wiki on 2020-08-30 00:32:40.685063 +0000 UTC
|
Automatically generated from Statping's Wiki on 2020-09-02 02:46:04.864615 +0000 UTC
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Group v-for="group in groups" v-bind:key="group.id" :group=group />
|
<Group v-for="group in groups" v-bind:key="group.id" :group=group />
|
||||||
|
|
||||||
<div class="col-12 full-col-12">
|
<div class="col-12 full-col-12">
|
||||||
<MessageBlock v-for="message in messages" v-bind:key="message.id" :message="message" />
|
<MessageBlock v-for="message in messages" v-bind:key="message.id" :message="message" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -64,20 +63,18 @@ export default {
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
loading_text() {
|
loading_text() {
|
||||||
if (this.core == null) {
|
if (!this.$store.getters.core.version) {
|
||||||
return "Loading Core"
|
return "Loading Core"
|
||||||
} else if (this.groups == null) {
|
} else if (this.$store.getters.groups.length === 0) {
|
||||||
return "Loading Groups"
|
return "Loading Groups"
|
||||||
} else if (this.services == null) {
|
} else if (this.$store.getters.services.length === 0) {
|
||||||
return "Loading Services"
|
return "Loading Services"
|
||||||
} else if (this.messages == null) {
|
} else if (this.$store.getters.messages == null) {
|
||||||
return "Loading Announcements"
|
return "Loading Announcements"
|
||||||
} else {
|
|
||||||
return "Completed"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
loaded() {
|
loaded() {
|
||||||
return this.core !== null && this.groups !== null && this.services !== null
|
return this.$store.getters.core.version && this.$store.getters.services.length !== 0
|
||||||
},
|
},
|
||||||
core() {
|
core() {
|
||||||
return this.$store.getters.core
|
return this.$store.getters.core
|
||||||
|
|
|
@ -13,7 +13,14 @@ import (
|
||||||
func apiNotifiersHandler(w http.ResponseWriter, r *http.Request) {
|
func apiNotifiersHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var notifs []notifications.Notification
|
var notifs []notifications.Notification
|
||||||
for _, n := range services.AllNotifiers() {
|
for _, n := range services.AllNotifiers() {
|
||||||
notifs = append(notifs, *n.Select())
|
notif := n.Select()
|
||||||
|
no, err := notifications.Find(notif.Method)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
sendErrorJson(err, w, r)
|
||||||
|
}
|
||||||
|
notif.UpdateFields(no)
|
||||||
|
notifs = append(notifs, *notif)
|
||||||
}
|
}
|
||||||
sort.Sort(notifications.NotificationOrder(notifs))
|
sort.Sort(notifications.NotificationOrder(notifs))
|
||||||
returnJson(notifs, w, r)
|
returnJson(notifs, w, r)
|
||||||
|
|
|
@ -40,7 +40,7 @@ func TestSlackNotifier(t *testing.T) {
|
||||||
|
|
||||||
t.Run("Load slack", func(t *testing.T) {
|
t.Run("Load slack", func(t *testing.T) {
|
||||||
slacker.Host = null.NewNullString(SLACK_URL)
|
slacker.Host = null.NewNullString(SLACK_URL)
|
||||||
slacker.Delay = time.Duration(100 * time.Millisecond)
|
slacker.Delay = 100 * time.Millisecond
|
||||||
slacker.Limits = 3
|
slacker.Limits = 3
|
||||||
Add(slacker)
|
Add(slacker)
|
||||||
assert.Equal(t, "Hunter Long", slacker.Author)
|
assert.Equal(t, "Hunter Long", slacker.Author)
|
||||||
|
|
Loading…
Reference in New Issue