mirror of https://github.com/statping/statping
fixed ICMP latency and ping duration, organized Vue files
parent
23fb2eb2a9
commit
7f5a6a2e7c
|
@ -23,7 +23,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
const ServiceInfo = () => import('@/components/Service/ServiceInfo')
|
||||
const ServiceInfo = () => import('@/components/Dashboard/ServiceInfo')
|
||||
|
||||
export default {
|
||||
name: 'DashboardIndex',
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<div v-if="false" class="row mb-4 align-content-center">
|
||||
|
||||
<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>
|
||||
</div>
|
||||
|
||||
|
@ -103,7 +103,7 @@
|
|||
import Checkin from '../../forms/Checkin';
|
||||
import FormIncident from '../../forms/Incident';
|
||||
import FormMessage from '../../forms/Message';
|
||||
import ServiceFailures from './ServiceFailures';
|
||||
import ServiceFailures from '../Service/ServiceFailures';
|
||||
import ServiceSparkLine from "./ServiceSparkLine";
|
||||
import Api from "../../API";
|
||||
|
|
@ -65,7 +65,7 @@
|
|||
offsetY: 0,
|
||||
},
|
||||
x: {
|
||||
show: false,
|
||||
show: true,
|
||||
},
|
||||
y: {
|
||||
formatter: (value) => { return value + " %" },
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
<script>
|
||||
import MiniSparkLine from './MiniSparkLine';
|
||||
import ServiceSparkLine from './ServiceSparkLine';
|
||||
import ServiceSparkLine from '../Dashboard/ServiceSparkLine';
|
||||
|
||||
export default {
|
||||
name: 'Analytics',
|
||||
|
|
|
@ -10,20 +10,6 @@
|
|||
|
||||
<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>
|
||||
|
||||
|
|
|
@ -91,14 +91,21 @@ func CheckIcmp(s *Service, record bool) (*Service, error) {
|
|||
timer := prometheus.NewTimer(metrics.ServiceTimer(s.Name))
|
||||
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 {
|
||||
recordFailure(s, fmt.Sprintf("Could not send ICMP to service %v, %v", s.Domain, err))
|
||||
}
|
||||
return s, err
|
||||
}
|
||||
|
||||
s.PingTime = dur
|
||||
s.Latency = dur
|
||||
s.LastResponse = ""
|
||||
s.Online = true
|
||||
if record {
|
||||
recordSuccess(s)
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
// in, out, err := Command("sass assets/scss assets/css/base.css")
|
||||
func Command(name string, args ...string) (string, string, error) {
|
||||
Log.Info("Running command: " + name + " " + strings.Join(args, " "))
|
||||
testCmd := exec.Command(name, args...)
|
||||
var stdout, stderr []byte
|
||||
var errStdout, errStderr error
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"errors"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
@ -36,20 +37,27 @@ func DirWritable(path string) (bool, error) {
|
|||
return true, nil
|
||||
}
|
||||
|
||||
func Ping(address string, secondsTimeout int) error {
|
||||
func Ping(address string, secondsTimeout int) (int64, error) {
|
||||
ping, err := exec.LookPath("ping")
|
||||
if err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
out, _, err := Command(ping, address, "-c", "1", "-W", strconv.Itoa(secondsTimeout))
|
||||
if err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
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") {
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue