1
0
mirror of https://github.com/beestat/app.git synced 2025-06-01 04:37:12 -04:00

Updating logger to support the use of retention policies

Also having the ecobee logger use it
This commit is contained in:
Jon Ziebell 2019-08-10 07:23:02 -04:00
parent b816715612
commit 09f6b1c728
3 changed files with 14 additions and 2 deletions

View File

@ -18,6 +18,8 @@ class ecobee extends external_api {
protected static $log_influx = true; protected static $log_influx = true;
protected static $log_mysql = 'error'; protected static $log_mysql = 'error';
protected static $influx_retention_policy = '30d';
protected static $cache = false; protected static $cache = false;
protected static $cache_for = null; protected static $cache_for = null;

View File

@ -22,6 +22,12 @@ class external_api extends cora\api {
*/ */
protected static $log_mysql = 'error'; 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 * 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 * 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'], 'http_code' => (int) $this->curl_info['http_code'],
'connect_time' => round($this->curl_info['connect_time'], 4) '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
] ]
); );
} }

View File

@ -17,8 +17,10 @@ class logger extends cora\api {
* Use these for things that need where clauses outside of timestamp. * Use these for things that need where clauses outside of timestamp.
* @param array $fields At least one field. These are not indexed. * @param array $fields At least one field. These are not indexed.
* @param string $timestamp The timestamp in microseconds. * @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 is not configured, do not log.
if( if(
$this->setting->get('influx_database_host') === null || $this->setting->get('influx_database_host') === null ||
@ -46,6 +48,7 @@ class logger extends cora\api {
$this->setting->get('influx_database_port') . $this->setting->get('influx_database_port') .
'/write' . '/write' .
'?db=' . $this->setting->get('influx_database_name') . '?db=' . $this->setting->get('influx_database_name') .
($retention_policy !== null ? ('&rp=' . $retention_policy) : '') .
'&precision=u'; '&precision=u';
exec( exec(