blob: 2142b8c4d8b425115363b6f6e47f689f718d63a0 [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
51template StatsDMetric tr_StatsDMetric(template MetricName name, template MetricValue val := ?, template MetricType mtype) := {
52 name := name,
53 val := val,
54 mtype := mtype
55}
56
57template StatsDMetric tr_StatsDMetricCounter(template MetricName name, template MetricValue val := ?) := {
58 name := name,
59 val := val,
60 mtype := "c"
61}
62
63template StatsDMetric tr_StatsDMetricGauge(template MetricName name, template MetricValue val := ?) := {
64 name := name,
65 val := val,
66 mtype := "g"
67}
68
69} with { encode "TEXT" }