diff --git a/api/ecobee.php b/api/ecobee.php index 70bb36f..787eff5 100644 --- a/api/ecobee.php +++ b/api/ecobee.php @@ -18,6 +18,8 @@ class ecobee extends external_api { protected static $log_influx = true; protected static $log_mysql = 'error'; + protected static $influx_retention_policy = '30d'; + protected static $cache = false; protected static $cache_for = null; diff --git a/api/external_api.php b/api/external_api.php index 626e760..adca8eb 100644 --- a/api/external_api.php +++ b/api/external_api.php @@ -22,6 +22,12 @@ class external_api extends cora\api { */ protected static $log_mysql = 'error'; + /** + * Default retention policy when inserting data. Autogen is the default + * infinite one; also available is 30d. + */ + protected static $influx_retention_policy = 'autogen'; + /** * Whether or not to cache API calls. This will store a hash of the request * and the response in the database and check there before performing the @@ -230,7 +236,8 @@ class external_api extends cora\api { 'http_code' => (int) $this->curl_info['http_code'], 'connect_time' => round($this->curl_info['connect_time'], 4) ], - 'timestamp' => $this->request_timestamp_microtime + 'timestamp' => $this->request_timestamp_microtime, + 'retention_policy' => $this::$influx_retention_policy ] ); } diff --git a/api/logger.php b/api/logger.php index e2ac85e..ca84fb0 100644 --- a/api/logger.php +++ b/api/logger.php @@ -17,8 +17,10 @@ class logger extends cora\api { * Use these for things that need where clauses outside of timestamp. * @param array $fields At least one field. These are not indexed. * @param string $timestamp The timestamp in microseconds. + * @param string $retention_policy The retention policy to write to. + * Defaults to "autogen" which is infinite. */ - public function log_influx($measurement, $tags, $fields, $timestamp) { + public function log_influx($measurement, $tags, $fields, $timestamp, $retention_policy = null) { // If this is not configured, do not log. if( $this->setting->get('influx_database_host') === null || @@ -46,6 +48,7 @@ class logger extends cora\api { $this->setting->get('influx_database_port') . '/write' . '?db=' . $this->setting->get('influx_database_name') . + ($retention_policy !== null ? ('&rp=' . $retention_policy) : '') . '&precision=u'; exec(