mirror of
https://github.com/sot-tech/mochi.git
synced 2026-06-11 23:43:29 -07:00
Disable prometheus fot in-memory store if period set to 0
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
// Package directory implements container which
|
||||
// checks if hash present in any of *.torrent file
|
||||
// placed in some directory
|
||||
package directory
|
||||
|
||||
import (
|
||||
@@ -40,9 +43,8 @@ func build(confBytes []byte) (container.Container, error) {
|
||||
dir = c.BlacklistPath
|
||||
}
|
||||
var w *dirwatch.Instance
|
||||
w, err = dirwatch.New(dir)
|
||||
if w, err = dirwatch.New(dir); err != nil {
|
||||
return nil, fmt.Errorf("unable to initialize directory watch")
|
||||
return nil, fmt.Errorf("unable to initialize directory watch: %v", err)
|
||||
}
|
||||
lst.watcher = w
|
||||
go func() {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Package list implements container with pre-defined
|
||||
// list of torrent hashes from config file
|
||||
package list
|
||||
|
||||
import (
|
||||
@@ -35,14 +37,13 @@ func build(confBytes []byte) (container.Container, error) {
|
||||
|
||||
hashList := c.Whitelist
|
||||
if l.Invert {
|
||||
l.Invert = true
|
||||
hashList = c.Blacklist
|
||||
}
|
||||
|
||||
for _, hashString := range hashList {
|
||||
hashinfo, err := hex.DecodeString(hashString)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("whitelist : invalid hash %s", hashString)
|
||||
return nil, fmt.Errorf("whitelist : invalid hash %s, %v", hashString, err)
|
||||
}
|
||||
if len(hashinfo) != 20 {
|
||||
return nil, fmt.Errorf("whitelist : hash %s is not 20 byes", hashString)
|
||||
|
||||
@@ -147,23 +147,27 @@ func New(provided Config) (storage.PeerStore, error) {
|
||||
}
|
||||
}()
|
||||
|
||||
// Start a goroutine for reporting statistics to Prometheus.
|
||||
ps.wg.Add(1)
|
||||
go func() {
|
||||
defer ps.wg.Done()
|
||||
t := time.NewTicker(cfg.PrometheusReportingInterval)
|
||||
for {
|
||||
select {
|
||||
case <-ps.closed:
|
||||
t.Stop()
|
||||
return
|
||||
case <-t.C:
|
||||
before := time.Now()
|
||||
ps.populateProm()
|
||||
log.Debug("storage: populateProm() finished", log.Fields{"timeTaken": time.Since(before)})
|
||||
if cfg.PrometheusReportingInterval > 0 {
|
||||
// Start a goroutine for reporting statistics to Prometheus.
|
||||
ps.wg.Add(1)
|
||||
go func() {
|
||||
defer ps.wg.Done()
|
||||
t := time.NewTicker(cfg.PrometheusReportingInterval)
|
||||
for {
|
||||
select {
|
||||
case <-ps.closed:
|
||||
t.Stop()
|
||||
return
|
||||
case <-t.C:
|
||||
before := time.Now()
|
||||
ps.populateProm()
|
||||
log.Debug("storage: populateProm() finished", log.Fields{"timeTaken": time.Since(before)})
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}()
|
||||
} else {
|
||||
log.Info("prometheus disabled because of zero reporting interval")
|
||||
}
|
||||
|
||||
return ps, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user