Skip to content

Commit

Permalink
fix(handlers, public): update timestamp logging to use Unix milliseconds
Browse files Browse the repository at this point in the history
- Changed timestamp logging in the HandleAPIRequest function to use Unix milliseconds for improved precision.
- Updated the recent requests display in the HTML to correctly parse and format timestamps using the new millisecond format, enhancing readability and consistency in metrics presentation.
  • Loading branch information
woodchen-ink committed Nov 30, 2024
1 parent 0a41beb commit f92b838
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (h *Handlers) HandleAPIRequest(w http.ResponseWriter, r *http.Request) {

if len(pathSegments) < 2 {
monitoring.LogRequest(monitoring.RequestLog{
Time: time.Now().Unix(),
Time: time.Now().UnixMilli(),
Path: r.URL.Path,
Method: r.Method,
StatusCode: http.StatusNotFound,
Expand All @@ -76,7 +76,7 @@ func (h *Handlers) HandleAPIRequest(w http.ResponseWriter, r *http.Request) {

if !ok {
monitoring.LogRequest(monitoring.RequestLog{
Time: time.Now().Unix(),
Time: time.Now().UnixMilli(),
Path: r.URL.Path,
Method: r.Method,
StatusCode: http.StatusNotFound,
Expand All @@ -92,7 +92,7 @@ func (h *Handlers) HandleAPIRequest(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Printf("Error fetching CSV content: %v", err)
monitoring.LogRequest(monitoring.RequestLog{
Time: time.Now().Unix(),
Time: time.Now().UnixMilli(),
Path: r.URL.Path,
Method: r.Method,
StatusCode: http.StatusInternalServerError,
Expand All @@ -106,7 +106,7 @@ func (h *Handlers) HandleAPIRequest(w http.ResponseWriter, r *http.Request) {

if len(selector.URLs) == 0 {
monitoring.LogRequest(monitoring.RequestLog{
Time: time.Now().Unix(),
Time: time.Now().UnixMilli(),
Path: r.URL.Path,
Method: r.Method,
StatusCode: http.StatusNotFound,
Expand All @@ -124,7 +124,7 @@ func (h *Handlers) HandleAPIRequest(w http.ResponseWriter, r *http.Request) {

duration := time.Since(start)
monitoring.LogRequest(monitoring.RequestLog{
Time: time.Now().Unix(),
Time: time.Now().UnixMilli(),
Path: r.URL.Path,
Method: r.Method,
StatusCode: http.StatusFound,
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ <h2>📊 接口调用次数 <span class="refresh-icon">🔄</span></h2>
// 最近请求
const recentRequestsHtml = metrics.recent_requests.map(req => `
<tr>
<td>${new Date(req.time * 1000).toLocaleString()}</td>
<td>${new Date(req.time).toLocaleString()}</td>
<td>${req.path}</td>
<td>${req.method}</td>
<td>${req.status_code}</td>
Expand Down

0 comments on commit f92b838

Please sign in to comment.