diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-06-16 14:55:35 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-06-16 14:55:35 +1200 |
commit | 6ceb897e22d426875d5fb4c3b434d000eb627afa (patch) | |
tree | 979ed7cbc7c4d5c24ae9c87fb10f3be59bd1ff54 /src/org/traccar/database | |
parent | 1c029a3bc2437230409c8daf39f03ec52014d579 (diff) | |
download | trackermap-server-6ceb897e22d426875d5fb4c3b434d000eb627afa.tar.gz trackermap-server-6ceb897e22d426875d5fb4c3b434d000eb627afa.tar.bz2 trackermap-server-6ceb897e22d426875d5fb4c3b434d000eb627afa.zip |
Implement statistics collection
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r-- | src/org/traccar/database/StatisticsManager.java | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/org/traccar/database/StatisticsManager.java b/src/org/traccar/database/StatisticsManager.java index 8abadddc5..09cfee856 100644 --- a/src/org/traccar/database/StatisticsManager.java +++ b/src/org/traccar/database/StatisticsManager.java @@ -15,6 +15,9 @@ */ package org.traccar.database; +import com.ning.http.client.Request; +import com.ning.http.client.RequestBuilder; +import org.joda.time.format.ISODateTimeFormat; import org.traccar.Context; import org.traccar.helper.Log; import org.traccar.model.Statistics; @@ -27,7 +30,7 @@ import java.util.Set; public class StatisticsManager { - private static final int SPLIT_MODE = Calendar.DAY_OF_MONTH; + private static final int SPLIT_MODE = Calendar.MINUTE; private int lastUpdate = Calendar.getInstance().get(SPLIT_MODE); @@ -63,6 +66,27 @@ public class StatisticsManager { Log.warning(e); } + String url = Context.getConfig().getString("server.statistics"); + if (url != null) { + String time = ISODateTimeFormat.dateTime().print(statistics.getCaptureTime().getTime()); + Request request = new RequestBuilder("POST") + .setUrl(url) + .addHeader("Content-Type", "application/x-www-form-urlencoded") + .addFormParam("version", Log.getAppVersion()) + .addFormParam("captureTime", time) + .addFormParam("activeUsers", String.valueOf(statistics.getActiveUsers())) + .addFormParam("activeDevices", String.valueOf(statistics.getActiveDevices())) + .addFormParam("requests", String.valueOf(statistics.getRequests())) + .addFormParam("messagesReceived", String.valueOf(statistics.getMessagesReceived())) + .addFormParam("messagesStored", String.valueOf(statistics.getMessagesStored())) + .addFormParam("mailSent", String.valueOf(statistics.getMailSent())) + .addFormParam("smsSent", String.valueOf(statistics.getSmsSent())) + .addFormParam("geocoderRequests", String.valueOf(statistics.getGeocoderRequests())) + .addFormParam("geolocationRequests", String.valueOf(statistics.getGeolocationRequests())) + .build(); + Context.getAsyncHttpClient().prepareRequest(request).execute(); + } + users.clear(); devices.clear(); requests = 0; |