<commit_before>/*
Copyright 2017 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package collector

import (
	"github.com/golang/glog"

	"github.com/prometheus/client_golang/prometheus"
)

type (
	nginxStatusCollector struct {
		scrapeChan     chan scrapeRequest
		ngxHealthPort  int
		ngxVtsPath     string
		data           *nginxStatusData
		watchNamespace string
		ingressClass   string
	}

	nginxStatusData struct {
		active   *prometheus.Desc
		accepted *prometheus.Desc
		handled  *prometheus.Desc
		requests *prometheus.Desc
		reading  *prometheus.Desc
		writing  *prometheus.Desc
		waiting  *prometheus.Desc
	}
)

// NewNginxStatus returns a new prometheus collector the default nginx status module
func NewNginxStatus(watchNamespace, ingressClass string, ngxHealthPort int, ngxVtsPath string) Stopable {

	p := nginxStatusCollector{
		scrapeChan:     make(chan scrapeRequest),
		ngxHealthPort:  ngxHealthPort,
		ngxVtsPath:     ngxVtsPath,
		watchNamespace: watchNamespace,
		ingressClass:   ingressClass,
	}

	p.data = &nginxStatusData{
		active: prometheus.NewDesc(
			prometheus.BuildFQName(ns, "", "active_connections"),
			"total number of active connections",
			[]string{"ingress_class", "namespace"}, nil),

		accepted: prometheus.NewDesc(
			prometheus.BuildFQName(ns, "", "accepted_connections"),
			"total number of accepted client connections",
			[]string{"ingress_class", "namespace"}, nil),

		handled: prometheus.NewDesc(
			prometheus.BuildFQName(ns, "", "handled_connections"),
			"total number of handled connections",
			[]string{"ingress_class", "namespace"}, nil),

		requests: prometheus.NewDesc(
			prometheus.BuildFQName(ns, "", "total_requests"),
			"total number of client requests",
			[]string{"ingress_class", "namespace"}, nil),

		reading: prometheus.NewDesc(
			prometheus.BuildFQName(ns, "", "current_reading_connections"),
			"current number of connections where nginx is reading the request header",
			[]string{"ingress_class", "namespace"}, nil),

		writing: prometheus.NewDesc(
			prometheus.BuildFQName(ns, "", "current_writing_connections"),
			"current number of connections where nginx is writing the response back to the client",
			[]string{"ingress_class", "namespace"}, nil),

		waiting: prometheus.NewDesc(
			prometheus.BuildFQName(ns, "", "current_waiting_connections"),
			"current number of idle client connections waiting for a request",
			[]string{"ingress_class", "namespace"}, nil),
	}

	go p.start()

	return p
}<commit_msg>updating nginx prometheus metrics names according to prometheus naming best practices (#1910)<commit_after>/*
Copyright 2017 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package collector

import (
	"github.com/golang/glog"

	"github.com/prometheus/client_golang/prometheus"
)

type (
	nginxStatusCollector struct {
		scrapeChan     chan scrapeRequest
		ngxHealthPort  int
		ngxVtsPath     string
		data           *nginxStatusData
		watchNamespace string
		ingressClass   string
	}

	nginxStatusData struct {
		active   *prometheus.Desc
		accepted *prometheus.Desc
		handled  *prometheus.Desc
		requests *prometheus.Desc
		reading  *prometheus.Desc
		writing  *prometheus.Desc
		waiting  *prometheus.Desc
	}
)

// NewNginxStatus returns a new prometheus collector the default nginx status module
func NewNginxStatus(watchNamespace, ingressClass string, ngxHealthPort int, ngxVtsPath string) Stopable {

	p := nginxStatusCollector{
		scrapeChan:     make(chan scrapeRequest),
		ngxHealthPort:  ngxHealthPort,
		ngxVtsPath:     ngxVtsPath,
		watchNamespace: watchNamespace,
		ingressClass:   ingressClass,
	}

	p.data = &nginxStatusData{
		active: prometheus.NewDesc(
			prometheus.BuildFQName(ns, "", "active_connections_total"),
			"total number of active connections",
			[]string{"ingress_class", "namespace"}, nil),

		accepted: prometheus.NewDesc(
			prometheus.BuildFQName(ns, "", "accepted_connections_total"),
			"total number of accepted client connections",
			[]string{"ingress_class", "namespace"}, nil),

		handled: prometheus.NewDesc(
			prometheus.BuildFQName(ns, "", "handled_connections_total"),
			"total number of handled connections",
			[]string{"ingress_class", "namespace"}, nil),

		requests: prometheus.NewDesc(
			prometheus.BuildFQName(ns, "", "requests_total"),
			"total number of client requests",
			[]string{"ingress_class", "namespace"}, nil),

		reading: prometheus.NewDesc(
			prometheus.BuildFQName(ns, "", "current_reading_connections_total"),
			"current number of connections where nginx is reading the request header",
			[]string{"ingress_class", "namespace"}, nil),

		writing: prometheus.NewDesc(
			prometheus.BuildFQName(ns, "", "current_writing_connections_total"),
			"current number of connections where nginx is writing the response back to the client",
			[]string{"ingress_class", "namespace"}, nil),

		waiting: prometheus.NewDesc(
			prometheus.BuildFQName(ns, "", "current_waiting_connections_total"),
			"current number of idle client connections waiting for a request",
			[]string{"ingress_class", "namespace"}, nil),
	}

	go p.start()

	return p
}
{'fraction_non_alphanumeric': 0.09708578912901113, 'fraction_numerical': 0.0032743942370661427, 'mean_word_length': 4.807034220532319, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '251028', 'n_tokens_mistral': 2058, 'n_tokens_neox': 1764, 'n_words': 541}