service dropdown for chart timeframe and interval

pull/576/head
hunterlong 2020-05-08 21:33:04 -07:00
parent 56b635dd9b
commit c490032bb2
5 changed files with 138 additions and 61 deletions

View File

@ -156,14 +156,11 @@ build-linux:
export PWD=`pwd` export PWD=`pwd`
@for arch in $(ARCHS);\ @for arch in $(ARCHS);\
do \ do \
for os in $(OS);\ echo "Building v${VERSION} for linux-$$arch"; \
do \
echo "Building v$$VERSION for $$os-$$arch"; \
mkdir -p releases/statping-$$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; \ 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; \ chmod +x releases/statping-$$os-$$arch/statping || true; \
tar -czf releases/statping-$$os-$$arch.tar.gz -C releases/statping-$$os-$$arch statping || true; \ tar -czf releases/statping-$$os-$$arch.tar.gz -C releases/statping-$$os-$$arch statping || true; \
done \
done done
find ./releases/ -name "*.tar.gz" -type f -size +1M -exec mv "{}" build/ \; find ./releases/ -name "*.tar.gz" -type f -size +1M -exec mv "{}" build/ \;
@ -172,9 +169,9 @@ build-mac:
export PWD=`pwd` export PWD=`pwd`
@for arch in $(ARCHS);\ @for arch in $(ARCHS);\
do \ do \
echo "Building v$$VERSION for darwin-$$arch"; \ echo "Building v${VERSION} for darwin-$$arch"; \
mkdir -p releases/statping-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; \ chmod +x releases/statping-darwin-$$arch/statping || true; \
tar -czf releases/statping-darwin-$$arch.tar.gz -C releases/statping-darwin-$$arch statping || true; \ tar -czf releases/statping-darwin-$$arch.tar.gz -C releases/statping-darwin-$$arch statping || true; \
done done
@ -185,9 +182,9 @@ build-win:
export PWD=`pwd` export PWD=`pwd`
@for arch in $(ARCHS);\ @for arch in $(ARCHS);\
do \ do \
echo "Building v$$VERSION for windows-$$arch"; \ echo "Building v${VERSION} for windows-$$arch"; \
mkdir -p releases/statping-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; \ chmod +x releases/statping-windows-$$arch/statping.exe || true; \
zip -j releases/statping-windows-$$arch.zip releases/statping-windows-$$arch/statping.exe || true; \ zip -j releases/statping-windows-$$arch.zip releases/statping-windows-$$arch/statping.exe || true; \
done done

View File

@ -14,6 +14,18 @@ HTML,BODY {
transition: height 0.3s ease; 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 { .copy-btn {
position: absolute; position: absolute;
right: 0; right: 0;

View File

@ -24,30 +24,40 @@
</router-link> </router-link>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div v-show="!expanded" v-observe-visibility="visibleChart" class="chart-container"> <div v-show="!expanded" v-observe-visibility="visibleChart" class="chart-container">
<ServiceChart :service="service" :visible="visible"/> <ServiceChart :service="service" :visible="visible" :chart_timeframe="chartTimeframe"/>
</div> </div>
<div class="row lower_canvas full-col-12 text-white" :class="{'bg-success': service.online, 'bg-danger': !service.online}"> <div class="row lower_canvas full-col-12 text-white" :class="{'bg-success': service.online, 'bg-danger': !service.online}">
<div class="col-md-8 col-6"> <div class="col-md-8 col-6">
<div class="dropup" :class="{show: dropDownMenu}"> <div class="dropup" :class="{show: dropDownMenu}">
<button style="font-size: 10pt;" @focusout="dropDownMenu = false" @click="dropDownMenu = !dropDownMenu" type="button" class="d-none col-4 float-left btn btn-sm float-right btn-block text-white dropdown-toggle service_scale" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <button style="font-size: 10pt;" @click.prevent="openMenu('timeframe')" type="button" class="col-4 float-left btn btn-sm float-right btn-block text-white dropdown-toggle service_scale pr-2">
24 Hours {{timepick.text}}
</button> </button>
<div class="dropdown-menu" :class="{show: dropDownMenu}"> <div class="service-tm-menu" :class="{'d-none': !dropDownMenu}">
<a v-for="(timeframe, i) in timeframes" @click="timeframe.picked = true" class="dropdown-item" href="#">{{timeframe.text}}</a> <a v-for="(timeframe, i) in timeframes" @click.prevent="changeTimeframe(timeframe)" class="dropdown-item" href="#" :class="{'active': timeframe.picked}">{{timeframe.text}}</a>
</div>
</div>
<div class="dropup" :class="{show: intervalMenu}">
<button style="font-size: 10pt;" @click.prevent="openMenu('interval')" type="button" class="col-4 float-left btn btn-sm float-right btn-block text-white dropdown-toggle service_scale pr-2">
{{intervalpick.text}}
</button>
<div class="service-tm-menu" :class="{'d-none': !intervalMenu}">
<a v-for="(interval, i) in intervals" @click.prevent="changeInterval(interval)" class="dropdown-item" href="#" :class="{'active': interval.picked}">{{interval.text}}</a>
</div> </div>
<span class="d-none float-left d-md-inline"> <span class="d-none float-left d-md-inline">
{{smallText(service)}} {{smallText(service)}}
</span> </span>
</div> </div>
</div> </div>
<div class="col-md-4 col-6 float-right"> <div class="col-md-4 col-6 float-right">
<button v-if="!expanded" @click="setService" class="btn btn-sm float-right dyn-dark text-white" :class="{'bg-success': service.online, 'bg-danger': !service.online}"> <button v-if="!expanded" @click="setService" class="btn btn-sm float-right dyn-dark text-white" :class="{'bg-success': service.online, 'bg-danger': !service.online}">
View Service View Service
@ -75,18 +85,54 @@ export default {
required: true required: true
}, },
}, },
computed: {
service() {
return this.track_service
},
timepick() {
return this.timeframes.find(s => s.value === this.timeframe_val)
},
intervalpick() {
return this.intervals.find(s => s.value === this.interval_val)
},
chartTimeframe() {
return {start_time: this.timeframe_val, interval: this.interval_val}
}
},
data() { data() {
return { return {
timer_func: null, timer_func: null,
expanded: false, expanded: false,
visible: false, visible: false,
dropDownMenu: false, dropDownMenu: false,
intervalMenu: false,
interval_val: "60m",
timeframe_val: this.timeset(259200),
timeframes: [ timeframes: [
{value: "72h", text: "3 Days", picked: true }, {value: this.timeset(1800), text: "30 Minutes"},
{value: "24h", text: "Since Yesterday" }, {value: this.timeset(3600), text: "1 Hour"},
{value: "3", text: "3 Hours" }, {value: this.timeset(21600), text: "6 Hours"},
{value: "1m", text: "1 Month" }, {value: this.timeset(43200), text: "12 Hours"},
{value: "3", text: "Last 3 Months" }, {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: 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" },
], ],
stats: { stats: {
total_failures: { total_failures: {
@ -121,15 +167,32 @@ export default {
beforeDestroy() { beforeDestroy() {
clearInterval(this.timer_func) clearInterval(this.timer_func)
}, },
computed: {
service() {
return this.track_service
}
},
async created() { async created() {
this.track_service = this.in_service this.track_service = this.in_service
}, },
methods: { methods: {
timeset (seconds) {
return this.toUnix(this.nowSubtract(seconds))
},
openMenu(tm) {
if (tm === "interval") {
this.intervalMenu = !this.intervalMenu
this.dropDownMenu = false
} else if (tm === "timeframe") {
this.dropDownMenu = !this.dropDownMenu
this.intervalMenu = false
}
},
changeInterval(tm) {
this.interval_val = tm.value
this.intervalMenu = false
this.dropDownMenu = false
},
changeTimeframe(tm) {
this.timeframe_val = tm.value
this.dropDownMenu = false
this.intervalMenu = false
},
async setService() { async setService() {
await this.$store.commit('setService', this.service) await this.$store.commit('setService', this.service)
this.$router.push('/service/'+this.service.id, {props: {in_service: this.service}}) this.$router.push('/service/'+this.service.id, {props: {in_service: this.service}})
@ -159,14 +222,14 @@ export default {
smallText(s) { smallText(s) {
const incidents = s.incidents const incidents = s.incidents
if (s.online) { if (s.online) {
return `Checked ${this.ago(s.last_success)} ago and responded in ${this.humanTime(s.latency)}` return `Checked ${this.ago(s.last_success)} ago`
} 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)) { if (!s.online) {
return `Service has never been online` return `Service is offline`
} }
return `Offline` return `Offline`
} }

View File

@ -37,7 +37,11 @@
visible: { visible: {
type: Boolean, type: Boolean,
required: true required: true
} },
chart_timeframe: {
type: Object,
required: true
},
}, },
data() { data() {
return { return {
@ -163,21 +167,22 @@
visible: function(newVal, oldVal) { visible: function(newVal, oldVal) {
if (newVal && !this.showing) { if (newVal && !this.showing) {
this.showing = true this.showing = true
this.chartHits("1h") this.chartHits(this.chart_timeframe)
}
},
chart_timeframe: function(newVal, oldVal) {
if (newVal) {
this.chartHits(newVal)
} }
} }
}, },
methods: { methods: {
async chartHits(group) { async chartHits(val) {
const start = this.toUnix(this.nowSubtract(84600 * 3)) const start = val.start_time
const end = this.toUnix(new Date()) const end = this.toUnix(new Date())
if (end-start < 283800) { this.data = await Api.service_hits(this.service.id, start, end, val.interval, false)
group = "5m" if (this.data === null && val.interval !== "5m") {
} await this.chartHits({start_time: val.start_time, interval: "5m"})
this.data = await Api.service_hits(this.service.id, start, end, group, false)
if (this.data === null && group !== "5m") {
await this.chartHits("10m")
} }
this.series = [{ this.series = [{
name: this.service.name, name: this.service.name,