-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.go
138 lines (119 loc) · 2.64 KB
/
status.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* Copyright 2019 Insolar Technologies
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package metrics
import (
"bytes"
"fmt"
"html/template"
"io"
"net/http"
"time"
"github.com/insolar/insolar/version"
)
var statusTmpl = `
<html>
<head>
<title>_status page</title>
<style>
* {
box-sizing: border-box;
}
h1 {
text-transform: uppercase;
}
section {
width: 100%;
border: 1px solid blue;
}
section header {
text-transform:uppercase;
width: 100%;
height: 48px;
padding: 0 12px;
line-height: 48px;
font-size: 24px;
background-color:blue;
color: whitesmoke;
}
dl {
display: grid;
grid-template-columns: 200px 1fr;
grid-template-rows: 1fr;
}
dl dt {
grid-column: 1;
font-weight: bold;
text-transform: capitalize;
text-align: right;
}
dl dd {
grid-column: 2;
}
</style>
</head>
<body>
<h1>STATUS</h1>
<h2>Build info</h2>
<pre>
{{ .VersionInfo }}
</pre>
<section>
<header>General</header>
<div class="content">
<dl>
<dt>Uptime:</dt> <dd>{{ .Uptime }}</dd>
<dt>metrics:</dt> <dd><a href="/metrics">/metrics</a></dd>
<dt>pprof:</dt> <dd><a href="/debug/pprof">/debug/pprof</a></dd>
<dt>rpcz:</dt> <dd> <a href="/debug/rpcz">/debug/rpcz</a></dd>
<dt>tracez:</dt> <dd><a href="/debug/tracez">/debug/tracez</a></dd>
</dl>
</div>
</section>
</body>
</html>
`
var parsedStatusTmpl = template.Must(template.New("proc_status").Parse(string(statusTmpl)))
type procStatus struct {
StartTime time.Time
}
func newProcStatus() *procStatus {
info := &procStatus{
StartTime: time.Now(),
}
return info
}
func (ps *procStatus) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var b bytes.Buffer
err := parsedStatusTmpl.Execute(&b, struct {
VersionInfo string
Uptime string
}{
VersionInfo: version.GetFullVersion(),
Uptime: fmt.Sprintf("%v", time.Since(ps.StartTime)),
})
if err != nil {
http.Error(w, fmt.Sprintln("Template error:", err),
http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "text/html")
_, err = io.Copy(w, &b)
if err != nil {
http.Error(w, fmt.Sprintln("Copy error:", err),
http.StatusInternalServerError)
return
}
}