fix(handlers, public): update timestamp logging to use Unix milliseconds

- 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.
This commit is contained in:
wood chen 2024-12-01 00:55:20 +08:00
parent 0a41bebf39
commit f92b8385d8
2 changed files with 6 additions and 6 deletions

View File

@ -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,
@ -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,
@ -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,
@ -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,
@ -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,

View File

@ -232,7 +232,7 @@
// 最近请求
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>