Do not use port 8618, it's a leftover from a time when we had two binaries.

Should fix 378 but needs testing from users having the problem since couldn't reproduce it here yet.
This commit is contained in:
Eugene Bujak
2018-10-17 18:55:27 +03:00
parent bdfb141d36
commit 5437a9d3a6
5 changed files with 22 additions and 196 deletions

View File

@@ -177,7 +177,9 @@ func setupPlugin(c *caddy.Controller) (*plug, error) {
if p.settings.QueryLogEnabled {
onceQueryLog.Do(func() {
go startQueryLogServer() // TODO: how to handle errors?
go periodicQueryLogRotate()
go periodicHourlyTopRotate()
go statsRotator()
})
}

View File

@@ -227,7 +227,7 @@ func (h *histogram) Collect(ch chan<- prometheus.Metric) {
// -----
// stats
// -----
func handleStats(w http.ResponseWriter, r *http.Request) {
func HandleStats(w http.ResponseWriter, r *http.Request) {
const numHours = 24
histrical := generateMapFromStats(&statistics.PerHour, 0, numHours)
// sum them up
@@ -299,7 +299,7 @@ func generateMapFromStats(stats *periodicStats, start int, end int) map[string]i
return result
}
func handleStatsHistory(w http.ResponseWriter, r *http.Request) {
func HandleStatsHistory(w http.ResponseWriter, r *http.Request) {
// handle time unit and prepare our time window size
now := time.Now()
timeUnitString := r.URL.Query().Get("time_unit")
@@ -378,6 +378,16 @@ func handleStatsHistory(w http.ResponseWriter, r *http.Request) {
}
}
func HandleStatsReset(w http.ResponseWriter, r *http.Request) {
purgeStats()
_, err := fmt.Fprintf(w, "OK\n")
if err != nil {
errortext := fmt.Sprintf("Couldn't write body: %s", err)
log.Println(errortext)
http.Error(w, errortext, http.StatusInternalServerError)
}
}
func clamp(value, low, high int) int {
if value < low {
return low

View File

@@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"log"
"net"
"net/http"
"os"
"path"
@@ -108,7 +107,7 @@ func logRequest(question *dns.Msg, answer *dns.Msg, result dnsfilter.Result, ela
}
}
func handleQueryLog(w http.ResponseWriter, r *http.Request) {
func HandleQueryLog(w http.ResponseWriter, r *http.Request) {
queryLogLock.RLock()
values := make([]*logEntry, len(queryLogCache))
copy(values, queryLogCache)
@@ -226,22 +225,6 @@ func handleQueryLog(w http.ResponseWriter, r *http.Request) {
}
}
func startQueryLogServer() {
listenAddr := net.JoinHostPort("127.0.0.1", queryLogAPIPort)
go periodicQueryLogRotate()
go periodicHourlyTopRotate()
go statsRotator()
http.HandleFunc("/querylog", handleQueryLog)
http.HandleFunc("/stats", handleStats)
http.HandleFunc("/stats_top", handleStatsTop)
http.HandleFunc("/stats_history", handleStatsHistory)
if err := http.ListenAndServe(listenAddr, nil); err != nil {
log.Fatalf("error in ListenAndServe: %s", err)
}
}
func trace(format string, args ...interface{}) {
pc := make([]uintptr, 10) // at least 1 entry needed
runtime.Callers(2, pc)

View File

@@ -268,7 +268,7 @@ func fillStatsFromQueryLog() error {
return nil
}
func handleStatsTop(w http.ResponseWriter, r *http.Request) {
func HandleStatsTop(w http.ResponseWriter, r *http.Request) {
domains := map[string]int{}
blocked := map[string]int{}
clients := map[string]int{}