Update process-exporter methods
This commit is contained in:
parent
2fa55eabf6
commit
1fed943b3d
3 changed files with 25 additions and 20 deletions
|
@ -70,8 +70,7 @@ func TestFlagConflict(t *testing.T) {
|
||||||
defer func() { os.Args = oldArgs }()
|
defer func() { os.Args = oldArgs }()
|
||||||
os.Args = []string{"cmd", "--publish-service", "namespace/test", "--http-port", "0", "--https-port", "0", "--publish-status-address", "1.1.1.1"}
|
os.Args = []string{"cmd", "--publish-service", "namespace/test", "--http-port", "0", "--https-port", "0", "--publish-status-address", "1.1.1.1"}
|
||||||
|
|
||||||
_, c, err := parseFlags()
|
_, _, err := parseFlags()
|
||||||
t.Logf("%v", c)
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Expected an error parsing flags but none returned")
|
t.Fatalf("Expected an error parsing flags but none returned")
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,9 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
ps "github.com/mitchellh/go-ps"
|
ps "github.com/mitchellh/go-ps"
|
||||||
"github.com/ncabatoff/process-exporter/proc"
|
"github.com/ncabatoff/process-exporter/proc"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IsRespawnIfRequired checks if error type is exec.ExitError or not
|
// IsRespawnIfRequired checks if error type is exec.ExitError or not
|
||||||
|
@ -37,7 +37,7 @@ func IsRespawnIfRequired(err error) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
waitStatus := exitError.Sys().(syscall.WaitStatus)
|
waitStatus := exitError.Sys().(syscall.WaitStatus)
|
||||||
glog.Warningf(`
|
klog.Warningf(`
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
NGINX master process died (%v): %v
|
NGINX master process died (%v): %v
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
@ -56,9 +56,9 @@ func WaitUntilPortIsAvailable(port int) {
|
||||||
}
|
}
|
||||||
conn.Close()
|
conn.Close()
|
||||||
// kill nginx worker processes
|
// kill nginx worker processes
|
||||||
fs, err := proc.NewFS("/proc")
|
fs, err := proc.NewFS("/proc", false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("unexpected error reading /proc information: %v", err)
|
klog.Errorf("unexpected error reading /proc information: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,14 +66,14 @@ func WaitUntilPortIsAvailable(port int) {
|
||||||
for _, p := range procs {
|
for _, p := range procs {
|
||||||
pn, err := p.Comm()
|
pn, err := p.Comm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("unexpected error obtaining process information: %v", err)
|
klog.Errorf("unexpected error obtaining process information: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if pn == "nginx" {
|
if pn == "nginx" {
|
||||||
osp, err := os.FindProcess(p.PID)
|
osp, err := os.FindProcess(p.PID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("unexpected error obtaining process information: %v", err)
|
klog.Errorf("unexpected error obtaining process information: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
osp.Signal(syscall.SIGQUIT)
|
osp.Signal(syscall.SIGQUIT)
|
||||||
|
|
|
@ -17,9 +17,10 @@ limitations under the License.
|
||||||
package collectors
|
package collectors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
common "github.com/ncabatoff/process-exporter"
|
common "github.com/ncabatoff/process-exporter"
|
||||||
"github.com/ncabatoff/process-exporter/proc"
|
"github.com/ncabatoff/process-exporter/proc"
|
||||||
|
@ -37,7 +38,7 @@ type Stopable interface {
|
||||||
Stop()
|
Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
// BinaryNameMatcher ...
|
// BinaryNameMatcher define a namer using the binary name
|
||||||
type BinaryNameMatcher struct {
|
type BinaryNameMatcher struct {
|
||||||
Name string
|
Name string
|
||||||
Binary string
|
Binary string
|
||||||
|
@ -45,7 +46,7 @@ type BinaryNameMatcher struct {
|
||||||
|
|
||||||
// MatchAndName returns false if the match failed, otherwise
|
// MatchAndName returns false if the match failed, otherwise
|
||||||
// true and the resulting name.
|
// true and the resulting name.
|
||||||
func (em BinaryNameMatcher) MatchAndName(nacl common.NameAndCmdline) (bool, string) {
|
func (em BinaryNameMatcher) MatchAndName(nacl common.ProcAttributes) (bool, string) {
|
||||||
if len(nacl.Cmdline) == 0 {
|
if len(nacl.Cmdline) == 0 {
|
||||||
return false, ""
|
return false, ""
|
||||||
}
|
}
|
||||||
|
@ -53,6 +54,11 @@ func (em BinaryNameMatcher) MatchAndName(nacl common.NameAndCmdline) (bool, stri
|
||||||
return em.Name == cmd, ""
|
return em.Name == cmd, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String returns the name of the binary to match
|
||||||
|
func (m BinaryNameMatcher) String() string {
|
||||||
|
return fmt.Sprintf("%+v", m.Binary)
|
||||||
|
}
|
||||||
|
|
||||||
type namedProcessData struct {
|
type namedProcessData struct {
|
||||||
numProcs *prometheus.Desc
|
numProcs *prometheus.Desc
|
||||||
cpuSecs *prometheus.Desc
|
cpuSecs *prometheus.Desc
|
||||||
|
@ -86,7 +92,7 @@ var binary = "/usr/bin/nginx"
|
||||||
|
|
||||||
// NewNGINXProcess returns a new prometheus collector for the nginx process
|
// NewNGINXProcess returns a new prometheus collector for the nginx process
|
||||||
func NewNGINXProcess(pod, namespace, ingressClass string) (NGINXProcessCollector, error) {
|
func NewNGINXProcess(pod, namespace, ingressClass string) (NGINXProcessCollector, error) {
|
||||||
fs, err := proc.NewFS("/proc")
|
fs, err := proc.NewFS("/proc", false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -98,11 +104,11 @@ func NewNGINXProcess(pod, namespace, ingressClass string) (NGINXProcessCollector
|
||||||
|
|
||||||
p := namedProcess{
|
p := namedProcess{
|
||||||
scrapeChan: make(chan scrapeRequest),
|
scrapeChan: make(chan scrapeRequest),
|
||||||
Grouper: proc.NewGrouper(true, nm),
|
Grouper: proc.NewGrouper(nm, true, false, false),
|
||||||
fs: fs,
|
fs: fs,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = p.Update(p.fs.AllProcs())
|
_, _, err = p.Update(p.fs.AllProcs())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -184,23 +190,23 @@ func (p namedProcess) Stop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p namedProcess) scrape(ch chan<- prometheus.Metric) {
|
func (p namedProcess) scrape(ch chan<- prometheus.Metric) {
|
||||||
_, err := p.Update(p.fs.AllProcs())
|
_, groups, err := p.Update(p.fs.AllProcs())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Warningf("unexpected error obtaining nginx process info: %v", err)
|
klog.Warningf("unexpected error obtaining nginx process info: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, gcounts := range p.Groups() {
|
for _, gcounts := range groups {
|
||||||
ch <- prometheus.MustNewConstMetric(p.data.numProcs,
|
ch <- prometheus.MustNewConstMetric(p.data.numProcs,
|
||||||
prometheus.GaugeValue, float64(gcounts.Procs))
|
prometheus.GaugeValue, float64(gcounts.Procs))
|
||||||
ch <- prometheus.MustNewConstMetric(p.data.memResidentbytes,
|
ch <- prometheus.MustNewConstMetric(p.data.memResidentbytes,
|
||||||
prometheus.GaugeValue, float64(gcounts.Memresident))
|
prometheus.GaugeValue, float64(gcounts.Memory.ResidentBytes))
|
||||||
ch <- prometheus.MustNewConstMetric(p.data.memVirtualbytes,
|
ch <- prometheus.MustNewConstMetric(p.data.memVirtualbytes,
|
||||||
prometheus.GaugeValue, float64(gcounts.Memvirtual))
|
prometheus.GaugeValue, float64(gcounts.Memory.VirtualBytes))
|
||||||
ch <- prometheus.MustNewConstMetric(p.data.startTime,
|
ch <- prometheus.MustNewConstMetric(p.data.startTime,
|
||||||
prometheus.GaugeValue, float64(gcounts.OldestStartTime.Unix()))
|
prometheus.GaugeValue, float64(gcounts.OldestStartTime.Unix()))
|
||||||
ch <- prometheus.MustNewConstMetric(p.data.cpuSecs,
|
ch <- prometheus.MustNewConstMetric(p.data.cpuSecs,
|
||||||
prometheus.CounterValue, gcounts.Cpu)
|
prometheus.CounterValue, gcounts.CPUSystemTime)
|
||||||
ch <- prometheus.MustNewConstMetric(p.data.readBytes,
|
ch <- prometheus.MustNewConstMetric(p.data.readBytes,
|
||||||
prometheus.CounterValue, float64(gcounts.ReadBytes))
|
prometheus.CounterValue, float64(gcounts.ReadBytes))
|
||||||
ch <- prometheus.MustNewConstMetric(p.data.writeBytes,
|
ch <- prometheus.MustNewConstMetric(p.data.writeBytes,
|
||||||
|
|
Loading…
Reference in a new issue