aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/elastic/gosigar/concrete_sigar.go
diff options
context:
space:
mode:
authorKurkó Mihály <kurkomisi@users.noreply.github.com>2018-01-24 04:51:04 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-01-24 04:51:04 +0800
commit05ade19302357eba6a24348f31df140ce0eca326 (patch)
tree50010a6f94401d7cc1829d36ea99d342d2825d39 /vendor/github.com/elastic/gosigar/concrete_sigar.go
parentec96216d1696bca2671bb7d043ba6af02c20738d (diff)
downloaddexon-05ade19302357eba6a24348f31df140ce0eca326.tar.gz
dexon-05ade19302357eba6a24348f31df140ce0eca326.tar.zst
dexon-05ade19302357eba6a24348f31df140ce0eca326.zip
dashboard: CPU, memory, diskIO and traffic on the footer (#15950)
* dashboard: footer, deep state update * dashboard: resolve asset path * dashboard: prevent state update on every reconnection * dashboard: fix linter issue * dashboard, cmd: minor UI fix, include commit hash * dashboard: gitCommit renamed to commit * dashboard: move the geth version to the right, make commit optional * dashboard: memory, traffic and CPU on footer * dashboard: fix merge * dashboard: CPU, diskIO on footer * dashboard: rename variables, use group declaration * dashboard: docs
Diffstat (limited to 'vendor/github.com/elastic/gosigar/concrete_sigar.go')
-rw-r--r--vendor/github.com/elastic/gosigar/concrete_sigar.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/vendor/github.com/elastic/gosigar/concrete_sigar.go b/vendor/github.com/elastic/gosigar/concrete_sigar.go
new file mode 100644
index 000000000..685aa6ded
--- /dev/null
+++ b/vendor/github.com/elastic/gosigar/concrete_sigar.go
@@ -0,0 +1,83 @@
+package gosigar
+
+import (
+ "time"
+)
+
+type ConcreteSigar struct{}
+
+func (c *ConcreteSigar) CollectCpuStats(collectionInterval time.Duration) (<-chan Cpu, chan<- struct{}) {
+ // samplesCh is buffered to 1 value to immediately return first CPU sample
+ samplesCh := make(chan Cpu, 1)
+
+ stopCh := make(chan struct{})
+
+ go func() {
+ var cpuUsage Cpu
+
+ // Immediately provide non-delta value.
+ // samplesCh is buffered to 1 value, so it will not block.
+ cpuUsage.Get()
+ samplesCh <- cpuUsage
+
+ ticker := time.NewTicker(collectionInterval)
+
+ for {
+ select {
+ case <-ticker.C:
+ previousCpuUsage := cpuUsage
+
+ cpuUsage.Get()
+
+ select {
+ case samplesCh <- cpuUsage.Delta(previousCpuUsage):
+ default:
+ // Include default to avoid channel blocking
+ }
+
+ case <-stopCh:
+ return
+ }
+ }
+ }()
+
+ return samplesCh, stopCh
+}
+
+func (c *ConcreteSigar) GetLoadAverage() (LoadAverage, error) {
+ l := LoadAverage{}
+ err := l.Get()
+ return l, err
+}
+
+func (c *ConcreteSigar) GetMem() (Mem, error) {
+ m := Mem{}
+ err := m.Get()
+ return m, err
+}
+
+func (c *ConcreteSigar) GetSwap() (Swap, error) {
+ s := Swap{}
+ err := s.Get()
+ return s, err
+}
+
+func (c *ConcreteSigar) GetFileSystemUsage(path string) (FileSystemUsage, error) {
+ f := FileSystemUsage{}
+ err := f.Get(path)
+ return f, err
+}
+
+func (c *ConcreteSigar) GetFDUsage() (FDUsage, error) {
+ fd := FDUsage{}
+ err := fd.Get()
+ return fd, err
+}
+
+// GetRusage return the resource usage of the process
+// Possible params: 0 = RUSAGE_SELF, 1 = RUSAGE_CHILDREN, 2 = RUSAGE_THREAD
+func (c *ConcreteSigar) GetRusage(who int) (Rusage, error) {
+ r := Rusage{}
+ err := r.Get(who)
+ return r, err
+}