-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
main.go
64 lines (51 loc) · 1.47 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"time"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/middleware/monitor"
)
func main() {
app := iris.New()
// Initialize and start the monitor middleware.
m := monitor.New(monitor.Options{
RefreshInterval: 2 * time.Second,
ViewRefreshInterval: 2 * time.Second,
ViewTitle: "MyServer Monitor",
})
// Manually stop monitoring on CMD/CTRL+C.
iris.RegisterOnInterrupt(m.Stop)
// Serve the actual server's process and operating system statistics as JSON.
app.Post("/monitor", m.Stats)
// Render with the default page.
app.Get("/monitor", m.View)
/* You can protect the /monitor under an /admin group of routes
with basic authentication or any type authorization and authentication system.
Example Code:
app.Post("/monitor", myProtectMiddleware, m.Stats)
app.Get("/monitor", myProtectMiddleware, m.View)
*/
/* You can also get the OS statistics using the Holder.GetStats method.
Example Code:
for {
stats := m.Holder.GetStats()
fmt.Printf("%#+v\n", stats)
time.Sleep(time.Second)
}
Note that the same stats are also stored in the expvar metrics:
- pid_cpu
- pid_ram
- pid_conns
- os_cpu
- os_ram
- os_total_ram
- os_load_avg
- os_conns
Check https://github.com/iris-contrib/middleware/tree/master/expmetric
which can be integrated with datadog or other platforms.
*/
app.Get("/", handler)
app.Listen(":8080")
}
func handler(ctx iris.Context) {
ctx.WriteString("Test Index Handler")
}