mirror of https://github.com/statping/statping
building
parent
a058659a34
commit
ffaa95b5f8
18
.travis.yml
18
.travis.yml
|
@ -18,7 +18,7 @@ services:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- VERSION=0.22
|
- VERSION=0.23
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
allow_failures:
|
allow_failures:
|
||||||
|
@ -33,14 +33,14 @@ deploy:
|
||||||
- provider: releases
|
- provider: releases
|
||||||
api_key: $GH_TOKEN
|
api_key: $GH_TOKEN
|
||||||
file:
|
file:
|
||||||
- "build/statup-osx-x64"
|
- "build/statup-osx-x64.tar.gz"
|
||||||
- "build/statup-osx-x32"
|
- "build/statup-osx-x32.tar.gz"
|
||||||
- "build/statup-linux-x64"
|
- "build/statup-linux-x64.tar.gz"
|
||||||
- "build/statup-linux-x32"
|
- "build/statup-linux-x32.tar.gz"
|
||||||
- "build/statup-linux-arm64"
|
- "build/statup-linux-arm64.tar.gz"
|
||||||
- "build/statup-linux-arm7"
|
- "build/statup-linux-arm7.tar.gz"
|
||||||
- "build/statup-windows-x64.exe"
|
- "build/statup-linux-alpine.tar.gz"
|
||||||
- "build/statup-linux-alpine"
|
- "build/statup-windows-x64.zip"
|
||||||
skip_cleanup: true
|
skip_cleanup: true
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
ENV VERSION=v0.22
|
ENV VERSION=v0.23
|
||||||
|
|
||||||
RUN apk --no-cache add ca-certificates
|
RUN apk --no-cache add ca-certificates
|
||||||
RUN wget https://github.com/hunterlong/statup/releases/download/$VERSION/statup-linux-alpine && \
|
RUN wget https://github.com/hunterlong/statup/releases/download/$VERSION/statup-linux-alpine.tar.gz && \
|
||||||
chmod +x statup-linux-alpine && \
|
tar -xvzf statup-linux-alpine.tar.gz && \
|
||||||
mv statup-linux-alpine /usr/local/bin/statup
|
chmod +x statup && \
|
||||||
|
mv statup /usr/local/bin/statup
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
VOLUME /app
|
VOLUME /app
|
||||||
RUN statup version
|
RUN statup version
|
||||||
|
|
28
api.go
28
api.go
|
@ -4,6 +4,9 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"crypto/sha1"
|
||||||
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ApiIndexHandler(w http.ResponseWriter, r *http.Request) {
|
func ApiIndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -27,11 +30,9 @@ func ApiServiceHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
func ApiServiceUpdateHandler(w http.ResponseWriter, r *http.Request) {
|
func ApiServiceUpdateHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
service := SelectService(StringInt(vars["id"]))
|
service := SelectService(StringInt(vars["id"]))
|
||||||
|
|
||||||
var s Service
|
var s Service
|
||||||
decoder := json.NewDecoder(r.Body)
|
decoder := json.NewDecoder(r.Body)
|
||||||
decoder.Decode(&s)
|
decoder.Decode(&s)
|
||||||
|
|
||||||
json.NewEncoder(w).Encode(service)
|
json.NewEncoder(w).Encode(service)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,3 +51,26 @@ func ApiAllUsersHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
users, _ := SelectAllUsers()
|
users, _ := SelectAllUsers()
|
||||||
json.NewEncoder(w).Encode(users)
|
json.NewEncoder(w).Encode(users)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewSHA1Hash(n ...int) string {
|
||||||
|
noRandomCharacters := 32
|
||||||
|
if len(n) > 0 {
|
||||||
|
noRandomCharacters = n[0]
|
||||||
|
}
|
||||||
|
randString := RandomString(noRandomCharacters)
|
||||||
|
hash := sha1.New()
|
||||||
|
hash.Write([]byte(randString))
|
||||||
|
bs := hash.Sum(nil)
|
||||||
|
return fmt.Sprintf("%x", bs)
|
||||||
|
}
|
||||||
|
|
||||||
|
var characterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||||
|
|
||||||
|
// RandomString generates a random string of n length
|
||||||
|
func RandomString(n int) string {
|
||||||
|
b := make([]rune, n)
|
||||||
|
for i := range b {
|
||||||
|
b[i] = characterRunes[rand.Intn(len(characterRunes))]
|
||||||
|
}
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
|
29
build.sh
29
build.sh
|
@ -22,9 +22,26 @@ cd build
|
||||||
ls
|
ls
|
||||||
cd ../
|
cd ../
|
||||||
|
|
||||||
mv build/$APP-darwin-10.6-amd64 build/$APP-osx-x64
|
mv build/$APP-darwin-10.6-amd64 build/$APP
|
||||||
mv build/$APP-darwin-10.6-386 build/$APP-osx-x32
|
tar -czvf build/$APP-osx-x64.tar.gz build/$APP
|
||||||
mv build/$APP-linux-amd64 build/$APP-linux-x64
|
|
||||||
mv build/$APP-linux-386 build/$APP-linux-x32
|
mv build/$APP-darwin-10.6-386 build/$APP
|
||||||
mv build/$APP-windows-6.0-amd64.exe build/$APP-windows-x64.exe
|
tar -czvf build/$APP-osx-x32.tar.gz build/$APP
|
||||||
mv build/$APP-linux-arm-7 build/$APP-linux-arm7
|
|
||||||
|
mv build/$APP-linux-amd64 build/$APP
|
||||||
|
tar -czvf build/$APP-linux-x64.tar.gz build/$APP
|
||||||
|
|
||||||
|
mv build/$APP-linux-386 build/$APP
|
||||||
|
tar -czvf build/$APP-linux-x32.tar.gz build/$APP
|
||||||
|
|
||||||
|
mv build/$APP-windows-6.0-amd64.exe build/$APP.exe
|
||||||
|
zip $APP-windows-x64.zip build/$APP.exe
|
||||||
|
|
||||||
|
mv build/$APP-linux-arm-7 build/$APP
|
||||||
|
tar -czvf build/$APP-linux-arm7.tar.gz build/$APP
|
||||||
|
|
||||||
|
mv build/$APP-linux-arm64 build/$APP
|
||||||
|
tar -czvf build/$APP-linux-arm64.tar.gz build/$APP
|
||||||
|
|
||||||
|
mv build/$APP-linux-alpine build/$APP
|
||||||
|
tar -czvf build/$APP-linux-alpine.tar.gz build/$APP
|
|
@ -1,6 +1,11 @@
|
||||||
var currentLocation = window.location;
|
var currentLocation = window.location;
|
||||||
$("#domain_input").val(currentLocation.origin);
|
$("#domain_input").val(currentLocation.origin);
|
||||||
|
|
||||||
|
function forceLower(strInput)
|
||||||
|
{
|
||||||
|
strInput.value=strInput.value.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
$('select#database_type').on('change', function(){
|
$('select#database_type').on('change', function(){
|
||||||
var selected = $('#database_type option:selected').val();
|
var selected = $('#database_type option:selected').val();
|
||||||
if (selected=="sqlite") {
|
if (selected=="sqlite") {
|
||||||
|
|
|
@ -78,7 +78,7 @@
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="formGroupExampleInput">Admin Username</label>
|
<label for="formGroupExampleInput">Admin Username</label>
|
||||||
<input type="text" name="username" class="form-control" value="{{.Username}}" id="formGroupExampleInput" value="admin" placeholder="admin" required>
|
<input type="text" name="username" class="form-control" value="{{.Username}}" id="formGroupExampleInput" value="admin" placeholder="admin" onkeyup="return forceLower(this);" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|
70
services.go
70
services.go
|
@ -1,10 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha1"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
"upper.io/db.v3"
|
"upper.io/db.v3"
|
||||||
|
@ -109,63 +107,28 @@ type DateScan struct {
|
||||||
|
|
||||||
func (s *Service) GraphData() string {
|
func (s *Service) GraphData() string {
|
||||||
var d []DateScan
|
var d []DateScan
|
||||||
|
|
||||||
since := time.Now().Add(time.Hour*-12 + time.Minute*0 + time.Second*0)
|
since := time.Now().Add(time.Hour*-12 + time.Minute*0 + time.Second*0)
|
||||||
|
|
||||||
sql := fmt.Sprintf("SELECT date_trunc('minute', created_at), AVG(latency)*1000 AS value FROM hits WHERE service=%v AND created_at > '%v' GROUP BY 1 ORDER BY date_trunc ASC;", s.Id, since.Format(time.RFC3339))
|
sql := fmt.Sprintf("SELECT date_trunc('minute', created_at), AVG(latency)*1000 AS value FROM hits WHERE service=%v AND created_at > '%v' GROUP BY 1 ORDER BY date_trunc ASC;", s.Id, since.Format(time.RFC3339))
|
||||||
|
|
||||||
fmt.Println(sql)
|
|
||||||
|
|
||||||
dated, err := dbSession.Query(db.Raw(sql))
|
dated, err := dbSession.Query(db.Raw(sql))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
fmt.Println(err)
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
for dated.Next() {
|
for dated.Next() {
|
||||||
|
|
||||||
var gd DateScan
|
var gd DateScan
|
||||||
|
|
||||||
var ff float64
|
var ff float64
|
||||||
|
|
||||||
dated.Scan(&gd.CreatedAt, &ff)
|
dated.Scan(&gd.CreatedAt, &ff)
|
||||||
gd.Value = int64(ff)
|
gd.Value = int64(ff)
|
||||||
|
|
||||||
d = append(d, gd)
|
d = append(d, gd)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
data, err := json.Marshal(d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
fmt.Println(err)
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
//
|
|
||||||
//hits, _ := s.LimitedHits()
|
|
||||||
//for _, h := range hits {
|
|
||||||
// val := h.CreatedAt
|
|
||||||
// o := GraphJson{
|
|
||||||
// X: val.String(),
|
|
||||||
// Y: h.Latency * 1000,
|
|
||||||
// }
|
|
||||||
// d = append(d, o)
|
|
||||||
//}
|
|
||||||
data, _ := json.Marshal(d)
|
|
||||||
return string(data)
|
return string(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
//func (s *Service) GraphData() string {
|
|
||||||
// var d []GraphJson
|
|
||||||
// hits, _ := s.LimitedHits()
|
|
||||||
// for _, h := range hits {
|
|
||||||
// val := h.CreatedAt
|
|
||||||
// o := GraphJson{
|
|
||||||
// X: val.String(),
|
|
||||||
// Y: h.Latency * 1000,
|
|
||||||
// }
|
|
||||||
// d = append(d, o)
|
|
||||||
// }
|
|
||||||
// data, _ := json.Marshal(d)
|
|
||||||
// return string(data)
|
|
||||||
//}
|
|
||||||
|
|
||||||
func (s *Service) AvgUptime() string {
|
func (s *Service) AvgUptime() string {
|
||||||
failed, _ := s.TotalFailures()
|
failed, _ := s.TotalFailures()
|
||||||
total, _ := s.TotalHits()
|
total, _ := s.TotalHits()
|
||||||
|
@ -234,26 +197,3 @@ func CountOnline() int {
|
||||||
}
|
}
|
||||||
return amount
|
return amount
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSHA1Hash(n ...int) string {
|
|
||||||
noRandomCharacters := 32
|
|
||||||
if len(n) > 0 {
|
|
||||||
noRandomCharacters = n[0]
|
|
||||||
}
|
|
||||||
randString := RandomString(noRandomCharacters)
|
|
||||||
hash := sha1.New()
|
|
||||||
hash.Write([]byte(randString))
|
|
||||||
bs := hash.Sum(nil)
|
|
||||||
return fmt.Sprintf("%x", bs)
|
|
||||||
}
|
|
||||||
|
|
||||||
var characterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
|
||||||
|
|
||||||
// RandomString generates a random string of n length
|
|
||||||
func RandomString(n int) string {
|
|
||||||
b := make([]rune, n)
|
|
||||||
for i := range b {
|
|
||||||
b[i] = characterRunes[rand.Intn(len(characterRunes))]
|
|
||||||
}
|
|
||||||
return string(b)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue