procstat_ostent

package
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: 15 Imported by: 0

README

* package procstat_ostent

#+BEGIN_SRC sh :results raw
fst=../vendor/github.com/influxdata/telegraf/plugins/inputs/procstat
snd=../procstat_ostent

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

#+BEGIN_SRC diff
#+RESULTS:
Only in ../vendor/github.com/influxdata/telegraf/plugins/inputs/procstat: README.md
Only in ../procstat_ostent: README.org
Only in ../procstat_ostent: proc.go
Only in ../procstat_ostent: process_gopsutil.go
Only in ../procstat_ostent: process_gosigar.go
diff --unified --ignore-all-space --recursive ../vendor/github.com/influxdata/telegraf/plugins/inputs/procstat/procstat.go ../procstat_ostent/procstat.go
--- ../vendor/github.com/influxdata/telegraf/plugins/inputs/procstat/procstat.go
+++ ../procstat_ostent/procstat.go
@@ -1,4 +1,4 @@
-package procstat
+package procstat_ostent
 
 import (
 	"fmt"
@@ -7,6 +7,7 @@
 	"os/exec"
 	"strconv"
 	"strings"
+	"time"
 
 	"github.com/shirou/gopsutil/process"
 
@@ -23,14 +24,14 @@
 	User        string
 
 	// pidmap maps a pid to a process object, so we don't recreate every gather
-	pidmap map[int32]*process.Process
+	pidmap map[int32]proc
 	// tagmap maps a pid to a map of tags for that pid
 	tagmap map[int32]map[string]string
 }
 
 func NewProcstat() *Procstat {
 	return &Procstat{
-		pidmap: make(map[int32]*process.Process),
+		pidmap: make(map[int32]proc),
 		tagmap: make(map[int32]map[string]string),
 	}
 }
@@ -64,14 +65,21 @@
 }
 
 func (p *Procstat) Gather(acc telegraf.Accumulator) error {
+	start := time.Now()
 	err := p.createProcesses()
 	if err != nil {
 		log.Printf("Error: procstat getting process, exe: [%s]	pidfile: [%s] pattern: [%s] user: [%s] %s",
 			p.Exe, p.PidFile, p.Pattern, p.User, err.Error())
 	} else {
 		for pid, proc := range p.pidmap {
-			p := NewSpecProcessor(p.ProcessName, p.Prefix, pid, acc, proc, p.tagmap[pid])
-			p.pushMetrics()
+			sp := NewSpecProcessor(p.ProcessName, p.Prefix, pid, acc, proc, p.tagmap[pid])
+			if err := sp.pushMetrics(); err != nil && isNotExist(err) {
+				delete(p.pidmap, pid)
+				delete(p.tagmap, pid)
+			}
+		}
+		if false {
+			fmt.Printf("Gathered %#v pids in %s\n", len(p.pidmap), time.Since(start))
 		}
 	}
 
@@ -90,10 +98,10 @@
 	for _, pid := range pids {
 		_, ok := p.pidmap[pid]
 		if !ok {
-			proc, err := process.NewProcess(pid)
+			proc, err := newProcess(pid)
 			if err == nil {
 				p.pidmap[pid] = proc
-			} else {
+			} else if !isNotExist(err) {
 				errstring += err.Error() + " "
 			}
 		}
@@ -118,6 +126,8 @@
 		pids, err = p.pidsFromPattern()
 	} else if p.User != "" {
 		pids, err = p.pidsFromUser()
+	} else if true {
+		pids, err = p.pidsAll()
 	} else {
 		err = fmt.Errorf("Either exe, pid_file, user, or pattern has to be specified")
 	}
@@ -125,6 +135,16 @@
 	return pids, err
 }
 
+func (p *Procstat) pidsAll() ([]int32, error) {
+	pids, err := process.Pids()
+	if err == nil {
+		for _, pid := range pids {
+			p.tagmap[pid] = make(map[string]string)
+		}
+	}
+	return pids, err
+}
+
 func (p *Procstat) pidsFromFile() ([]int32, error) {
 	var out []int32
 	var outerr error
@@ -228,7 +248,7 @@
 }
 
 func init() {
-	inputs.Add("procstat", func() telegraf.Input {
+	inputs.Add("procstat_ostent", func() telegraf.Input {
 		return NewProcstat()
 	})
 }
Only in ../vendor/github.com/influxdata/telegraf/plugins/inputs/procstat: procstat_test.go
diff --unified --ignore-all-space --recursive ../vendor/github.com/influxdata/telegraf/plugins/inputs/procstat/spec_processor.go ../procstat_ostent/spec_processor.go
--- ../vendor/github.com/influxdata/telegraf/plugins/inputs/procstat/spec_processor.go
+++ ../procstat_ostent/spec_processor.go
@@ -1,12 +1,6 @@
-package procstat
+package procstat_ostent
 
-import (
-	"time"
-
-	"github.com/shirou/gopsutil/process"
-
-	"github.com/influxdata/telegraf"
-)
+import "github.com/influxdata/telegraf"
 
 type SpecProcessor struct {
 	Prefix string
@@ -14,7 +8,7 @@
 	tags   map[string]string
 	fields map[string]interface{}
 	acc    telegraf.Accumulator
-	proc   *process.Process
+	proc   proc
 }
 
 func NewSpecProcessor(
@@ -22,7 +16,7 @@
 	prefix string,
 	pid int32,
 	acc telegraf.Accumulator,
-	p *process.Process,
+	p proc,
 	tags map[string]string,
 ) *SpecProcessor {
 	if processName != "" {
@@ -43,27 +37,51 @@
 	}
 }
 
-func (p *SpecProcessor) pushMetrics() {
+func (p *SpecProcessor) pushMetrics() error {
 	var prefix string
 	if p.Prefix != "" {
 		prefix = p.Prefix + "_"
 	}
 	fields := map[string]interface{}{"pid": p.pid}
 
+	uids, err := p.proc.Uids()
+	if err != nil {
+		return err
+	}
+	fields[prefix+"uid"] = uids[0]
+	//
+	nice, err := p.proc.Nice()
+	if err != nil {
+		return err
+	}
+	fields[prefix+"nice"] = nice
+	prio, err := p.proc.Prio()
+	if err != nil {
+		return err
+	}
+	fields[prefix+"prio"] = prio
+
+	/*
 	numThreads, err := p.proc.NumThreads()
 	if err == nil {
 		fields[prefix+"num_threads"] = numThreads
+		} else {
+			return err
 	}
 
 	fds, err := p.proc.NumFDs()
 	if err == nil {
 		fields[prefix+"num_fds"] = fds
+		} else {
+			return err
 	}
 
 	ctx, err := p.proc.NumCtxSwitches()
 	if err == nil {
 		fields[prefix+"voluntary_context_switches"] = ctx.Voluntary
 		fields[prefix+"involuntary_context_switches"] = ctx.Involuntary
+		} else {
+			return err
 	}
 
 	io, err := p.proc.IOCounters()
@@ -72,12 +90,16 @@
 		fields[prefix+"write_count"] = io.WriteCount
 		fields[prefix+"read_bytes"] = io.ReadBytes
 		fields[prefix+"write_bytes"] = io.WriteBytes
+		} else {
+			return err
 	}
+	*/
 
 	cpu_time, err := p.proc.Times()
 	if err == nil {
 		fields[prefix+"cpu_time_user"] = cpu_time.User
 		fields[prefix+"cpu_time_system"] = cpu_time.System
+		/*
 		fields[prefix+"cpu_time_idle"] = cpu_time.Idle
 		fields[prefix+"cpu_time_nice"] = cpu_time.Nice
 		fields[prefix+"cpu_time_iowait"] = cpu_time.Iowait
@@ -87,19 +109,31 @@
 		fields[prefix+"cpu_time_stolen"] = cpu_time.Stolen
 		fields[prefix+"cpu_time_guest"] = cpu_time.Guest
 		fields[prefix+"cpu_time_guest_nice"] = cpu_time.GuestNice
+		*/
+	} else {
+		return err
 	}
 
+	/*
 	cpu_perc, err := p.proc.Percent(time.Duration(0))
 	if err == nil && cpu_perc != 0 {
 		fields[prefix+"cpu_usage"] = cpu_perc
+		} else if err != nil {
+			return err
 	}
+	*/
 
 	mem, err := p.proc.MemoryInfo()
 	if err == nil {
 		fields[prefix+"memory_rss"] = mem.RSS
 		fields[prefix+"memory_vms"] = mem.VMS
+		if false {
 		fields[prefix+"memory_swap"] = mem.Swap
 	}
+	} else {
+		return err
+	}
 
-	p.acc.AddFields("procstat", fields, p.tags)
+	p.acc.AddFields("procstat_ostent", fields, p.tags)
+	return nil
 }
#+END_SRC

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Procstat

type Procstat struct {
	PidFile     string `toml:"pid_file"`
	Exe         string
	Pattern     string
	Prefix      string
	ProcessName string
	User        string
	// contains filtered or unexported fields
}

func NewProcstat

func NewProcstat() *Procstat

func (*Procstat) Description

func (_ *Procstat) Description() string

func (*Procstat) Gather

func (p *Procstat) Gather(acc telegraf.Accumulator) error

func (*Procstat) SampleConfig

func (_ *Procstat) SampleConfig() string

type SpecProcessor

type SpecProcessor struct {
	Prefix string
	// contains filtered or unexported fields
}

func NewSpecProcessor

func NewSpecProcessor(
	processName string,
	prefix string,
	pid int32,
	acc telegraf.Accumulator,
	p proc,
	tags map[string]string,
) *SpecProcessor

Jump to

Keyboard shortcuts

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