-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvmod_dyncounters.vcc
137 lines (100 loc) · 3.39 KB
/
vmod_dyncounters.vcc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#
# Copyright (c) 2020 Emmanuel Hocdet
# https://github.com/ehocdet/libvmod-dyncounters/
#
$Module dyncounters 3 "Varnish dynamic counters module"
$ABI vrt
DESCRIPTION
===========
`vmod_dyncounters` enables custom counters in a dynamic manner.
Dynamic counters can persist between VCL loads.
This module is designed to support many dynamic counters: you
must take care of cardinality and VSM memory.
vcl sample:
::
import dyncounters;
sub vcl_init {
new TEST = dyncounters.head();
}
sub vcl_recv {
TEST.incr(req.method, "suffix", 1);
}
varnishstat -1 -f "TEST*":
::
TEST.GET.suffix 1 0.00
TEST.HEAD.suffix 2 0.00
vcl sample:
::
import dyncounters;
import proxy;
sub vcl_init {
new SSL = dyncounters.head();
SSL.doc("req", format=integer, type=counter, level=info, oneliner="requests");
}
sub vcl_recv {
if (proxy.is_ssl()) {
SSL.incr(proxy.ssl_version() + ":" + proxy.ssl_cipher() + ":" + req.proto, "req", 1);
}
}
varnishstat -1 -f "SSL*":
::
SSL.TLSv1.2:ECDHE-ECDSA-AES256-GCM-SHA384:HTTP/1.1.req 7 0.00 requests
SSL.TLSv1.2:ECDHE-ECDSA-AES128-GCM-SHA256:HTTP/1.1.req 1 0.00 requests
SSL.TLSv1.3:TLS_AES_128_GCM_SHA256:HTTP/1.1.req 6 0.00 requests
$Event dyncounters_event
$Object head()
Description
Create a head of dynamic counters. The object name is the prefix
of all counter names attached to the head. It appears as such in
varnishstat, at the same level as MGT, MAIN, VBE, ...
The head and its counters persist between VCLs as long as a VCL
has vcl_init the object.
Example
new DYNC = dyncounters.head();
$Method VOID .doc(STRING suffix, ENUM {bitmap, bytes, duration, integer} format=integer, ENUM {bitmap, counter, gauge} type=counter, ENUM {info, debug, diag} level=info, STRING oneliner="")
Description
Create a documentation for all counters with suffix ``suffix``
attached to the object head. This documentation is unique and
persist with object head: any re-declaration of suffix will be
ignored.
``suffix``
Counter suffix.
``format``
Counter format.
``type``
Counter type.
``level``
Counter level.
``oneliner``
Counter description.
Example
DYNC.doc("req", format=integer, type=counter, level=info, oneliner="requests");
$Method VOID .incr(STRANDS radical, STRING suffix, INT d)
Description
Increment value of counter "<head name>.<radical>.<suffix>"
The counter is created on the fly if it does not exist.
Documentation for "suffix" is created on the fly if it does
not exist (with default values).
Negative values are ignored.
Example
DYNC.incr(req.method, "req", 1);
$Method VOID .decr(STRANDS radical, STRING suffix, INT d)
Description
Decrement value of counter "<head name>.<radical>.<suffix>"
The counter is created on the fly if it does not exist.
Documentation for "suffix" is created on the fly if it does
not exist (with default values).
Negative values are ignored.
Example
DYNC.decr(req.method, "req", 1);
$Method VOID .set(STRANDS radical, STRING suffix, INT d)
Description
Set value of counter "<head name>.<radical>.<suffix>"
The counter is created on the fly if it does not exist.
Documentation for "suffix" is created on the fly if it does
not exist (with default values).
Negative values are ignored.
Example
DYNC.set(req.method, "req", 1);
SEE ALSO
========vcl\(7),varnishd\(1)