Skip to content

Commit

Permalink
fmt import path, modify control and debug scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
niean committed Aug 24, 2015
1 parent 34f69f7 commit 4d7484e
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 111 deletions.
27 changes: 24 additions & 3 deletions README.md
@@ -1,9 +1,30 @@
# anteye
anteye is a small and simple monitor system. anteye should monitor cluster less then 50 instances. it can send notice msgs via **mail****sms** or **callback**.
anteye is a small and simple monitor system. anteye should monitor cluster less then 50 instances. it can send notice msgs via **mail****sms** or **callback(TODO)**.
we suggest you deploy more than one anteye instances in the production environment.

## install
install from src

You can install anteye from the latest [release](),

```bash
# download release
wget -q

# config, change configs as you like
mv cfg.example.json cfg.json
vim cfg.json
...

# start
./control start

# stop
./control stop

```

Or you can install anteye from scratch

```bash
# download src
git clone git@github.com:niean/anteys.git
Expand Down Expand Up @@ -54,7 +75,7 @@ monitor
```

## interface
anteye sends alarm msgs via http interfaces. these interfaces defined as followings:
anteye sends msgs via http interfaces. these interfaces defined as followings:

```bash
# sms interface
Expand Down
14 changes: 7 additions & 7 deletions cfg.example.json
Expand Up @@ -6,12 +6,12 @@
},
"mail" : {
"enable": true,
"url" : "http://tycloudstart.com:1986/mail/sender",
"receivers" : "nieanan@xiaomi.com,nieanan3602@163.com"
"url" : "http://mail.server:1986/mail/sender",
"receivers" : "nieanan@xiaomi.com,niean.sail@gmail.com"
},
"sms" : {
"enable": true,
"url" : "http://tycloudstart.com:1986/sms/sender",
"enable": false,
"url" : "http://sms.server:1986/sms/sender",
"receivers" : "18001163885,13811685238"
},
"callback" : {
Expand All @@ -20,9 +20,9 @@
},
"monitor" : {
"cluster" : [
"transfer,127.0.0.1:6060/health",
"task,127.0.0.1:16269/health",
"graph,127.0.0.1:6071/health"
"transfer,test.hostname01:6060/health",
"task,test.hostname01:8002/health",
"graph,test.hostname01:6071/health"
]
}
}
142 changes: 81 additions & 61 deletions control
@@ -1,5 +1,5 @@
#!/bin/bash
workspace=$(cd $(dirname $0)/; pwd)
workspace=$(cd $(dirname $0) && pwd)
cd $workspace

module=anteye
Expand All @@ -8,80 +8,92 @@ conf=cfg.json
pidfile=var/app.pid
logfile=var/app.log

mkdir -p var
mkdir -p var &>/dev/null


## build & pack
function build() {
commit=$(git log -1 --pretty=%h)
cat <<EOF > ./g/git.go
package g
const (
COMMIT = "$commit"
)
EOF
go build -o $app main.go
sc=$?
if [ $sc -ne 0 ];then
echo "build error"
exit $sc
else
echo -n "build ok, vsn="
./$app -v
fi
}

function pack() {
build
git log -1 --pretty=%h > gitversion
version=`./$app -v`
tar zcvf $app-$version.tar.gz control $app cfg.example.json gitversion ./test/debug
rm -f gitversion &>/dev/null
}

function packbin() {
build
git log -1 --pretty=%h > gitversion
version=`./$app -v`
tar zcvf $app-bin-$version.tar.gz $app gitversion
rm -f gitversion &>/dev/null
}

## opt
function start() {
check_pid
running=$?
if [ $running -gt 0 ];then
echo -n "$app now is running already, pid="
echo -n "started, pid="
cat $pidfile
return 1
fi

nohup ./$app -c $conf &> $logfile &
echo $! > $pidfile
echo "$app started..., pid=$!"
echo "start ok, pid=$!"
}

function stop() {
pid=`cat $pidfile`
kill -9 $pid
echo "$app stoped..."
echo "stoped"
}

function restart() {
stop
sleep 1
start
}

## other
function status() {
check_pid
running=$?
if [ $running -gt 0 ];then
echo -n "$app now is running, pid="
echo -n "running, pid="
cat $pidfile
else
echo "$app is stoped"
echo "stoped"
fi
}

function show_version() {
function version() {
./$app -vg
}

## build
function tailf() {
tail -f $logfile
}

function build() {
commit=$(git log -1 --pretty=%h)
cat <<EOF > ./g/git.go
package g
const (
COMMIT = "$commit"
)
EOF
go build -o $app main.go
show_version
}

function pack() {
build
git log -1 --pretty=%h > gitversion
version=`./$app -v`
tar zcvf $app-$version.tar.gz $app cfg.example.json gitversion control ./test
}

function packbin() {
build
git log -1 --pretty=%h > gitversion
version=`./$app -v`
tar zcvf $app-bin-$version.tar.gz $app gitversion
}

## help
function help() {
echo "$0 build|pack|packbin|start|stop|restart|status|tail"
}

## internal
function check_pid() {
if [ -f $pidfile ];then
Expand All @@ -94,37 +106,45 @@ function check_pid() {
return 0
}

## __main__
## usage
function usage() {
echo "$0 build|pack|packbin|start|stop|restart|status|tail|version"
}

## main
action=$1
case $action in
"start")
## build
"build" )
build
;;
"pack" )
pack
;;
"packbin" )
packbin
;;
## opt
"start" )
start
;;
"stop")
"stop" )
stop
;;
"restart")
stop && sleep 1 && start
"restart" )
restart
;;
"status")
## other
"status" )
status
;;
"tail")
tailf
;;
"version")
show_version
;;
"build")
build
;;
"pack")
pack
"version" )
version
;;
"packbin")
packbin
"tail" )
tailf
;;
*)
help
* )
usage
;;
esac
4 changes: 3 additions & 1 deletion g/g.go
Expand Up @@ -7,8 +7,10 @@ import (

// changelog:
// 0.0.1: init project
// 0.0.2: fmt import path, modify control and debug scripts

const (
VERSION = "0.0.1"
VERSION = "0.0.2"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion g/git.go
@@ -1,4 +1,4 @@
package g
const (
COMMIT = "08f9111"
COMMIT = "34f69f7"
)
3 changes: 2 additions & 1 deletion http/common.go
Expand Up @@ -2,9 +2,10 @@ package http

import (
"fmt"
"github.com/niean/anteye/g"
"github.com/toolkits/file"
"net/http"

"github.com/niean/anteye/g"
)

func configCommonRoutes() {
Expand Down
5 changes: 3 additions & 2 deletions http/http.go
Expand Up @@ -2,9 +2,10 @@ package http

import (
"encoding/json"
"github.com/niean/anteye/g"
"log"
"net/http"

"github.com/niean/anteye/g"
)

type Dto struct {
Expand Down Expand Up @@ -40,7 +41,7 @@ func startHttpServer() {
MaxHeaderBytes: 1 << 30,
}

log.Println("http.startHttpServer, ok, listening ", addr)
log.Println("http.startHttpServer ok, listening ", addr)
log.Fatalln(s.ListenAndServe())
}

Expand Down
7 changes: 2 additions & 5 deletions http/proc_http.go
@@ -1,17 +1,14 @@
package http

import (
"github.com/niean/anteye/proc"
"net/http"

"github.com/niean/anteye/proc"
)

func configProcHttpRoutes() {
// counter
http.HandleFunc("/counter/all", func(w http.ResponseWriter, r *http.Request) {
RenderDataJson(w, proc.GetAll())
})
// TO BE DISCARDed
http.HandleFunc("/statistics/all", func(w http.ResponseWriter, r *http.Request) {
RenderDataJson(w, proc.GetAll())
})
}
3 changes: 2 additions & 1 deletion main.go
Expand Up @@ -3,11 +3,12 @@ package main
import (
"flag"
"fmt"
"os"

"github.com/niean/anteye/g"
"github.com/niean/anteye/http"
"github.com/niean/anteye/monitor"
"github.com/niean/anteye/proc"
"os"
)

func main() {
Expand Down
16 changes: 9 additions & 7 deletions monitor/monitor.go
Expand Up @@ -3,19 +3,21 @@ package monitor
import (
"bytes"
"fmt"
"github.com/niean/anteye/g"
"github.com/niean/anteye/proc"
ncron "github.com/niean/cron"
nmap "github.com/niean/gotools/container/nmap"
nhttpclient "github.com/niean/gotools/http/httpclient"
ntime "github.com/niean/gotools/time"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"sync"
"time"

ncron "github.com/niean/cron"
nmap "github.com/niean/gotools/container/nmap"
nhttpclient "github.com/niean/gotools/http/httpclient"
ntime "github.com/niean/gotools/time"

"github.com/niean/anteye/g"
"github.com/niean/anteye/proc"
)

var (
Expand All @@ -31,7 +33,7 @@ func Start() {
monitorCron.AddFuncCC(cronSpec, func() { monitor() }, 1)
monitorCron.Start()
go alarmJudge()
log.Println("monitor.Start, ok")
log.Println("monitor.Start ok")
}

// alarm judge
Expand Down

0 comments on commit 4d7484e

Please sign in to comment.