70 lines
1.7 KiB
Plaintext
70 lines
1.7 KiB
Plaintext
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 StatsDMetric tr_StatsDMetric(template MetricName name, template MetricValue val := ?, template MetricType mtype) := {
|
|
name := name,
|
|
val := val,
|
|
mtype := mtype
|
|
}
|
|
|
|
template StatsDMetric tr_StatsDMetricCounter(template MetricName name, template MetricValue val := ?) := {
|
|
name := name,
|
|
val := val,
|
|
mtype := "c"
|
|
}
|
|
|
|
template StatsDMetric tr_StatsDMetricGauge(template MetricName name, template MetricValue val := ?) := {
|
|
name := name,
|
|
val := val,
|
|
mtype := "g"
|
|
}
|
|
|
|
} with { encode "TEXT" }
|