Daniel Willmann | 7423728 | 2020-08-12 12:44:04 +0200 | [diff] [blame] | 1 | module 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 | |
| 16 | type charstring MetricName with { |
| 17 | variant "END(':')"; |
| 18 | }; |
| 19 | |
| 20 | type integer MetricValue with { |
| 21 | variant "END('|', '\|#(1)')"; |
| 22 | }; |
| 23 | |
| 24 | type charstring MetricType (pattern "(g|c|ms|h|m)"); |
| 25 | |
| 26 | type charstring MetricSampleRate (pattern "\d.\d+") with { |
| 27 | variant "BEGIN('|@')" |
| 28 | }; |
| 29 | |
| 30 | type record StatsDMetric { |
| 31 | MetricName name, |
| 32 | MetricValue val, |
| 33 | MetricType mtype, |
| 34 | MetricSampleRate srate optional |
| 35 | }; |
| 36 | |
| 37 | type record of StatsDMetric StatsDMessage with { |
| 38 | variant "SEPARATOR('\n')"; |
| 39 | }; |
| 40 | |
| 41 | external function enc_StatsDMessage(in StatsDMessage id) return charstring |
| 42 | with { extension "prototype(convert) encode(TEXT)"}; |
| 43 | |
| 44 | external function dec_StatsDMessage(in charstring id) return StatsDMessage |
| 45 | with { extension "prototype(convert) decode(TEXT)"}; |
| 46 | |
| 47 | template StatsDMessage tr_StatsDMsg1(template StatsDMetric metric) := { |
| 48 | [0] := metric |
| 49 | } |
| 50 | |
Harald Welte | 09daa2e | 2020-08-21 12:29:38 +0200 | [diff] [blame] | 51 | template (present) StatsDMetric tr_StatsDMetric(template (present) MetricName name, template (present) MetricValue val := ?, |
| 52 | template (present) MetricType mtype) := { |
Daniel Willmann | 7423728 | 2020-08-12 12:44:04 +0200 | [diff] [blame] | 53 | name := name, |
| 54 | val := val, |
Harald Welte | aecdcec | 2020-08-21 12:25:12 +0200 | [diff] [blame] | 55 | mtype := mtype, |
| 56 | srate := * |
Daniel Willmann | 7423728 | 2020-08-12 12:44:04 +0200 | [diff] [blame] | 57 | } |
| 58 | |
Harald Welte | 09daa2e | 2020-08-21 12:29:38 +0200 | [diff] [blame] | 59 | template (present) StatsDMetric tr_StatsDMetricCounter(template (present) MetricName name, template (present) MetricValue val := ?) := |
| 60 | tr_StatsDMetric(name, val, "c"); |
Daniel Willmann | 7423728 | 2020-08-12 12:44:04 +0200 | [diff] [blame] | 61 | |
Harald Welte | 09daa2e | 2020-08-21 12:29:38 +0200 | [diff] [blame] | 62 | template (present) StatsDMetric tr_StatsDMetricGauge(template (present) MetricName name, template (present) MetricValue val := ?) := |
| 63 | tr_StatsDMetric(name, val, "g"); |
Daniel Willmann | 7423728 | 2020-08-12 12:44:04 +0200 | [diff] [blame] | 64 | |
| 65 | } with { encode "TEXT" } |