Skip to content

Commit

Permalink
Prometheus for index and car lookups; closes #126
Browse files Browse the repository at this point in the history
  • Loading branch information
gagliardetto committed Jul 11, 2024
1 parent 20e5219 commit fc8ae64
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
14 changes: 14 additions & 0 deletions http-range.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package main

import (
"io"
"path/filepath"
"strings"
"time"

"github.com/rpcpool/yellowstone-faithful/metrics"
"k8s.io/klog/v2"
)

Expand Down Expand Up @@ -43,6 +45,15 @@ func (r *readCloserWrapper) ReadAt(p []byte, off int64) (n int, err error) {
// if has suffix .index, then it's an index file
if strings.HasSuffix(r.name, ".index") {
prefix = icon + azureBG("[READ-INDEX]")
// get the index name, which is the part before the .index suffix, after the last .
indexName := strings.TrimSuffix(r.name, ".index")
// split the index name by . and get the last part
byDot := strings.Split(indexName, ".")
if len(byDot) > 0 {
indexName = byDot[len(byDot)-1]
}
// TODO: distinguish between remote and local index reads
metrics.IndexLookups.WithLabelValues(indexName).Observe(float64(took.Seconds()))
}
// if has suffix .car, then it's a car file
if strings.HasSuffix(r.name, ".car") || r.isSplitCar {
Expand All @@ -51,6 +62,9 @@ func (r *readCloserWrapper) ReadAt(p []byte, off int64) (n int, err error) {
} else {
prefix = icon + purpleBG("[READ-CAR]")
}
carName := filepath.Base(r.name)
// TODO: distinguish between remote and local index reads
metrics.CarLookups.WithLabelValues(carName).Observe(float64(took.Seconds()))
}
klog.V(5).Infof(prefix+" %s:%d+%d (%s)\n", (r.name), off, len(p), took)
}
Expand Down
18 changes: 18 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,21 @@ var Version = promauto.NewGaugeVec(
},
[]string{"started_at", "tag", "commit", "compiler", "goarch", "goos", "goamd64", "vcs", "vcs_revision", "vcs_time", "vcs_modified"},
)

var IndexLookups = promauto.NewHistogramVec(
prometheus.HistogramOpts{
Name: "index_lookups",
Help: "Index lookups",
Buckets: prometheus.ExponentialBuckets(0.000001, 10, 10),
},
[]string{"index_type"},
)

var CarLookups = promauto.NewHistogramVec(
prometheus.HistogramOpts{
Name: "car_lookups",
Help: "Car lookups",
Buckets: prometheus.ExponentialBuckets(0.000001, 10, 10),
},
[]string{"car"},
)

0 comments on commit fc8ae64

Please sign in to comment.