2017-06-12 14:12:03 +00:00
|
|
|
package collector
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
|
|
|
|
"github.com/bcicen/ctop/logging"
|
2017-06-27 16:21:16 +00:00
|
|
|
"github.com/bcicen/ctop/models"
|
2017-06-12 14:12:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var log = logging.Init()
|
|
|
|
|
2017-06-27 17:18:17 +00:00
|
|
|
type LogCollector interface {
|
2017-07-04 12:32:25 +00:00
|
|
|
Stream() chan models.Log
|
2017-06-27 17:18:17 +00:00
|
|
|
Stop()
|
|
|
|
}
|
|
|
|
|
2017-06-27 16:21:16 +00:00
|
|
|
type Collector interface {
|
|
|
|
Stream() chan models.Metrics
|
2017-06-27 17:18:17 +00:00
|
|
|
Logs() LogCollector
|
2017-06-27 16:21:16 +00:00
|
|
|
Running() bool
|
|
|
|
Start()
|
|
|
|
Stop()
|
|
|
|
}
|
|
|
|
|
2017-06-12 14:12:03 +00:00
|
|
|
func round(num float64) int {
|
|
|
|
return int(num + math.Copysign(0.5, num))
|
|
|
|
}
|
|
|
|
|
|
|
|
// return rounded percentage
|
|
|
|
func percent(val float64, total float64) int {
|
|
|
|
if total <= 0 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return round((val / total) * 100)
|
|
|
|
}
|