mirror of https://github.com/statping/statping
cleaned
parent
fb15c5cfe3
commit
b2f07a146f
|
@ -22,3 +22,4 @@ source/rice-box.go
|
||||||
sass
|
sass
|
||||||
.DS_Store
|
.DS_Store
|
||||||
source/css/base.css.map
|
source/css/base.css.map
|
||||||
|
/dev/test/node_modules/
|
||||||
|
|
|
@ -11,6 +11,8 @@ go_import_path: github.com/hunterlong/statup
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
- $GOPATH/pkg/dep
|
- $GOPATH/pkg/dep
|
||||||
|
- ~/.npm
|
||||||
|
- ~/.cache
|
||||||
|
|
||||||
sudo: required
|
sudo: required
|
||||||
|
|
||||||
|
|
|
@ -144,8 +144,8 @@ func RunOnce() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Log(4, err)
|
utils.Log(4, err)
|
||||||
}
|
}
|
||||||
for _, s := range core.CoreApp.DbServices {
|
for _, s := range core.CoreApp.Services() {
|
||||||
out := core.ServiceCheck(core.ReturnService(s), true)
|
out := s.Check(true)
|
||||||
fmt.Printf(" Service %v | URL: %v | Latency: %0.0fms | Online: %v\n", out.Name, out.Domain, (out.Latency * 1000), out.Online)
|
fmt.Printf(" Service %v | URL: %v | Latency: %0.0fms | Online: %v\n", out.Name, out.Domain, (out.Latency * 1000), out.Online)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ func TestRunAll(t *testing.T) {
|
||||||
t.Run(dbt+" Select Users", func(t *testing.T) {
|
t.Run(dbt+" Select Users", func(t *testing.T) {
|
||||||
RunUser_SelectAll(t)
|
RunUser_SelectAll(t)
|
||||||
})
|
})
|
||||||
t.Run(dbt+" Select DbServices", func(t *testing.T) {
|
t.Run(dbt+" Select Services", func(t *testing.T) {
|
||||||
RunSelectAllServices(t)
|
RunSelectAllServices(t)
|
||||||
})
|
})
|
||||||
t.Run(dbt+" Select One Service", func(t *testing.T) {
|
t.Run(dbt+" Select One Service", func(t *testing.T) {
|
||||||
|
@ -353,7 +353,7 @@ func RunOneService_Check(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunService_Create(t *testing.T) {
|
func RunService_Create(t *testing.T) {
|
||||||
service := &core.Service{Service: &types.Service{
|
service := core.ReturnService(&types.Service{
|
||||||
Name: "test service",
|
Name: "test service",
|
||||||
Domain: "https://google.com",
|
Domain: "https://google.com",
|
||||||
ExpectedStatus: 200,
|
ExpectedStatus: 200,
|
||||||
|
@ -362,7 +362,7 @@ func RunService_Create(t *testing.T) {
|
||||||
Type: "http",
|
Type: "http",
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
Timeout: 30,
|
Timeout: 30,
|
||||||
}}
|
})
|
||||||
id, err := service.Create()
|
id, err := service.Create()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, int64(6), id)
|
assert.Equal(t, int64(6), id)
|
||||||
|
@ -401,7 +401,7 @@ func RunService_GraphData(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunBadService_Create(t *testing.T) {
|
func RunBadService_Create(t *testing.T) {
|
||||||
service := &core.Service{Service: &types.Service{
|
service := core.ReturnService(&types.Service{
|
||||||
Name: "Bad Service",
|
Name: "Bad Service",
|
||||||
Domain: "https://9839f83h72gey2g29278hd2od2d.com",
|
Domain: "https://9839f83h72gey2g29278hd2od2d.com",
|
||||||
ExpectedStatus: 200,
|
ExpectedStatus: 200,
|
||||||
|
@ -410,7 +410,7 @@ func RunBadService_Create(t *testing.T) {
|
||||||
Type: "http",
|
Type: "http",
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
Timeout: 30,
|
Timeout: 30,
|
||||||
}}
|
})
|
||||||
id, err := service.Create()
|
id, err := service.Create()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, int64(7), id)
|
assert.Equal(t, int64(7), id)
|
||||||
|
@ -421,7 +421,7 @@ func RunBadService_Check(t *testing.T) {
|
||||||
assert.NotNil(t, service)
|
assert.NotNil(t, service)
|
||||||
assert.Equal(t, "Bad Service", service.Name)
|
assert.Equal(t, "Bad Service", service.Name)
|
||||||
for i := 0; i <= 10; i++ {
|
for i := 0; i <= 10; i++ {
|
||||||
core.ServiceHTTPCheck(service, true)
|
service.Check(true)
|
||||||
}
|
}
|
||||||
assert.True(t, service.IsRunning())
|
assert.True(t, service.IsRunning())
|
||||||
}
|
}
|
||||||
|
@ -439,18 +439,13 @@ func RunDeleteService(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunCreateService_Hits(t *testing.T) {
|
func RunCreateService_Hits(t *testing.T) {
|
||||||
services, err := core.CoreApp.SelectAllServices()
|
services := core.CoreApp.Services()
|
||||||
assert.Nil(t, err)
|
|
||||||
assert.NotNil(t, services)
|
assert.NotNil(t, services)
|
||||||
assert.Equal(t, 6, len(services))
|
assert.Equal(t, 6, len(services))
|
||||||
for i := 0; i <= 15; i++ {
|
for i := 0; i <= 15; i++ {
|
||||||
for _, s := range services {
|
for _, s := range services {
|
||||||
var service *core.Service
|
var service *core.Service
|
||||||
if s.Type == "http" {
|
service = s.Check(true)
|
||||||
service = core.ServiceHTTPCheck(core.ReturnService(s), true)
|
|
||||||
} else {
|
|
||||||
service = core.ServiceTCPCheck(core.ReturnService(s), true)
|
|
||||||
}
|
|
||||||
assert.NotNil(t, service)
|
assert.NotNil(t, service)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,15 +28,12 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FailureData types.FailureData
|
|
||||||
|
|
||||||
func CheckServices() {
|
func CheckServices() {
|
||||||
CoreApp.SelectAllServices()
|
CoreApp.SelectAllServices()
|
||||||
utils.Log(1, fmt.Sprintf("Starting monitoring process for %v DbServices", len(CoreApp.DbServices)))
|
utils.Log(1, fmt.Sprintf("Starting monitoring process for %v DbServices", len(CoreApp.DbServices)))
|
||||||
for _, ser := range CoreApp.DbServices {
|
for _, ser := range CoreApp.Services() {
|
||||||
//go obj.StartCheckins()
|
//go obj.StartCheckins()
|
||||||
s := ReturnService(ser)
|
go ser.CheckQueue(true)
|
||||||
go s.CheckQueue(true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +48,7 @@ CheckLoop:
|
||||||
break CheckLoop
|
break CheckLoop
|
||||||
default:
|
default:
|
||||||
utils.Log(1, fmt.Sprintf("Checking service: %v", s.Name))
|
utils.Log(1, fmt.Sprintf("Checking service: %v", s.Name))
|
||||||
ServiceCheck(s, record)
|
s.Check(record)
|
||||||
// Set next time checkpoint and maybe sleep.
|
// Set next time checkpoint and maybe sleep.
|
||||||
s.Checkpoint = s.Checkpoint.Add(time.Duration(s.Interval) * time.Second)
|
s.Checkpoint = s.Checkpoint.Add(time.Duration(s.Interval) * time.Second)
|
||||||
if sleepDuration := s.Checkpoint.Sub(time.Now()); sleepDuration > 0 {
|
if sleepDuration := s.Checkpoint.Sub(time.Now()); sleepDuration > 0 {
|
||||||
|
@ -62,7 +59,7 @@ CheckLoop:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func DNSCheck(s *Service) (float64, error) {
|
func (s *Service) dnsCheck() (float64, error) {
|
||||||
t1 := time.Now()
|
t1 := time.Now()
|
||||||
url, err := url.Parse(s.Domain)
|
url, err := url.Parse(s.Domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -77,7 +74,7 @@ func DNSCheck(s *Service) (float64, error) {
|
||||||
return subTime, err
|
return subTime, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func ServiceTCPCheck(s *Service, record bool) *Service {
|
func (s *Service) checkTcp(record bool) *Service {
|
||||||
t1 := time.Now()
|
t1 := time.Now()
|
||||||
domain := fmt.Sprintf("%v", s.Domain)
|
domain := fmt.Sprintf("%v", s.Domain)
|
||||||
if s.Port != 0 {
|
if s.Port != 0 {
|
||||||
|
@ -105,18 +102,18 @@ func ServiceTCPCheck(s *Service, record bool) *Service {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func ServiceCheck(s *Service, record bool) *Service {
|
func (s *Service) Check(record bool) *Service {
|
||||||
switch s.Type {
|
switch s.Type {
|
||||||
case "http":
|
case "http":
|
||||||
ServiceHTTPCheck(s, record)
|
s.checkHttp(record)
|
||||||
case "tcp":
|
case "tcp":
|
||||||
ServiceTCPCheck(s, record)
|
s.checkTcp(record)
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func ServiceHTTPCheck(s *Service, record bool) *Service {
|
func (s *Service) checkHttp(record bool) *Service {
|
||||||
dnsLookup, err := DNSCheck(s)
|
dnsLookup, err := s.dnsCheck()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if record {
|
if record {
|
||||||
RecordFailure(s, fmt.Sprintf("Could not get IP address for domain %v, %v", s.Domain, err))
|
RecordFailure(s, fmt.Sprintf("Could not get IP address for domain %v, %v", s.Domain, err))
|
||||||
|
|
|
@ -67,7 +67,7 @@ func TestUpdateAllServices(t *testing.T) {
|
||||||
|
|
||||||
func TestServiceHTTPCheck(t *testing.T) {
|
func TestServiceHTTPCheck(t *testing.T) {
|
||||||
service := SelectService(1)
|
service := SelectService(1)
|
||||||
checked := ServiceCheck(service, true)
|
checked := service.Check(true)
|
||||||
assert.Equal(t, "Changed Updated Google", checked.Name)
|
assert.Equal(t, "Changed Updated Google", checked.Name)
|
||||||
assert.True(t, checked.Online)
|
assert.True(t, checked.Online)
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ func TestCheckHTTPService(t *testing.T) {
|
||||||
|
|
||||||
func TestServiceTCPCheck(t *testing.T) {
|
func TestServiceTCPCheck(t *testing.T) {
|
||||||
service := SelectService(5)
|
service := SelectService(5)
|
||||||
checked := ServiceCheck(service, true)
|
checked := service.Check(true)
|
||||||
assert.Equal(t, "Changed Google DNS", checked.Name)
|
assert.Equal(t, "Changed Google DNS", checked.Name)
|
||||||
assert.True(t, checked.Online)
|
assert.True(t, checked.Online)
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ func TestCreateFailingHTTPService(t *testing.T) {
|
||||||
|
|
||||||
func TestServiceFailedCheck(t *testing.T) {
|
func TestServiceFailedCheck(t *testing.T) {
|
||||||
service := SelectService(7)
|
service := SelectService(7)
|
||||||
checked := ServiceCheck(service, true)
|
checked := service.Check(true)
|
||||||
assert.Equal(t, "Bad URL", checked.Name)
|
assert.Equal(t, "Bad URL", checked.Name)
|
||||||
assert.False(t, checked.Online)
|
assert.False(t, checked.Online)
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ func TestCreateFailingTCPService(t *testing.T) {
|
||||||
|
|
||||||
func TestServiceFailedTCPCheck(t *testing.T) {
|
func TestServiceFailedTCPCheck(t *testing.T) {
|
||||||
service := SelectService(8)
|
service := SelectService(8)
|
||||||
checked := ServiceCheck(service, true)
|
checked := service.Check(true)
|
||||||
assert.Equal(t, "Bad TCP", checked.Name)
|
assert.Equal(t, "Bad TCP", checked.Name)
|
||||||
assert.False(t, checked.Online)
|
assert.False(t, checked.Online)
|
||||||
}
|
}
|
||||||
|
@ -254,7 +254,36 @@ func TestServiceCloseRoutine(t *testing.T) {
|
||||||
s.Interval = 1
|
s.Interval = 1
|
||||||
s.Start()
|
s.Start()
|
||||||
assert.True(t, s.IsRunning())
|
assert.True(t, s.IsRunning())
|
||||||
|
t.Log(s.Checkpoint)
|
||||||
go s.CheckQueue(false)
|
go s.CheckQueue(false)
|
||||||
|
t.Log(s.Checkpoint)
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
t.Log(s.Checkpoint)
|
||||||
|
assert.True(t, s.IsRunning())
|
||||||
|
s.Close()
|
||||||
|
assert.False(t, s.IsRunning())
|
||||||
|
s.Close()
|
||||||
|
assert.False(t, s.IsRunning())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestServiceCheckQueue(t *testing.T) {
|
||||||
|
s := ReturnService(new(types.Service))
|
||||||
|
s.Name = "example"
|
||||||
|
s.Domain = "https://google.com"
|
||||||
|
s.Type = "http"
|
||||||
|
s.Method = "GET"
|
||||||
|
s.ExpectedStatus = 200
|
||||||
|
s.Interval = 1
|
||||||
|
s.Start()
|
||||||
|
assert.True(t, s.IsRunning())
|
||||||
|
go s.CheckQueue(false)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
t.Log(s.Checkpoint)
|
||||||
|
time.Sleep(6 * time.Second)
|
||||||
|
}()
|
||||||
|
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
assert.True(t, s.IsRunning())
|
assert.True(t, s.IsRunning())
|
||||||
s.Close()
|
s.Close()
|
||||||
|
|
|
@ -19,5 +19,7 @@ ENV IS_DOCKER=true
|
||||||
RUN make dev-deps
|
RUN make dev-deps
|
||||||
RUN make install
|
RUN make install
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
VOLUME /app
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
ENTRYPOINT make run
|
ENTRYPOINT statup
|
|
@ -76,6 +76,9 @@ type ServiceInterface interface {
|
||||||
SelectHitsGroupBy(string) ([]*Hit, error)
|
SelectHitsGroupBy(string) ([]*Hit, error)
|
||||||
// Go Routines
|
// Go Routines
|
||||||
CheckQueue(bool)
|
CheckQueue(bool)
|
||||||
|
Check(bool) *Service
|
||||||
|
checkHttp(bool) *Service
|
||||||
|
checkTcp(bool) *Service
|
||||||
// Checkin functions
|
// Checkin functions
|
||||||
AllCheckins() []*Checkin
|
AllCheckins() []*Checkin
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,3 @@ type PluginJSON struct {
|
||||||
Author string `json:"author"`
|
Author string `json:"author"`
|
||||||
Namespace string `json:"namespace"`
|
Namespace string `json:"namespace"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FailureData struct {
|
|
||||||
Issue string
|
|
||||||
}
|
|
||||||
|
|
|
@ -22,8 +22,8 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LogRow struct {
|
type LogRow struct {
|
||||||
|
|
Loading…
Reference in New Issue