* package system_ostent
Package =system_ostent= implements "=system_ostent=" input plugin.
It derived from "=system=" plugin with the following changes.
#+BEGIN_SRC sh :results raw
fst=../vendor/github.com/influxdata/telegraf/plugins/inputs/system/system.go
snd=../system_ostent/system_ostent.go
printf -- '--- %s\n' "$fst"
printf -- '+++ %s\n' "$snd"
diff --unified --ignore-all-space \
"$fst" \
"$snd" |
sed 1,2d # filenames printed already
exit $? # ......................................................... END HERE .
# bash syntax: have above: #+BEGIN_SRC bash
diff --unified \
<(go run print_ast.go -- "$fst" | grep -vF -- "$fst" | grep -v Rparen:) \
<(go run print_ast.go -- "$snd" | grep -vF -- "$snd" | grep -v Rparen:) |
sed 1,2d # filenames printed already
#+END_SRC
#+BEGIN_SRC diff
#+RESULTS:
--- ../vendor/github.com/influxdata/telegraf/plugins/inputs/system/system.go
+++ ../system_ostent/system_ostent.go
@@ -1,10 +1,8 @@
-package system
+package system_ostent
import (
- "bufio"
- "bytes"
- "fmt"
- "runtime"
+ "os"
+ "strings"
"github.com/shirou/gopsutil/host"
"github.com/shirou/gopsutil/load"
@@ -27,12 +25,12 @@
return err
}
- hostinfo, err := host.Info()
+ hostname, err := os.Hostname()
if err != nil {
return err
}
- users, err := host.Users()
+ upseconds, err := host.Uptime()
if err != nil {
return err
}
@@ -41,16 +39,15 @@
"load1": loadavg.Load1,
"load5": loadavg.Load5,
"load15": loadavg.Load15,
- "uptime": hostinfo.Uptime,
- "n_users": len(users),
- "uptime_format": format_uptime(hostinfo.Uptime),
- "n_cpus": runtime.NumCPU(),
+ "hostname_short": strings.Split(hostname, ".")[0],
+ "uptime_format": format_uptime(upseconds),
}
- acc.AddFields("system", fields, nil)
+ acc.AddFields("system_ostent", fields, nil)
return nil
}
+/*
func format_uptime(uptime uint64) string {
buf := new(bytes.Buffer)
w := bufio.NewWriter(buf)
@@ -75,9 +72,10 @@
w.Flush()
return buf.String()
}
+*/
func init() {
- inputs.Add("system", func() telegraf.Input {
+ inputs.Add("system_ostent", func() telegraf.Input {
return &SystemStats{}
})
}
#+END_SRC