Skip to content

Commit da55dcc

Browse files
authored
Merge pull request #136 from Ente/telemetry-server-statistics
v8.6: Telemetry server statistics
2 parents caa14e8 + df1fbe7 commit da55dcc

File tree

15 files changed

+158
-12
lines changed

15 files changed

+158
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## v8.6
4+
5+
* Telemetry statistics page for environments using the Telemetry Server. Please check `README.md`
6+
37
## v8.5.1
48

59
* Fixed undefined variable warning message <!-- [#133](https://github.com/Ente/timetrack/issues/133) -->

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ In step 2, you need to configure the `app.json.sample` within the `api/v1/inc` f
116116
- `demo`: If set to `true`, demo credentials are shown on the login page. Useful for demo installations.
117117
- `telemetry`: Enable/disable telemetry (Default: `enabled` - **PLEASE DISABLE IF NEEDED**)
118118
- `telemetry_server_url`: Full server url to telemetry upload
119+
- `telemetryServer`: Enables/disables the Server Telemetry Statistics page
119120

120121
#### **SMTP section**
121122

@@ -254,6 +255,23 @@ To upload a new theme, simply place it into the `/assets/css` folder.
254255

255256
The theme the user selected is saved as a cookie, meaning it is only selected on the current device. On mobile or on another device, the user has to set the desired theme again.
256257

258+
## Run as Telemetry server
259+
260+
Basically, there are only a few steps to do
261+
262+
1. Navigate to the telemetry server directory: `cd api/v1/class/telemetry/server`
263+
2. Start server: `nohup php -S 0.0.0.0:8888 server.php > telemetry.log 2>&1 &`
264+
3. Set `telemetryServer` inside app.json `general` section to `true`.
265+
4. Check received telemetry data on the "Server Telemetry" page.
266+
267+
## Change Telemetry server URL for managed environments
268+
269+
If you want all of your TimeTrack instances to point to your telemetry server instance, you need to change the app.json `general` `telemetry_server_url` attribute to your URL.
270+
Also make sure the `telemetry` attribute is set to `"enabled"`.
271+
272+
To check if all worked simply visit the Settings page using an admin account. Check the checkbox within the Telemetry section at the bottom of the page and click the Submit button.
273+
On your server timetrack instance you need to visit the "Server Telemetry" page to check if you received the new/updated telemetry data.
274+
257275
## Updates
258276

259277
TimeTrack has to be updated in two ways: database and application.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.5.1
1+
8.6

api/v1/class/i18n/suite/nav/snippets_DE.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"a_sickness": "Alle Krankheiten",
1111
"a_vacation": "Alle Urlaube",
1212
"a_plugins": "Plugins",
13-
"a_projects": "Projektmanagement"
13+
"a_projects": "Projektmanagement",
14+
"a_serverTelemetry": "Server-Telemetrie"
1415
}

api/v1/class/i18n/suite/nav/snippets_EN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"a_sickness": "Sickness reports",
1111
"a_vacation": "Vacation reports",
1212
"a_plugins": "Plugins",
13-
"a_projects": "Projects management"
13+
"a_projects": "Projects management",
14+
"a_serverTelemetry": "Server Telemetry"
1415
}

api/v1/class/i18n/suite/nav/snippets_NL.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"a_sickness": "Alle ziekten",
1111
"a_vacation": "Alle vakanties",
1212
"a_plugins": "Plug-ins",
13-
"a_projects": "Projects management"
13+
"a_projects": "Projects management",
14+
"a_serverTelemetry": "Server Telemetry"
1415
}

api/v1/class/i18n/suite/status/snippets_DE.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@
5252
"plugins_disabled": "Fehler: Das Plugin-System ist deaktiviert. Bitte wende dich an deinen Administrator!",
5353
"telemetry_sent": "Hinweis: Telemetriedaten wurden erfolgreich gesendet!",
5454
"telemetry_disabled": "Hinweis: Telemetriedaten wurden nicht gesendet!",
55-
"success": "Hinweis: Die Aktion wurde erfolgreich ausgeführt!"
55+
"success": "Hinweis: Die Aktion wurde erfolgreich ausgeführt!",
56+
"telemetryServer_disabled": "Hinweis: Die Serverfunktion der Telemetry ist derzeit deaktiviert!"
5657
}

api/v1/class/i18n/suite/status/snippets_EN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@
5252
"plugins_disabled": "Error: The plugin system is disabled. Please contact your administrator!",
5353
"telemetry_sent": "Note: Telemetry data sent successfully!",
5454
"telemetry_disabled": "Note: Telemetry data not sent!",
55-
"success": "Note: The action was completed successfully!"
55+
"success": "Note: The action was completed successfully!",
56+
"telemetryServer_disabled": "Note: The server telemetry functionality is currently disabled!"
5657
}

api/v1/class/telemetry/server/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
Make sure your clients point to a specific client for the telemetry server.
44
Install TimeTrack on that server and start the telemetry server with `cd path/to/timetrack/api/v1/class/telemetry/server && php -S 0.0.0.0:8888 server.php`
55

6-
Inside DB check the results within the `telemetry_server` table. A GUI is comming soon.
6+
Inside DB check the results within the `telemetry_server` table. Set `telemetryServer` var within app.json `general` section to `true`.
7+
A new entry called Server Telemetry will appear within the Navigation bar.

api/v1/class/telemetry/telemetry.arbeit.inc.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,69 @@ public function isTelemetryEnabled(): bool
5757
return isset($ini["general"]["telemetry"]) && $ini["general"]["telemetry"] === "enabled";
5858
}
5959

60+
public function isTelemetryServerEnabled(): bool
61+
{
62+
$ini = $this->get_app_ini();
63+
return isset($ini["general"]["telemetryServer"]) && $ini["general"]["telemetryServer"] == true;
64+
}
65+
66+
public function getServerTelemetryData(): array
67+
{
68+
$stmt = $this->db->sendQuery("SELECT * FROM telemetry_server ORDER BY id DESC");
69+
$stmt->execute();
70+
return $stmt->fetchAll(\PDO::FETCH_ASSOC) ?: [];
71+
}
72+
73+
74+
public function renderServerTelemetryHTML(): void
75+
{
76+
$rows = $this->getServerTelemetryData();
77+
78+
if (empty($rows)) {
79+
echo "<p>{$this->i18n['no_data']}</p>";
80+
return;
81+
}
82+
83+
$columns = [
84+
"instance_uuid",
85+
"time_track_version",
86+
"api_version",
87+
"php_version",
88+
"os_version_and_name",
89+
"total_plugins",
90+
"total_users",
91+
"total_worktimes",
92+
"api_calls_total",
93+
"created_at",
94+
"updated_at"
95+
];
96+
97+
$html = '<div style="overflow-x:auto; width:100%;">';
98+
99+
$html .= "<table class='v8-table'><thead><tr>";
100+
101+
foreach ($columns as $col) {
102+
$html .= "<th>" . htmlspecialchars($col) . "</th>";
103+
}
104+
105+
$html .= "</tr></thead><tbody>";
106+
107+
foreach ($rows as $row) {
108+
$html .= "<tr>";
109+
110+
foreach ($columns as $col) {
111+
$value = $row[$col] ?? "-";
112+
$html .= "<td>" . htmlspecialchars((string)$value) . "</td>";
113+
}
114+
115+
$html .= "</tr>";
116+
}
117+
118+
$html .= "</tbody></table></div>";
119+
120+
echo $html;
121+
}
122+
60123

61124

62125
public function sendRequest($data)

0 commit comments

Comments
 (0)