notifier endpoint fixes, timeframe rounding chart data

pull/805/head
hunterlong 2020-09-01 20:50:17 -07:00
parent 5bc10fcc85
commit 1c57f5af53
10 changed files with 46 additions and 36 deletions

View File

@ -8,7 +8,7 @@ const tokenKey = "statping_auth";
class Api {
constructor() {
this.version = "0.90.65";
this.commit = "3051206a7a843b97c92462a536f1c54ee92fbab8";
this.commit = "5bc10fcc8536a08ce7a099a0b4cbceb2dc9fc35b";
}
async oauth() {

View File

@ -121,13 +121,14 @@
}
},
async getUptime() {
const start = this.nowSubtract(3 * 86400)
this.uptime = await Api.service_uptime(this.service.id, this.toUnix(start), this.toUnix(this.now()))
const end = this.endOf("day", 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() {
this.set1 = await this.getHits(24 * 7, "720m")
this.set1 = await this.getHits(86400 * 7, "12h")
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.loaded = true
},
@ -145,14 +146,13 @@
});
total = total / data.length
},
async getHits(hours, group) {
const start = this.nowSubtract(3600 * hours)
const fetched = await Api.service_hits(this.service.id, this.toUnix(start), this.toUnix(this.now()), group, true)
async getHits(seconds, group) {
let start = this.nowSubtract(seconds)
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)
return [{name: "Latency", ...data}]
},
calc(s) {
let data = s[0].data

View File

@ -157,7 +157,8 @@ export default {
},
async loadFailures() {
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.data = [{data: this.convertChartData(data)}]
}

View File

@ -61,7 +61,6 @@
const Analytics = () => import(/* webpackChunkName: "service" */ './Analytics');
const ServiceChart = () => import(/* webpackChunkName: "service" */ "./ServiceChart");
const ServiceTopStats = () => import(/* webpackChunkName: "service" */ "@/components/Service/ServiceTopStats");
const Graphing = () => import(/* webpackChunkName: "service" */ '../../graphing');
export default {
name: 'ServiceBlock',

View File

@ -195,13 +195,10 @@
methods: {
async chartHits(val) {
this.ready = false
const start = val.start_time
const end = this.toUnix(new Date())
this.data = await Api.service_hits(this.service.id, start, end, val.interval, false)
if (this.data === null && val.interval !== "5m") {
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)
const end = this.endOf("hour", this.now())
const start = this.beginningOf("hour", this.fromUnix(val.start_time))
this.data = await Api.service_hits(this.service.id, this.toUnix(start), this.toUnix(end), val.interval, false)
this.ping_data = await Api.service_ping(this.service.id, this.toUnix(start), this.toUnix(end), val.interval, false)
this.series = [
{name: "Latency", ...this.convertToChartData(this.data)},

View File

@ -1,5 +1,5 @@
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 format from 'date-fns/format'
import parseISO from 'date-fns/parseISO'
@ -59,6 +59,8 @@ export default Vue.mixin({
},
endOf(method, val) {
switch (method) {
case "hour":
return endOfHour(val)
case "day":
return endOfDay(val)
case "today":
@ -70,10 +72,17 @@ export default Vue.mixin({
case "month":
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) {
switch (method) {
case "hour":
return startOfHour(val)
case "day":
return startOfDay(val)
case "today":
@ -83,11 +92,11 @@ export default Vue.mixin({
case "yesterday":
return startOfYesterday()
case "week":
return startOfWeek()
return startOfWeek(val)
case "month":
return startOfMonth(val)
}
return roundToNearestMinutes(val)
return val
},
isZero(val) {
return getUnixTime(parseISO(val)) <= 0

View File

@ -2275,7 +2275,7 @@ OluFxewsEO0QNDrfFb+0gnjYlnGqOFcZjUMXbDdY5oLSPtXohynuTK1qyQ==
</div>
<div class="text-center small text-dim" v-pre>
Automatically generated from Statping's Wiki on 2020-08-30 00:32:40.685063 &#43;0000 UTC
Automatically generated from Statping's Wiki on 2020-09-02 02:46:04.864615 &#43;0000 UTC
</div>
</div>

View File

@ -24,7 +24,6 @@
</div>
<Group v-for="group in groups" v-bind:key="group.id" :group=group />
<div class="col-12 full-col-12">
<MessageBlock v-for="message in messages" v-bind:key="message.id" :message="message" />
</div>
@ -64,20 +63,18 @@ export default {
},
computed: {
loading_text() {
if (this.core == null) {
if (!this.$store.getters.core.version) {
return "Loading Core"
} else if (this.groups == null) {
} else if (this.$store.getters.groups.length === 0) {
return "Loading Groups"
} else if (this.services == null) {
} else if (this.$store.getters.services.length === 0) {
return "Loading Services"
} else if (this.messages == null) {
} else if (this.$store.getters.messages == null) {
return "Loading Announcements"
} else {
return "Completed"
}
},
loaded() {
return this.core !== null && this.groups !== null && this.services !== null
return this.$store.getters.core.version && this.$store.getters.services.length !== 0
},
core() {
return this.$store.getters.core

View File

@ -13,7 +13,14 @@ import (
func apiNotifiersHandler(w http.ResponseWriter, r *http.Request) {
var notifs []notifications.Notification
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))
returnJson(notifs, w, r)

View File

@ -40,7 +40,7 @@ func TestSlackNotifier(t *testing.T) {
t.Run("Load slack", func(t *testing.T) {
slacker.Host = null.NewNullString(SLACK_URL)
slacker.Delay = time.Duration(100 * time.Millisecond)
slacker.Delay = 100 * time.Millisecond
slacker.Limits = 3
Add(slacker)
assert.Equal(t, "Hunter Long", slacker.Author)