fixed ICMP latency and ping duration, organized Vue files

pull/730/head^2
hunterlong 2020-07-09 11:19:31 -07:00
parent 23fb2eb2a9
commit 7f5a6a2e7c
8 changed files with 27 additions and 27 deletions

View File

@ -23,7 +23,7 @@
</template> </template>
<script> <script>
const ServiceInfo = () => import('@/components/Service/ServiceInfo') const ServiceInfo = () => import('@/components/Dashboard/ServiceInfo')
export default { export default {
name: 'DashboardIndex', name: 'DashboardIndex',

View File

@ -17,7 +17,7 @@
<div v-if="false" class="row mb-4 align-content-center"> <div v-if="false" class="row mb-4 align-content-center">
<div v-if="!service.online" class="col-3 text-left"> <div v-if="!service.online" class="col-3 text-left">
<span class="text-danger font-5 font-weight-bold"></span> <span css="text-danger font-5 font-weight-bold"></span>
<span class="font-2 d-block">Current Downtime</span> <span class="font-2 d-block">Current Downtime</span>
</div> </div>
@ -103,7 +103,7 @@
import Checkin from '../../forms/Checkin'; import Checkin from '../../forms/Checkin';
import FormIncident from '../../forms/Incident'; import FormIncident from '../../forms/Incident';
import FormMessage from '../../forms/Message'; import FormMessage from '../../forms/Message';
import ServiceFailures from './ServiceFailures'; import ServiceFailures from '../Service/ServiceFailures';
import ServiceSparkLine from "./ServiceSparkLine"; import ServiceSparkLine from "./ServiceSparkLine";
import Api from "../../API"; import Api from "../../API";

View File

@ -65,7 +65,7 @@
offsetY: 0, offsetY: 0,
}, },
x: { x: {
show: false, show: true,
}, },
y: { y: {
formatter: (value) => { return value + " %" }, formatter: (value) => { return value + " %" },

View File

@ -14,7 +14,7 @@
<script> <script>
import MiniSparkLine from './MiniSparkLine'; import MiniSparkLine from './MiniSparkLine';
import ServiceSparkLine from './ServiceSparkLine'; import ServiceSparkLine from '../Dashboard/ServiceSparkLine';
export default { export default {
name: 'Analytics', name: 'Analytics',

View File

@ -10,20 +10,6 @@
<ServiceTopStats :service="service"/> <ServiceTopStats :service="service"/>
<div v-if="expanded" class="row">
<Analytics title="Last Failure" :func="stats.total_failures"/>
<Analytics title="Total Failures" :func="stats.total_failures"/>
<Analytics title="Highest Latency" :func="stats.high_latency"/>
<Analytics title="Lowest Latency" :func="stats.lowest_latency"/>
<Analytics title="Total Uptime" :func="stats.high_ping"/>
<Analytics title="Total Downtime" :func="stats.low_ping"/>
<div class="col-12">
<router-link :to="serviceLink(service)" class="btn btn-block btn-outline-success mt-4" :class="{'btn-outline-success': service.online, 'btn-outline-danger': !service.online}">
View More Details
</router-link>
</div>
</div>
</div> </div>
</div> </div>

View File

@ -91,14 +91,21 @@ func CheckIcmp(s *Service, record bool) (*Service, error) {
timer := prometheus.NewTimer(metrics.ServiceTimer(s.Name)) timer := prometheus.NewTimer(metrics.ServiceTimer(s.Name))
defer timer.ObserveDuration() defer timer.ObserveDuration()
if err := utils.Ping(s.Domain, s.Timeout); err != nil { dur, err := utils.Ping(s.Domain, s.Timeout)
if err != nil {
if record { if record {
recordFailure(s, fmt.Sprintf("Could not send ICMP to service %v, %v", s.Domain, err)) recordFailure(s, fmt.Sprintf("Could not send ICMP to service %v, %v", s.Domain, err))
} }
return s, err return s, err
} }
s.PingTime = dur
s.Latency = dur
s.LastResponse = "" s.LastResponse = ""
s.Online = true s.Online = true
if record {
recordSuccess(s)
}
return s, nil return s, nil
} }

View File

@ -105,7 +105,6 @@ func (t Timestamp) Ago() string {
// Command will run a terminal command with 'sh -c COMMAND' and return stdout and errOut as strings // Command will run a terminal command with 'sh -c COMMAND' and return stdout and errOut as strings
// in, out, err := Command("sass assets/scss assets/css/base.css") // in, out, err := Command("sass assets/scss assets/css/base.css")
func Command(name string, args ...string) (string, string, error) { func Command(name string, args ...string) (string, string, error) {
Log.Info("Running command: " + name + " " + strings.Join(args, " "))
testCmd := exec.Command(name, args...) testCmd := exec.Command(name, args...)
var stdout, stderr []byte var stdout, stderr []byte
var errStdout, errStderr error var errStdout, errStderr error

View File

@ -6,6 +6,7 @@ import (
"errors" "errors"
"os" "os"
"os/exec" "os/exec"
"regexp"
"strconv" "strconv"
"strings" "strings"
"syscall" "syscall"
@ -36,20 +37,27 @@ func DirWritable(path string) (bool, error) {
return true, nil return true, nil
} }
func Ping(address string, secondsTimeout int) error { func Ping(address string, secondsTimeout int) (int64, error) {
ping, err := exec.LookPath("ping") ping, err := exec.LookPath("ping")
if err != nil { if err != nil {
return err return 0, err
} }
out, _, err := Command(ping, address, "-c", "1", "-W", strconv.Itoa(secondsTimeout)) out, _, err := Command(ping, address, "-c", "1", "-W", strconv.Itoa(secondsTimeout))
if err != nil { if err != nil {
return err return 0, err
} }
if strings.Contains(out, "Unknown host") { if strings.Contains(out, "Unknown host") {
return errors.New("unknown host") return 0, errors.New("unknown host")
} }
if strings.Contains(out, "100.0% packet loss") { if strings.Contains(out, "100.0% packet loss") {
return errors.New("destination host unreachable") return 0, errors.New("destination host unreachable")
} }
return nil
r := regexp.MustCompile(`time=(.*) ms`)
strs := r.FindStringSubmatch(out)
if len(strs) < 2 {
return 0, errors.New("could not parse ping duration")
}
f, _ := strconv.ParseFloat(strs[1], 64)
return int64(f * 1000), nil
} }