Skip to content

Commit

Permalink
Use base units for metrics
Browse files Browse the repository at this point in the history
For Prometheus the best practice[0] is to use base units. Use seconds
instead of milliseconds.

[0]: https://prometheus.io/docs/practices/naming/#base-units
  • Loading branch information
SuperQ committed Apr 15, 2019
1 parent 47240be commit 6bfe720
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions examples/rails.mtail
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ counter rails_requests_started by verb
counter rails_requests_completed_total
counter rails_requests_completed by status

histogram rails_requests_completed_milliseconds by status buckets 5, 10, 50, 100, 250, 500, 1000, 2500, 5000, 15000
histogram rails_requests_completed_seconds by status buckets 0.005, 0.01, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 15.0

/^Started (?P<verb>[A-Z]+) .*/ {
###
Expand All @@ -19,7 +19,7 @@ histogram rails_requests_completed_milliseconds by status buckets 5, 10, 50, 100
rails_requests_started[$verb]++
}

/^Completed (?P<status>\d{3}) .+ in (?P<request_milliseconds>\d+)ms .*$/ {
/^Completed (?P<status>\d{3}) .+ in (?P<request_seconds>\d+)ms .*$/ {
###
# Total numer of completed requests by status
#
Expand All @@ -33,5 +33,5 @@ histogram rails_requests_completed_milliseconds by status buckets 5, 10, 50, 100
# collecting system can compute the percentile bands by taking the ratio of
# each bucket value over the final bucket.

rails_requests_completed_milliseconds[$status] = $request_milliseconds
rails_requests_completed_seconds[$status] = $request_seconds / 1000.0
}
6 changes: 3 additions & 3 deletions internal/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ var (
lineProcessingDurations = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "mtail",
Subsystem: "vm",
Name: "line_processing_duration_milliseconds",
Help: "VM line processing time distribution in milliseconds.",
Name: "line_processing_duration_seconds",
Help: "VM line processing time distribution in seconds.",
Buckets: prometheus.DefBuckets,
}, []string{"prog"})
)
Expand Down Expand Up @@ -731,7 +731,7 @@ func (v *VM) execute(t *thread, i code.Instr) {
func (v *VM) processLine(line *logline.LogLine) {
start := time.Now()
defer func() {
lineProcessingDurations.WithLabelValues(v.name).Observe(float64(time.Since(start).Nanoseconds()) / 1.e6)
lineProcessingDurations.WithLabelValues(v.name).Observe(time.Since(start).Seconds())
}()
t := new(thread)
t.matched = false
Expand Down

0 comments on commit 6bfe720

Please sign in to comment.