Permalink
Browse files

Make query logging (globally) configurable

  • Loading branch information...
abh committed Nov 13, 2016
1 parent 0aab8e6 commit 7b5172f98224f09ee03aa217b98baf7d003a284d
Showing with 36 additions and 220 deletions.
  1. +5 −2 README.md
  2. +5 −2 config.go
  3. +8 −0 dns/geodns.conf.sample
  4. +13 −1 geodns.go
  5. +3 −4 querylog/querylog.go
  6. +0 −207 querylog/querylog_easyjson.go
  7. +2 −4 server.go
View
@@ -144,10 +144,13 @@ with `max_hosts` 2 then .4 will be returned about 4 times more often than .1.
## Configuration file
The geodns.conf file allows you to specify a specific directory for the GeoIP
data files and enable posting metrics to StatHat. See the `geodns.conf.sample`
file for example configuration.
data files and other options. See the `geodns.conf.sample` file for example
configuration.
The global configuration file is not reloaded at runtime.
Most of the configuration is "per zone" and done in the zone .json files.
The zone configuration files are automatically reloaded when they change.
## Zone format
View
@@ -25,6 +25,11 @@ type AppConfig struct {
User string
Password string
}
QueryLog struct {
Path string
MaxSize int
Keep int
}
}
var Config = new(AppConfig)
@@ -50,8 +55,6 @@ func (conf *AppConfig) GeoIPDirectory() string {
func configWatcher(fileName string) {
configReader(fileName)
watcher, err := fsnotify.NewWatcher()
if err != nil {
fmt.Println(err)
View
@@ -7,6 +7,14 @@
;; Directory containing the GeoIP .dat database files
;directory=/usr/local/share/GeoIP/
[querylog]
;; directory to save query logs; disabled if not specified
path = log/queries.log
;; max size per file in megabytes before rotating (default 200)
; maxsize = 100
;; keep up to this many rotated log files (default 1)
; keep = 2
[stathat]
;; Add an API key to send query counts and other metrics to stathat
;apikey=abc123
View
@@ -29,6 +29,7 @@ import (
"strings"
"time"
"github.com/abh/geodns/querylog"
"github.com/pborman/uuid"
)
@@ -95,7 +96,6 @@ func main() {
}
srv := Server{}
srv.SetQueryLogger("log/queries.log")
if len(*flagLogFile) > 0 {
logToFileOpen(*flagLogFile)
@@ -155,11 +155,23 @@ func main() {
}()
}
// load geodns.conf config
configReader(configFileName)
// load (and re-load) zone data
go configWatcher(configFileName)
metrics := NewMetrics()
go metrics.Updater()
if qlc := Config.QueryLog; len(qlc.Path) > 0 {
ql, err := querylog.NewFileLogger(qlc.Path, qlc.MaxSize, qlc.Keep)
if err != nil {
log.Fatalf("Could not start file query logger: %s", err)
}
srv.SetQueryLogger(ql)
}
if *flaginter == "*" {
addrs, _ := net.InterfaceAddrs()
ips := make([]string, 0)
View
@@ -29,13 +29,12 @@ type FileLogger struct {
logger lumberjack.Logger
}
func NewFileLogger(filename string) (*FileLogger, error) {
func NewFileLogger(filename string, maxsize int, keep int) (*FileLogger, error) {
fl := &FileLogger{}
fl.logger = lumberjack.Logger{
Filename: filename,
MaxSize: 500, // megabytes
MaxBackups: 3,
MaxAge: 28, //days
MaxSize: maxsize, // megabytes
MaxBackups: keep,
}
return fl, nil
}

This file was deleted.

Oops, something went wrong.
View
@@ -18,10 +18,8 @@ func NewServer() *Server {
// Setup the QueryLogger. For now it only supports writing to a file (and all
// zones get logged to the same file).
func (srv *Server) SetQueryLogger(file string) error {
var err error
srv.queryLogger, err = querylog.NewFileLogger(file)
return err
func (srv *Server) SetQueryLogger(logger querylog.QueryLogger) {
srv.queryLogger = logger
}
func (srv *Server) setupServerFunc(Zone *Zone) func(dns.ResponseWriter, *dns.Msg) {

0 comments on commit 7b5172f

Please sign in to comment.