run e2e
This commit is contained in:
parent
6ce0e63f7e
commit
9990a31bfc
3 changed files with 2268 additions and 318 deletions
|
@ -28,45 +28,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type exeMatcher struct {
|
|
||||||
name string
|
|
||||||
args []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (em exeMatcher) MatchAndName(nacl common.NameAndCmdline) (bool, string) {
|
|
||||||
if len(nacl.Cmdline) == 0 {
|
|
||||||
return false, ""
|
|
||||||
}
|
|
||||||
cmd := filepath.Base(nacl.Cmdline[0])
|
|
||||||
return em.name == cmd, ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *NGINXController) setupMonitor(args []string, vtsCollector *bool) {
|
|
||||||
|
|
||||||
// TODO fix true
|
|
||||||
pc, err := newProcessCollector(true, exeMatcher{"nginx", args}, vtsCollector)
|
|
||||||
if err != nil {
|
|
||||||
glog.Warningf("unexpected error registering nginx collector: %v", err)
|
|
||||||
}
|
|
||||||
n.namedProcessCollector = pc
|
|
||||||
|
|
||||||
err = prometheus.Register(pc)
|
|
||||||
if err != nil {
|
|
||||||
glog.Warningf("unexpected error registering nginx collector: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *NGINXController) reloadMonitor(enableVts *bool) {
|
|
||||||
|
|
||||||
if enableVts == nil {
|
|
||||||
falseVar := false
|
|
||||||
n.namedProcessCollector.vtsCollector = &falseVar
|
|
||||||
return
|
|
||||||
}
|
|
||||||
falseVar := true
|
|
||||||
n.namedProcessCollector.vtsCollector = &falseVar
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// descriptions borrow from https://github.com/vozlt/nginx-module-vts
|
// descriptions borrow from https://github.com/vozlt/nginx-module-vts
|
||||||
|
@ -228,6 +189,40 @@ var (
|
||||||
nil, nil)
|
nil, nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type exeMatcher struct {
|
||||||
|
name string
|
||||||
|
args []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (em exeMatcher) MatchAndName(nacl common.NameAndCmdline) (bool, string) {
|
||||||
|
if len(nacl.Cmdline) == 0 {
|
||||||
|
return false, ""
|
||||||
|
}
|
||||||
|
cmd := filepath.Base(nacl.Cmdline[0])
|
||||||
|
return em.name == cmd, ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *NGINXController) setupMonitor(args[] string, vtsCollector *bool) {
|
||||||
|
// TODO fix true
|
||||||
|
pc, err := newProcessCollector(true, exeMatcher{"nginx", args}, vtsCollector)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
glog.Warningf("unexpected error registering nginx collector: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = prometheus.Register(pc)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if err, ok := err.(prometheus.AlreadyRegisteredError); ok {
|
||||||
|
glog.Warningf("unexpected error registering nginx collector: %v", err)
|
||||||
|
}else{
|
||||||
|
glog.Warningf("unexpected error registering nginx collector: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
type (
|
type (
|
||||||
scrapeRequest struct {
|
scrapeRequest struct {
|
||||||
results chan<- prometheus.Metric
|
results chan<- prometheus.Metric
|
||||||
|
@ -252,13 +247,13 @@ func newProcessCollector(
|
||||||
// return nil, err
|
// return nil, err
|
||||||
//}
|
//}
|
||||||
p := &namedProcessCollector{
|
p := &namedProcessCollector{
|
||||||
scrapeChan: make(chan scrapeRequest),
|
scrapeChan: make(chan scrapeRequest),
|
||||||
Grouper: proc.NewGrouper(children, n),
|
Grouper: proc.NewGrouper(children, n),
|
||||||
//fs: fs,
|
//fs: fs,
|
||||||
vtsCollector: vtsCollector,
|
vtsCollector: vtsCollector,
|
||||||
}
|
}
|
||||||
|
|
||||||
//_, err = p.Update(p.fs.AllProcs())
|
//p.Update(p.fs.AllProcs())
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// return nil, err
|
// return nil, err
|
||||||
//}
|
//}
|
||||||
|
@ -280,6 +275,7 @@ func (p *namedProcessCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||||
ch <- startTimeDesc
|
ch <- startTimeDesc
|
||||||
|
|
||||||
if *p.vtsCollector {
|
if *p.vtsCollector {
|
||||||
|
glog.Info("registering vts describe")
|
||||||
|
|
||||||
ch <- vtsBytesDesc
|
ch <- vtsBytesDesc
|
||||||
ch <- vtsCacheDesc
|
ch <- vtsCacheDesc
|
||||||
|
@ -287,7 +283,6 @@ func (p *namedProcessCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||||
ch <- readBytesDesc
|
ch <- readBytesDesc
|
||||||
ch <- vtsRequestDesc
|
ch <- vtsRequestDesc
|
||||||
ch <- vtsResponseDesc
|
ch <- vtsResponseDesc
|
||||||
ch <- writeBytesDesc
|
|
||||||
ch <- vtsUpstreamBackupDesc
|
ch <- vtsUpstreamBackupDesc
|
||||||
ch <- vtsUpstreamBytesDesc
|
ch <- vtsUpstreamBytesDesc
|
||||||
ch <- vtsUpstreamDownDesc
|
ch <- vtsUpstreamDownDesc
|
||||||
|
@ -313,15 +308,13 @@ func (p *namedProcessCollector) Collect(ch chan<- prometheus.Metric) {
|
||||||
|
|
||||||
func (p *namedProcessCollector) start() {
|
func (p *namedProcessCollector) start() {
|
||||||
|
|
||||||
//glog.Warningf("OOO %v", p.configmap.Data)
|
|
||||||
|
|
||||||
for req := range p.scrapeChan {
|
for req := range p.scrapeChan {
|
||||||
ch := req.results
|
ch := req.results
|
||||||
p.scrapeNginxStatus(ch)
|
p.scrapeNginxStatus(ch)
|
||||||
|
p.scrapeProcs(ch)
|
||||||
|
p.scrapeVts(ch)
|
||||||
|
|
||||||
if *p.vtsCollector {
|
|
||||||
p.scrapeVts(ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
req.done <- struct{}{}
|
req.done <- struct{}{}
|
||||||
}
|
}
|
||||||
|
@ -334,7 +327,6 @@ func (p *namedProcessCollector) scrapeNginxStatus(ch chan<- prometheus.Metric) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
p.scrapeProcs(ch)
|
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(activeDesc,
|
ch <- prometheus.MustNewConstMetric(activeDesc,
|
||||||
prometheus.GaugeValue, float64(s.Active))
|
prometheus.GaugeValue, float64(s.Active))
|
||||||
|
@ -355,6 +347,11 @@ func (p *namedProcessCollector) scrapeNginxStatus(ch chan<- prometheus.Metric) {
|
||||||
|
|
||||||
func (p *namedProcessCollector) scrapeVts(ch chan<- prometheus.Metric) {
|
func (p *namedProcessCollector) scrapeVts(ch chan<- prometheus.Metric) {
|
||||||
|
|
||||||
|
if ! *p.vtsCollector {
|
||||||
|
glog.Warningf("vts metrics not enabled")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
glog.Info("starting scrap on vts")
|
||||||
nginxMetrics, err := getNginxVtsMetrics()
|
nginxMetrics, err := getNginxVtsMetrics()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Warningf("unexpected error obtaining nginx status info: %v", err)
|
glog.Warningf("unexpected error obtaining nginx status info: %v", err)
|
||||||
|
@ -434,34 +431,35 @@ func (p *namedProcessCollector) scrapeVts(ch chan<- prometheus.Metric) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *namedProcessCollector) scrapeProcs(ch chan<- prometheus.Metric) {
|
func (p *namedProcessCollector) scrapeProcs(ch chan<- prometheus.Metric) {
|
||||||
|
|
||||||
_, err := p.Update(p.fs.AllProcs())
|
//_, err := p.Update(p.fs.AllProcs())
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
glog.Warningf("unexpected error obtaining nginx process info: %v", err)
|
// glog.Warningf("unexpected error obtaining nginx process info: %v", err)
|
||||||
return
|
// return
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
for gname, gcounts := range p.Groups() {
|
//for gname, gcounts := range p.Groups() {
|
||||||
glog.Infof("%v", gname)
|
// glog.Infof("%v", gname)
|
||||||
glog.Infof("%v", gcounts)
|
// glog.Infof("%v", gcounts)
|
||||||
ch <- prometheus.MustNewConstMetric(numprocsDesc,
|
// ch <- prometheus.MustNewConstMetric(numprocsDesc,
|
||||||
prometheus.GaugeValue, float64(gcounts.Procs))
|
// prometheus.GaugeValue, float64(gcounts.Procs))
|
||||||
ch <- prometheus.MustNewConstMetric(memResidentbytesDesc,
|
// ch <- prometheus.MustNewConstMetric(memResidentbytesDesc,
|
||||||
prometheus.GaugeValue, float64(gcounts.Memresident))
|
// prometheus.GaugeValue, float64(gcounts.Memresident))
|
||||||
ch <- prometheus.MustNewConstMetric(memVirtualbytesDesc,
|
// ch <- prometheus.MustNewConstMetric(memVirtualbytesDesc,
|
||||||
prometheus.GaugeValue, float64(gcounts.Memvirtual))
|
// prometheus.GaugeValue, float64(gcounts.Memvirtual))
|
||||||
ch <- prometheus.MustNewConstMetric(startTimeDesc,
|
// ch <- prometheus.MustNewConstMetric(startTimeDesc,
|
||||||
prometheus.GaugeValue, float64(gcounts.OldestStartTime.Unix()))
|
// prometheus.GaugeValue, float64(gcounts.OldestStartTime.Unix()))
|
||||||
ch <- prometheus.MustNewConstMetric(cpuSecsDesc,
|
// ch <- prometheus.MustNewConstMetric(cpuSecsDesc,
|
||||||
prometheus.CounterValue, gcounts.Cpu)
|
// prometheus.CounterValue, gcounts.Cpu)
|
||||||
ch <- prometheus.MustNewConstMetric(readBytesDesc,
|
// ch <- prometheus.MustNewConstMetric(readBytesDesc,
|
||||||
prometheus.CounterValue, float64(gcounts.ReadBytes))
|
// prometheus.CounterValue, float64(gcounts.ReadBytes))
|
||||||
ch <- prometheus.MustNewConstMetric(writeBytesDesc,
|
// ch <- prometheus.MustNewConstMetric(writeBytesDesc,
|
||||||
prometheus.CounterValue, float64(gcounts.WriteBytes))
|
// prometheus.CounterValue, float64(gcounts.WriteBytes))
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
func reflectMetrics(value interface{}, desc *prometheus.Desc, ch chan<- prometheus.Metric, labels ...string) {
|
func reflectMetrics(value interface{}, desc *prometheus.Desc, ch chan<- prometheus.Metric, labels ...string) {
|
||||||
|
@ -478,4 +476,3 @@ func reflectMetrics(value interface{}, desc *prometheus.Desc, ch chan<- promethe
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -213,11 +213,8 @@ func buildLocation(input interface{}) string {
|
||||||
|
|
||||||
func buildAuthLocation(input interface{}) string {
|
func buildAuthLocation(input interface{}) string {
|
||||||
location, ok := input.(*ingress.Location)
|
location, ok := input.(*ingress.Location)
|
||||||
if !ok {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
if location.ExternalAuth.URL == "" {
|
if !ok || location.ExternalAuth.URL == "" {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue