system_ostent

package
Version: v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2016 License: MIT Imports: 11 Imported by: 0

README

* 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
snd=../system_ostent

(diff --unified --ignore-all-space --recursive \
 "$fst"/net.go \
 "$snd"/net.go;
 diff --unified --ignore-all-space --recursive \
 "$fst"/system.go \
 "$snd"/system_ostent.go) |
awk '{ if ($1 == "---" || $1 == "+++") { $_ = $1 FS $2; }; print }'
#+END_SRC

#+BEGIN_SRC diff
#+RESULTS:
--- ../vendor/github.com/influxdata/telegraf/plugins/inputs/system/net.go
+++ ../system_ostent/net.go
@@ -1,15 +1,23 @@
-package system
+package system_ostent
 
 import (
 	"fmt"
 	"net"
-	"strings"
+
+	psnet "github.com/shirou/gopsutil/net"
 
 	"github.com/influxdata/telegraf"
 	"github.com/influxdata/telegraf/plugins/inputs"
+
+	"github.com/ostrost/ostent/system_ostent/internal"
 )
 
+type PS interface{}
+type systemPS struct{}
+
 type NetIOStats struct {
+	internal.LastNetIOStats `toml:"-"`
+
 	ps PS
 
 	skipChecks bool
@@ -33,12 +41,19 @@
 }
 
 func (s *NetIOStats) Gather(acc telegraf.Accumulator) error {
-	netio, err := s.ps.NetIO()
+	netio, err := internal.IOCounters(true)
 	if err != nil {
 		return fmt.Errorf("error getting net io info: %s", err)
 	}
 
+	interfaces, err := psnet.Interfaces()
+	if err != nil {
+		return err
+	}
+
 	for _, io := range netio {
+		var isLoopback bool
+
 		if len(s.Interfaces) != 0 {
 			var found bool
 
@@ -59,7 +74,8 @@
 			}
 
 			if iface.Flags&net.FlagLoopback == net.FlagLoopback {
-				continue
+				// continue // DO NOT skip loopback interface
+				isLoopback = true
 			}
 
 			if iface.Flags&net.FlagUp == 0 {
@@ -70,6 +86,7 @@
 		tags := map[string]string{
 			"interface": io.Name,
 		}
+		internal.AddTags(interfaces, io.Name, isLoopback, tags)
 
 		fields := map[string]interface{}{
 			"bytes_sent":   io.BytesSent,
@@ -81,9 +98,11 @@
 			"drop_in":      io.Dropin,
 			"drop_out":     io.Dropout,
 		}
+		s.AddDeltaFields(io, fields)
 		acc.AddFields("net", fields, tags)
 	}
 
+	/*
 	// Get system wide stats for different network protocols
 	// (ignore these stats if the call fails)
 	netprotos, _ := s.ps.NetProto()
@@ -99,12 +118,13 @@
 		"interface": "all",
 	}
 	acc.AddFields("net", fields, tags)
+	*/
 
 	return nil
 }
 
 func init() {
-	inputs.Add("net", func() telegraf.Input {
+	inputs.Add("net_ostent", func() telegraf.Input {
 		return &NetIOStats{ps: &systemPS{}}
 	})
 }
--- ../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,17 @@
 		"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(),
 	}
-	acc.AddFields("system", fields, nil)
+	acc.AddFields("system_ostent", fields, nil)
+	acc.AddFields("system_ostent", map[string]interface{}{
+		"hostname_short": strings.Split(hostname, ".")[0],
+		"uptime_format":  format_uptime(upseconds),
+	}, map[string]string{"kind": "system_ostent_runtime"})
 
 	return nil
 }
 
+/*
 func format_uptime(uptime uint64) string {
 	buf := new(bytes.Buffer)
 	w := bufio.NewWriter(buf)
@@ -75,9 +74,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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NetIOStats

type NetIOStats struct {
	internal.LastNetIOStats `toml:"-"`

	Interfaces []string
	// contains filtered or unexported fields
}

func (*NetIOStats) Description

func (_ *NetIOStats) Description() string

func (*NetIOStats) Gather

func (s *NetIOStats) Gather(acc telegraf.Accumulator) error

func (*NetIOStats) SampleConfig

func (_ *NetIOStats) SampleConfig() string

type PS

type PS interface{}

type SystemStats

type SystemStats struct{}

func (*SystemStats) Description

func (_ *SystemStats) Description() string

func (*SystemStats) Gather

func (_ *SystemStats) Gather(acc telegraf.Accumulator) error

func (*SystemStats) SampleConfig

func (_ *SystemStats) SampleConfig() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL