Merge pull request 'Remove windows pidusage monitoring' (#24) from rmWinMonitor into trunk
continuous-integration/drone/push Build is pending
Details
continuous-integration/drone/push Build is pending
Details
Reviewed-on: #24
This commit is contained in:
commit
e6c184df4e
10
README.md
10
README.md
|
@ -1,5 +1,15 @@
|
||||||
# Cwtch Server
|
# Cwtch Server
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
Pretty straight forward:
|
||||||
|
- build the app in `app/` with `go build`
|
||||||
|
- build the docker container in `docker/` with `docker build . -t openpriv/server`
|
||||||
|
|
||||||
|
### Windows
|
||||||
|
|
||||||
|
The server package relies on sqlite which in turn requires the use of CGO. As per [this issue](https://github.com/golang/go/issues/12029) that means [TDM-GCC](https://jmeubank.github.io/tdm-gcc/download/) is required to be installed and used to compile on Windows
|
||||||
|
|
||||||
## Running
|
## Running
|
||||||
|
|
||||||
- cd app
|
- cd app
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/struCoder/pidusage"
|
"github.com/struCoder/pidusage"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -31,8 +32,8 @@ type Monitors struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start initializes a Monitors's monitors
|
// Start initializes a Monitors's monitors
|
||||||
func (mp *Monitors) Start(ts tapir.Service, configDir string, log bool) {
|
func (mp *Monitors) Start(ts tapir.Service, configDir string, doLogging bool) {
|
||||||
mp.log = log
|
mp.log = doLogging
|
||||||
mp.configDir = configDir
|
mp.configDir = configDir
|
||||||
mp.starttime = time.Now()
|
mp.starttime = time.Now()
|
||||||
mp.breakChannel = make(chan bool)
|
mp.breakChannel = make(chan bool)
|
||||||
|
@ -48,18 +49,36 @@ func (mp *Monitors) Start(ts tapir.Service, configDir string, log bool) {
|
||||||
})
|
})
|
||||||
|
|
||||||
var pidUsageLock sync.Mutex
|
var pidUsageLock sync.Mutex
|
||||||
|
// pidusage doesn't support windows
|
||||||
|
if runtime.GOOS != "windows" {
|
||||||
mp.CPU = NewMonitorHistory(Percent, Average, func() float64 {
|
mp.CPU = NewMonitorHistory(Percent, Average, func() float64 {
|
||||||
pidUsageLock.Lock()
|
pidUsageLock.Lock()
|
||||||
defer pidUsageLock.Unlock()
|
defer pidUsageLock.Unlock()
|
||||||
sysInfo, _ := pidusage.GetStat(os.Getpid())
|
sysInfo, err := pidusage.GetStat(os.Getpid())
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("pidusage.GetStat failed with: %s", err)
|
||||||
|
return 0.0
|
||||||
|
}
|
||||||
return float64(sysInfo.CPU)
|
return float64(sysInfo.CPU)
|
||||||
})
|
})
|
||||||
mp.Memory = NewMonitorHistory(MegaBytes, Average, func() float64 {
|
mp.Memory = NewMonitorHistory(MegaBytes, Average, func() float64 {
|
||||||
pidUsageLock.Lock()
|
pidUsageLock.Lock()
|
||||||
defer pidUsageLock.Unlock()
|
defer pidUsageLock.Unlock()
|
||||||
sysInfo, _ := pidusage.GetStat(os.Getpid())
|
sysInfo, err := pidusage.GetStat(os.Getpid())
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("pidusage.GetStat failed with: %s", err)
|
||||||
|
return 0.0
|
||||||
|
}
|
||||||
return float64(sysInfo.Memory)
|
return float64(sysInfo.Memory)
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
mp.CPU = NewMonitorHistory(Percent, Average, func() float64 {
|
||||||
|
return 0.0
|
||||||
|
})
|
||||||
|
mp.Memory = NewMonitorHistory(MegaBytes, Average, func() float64 {
|
||||||
|
return 0.0
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: replace with ts.
|
// TODO: replace with ts.
|
||||||
mp.ClientConns = NewMonitorHistory(Count, Average, func() float64 { return float64(ts.Metrics().ConnectionCount) })
|
mp.ClientConns = NewMonitorHistory(Count, Average, func() float64 { return float64(ts.Metrics().ConnectionCount) })
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package metrics
|
||||||
|
|
||||||
|
import (
|
||||||
|
tor2 "git.openprivacy.ca/cwtch.im/tapir/networks/tor"
|
||||||
|
"git.openprivacy.ca/openprivacy/log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMonitors(t *testing.T) {
|
||||||
|
log.SetLevel(log.LevelInfo)
|
||||||
|
os.RemoveAll("testLog")
|
||||||
|
os.Mkdir("testLog", 0700)
|
||||||
|
service := new(tor2.BaseOnionService)
|
||||||
|
mp := Monitors{}
|
||||||
|
mp.Start(service, "testLog", true)
|
||||||
|
log.Infof("sleeping for minute to give to for monitors to trigger...")
|
||||||
|
// wait a minute for it to trigger
|
||||||
|
time.Sleep(62 * time.Second)
|
||||||
|
|
||||||
|
// it didn't segfault? that's good, did it create a log file?
|
||||||
|
if _, err := os.Stat(filepath.Join("testLog", "serverMonitorReport.txt")); err != nil {
|
||||||
|
t.Errorf("serverMonitorReport.txt not generated")
|
||||||
|
}
|
||||||
|
|
||||||
|
mp.Stop()
|
||||||
|
os.RemoveAll("testLog")
|
||||||
|
}
|
Loading…
Reference in New Issue