-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4285b29
commit 6984981
Showing
5 changed files
with
133 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package collectors | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"k8s.io/client-go/util/workqueue" | ||
) | ||
|
||
const workqueueSubsystem = "workqueue" | ||
|
||
// WorkQueueMetricsCollector implements prometheus.Collector interface | ||
type WorkQueueMetricsCollector struct { | ||
depth *prometheus.GaugeVec | ||
latency *prometheus.HistogramVec | ||
workDuration *prometheus.HistogramVec | ||
} | ||
|
||
// NewWorkQueueMetricsCollector creates a new WorkQueueMetricsCollector | ||
func NewWorkQueueMetricsCollector(constLabels map[string]string) *WorkQueueMetricsCollector { | ||
return &WorkQueueMetricsCollector{ | ||
depth: prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: workqueueSubsystem, | ||
Name: "depth", | ||
Help: "Current depth of workqueue", | ||
ConstLabels: constLabels, | ||
}, | ||
[]string{"name"}, | ||
), | ||
latency: prometheus.NewHistogramVec( | ||
prometheus.HistogramOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: workqueueSubsystem, | ||
Name: "queue_duration_seconds", | ||
Help: "How long in seconds an item stays in workqueue before being requested", | ||
Buckets: prometheus.ExponentialBuckets(10e-9, 10, 10), | ||
ConstLabels: constLabels, | ||
}, | ||
[]string{"name"}, | ||
), | ||
workDuration: prometheus.NewHistogramVec( | ||
prometheus.HistogramOpts{ | ||
Namespace: metricsNamespace, | ||
Subsystem: workqueueSubsystem, | ||
Name: "work_duration_seconds", | ||
Help: "How long in seconds processing an item from workqueue takes", | ||
Buckets: prometheus.ExponentialBuckets(10e-9, 10, 10), | ||
ConstLabels: constLabels, | ||
}, | ||
[]string{"name"}, | ||
), | ||
} | ||
} | ||
|
||
// Collect implements the prometheus.Collector interface Collect method | ||
func (wqc *WorkQueueMetricsCollector) Collect(ch chan<- prometheus.Metric) { | ||
wqc.depth.Collect(ch) | ||
wqc.latency.Collect(ch) | ||
wqc.workDuration.Collect(ch) | ||
} | ||
|
||
// Describe implements prometheus.Collector interface Describe method | ||
func (wqc *WorkQueueMetricsCollector) Describe(ch chan<- *prometheus.Desc) { | ||
wqc.depth.Describe(ch) | ||
wqc.latency.Describe(ch) | ||
wqc.workDuration.Describe(ch) | ||
} | ||
|
||
// Register registers all the metrics of the collector | ||
func (wqc *WorkQueueMetricsCollector) Register(registry *prometheus.Registry) error { | ||
workqueue.SetProvider(wqc) | ||
return registry.Register(wqc) | ||
} | ||
|
||
// NewDepthMetric implements the workqueue.MetricsProvider interface NewDepthMetric method | ||
func (wqc *WorkQueueMetricsCollector) NewDepthMetric(name string) workqueue.GaugeMetric { | ||
return wqc.depth.WithLabelValues(name) | ||
} | ||
|
||
// NewLatencyMetric implements the workqueue.MetricsProvider interface NewLatencyMetric method | ||
func (wqc *WorkQueueMetricsCollector) NewLatencyMetric(name string) workqueue.HistogramMetric { | ||
return wqc.latency.WithLabelValues(name) | ||
|
||
} | ||
|
||
// NewWorkDurationMetric implements the workqueue.MetricsProvider interface NewWorkDurationMetric method | ||
func (wqc *WorkQueueMetricsCollector) NewWorkDurationMetric(name string) workqueue.HistogramMetric { | ||
return wqc.workDuration.WithLabelValues(name) | ||
} | ||
|
||
// noopMetric implements the workqueue.GaugeMetric and workqueue.HistogramMetric interfaces | ||
type noopMetric struct{} | ||
|
||
func (noopMetric) Inc() {} | ||
func (noopMetric) Dec() {} | ||
func (noopMetric) Set(float64) {} | ||
func (noopMetric) Observe(float64) {} | ||
|
||
// NewAddsMetric implements the workqueue.MetricsProvider interface NewAddsMetric method | ||
func (*WorkQueueMetricsCollector) NewAddsMetric(string) workqueue.CounterMetric { | ||
return noopMetric{} | ||
} | ||
|
||
// NewUnfinishedWorkSecondsMetric implements the workqueue.MetricsProvider interface NewUnfinishedWorkSecondsMetric method | ||
func (*WorkQueueMetricsCollector) NewUnfinishedWorkSecondsMetric(string) workqueue.SettableGaugeMetric { | ||
return noopMetric{} | ||
} | ||
|
||
// NewLongestRunningProcessorSecondsMetric implements the workqueue.MetricsProvider interface NewLongestRunningProcessorSecondsMetric method | ||
func (*WorkQueueMetricsCollector) NewLongestRunningProcessorSecondsMetric(string) workqueue.SettableGaugeMetric { | ||
return noopMetric{} | ||
} | ||
|
||
// NewRetriesMetric implements the workqueue.MetricsProvider interface NewRetriesMetric method | ||
func (*WorkQueueMetricsCollector) NewRetriesMetric(string) workqueue.CounterMetric { | ||
return noopMetric{} | ||
} |