@@ -2,12 +2,19 @@ const std = @import("std");
2
2
const m = @import ("metrics" );
3
3
4
4
var metrics = m .initializeNoop (Metrics );
5
+ var arena : ? std.heap.ArenaAllocator = null ;
5
6
6
7
const WithIndex = struct { index : []const u8 };
7
8
9
+ const SearchDuration = m .Histogram (
10
+ f64 ,
11
+ &.{ 0.005 , 0.01 , 0.05 , 0.1 , 0.5 , 1 , 5 , 10 },
12
+ );
13
+
8
14
const Metrics = struct {
9
15
search_hits : m .Counter (u64 ),
10
16
search_misses : m .Counter (u64 ),
17
+ search_duration : SearchDuration ,
11
18
searches : m .Counter (u64 ),
12
19
updates : m .Counter (u64 ),
13
20
checkpoints : m .Counter (u64 ),
@@ -28,6 +35,10 @@ pub fn searchMiss() void {
28
35
metrics .search_misses .incr ();
29
36
}
30
37
38
+ pub fn searchDuration (duration_ms : i64 ) void {
39
+ metrics .search_duration .observe (@as (f64 , @floatFromInt (duration_ms )) / 1000.0 );
40
+ }
41
+
31
42
pub fn update (count : usize ) void {
32
43
metrics .updates .incrBy (@intCast (count ));
33
44
}
@@ -49,20 +60,24 @@ pub fn docs(index_name: []const u8, value: u32) void {
49
60
}
50
61
51
62
pub fn initializeMetrics (allocator : std.mem.Allocator , comptime opts : m.RegistryOpts ) ! void {
63
+ arena = std .heap .ArenaAllocator .init (allocator );
64
+ const alloc = arena .? .allocator ();
65
+
52
66
metrics = .{
53
67
.search_hits = m .Counter (u64 ).init ("search_hits_total" , .{}, opts ),
54
68
.search_misses = m .Counter (u64 ).init ("search_misses_total" , .{}, opts ),
69
+ .search_duration = SearchDuration .init ("search_duration_seconds" , .{}, opts ),
55
70
.searches = m .Counter (u64 ).init ("searches_total" , .{}, opts ),
56
71
.updates = m .Counter (u64 ).init ("updates_total" , .{}, opts ),
57
72
.checkpoints = m .Counter (u64 ).init ("checkpoints_total" , .{}, opts ),
58
73
.memory_segment_merges = m .Counter (u64 ).init ("memory_segment_merges_total" , .{}, opts ),
59
74
.file_segment_merges = m .Counter (u64 ).init ("file_segment_merges_total" , .{}, opts ),
60
- .docs = try m .GaugeVec (u32 , WithIndex ).init (allocator , "docs" , .{}, opts ),
75
+ .docs = try m .GaugeVec (u32 , WithIndex ).init (alloc , "docs" , .{}, opts ),
61
76
};
62
77
}
63
78
64
79
pub fn deinitMetrics () void {
65
- metrics . docs .deinit ();
80
+ arena .? .deinit ();
66
81
}
67
82
68
83
pub fn writeMetrics (writer : anytype ) ! void {
0 commit comments