CSV support for telemetry

This commit is contained in:
Victor D'Agostino 2018-04-25 16:44:26 +02:00
parent b197e2fc78
commit d9f999168d
2 changed files with 12 additions and 6 deletions

8
doc.md
View file

@ -319,7 +319,7 @@ w.postMessage('start {"url_dl": "newGarbageURL", "url_ul": "newEmptyURL", "url_p
Telemetry currently requires PHP and either MySQL, PostgreSQL or SQLite.
To set up the telemetry, we need to do 4 things:
* copy `telemetry.php` and `telemetry_settings.php`
* edit `telemetry_settings.php` to add your database settings
* edit `telemetry_settings.php` to add your database settings or the csv filename and date timezone if CSV is used instead of database storage.
* create the database
* enable telemetry
@ -352,6 +352,12 @@ $PostgreSql_hostname="DB_HOSTNAME"; //database address, usually localhost
$PostgreSql_databasename="DB_NAME"; //the name of the database where you loaded telemetry_postgresql.sql
```
If you choose to use CSV file, you must set the Csv_File and timezone variables.
```php
$Csv_File="myReportFile.csv";
$timezone='Europe/Paris';
```
### Enabling telemetry
Edit your test page; where you start the worker, you need to specify the `telemetry_level`.
There are 3 levels:

View file

@ -52,18 +52,18 @@ if($db_type=="mysql"){
elseif($db_type=="csv"){
// Prepare the csv formatted string
date_default_timezone_set($timezone);
$date = date('Y-m-d H:M:S');
$str = '"' . $ip . '",';
$date = date('Y-m-d H:i:s');
$str = '"' . $date . '",';
$str .= '"' . $ip . '",';
$str .= '"' . $ua . '",';
$str .= '"' . $dl . '",';
$str .= '"' . $ul . '",';
$str .= '"' . $ping . '",';
$str .= '"' . $jitter . '",';
$str .= '"' . $$log . '"' . "\n";
$str .= '"' . $jitter . '"' . "\n";
// Set header if this is a new file
if (!file_exists($Csv_File)) {
$header = '"ip","ua","download","upload","ping","jitter","log"' . "\n";
$header = '"date","ip","ua","download","upload","ping","jitter"' . "\n";
file_put_contents($Csv_File, $header, FILE_APPEND);
}