Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
b5b53b38
authored
2013-11-17 23:10:21 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add more feture in admin
1,增加QPS的限制 2,增加任务 3,增加healthcheck
1 parent
ea513002
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
128 additions
and
0 deletions
admin.go
admin/healthcheck.go
admin/statistics.go
admin/task.go
admin.go
View file @
b5b53b3
...
...
@@ -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 @
b5b53b3
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 @
b5b53b3
...
...
@@ -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 @
b5b53b3
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
Styling with
Markdown
is supported
Attach a file
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 post a comment