From 6ceb897e22d426875d5fb4c3b434d000eb627afa Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 16 Jun 2017 14:55:35 +1200 Subject: Implement statistics collection --- src/org/traccar/database/StatisticsManager.java | 26 ++++++++++++++++++++++++- src/org/traccar/model/Statistics.java | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'src/org') 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; diff --git a/src/org/traccar/model/Statistics.java b/src/org/traccar/model/Statistics.java index 93a9c0d39..c7ae5af7a 100644 --- a/src/org/traccar/model/Statistics.java +++ b/src/org/traccar/model/Statistics.java @@ -116,6 +116,7 @@ public class Statistics extends Extensible { public void setGeocoderRequests(int geocoderRequests) { this.geocoderRequests = geocoderRequests; } + private int geolocationRequests; public int getGeolocationRequests() { -- cgit v1.2.3