add stats page
This commit is contained in:
parent
3ace323b48
commit
84a69f25b4
@ -112,6 +112,95 @@ func main() {
|
|||||||
`, count)
|
`, count)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
mux.HandleFunc("/stats", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("content-type", "text/html")
|
||||||
|
|
||||||
|
// Query the number of events for each kind, sorted by kind
|
||||||
|
rows, err := db.DB.Query("SELECT kind, COUNT(*) FROM event GROUP BY kind ORDER BY kind")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error querying event kinds: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
stats := make(map[string]int)
|
||||||
|
for rows.Next() {
|
||||||
|
var kind string
|
||||||
|
var count int
|
||||||
|
if err := rows.Scan(&kind, &count); err != nil {
|
||||||
|
fmt.Printf("Error scanning row: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
stats[kind] = count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Improved HTML content for stats
|
||||||
|
fmt.Fprintf(w, `
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Scrapestr Relay Stats</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
background-color: #f4f4f4;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
background-color: #fff;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
table {
|
||||||
|
width: 100%%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
th, td {
|
||||||
|
padding: 10px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
}
|
||||||
|
th {
|
||||||
|
background-color: #f4f4f4;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>Event Stats</h1>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Kind</th>
|
||||||
|
<th>Count</th>
|
||||||
|
</tr>
|
||||||
|
`)
|
||||||
|
for kind, count := range stats {
|
||||||
|
fmt.Fprintf(w, `
|
||||||
|
<tr>
|
||||||
|
<td>%s</td>
|
||||||
|
<td>%d</td>
|
||||||
|
</tr>
|
||||||
|
`, kind, count)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, `
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`)
|
||||||
|
})
|
||||||
|
|
||||||
fmt.Println("running on :3334")
|
fmt.Println("running on :3334")
|
||||||
http.ListenAndServe(":3334", relay)
|
http.ListenAndServe(":3334", relay)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user