github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/builder/dockerfile/metrics.go (about)

     1  package dockerfile // import "github.com/demonoid81/moby/builder/dockerfile"
     2  
     3  import (
     4  	metrics "github.com/docker/go-metrics"
     5  )
     6  
     7  var (
     8  	buildsTriggered metrics.Counter
     9  	buildsFailed    metrics.LabeledCounter
    10  )
    11  
    12  // Build metrics prometheus messages, these values must be initialized before
    13  // using them. See the example below in the "builds_failed" metric definition.
    14  const (
    15  	metricsDockerfileSyntaxError        = "dockerfile_syntax_error"
    16  	metricsDockerfileEmptyError         = "dockerfile_empty_error"
    17  	metricsCommandNotSupportedError     = "command_not_supported_error"
    18  	metricsErrorProcessingCommandsError = "error_processing_commands_error"
    19  	metricsBuildTargetNotReachableError = "build_target_not_reachable_error"
    20  	metricsMissingOnbuildArgumentsError = "missing_onbuild_arguments_error"
    21  	metricsUnknownInstructionError      = "unknown_instruction_error"
    22  	metricsBuildCanceled                = "build_canceled"
    23  )
    24  
    25  func init() {
    26  	buildMetrics := metrics.NewNamespace("builder", "", nil)
    27  
    28  	buildsTriggered = buildMetrics.NewCounter("builds_triggered", "Number of triggered image builds")
    29  	buildsFailed = buildMetrics.NewLabeledCounter("builds_failed", "Number of failed image builds", "reason")
    30  	for _, r := range []string{
    31  		metricsDockerfileSyntaxError,
    32  		metricsDockerfileEmptyError,
    33  		metricsCommandNotSupportedError,
    34  		metricsErrorProcessingCommandsError,
    35  		metricsBuildTargetNotReachableError,
    36  		metricsMissingOnbuildArgumentsError,
    37  		metricsUnknownInstructionError,
    38  		metricsBuildCanceled,
    39  	} {
    40  		buildsFailed.WithValues(r)
    41  	}
    42  
    43  	metrics.Register(buildMetrics)
    44  }