1
0
Fork 0
mirror of https://github.com/alice-lg/birdwatcher.git synced 2025-03-09 00:00:05 +01:00

Make cache ttl for bird responses a config option

For bird and bird6 you may add ttl to the respective config file sections.
See example config in this commit.
This allows to have individual ttls for the cache of bird cli output per daemon.
This commit is contained in:
Benedikt Rudolph 2018-04-12 11:37:02 +02:00
parent e4ec6591b9
commit 46356aa9eb
4 changed files with 9 additions and 3 deletions

View file

@ -49,7 +49,11 @@ func fromCache(key string) (Parsed, bool) {
}
func toCache(key string, val Parsed) {
val["ttl"] = time.Now().Add(10 * time.Minute)
var ttl int = 5
if ClientConf.CacheTtl > 0 {
ttl = ClientConf.CacheTtl
}
val["ttl"] = time.Now().Add(time.Duration(ttl) * time.Minute)
Cache.Lock()
Cache.m[key] = val
Cache.Unlock()

View file

@ -13,6 +13,7 @@ type BirdConfig struct {
Listen string
ConfigFilename string `toml:"config"`
BirdCmd string `toml:"birdc"`
CacheTtl int `toml:"ttl"`
}
type ParserConfig struct {

View file

@ -89,6 +89,7 @@ func PrintServiceInfo(conf *Config, birdConf bird.BirdConfig) {
log.Println("Starting Birdwatcher")
log.Println(" Using:", birdConf.BirdCmd)
log.Println(" Listen:", birdConf.Listen)
log.Println(" Cache TTL:", birdConf.CacheTtl)
// Endpoint Info
if len(conf.Server.AllowFrom) == 0 {

View file

@ -45,12 +45,13 @@ requests_per_minute = 10
listen = "0.0.0.0:29188"
config = "/etc/bird.conf"
birdc = "/sbin/birdc"
ttl = 5 # time to live (in minutes) for caching of cli output
[bird6]
listen = "0.0.0.0:29189"
config = "/etc/bird6.conf"
birdc = "/sbin/birdc6"
ttl = 5 # time to live (in minutes) for caching of cli output
[parser]
# Remove fields e.g. interface
@ -60,4 +61,3 @@ filter_fields = []
per_peer_tables = true
peer_protocol_prefix = 'ID'
pipe_protocol_prefix = 'P'