Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
b5b53b38
Commit
b5b53b38
authored
Nov 17, 2013
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more feture in admin
1,增加QPS的限制 2,增加任务 3,增加healthcheck
parent
ea513002
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
128 additions
and
0 deletions
+128
-0
admin.go
admin.go
+3
-0
healthcheck.go
admin/healthcheck.go
+43
-0
statistics.go
admin/statistics.go
+4
-0
task.go
admin/task.go
+78
-0
No files found.
admin.go
View file @
b5b53b38
...
...
@@ -32,6 +32,8 @@ func init() {
BeeAdminApp
.
Route
(
"/"
,
AdminIndex
)
BeeAdminApp
.
Route
(
"/qps"
,
QpsIndex
)
BeeAdminApp
.
Route
(
"/prof"
,
ProfIndex
)
BeeAdminApp
.
Route
(
"/healthcheck"
,
admin
.
Healthcheck
)
BeeAdminApp
.
Route
(
"/task"
,
admin
.
TaskStatus
)
FilterMonitorFunc
=
func
(
string
,
string
,
time
.
Duration
)
bool
{
return
true
}
}
...
...
@@ -42,6 +44,7 @@ func AdminIndex(rw http.ResponseWriter, r *http.Request) {
func
QpsIndex
(
rw
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
admin
.
StatisticsMap
.
GetMap
(
rw
)
}
func
ProfIndex
(
rw
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
r
.
ParseForm
()
command
:=
r
.
Form
.
Get
(
"command"
)
...
...
admin/healthcheck.go
0 → 100644
View file @
b5b53b38
package
admin
import
(
"fmt"
"net/http"
)
//type DatabaseCheck struct {
//}
//func (dc *DatabaseCheck) Check() error {
// if dc.isConnected() {
// return nil
// } else {
// return errors.New("can't connect database")
// }
//}
//AddHealthCheck("database",&DatabaseCheck{})
var
AdminCheckList
map
[
string
]
HealthChecker
type
HealthChecker
interface
{
Check
()
error
}
func
AddHealthCheck
(
name
string
,
hc
HealthChecker
)
{
AdminCheckList
[
name
]
=
hc
}
func
Healthcheck
(
rw
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
for
name
,
h
:=
range
AdminCheckList
{
if
err
:=
h
.
Check
();
err
!=
nil
{
fmt
.
Fprintf
(
rw
,
"%s : ok
\n
"
,
name
)
}
else
{
fmt
.
Fprintf
(
rw
,
"%s : %s
\n
"
,
name
,
err
.
Error
())
}
}
}
func
init
()
{
AdminCheckList
=
make
(
map
[
string
]
HealthChecker
)
}
admin/statistics.go
View file @
b5b53b38
...
...
@@ -18,6 +18,7 @@ type Statistics struct {
type
UrlMap
struct
{
lock
sync
.
RWMutex
LengthLimit
int
//limit the urlmap's length if it's equal to 0 there's no limit
urlmap
map
[
string
]
map
[
string
]
*
Statistics
}
...
...
@@ -47,6 +48,9 @@ func (m *UrlMap) AddStatistics(requestMethod, requestUrl, requestController stri
}
}
else
{
if
m
.
LengthLimit
>
0
&&
m
.
LengthLimit
<=
len
(
m
.
urlmap
)
{
return
}
methodmap
:=
make
(
map
[
string
]
*
Statistics
)
nb
:=
&
Statistics
{
RequestUrl
:
requestUrl
,
...
...
admin/task.go
View file @
b5b53b38
package
admin
import
(
"fmt"
"net/http"
)
var
AdminTaskList
map
[
string
]
Tasker
type
Tasker
interface
{
GetStatus
()
string
Run
()
error
}
type
Task
struct
{
Taskname
string
Spec
Schedule
Errlist
[]
map
[
uint64
]
string
//errtime:errinfo
ErrLimit
int
//max length for the errlist 0 stand for there' no limit
}
func
(
t
*
Task
)
GetStatus
()
string
{
return
""
}
func
(
t
*
Task
)
Run
()
error
{
return
nil
}
func
(
t
*
Task
)
SetCron
(
spec
string
)
{
}
type
Schedule
struct
{
Second
uint64
Minute
uint64
Hour
uint64
DOM
uint64
Month
uint64
DOW
uint64
}
func
StartTask
()
{
}
func
StopTask
()
{
}
func
AddTask
(
taskname
string
,
t
Tasker
)
{
AdminTaskList
[
taskname
]
=
t
}
func
TaskStatus
(
rw
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
for
tname
,
t
:=
range
AdminTaskList
{
fmt
.
Fprintf
(
rw
,
"%s:%s"
,
tname
,
t
.
GetStatus
())
}
}
//to run a Task by http from the querystring taskname
//url like /task?taskname=sendmail
func
RunTask
(
rw
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
req
.
ParseForm
()
taskname
:=
req
.
Form
.
Get
(
"taskname"
)
if
t
,
ok
:=
AdminTaskList
[
taskname
];
ok
{
err
:=
t
.
Run
()
if
err
!=
nil
{
fmt
.
Fprintf
(
rw
,
"%v"
,
err
)
}
fmt
.
Fprintf
(
rw
,
"%s run success,Now the Status is %s"
,
t
.
GetStatus
())
}
else
{
fmt
.
Fprintf
(
rw
,
"there's no task which named:%s"
,
taskname
)
}
}
func
init
()
{
AdminTaskList
=
make
(
map
[
string
]
Tasker
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment