blob: 89385711e7052da50adef5e03c49bd9184e79e41 [file] [log] [blame]
Daniel Willmann74237282020-08-12 12:44:04 +02001module StatsD_Types {
2
3/* Definition of abstract types for the StatsD protocol. USes the TITAN "TEXT"
4 * codec to auto-generate encoder/decoder functions
5 *
6 * (C) 2020 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
7 * All rights reserved.
8 *
9 * Author: Daniel Willmann <dwillmann@sysmocom.de>
10 *
11 * Released under the terms of GNU General Public License, Version 2 or
12 * (at your option) any later version.
13 * SPDX-License-Identifier: GPL-2.0-or-later
14 */
15
16type charstring MetricName with {
17 variant "END(':')";
18};
19
20type integer MetricValue with {
21 variant "END('|', '\|#(1)')";
22};
23
24type charstring MetricType (pattern "(g|c|ms|h|m)");
25
26type charstring MetricSampleRate (pattern "\d.\d+") with {
27 variant "BEGIN('|@')"
28};
29
30type record StatsDMetric {
31 MetricName name,
32 MetricValue val,
33 MetricType mtype,
34 MetricSampleRate srate optional
35};
36
37type record of StatsDMetric StatsDMessage with {
38 variant "SEPARATOR('\n')";
39};
40
41external function enc_StatsDMessage(in StatsDMessage id) return charstring
42with { extension "prototype(convert) encode(TEXT)"};
43
44external function dec_StatsDMessage(in charstring id) return StatsDMessage
45with { extension "prototype(convert) decode(TEXT)"};
46
47template StatsDMessage tr_StatsDMsg1(template StatsDMetric metric) := {
48 [0] := metric
49}
50
Harald Welte09daa2e2020-08-21 12:29:38 +020051template (present) StatsDMetric tr_StatsDMetric(template (present) MetricName name, template (present) MetricValue val := ?,
52 template (present) MetricType mtype) := {
Daniel Willmann74237282020-08-12 12:44:04 +020053 name := name,
54 val := val,
Harald Welteaecdcec2020-08-21 12:25:12 +020055 mtype := mtype,
56 srate := *
Daniel Willmann74237282020-08-12 12:44:04 +020057}
58
Harald Welte09daa2e2020-08-21 12:29:38 +020059template (present) StatsDMetric tr_StatsDMetricCounter(template (present) MetricName name, template (present) MetricValue val := ?) :=
60 tr_StatsDMetric(name, val, "c");
Daniel Willmann74237282020-08-12 12:44:04 +020061
Harald Welte09daa2e2020-08-21 12:29:38 +020062template (present) StatsDMetric tr_StatsDMetricGauge(template (present) MetricName name, template (present) MetricValue val := ?) :=
63 tr_StatsDMetric(name, val, "g");
Daniel Willmann74237282020-08-12 12:44:04 +020064
65} with { encode "TEXT" }