Permalink
Browse files

CSV support for telemetry (#133)

Added CSV support for telemetry (#133)
  • Loading branch information...
Victor-D authored and adolfintel committed Apr 25, 2018
1 parent cd1168f commit 12b90dd47a36e402bbfd8fe067012ec6c1fd3d82
Showing with 33 additions and 2 deletions.
  1. +7 −1 doc.md
  2. +21 −0 telemetry.php
  3. +5 −1 telemetry_settings.php
8 doc.md
@@ -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:
@@ -49,4 +49,25 @@
$stmt->execute(array($ip,$ua,$lang,$dl,$ul,$ping,$jitter,$log)) or die("3");
$conn = null;
}
elseif($db_type=="csv"){
// Prepare the csv formatted string
date_default_timezone_set($timezone);
$date = date('Y-m-d H:i:s');
$str = '"' . $date . '",';
$str .= '"' . $ip . '",';
$str .= '"' . $ua . '",';
$str .= '"' . $dl . '",';
$str .= '"' . $ul . '",';
$str .= '"' . $ping . '",';
$str .= '"' . $jitter . '"' . "\n";
// Set header if this is a new file
if (!file_exists($Csv_File)) {
$header = '"date","ip","ua","download","upload","ping","jitter"' . "\n";
file_put_contents($Csv_File, $header, FILE_APPEND);
}
// Writting line to file
file_put_contents($Csv_File, $str, FILE_APPEND);
}
?>
@@ -1,6 +1,6 @@
<?php
$db_type="mysql"; //Type of db: "mysql", "sqlite" or "postgresql"
$db_type="mysql"; //Type of db: "mysql", "sqlite" or "postgresql" or "csv"
// Sqlite3 settings
$Sqlite_db_file = "../telemetry.sql";
@@ -17,4 +17,8 @@
$PostgreSql_hostname="DB_HOSTNAME";
$PostgreSql_databasename="DB_NAME";
// CSV settings
$Csv_File="reports.csv";
$timezone='UTC';
?>

1 comment on commit 12b90dd

@ltguide

This comment has been minimized.

ltguide commented on 12b90dd Apr 25, 2018

There's a csv output helper function, fputcsv that you might be interested in 😃

Please sign in to comment.