updating spacing in nginx metrics
This commit is contained in:
parent
c817c914e9
commit
9e3123d105
1 changed files with 69 additions and 69 deletions
|
@ -17,107 +17,107 @@ limitations under the License.
|
||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
nginxStatusCollector struct {
|
nginxStatusCollector struct {
|
||||||
scrapeChan chan scrapeRequest
|
scrapeChan chan scrapeRequest
|
||||||
ngxHealthPort int
|
ngxHealthPort int
|
||||||
ngxVtsPath string
|
ngxVtsPath string
|
||||||
data *nginxStatusData
|
data *nginxStatusData
|
||||||
watchNamespace string
|
watchNamespace string
|
||||||
ingressClass string
|
ingressClass string
|
||||||
}
|
}
|
||||||
|
|
||||||
nginxStatusData struct {
|
nginxStatusData struct {
|
||||||
connections_total *prometheus.Desc
|
connections_total *prometheus.Desc
|
||||||
requests_total *prometheus.Desc
|
requests_total *prometheus.Desc
|
||||||
connections *prometheus.Desc
|
connections *prometheus.Desc
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewNginxStatus returns a new prometheus collector the default nginx status module
|
// NewNginxStatus returns a new prometheus collector the default nginx status module
|
||||||
func NewNginxStatus(watchNamespace, ingressClass string, ngxHealthPort int, ngxVtsPath string) Stopable {
|
func NewNginxStatus(watchNamespace, ingressClass string, ngxHealthPort int, ngxVtsPath string) Stopable {
|
||||||
|
|
||||||
p := nginxStatusCollector{
|
p := nginxStatusCollector{
|
||||||
scrapeChan: make(chan scrapeRequest),
|
scrapeChan: make(chan scrapeRequest),
|
||||||
ngxHealthPort: ngxHealthPort,
|
ngxHealthPort: ngxHealthPort,
|
||||||
ngxVtsPath: ngxVtsPath,
|
ngxVtsPath: ngxVtsPath,
|
||||||
watchNamespace: watchNamespace,
|
watchNamespace: watchNamespace,
|
||||||
ingressClass: ingressClass,
|
ingressClass: ingressClass,
|
||||||
}
|
}
|
||||||
|
|
||||||
p.data = &nginxStatusData{
|
p.data = &nginxStatusData{
|
||||||
connections_total: prometheus.NewDesc(
|
connections_total: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(ns, "", "connections_total"),
|
prometheus.BuildFQName(ns, "", "connections_total"),
|
||||||
"total number of connections with state {active, accepted, handled}",
|
"total number of connections with state {active, accepted, handled}",
|
||||||
[]string{"ingress_class", "namespace", "state"}, nil),
|
[]string{"ingress_class", "namespace", "state"}, nil),
|
||||||
|
|
||||||
requests_total: prometheus.NewDesc(
|
requests_total: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(ns, "", "requests_total"),
|
prometheus.BuildFQName(ns, "", "requests_total"),
|
||||||
"total number of client requests",
|
"total number of client requests",
|
||||||
[]string{"ingress_class", "namespace"}, nil),
|
[]string{"ingress_class", "namespace"}, nil),
|
||||||
|
|
||||||
connections: prometheus.NewDesc(
|
connections: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(ns, "", "connections"),
|
prometheus.BuildFQName(ns, "", "connections"),
|
||||||
"current number of client connections with state {reading, writing, waiting}",
|
"current number of client connections with state {reading, writing, waiting}",
|
||||||
[]string{"ingress_class", "namespace", "state"}, nil),
|
[]string{"ingress_class", "namespace", "state"}, nil),
|
||||||
}
|
}
|
||||||
|
|
||||||
go p.start()
|
go p.start()
|
||||||
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
// Describe implements prometheus.Collector.
|
// Describe implements prometheus.Collector.
|
||||||
func (p nginxStatusCollector) Describe(ch chan<- *prometheus.Desc) {
|
func (p nginxStatusCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||||
ch <- p.data.connections_total
|
ch <- p.data.connections_total
|
||||||
ch <- p.data.requests_total
|
ch <- p.data.requests_total
|
||||||
ch <- p.data.connections
|
ch <- p.data.connections
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect implements prometheus.Collector.
|
// Collect implements prometheus.Collector.
|
||||||
func (p nginxStatusCollector) Collect(ch chan<- prometheus.Metric) {
|
func (p nginxStatusCollector) Collect(ch chan<- prometheus.Metric) {
|
||||||
req := scrapeRequest{results: ch, done: make(chan struct{})}
|
req := scrapeRequest{results: ch, done: make(chan struct{})}
|
||||||
p.scrapeChan <- req
|
p.scrapeChan <- req
|
||||||
<-req.done
|
<-req.done
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p nginxStatusCollector) start() {
|
func (p nginxStatusCollector) start() {
|
||||||
for req := range p.scrapeChan {
|
for req := range p.scrapeChan {
|
||||||
ch := req.results
|
ch := req.results
|
||||||
p.scrape(ch)
|
p.scrape(ch)
|
||||||
req.done <- struct{}{}
|
req.done <- struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p nginxStatusCollector) Stop() {
|
func (p nginxStatusCollector) Stop() {
|
||||||
close(p.scrapeChan)
|
close(p.scrapeChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
// nginxStatusCollector scrape the nginx status
|
// nginxStatusCollector scrape the nginx status
|
||||||
func (p nginxStatusCollector) scrape(ch chan<- prometheus.Metric) {
|
func (p nginxStatusCollector) scrape(ch chan<- prometheus.Metric) {
|
||||||
s, err := getNginxStatus(p.ngxHealthPort, p.ngxVtsPath)
|
s, err := getNginxStatus(p.ngxHealthPort, p.ngxVtsPath)
|
||||||
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)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstMetric(p.data.connections_total,
|
ch <- prometheus.MustNewConstMetric(p.data.connections_total,
|
||||||
prometheus.CounterValue, float64(s.Active), p.ingressClass, p.watchNamespace, "active")
|
prometheus.CounterValue, float64(s.Active), p.ingressClass, p.watchNamespace, "active")
|
||||||
ch <- prometheus.MustNewConstMetric(p.data.connections_total,
|
ch <- prometheus.MustNewConstMetric(p.data.connections_total,
|
||||||
prometheus.CounterValue, float64(s.Accepted), p.ingressClass, p.watchNamespace, "accepted")
|
prometheus.CounterValue, float64(s.Accepted), p.ingressClass, p.watchNamespace, "accepted")
|
||||||
ch <- prometheus.MustNewConstMetric(p.data.connections_total,
|
ch <- prometheus.MustNewConstMetric(p.data.connections_total,
|
||||||
prometheus.CounterValue, float64(s.Handled), p.ingressClass, p.watchNamespace, "handled")
|
prometheus.CounterValue, float64(s.Handled), p.ingressClass, p.watchNamespace, "handled")
|
||||||
ch <- prometheus.MustNewConstMetric(p.data.requests_total,
|
ch <- prometheus.MustNewConstMetric(p.data.requests_total,
|
||||||
prometheus.CounterValue, float64(s.Requests), p.ingressClass, p.watchNamespace)
|
prometheus.CounterValue, float64(s.Requests), p.ingressClass, p.watchNamespace)
|
||||||
ch <- prometheus.MustNewConstMetric(p.data.connections,
|
ch <- prometheus.MustNewConstMetric(p.data.connections,
|
||||||
prometheus.GaugeValue, float64(s.Reading), p.ingressClass, p.watchNamespace, "reading")
|
prometheus.GaugeValue, float64(s.Reading), p.ingressClass, p.watchNamespace, "reading")
|
||||||
ch <- prometheus.MustNewConstMetric(p.data.connections,
|
ch <- prometheus.MustNewConstMetric(p.data.connections,
|
||||||
prometheus.GaugeValue, float64(s.Writing), p.ingressClass, p.watchNamespace, "writing")
|
prometheus.GaugeValue, float64(s.Writing), p.ingressClass, p.watchNamespace, "writing")
|
||||||
ch <- prometheus.MustNewConstMetric(p.data.connections,
|
ch <- prometheus.MustNewConstMetric(p.data.connections,
|
||||||
prometheus.GaugeValue, float64(s.Waiting), p.ingressClass, p.watchNamespace, "waiting")
|
prometheus.GaugeValue, float64(s.Waiting), p.ingressClass, p.watchNamespace, "waiting")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue