diff options
Diffstat (limited to 'vendor/gipfl/influxdb/src/LineProtocol.php')
-rw-r--r-- | vendor/gipfl/influxdb/src/LineProtocol.php | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/vendor/gipfl/influxdb/src/LineProtocol.php b/vendor/gipfl/influxdb/src/LineProtocol.php new file mode 100644 index 0000000..b3b5f4a --- /dev/null +++ b/vendor/gipfl/influxdb/src/LineProtocol.php @@ -0,0 +1,63 @@ +<?php + +namespace gipfl\InfluxDb; + +use function ksort; +use function strlen; + +abstract class LineProtocol +{ + public static function renderMeasurement($measurement, $tags = [], $fields = [], $timestamp = null) + { + return Escape::measurement($measurement) + . static::renderTags($tags) + . static::renderFields($fields) + . static::renderTimeStamp($timestamp) + . "\n"; + } + + public static function renderTags($tags) + { + ksort($tags); + $string = ''; + foreach ($tags as $key => $value) { + if ($value === null || strlen($value) === 0) { + continue; + } + $string .= ',' . static::renderTag($key, $value); + } + + return $string; + } + + public static function renderFields($fields) + { + $string = ''; + foreach ($fields as $key => $value) { + $string .= ',' . static::renderField($key, $value); + } + $string[0] = ' '; + + return $string; + } + + public static function renderTimeStamp($timestamp) + { + if ($timestamp === null) { + return ''; + } else { + return " $timestamp"; + } + } + + public static function renderTag($key, $value) + { + return Escape::key($key) . '=' . Escape::tagValue($value); + } + + public static function renderField($key, $value) + { + + return Escape::key($key) . '=' . Escape::fieldValue($value); + } +} |