Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
Switch to counters for the job scheduling duration
Browse files Browse the repository at this point in the history
Using gauges has the drawback that the last emitted value will persist even if the job is removed and no new metrics are emitted for this particular job.
  • Loading branch information
databus23 committed May 23, 2018
1 parent 9828135 commit fd160b5
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions metric/emitter/prometheus.go
Expand Up @@ -28,9 +28,10 @@ type PrometheusEmitter struct {

httpRequestsDuration *prometheus.HistogramVec

schedulingFullDuration *prometheus.GaugeVec
schedulingLoadingDuration *prometheus.GaugeVec
schedulingJobDuration *prometheus.GaugeVec
schedulingFullDuration *prometheus.GaugeVec
schedulingLoadingDuration *prometheus.GaugeVec
schedulingJobDurationTotalVec *prometheus.CounterVec
schedulingJobTotalVec *prometheus.CounterVec

dbQueriesTotal prometheus.Counter
dbConnections *prometheus.GaugeVec
Expand Down Expand Up @@ -183,16 +184,27 @@ func (config *PrometheusConfig) NewEmitter() (metric.Emitter, error) {
)
prometheus.MustRegister(schedulingLoadingDuration)

schedulingJobDuration := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
schedulingJobDurationTotalVec := prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "concourse",
Subsystem: "scheduling",
Name: "job_duration_seconds",
Help: "Last time taken to calculate the set of valid input versions for a pipeline.",
Name: "job_duration_seconds_total",
Help: "Total amount of time spend calculating the set of valid input versions for a job.",
},
[]string{"pipeline", "job"},
)
prometheus.MustRegister(schedulingJobDuration)
schedulingJobTotalVec := prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "concourse",
Subsystem: "scheduling",
Name: "job_total",
Help: "Number of times the job was scheduled",
},
[]string{"pipeline", "job"},
)

prometheus.MustRegister(schedulingJobDurationTotalVec)
prometheus.MustRegister(schedulingJobTotalVec)

dbQueriesTotal := prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "concourse",
Expand Down Expand Up @@ -235,9 +247,10 @@ func (config *PrometheusConfig) NewEmitter() (metric.Emitter, error) {

httpRequestsDuration: httpRequestsDuration,

schedulingFullDuration: schedulingFullDuration,
schedulingLoadingDuration: schedulingLoadingDuration,
schedulingJobDuration: schedulingJobDuration,
schedulingFullDuration: schedulingFullDuration,
schedulingLoadingDuration: schedulingLoadingDuration,
schedulingJobDurationTotalVec: schedulingJobDurationTotalVec,
schedulingJobTotalVec: schedulingJobTotalVec,

dbQueriesTotal: dbQueriesTotal,
dbConnections: dbConnections,
Expand Down Expand Up @@ -392,8 +405,10 @@ func (emitter *PrometheusEmitter) schedulingMetrics(logger lager.Logger, event m
if !exists {
logger.Error("failed-to-find-job-in-event", fmt.Errorf("expected job to exist in event.Attributes"))
}
// concourse_scheduling_job_duration_seconds
emitter.schedulingJobDuration.WithLabelValues(pipeline, job).Set(duration / 1000)
// concourse_scheduling_job_duration_seconds_total
emitter.schedulingJobDurationTotalVec.WithLabelValues(pipeline, job).Add(duration / 1000)
// concourse_scheduling_job_total
emitter.schedulingJobTotalVec.WithLabelValues(pipeline, job).Inc()
default:
}
}
Expand Down

0 comments on commit fd160b5

Please sign in to comment.