aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/elastic/gosigar/sigar_freebsd.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/sigar_freebsd.go
parentec96216d1696bca2671bb7d043ba6af02c20738d (diff)
downloaddexon-05ade19302357eba6a24348f31df140ce0eca326.tar
dexon-05ade19302357eba6a24348f31df140ce0eca326.tar.gz
dexon-05ade19302357eba6a24348f31df140ce0eca326.tar.bz2
dexon-05ade19302357eba6a24348f31df140ce0eca326.tar.lz
dexon-05ade19302357eba6a24348f31df140ce0eca326.tar.xz
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/sigar_freebsd.go')
-rw-r--r--vendor/github.com/elastic/gosigar/sigar_freebsd.go108
1 files changed, 108 insertions, 0 deletions
diff --git a/vendor/github.com/elastic/gosigar/sigar_freebsd.go b/vendor/github.com/elastic/gosigar/sigar_freebsd.go
new file mode 100644
index 000000000..602b4a0aa
--- /dev/null
+++ b/vendor/github.com/elastic/gosigar/sigar_freebsd.go
@@ -0,0 +1,108 @@
+// Copied and modified from sigar_linux.go.
+
+package gosigar
+
+import (
+ "io/ioutil"
+ "strconv"
+ "strings"
+ "unsafe"
+)
+
+/*
+#include <sys/param.h>
+#include <sys/mount.h>
+#include <sys/ucred.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <time.h>
+*/
+import "C"
+
+func init() {
+ system.ticks = uint64(C.sysconf(C._SC_CLK_TCK))
+
+ Procd = "/compat/linux/proc"
+
+ getLinuxBootTime()
+}
+
+func getMountTableFileName() string {
+ return Procd + "/mtab"
+}
+
+func (self *Uptime) Get() error {
+ ts := C.struct_timespec{}
+
+ if _, err := C.clock_gettime(C.CLOCK_UPTIME, &ts); err != nil {
+ return err
+ }
+
+ self.Length = float64(ts.tv_sec) + 1e-9*float64(ts.tv_nsec)
+
+ return nil
+}
+
+func (self *FDUsage) Get() error {
+ val := C.uint32_t(0)
+ sc := C.size_t(4)
+
+ name := C.CString("kern.openfiles")
+ _, err := C.sysctlbyname(name, unsafe.Pointer(&val), &sc, nil, 0)
+ C.free(unsafe.Pointer(name))
+ if err != nil {
+ return err
+ }
+ self.Open = uint64(val)
+
+ name = C.CString("kern.maxfiles")
+ _, err = C.sysctlbyname(name, unsafe.Pointer(&val), &sc, nil, 0)
+ C.free(unsafe.Pointer(name))
+ if err != nil {
+ return err
+ }
+ self.Max = uint64(val)
+
+ self.Unused = self.Max - self.Open
+
+ return nil
+}
+
+func (self *ProcFDUsage) Get(pid int) error {
+ err := readFile("/proc/"+strconv.Itoa(pid)+"/rlimit", func(line string) bool {
+ if strings.HasPrefix(line, "nofile") {
+ fields := strings.Fields(line)
+ if len(fields) == 3 {
+ self.SoftLimit, _ = strconv.ParseUint(fields[1], 10, 64)
+ self.HardLimit, _ = strconv.ParseUint(fields[2], 10, 64)
+ }
+ return false
+ }
+ return true
+ })
+ if err != nil {
+ return err
+ }
+
+ // linprocfs only provides this information for this process (self).
+ fds, err := ioutil.ReadDir(procFileName(pid, "fd"))
+ if err != nil {
+ return err
+ }
+ self.Open = uint64(len(fds))
+
+ return nil
+}
+
+func parseCpuStat(self *Cpu, line string) error {
+ fields := strings.Fields(line)
+
+ self.User, _ = strtoull(fields[1])
+ self.Nice, _ = strtoull(fields[2])
+ self.Sys, _ = strtoull(fields[3])
+ self.Idle, _ = strtoull(fields[4])
+ return nil
+}