Add build version (and start date).

This commit is contained in:
Lapo Luchini 2025-06-22 10:14:31 +02:00
parent ce7853091c
commit cf9abf5001
No known key found for this signature in database
GPG Key ID: AE3AE4564225519A
2 changed files with 11 additions and 0 deletions

View File

@ -1194,6 +1194,9 @@ func (s *Server) GenerateRoutes(rc *ollama.Registry) (http.Handler, error) {
slog.Warn(fmt.Sprintf("Metrics initialization failed with %s", err))
}
s.metrics = m
s.metrics.Start.Record(nil, time.Now().UnixMicro()/1e6, metric.WithAttributes(
attribute.String("version", version.Version),
))
r := gin.Default()
r.HandleMethodNotAllowed = true

View File

@ -20,6 +20,7 @@ const (
)
type Metrics struct {
Start metric.Int64Gauge
Requests metric.Int64Counter
TotalDuration metric.Float64Counter
LoadDuration metric.Float64Counter
@ -30,6 +31,12 @@ type Metrics struct {
}
func NewMetrics(meter metric.Meter) *Metrics {
build, _ := meter.Int64Gauge(
"ollama_build_info",
metric.WithDescription("Ollama start date (as Unixtime) and build version."),
metric.WithUnit("seconds"),
)
req, _ := meter.Int64Counter(
"http_requests_total",
metric.WithDescription("The total number of requests on the endpoints."),
@ -73,6 +80,7 @@ func NewMetrics(meter metric.Meter) *Metrics {
)
return &Metrics{
Start: build,
Requests: req,
TotalDuration: totalDuration,
LoadDuration: loadDuration,