aboutsummaryrefslogtreecommitdiffstats
path: root/library/StatsD_Types.ttcn
blob: 89385711e7052da50adef5e03c49bd9184e79e41 (plain)
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
module StatsD_Types {

/* Definition of abstract types for the StatsD protocol. USes the TITAN "TEXT"
 * codec to auto-generate encoder/decoder functions
 *
 * (C) 2020 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
 * All rights reserved.
 *
 * Author: Daniel Willmann <dwillmann@sysmocom.de>
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

type charstring MetricName with {
	variant "END(':')";
};

type integer MetricValue with {
	variant "END('|', '\|#(1)')";
};

type charstring MetricType (pattern "(g|c|ms|h|m)");

type charstring MetricSampleRate (pattern "\d.\d+") with {
	variant "BEGIN('|@')"
};

type record StatsDMetric {
	MetricName	name,
	MetricValue	val,
	MetricType	mtype,
	MetricSampleRate srate optional
};

type record of StatsDMetric StatsDMessage with {
	variant "SEPARATOR('\n')";
};

external function enc_StatsDMessage(in StatsDMessage id) return charstring
with { extension "prototype(convert) encode(TEXT)"};

external function dec_StatsDMessage(in charstring id) return StatsDMessage
with { extension "prototype(convert) decode(TEXT)"};

template StatsDMessage tr_StatsDMsg1(template StatsDMetric metric) := {
	[0] := metric
}

template (present) StatsDMetric tr_StatsDMetric(template (present) MetricName name, template (present) MetricValue val := ?,
						template (present) MetricType mtype) := {
	name := name,
	val := val,
	mtype := mtype,
	srate := *
}

template (present) StatsDMetric tr_StatsDMetricCounter(template (present) MetricName name, template (present) MetricValue val := ?) :=
	tr_StatsDMetric(name, val, "c");

template (present) StatsDMetric tr_StatsDMetricGauge(template (present) MetricName name, template (present) MetricValue val := ?) :=
	tr_StatsDMetric(name, val, "g");

} with { encode "TEXT" }