use of org.traccar.model.Statistics in project traccar by tananaev.
the class StatisticsManager method checkSplit.
private void checkSplit() {
int currentUpdate = Calendar.getInstance().get(SPLIT_MODE);
if (lastUpdate.getAndSet(currentUpdate) != currentUpdate) {
Statistics statistics = new Statistics();
synchronized (this) {
statistics.setCaptureTime(new Date());
statistics.setActiveUsers(users.size());
statistics.setActiveDevices(deviceProtocols.size());
statistics.setRequests(requests);
statistics.setMessagesReceived(messagesReceived);
statistics.setMessagesStored(messagesStored);
statistics.setMailSent(mailSent);
statistics.setSmsSent(smsSent);
statistics.setGeocoderRequests(geocoderRequests);
statistics.setGeolocationRequests(geolocationRequests);
if (!deviceProtocols.isEmpty()) {
Map<String, Integer> protocols = new HashMap<>();
for (String protocol : deviceProtocols.values()) {
protocols.compute(protocol, (key, count) -> count != null ? count + 1 : 1);
}
statistics.setProtocols(protocols);
}
users.clear();
deviceProtocols.clear();
requests = 0;
messagesReceived = 0;
messagesStored = 0;
mailSent = 0;
smsSent = 0;
geocoderRequests = 0;
geolocationRequests = 0;
}
try {
dataManager.addObject(statistics);
} catch (StorageException e) {
LOGGER.warn("Error saving statistics", e);
}
String url = config.getString(Keys.SERVER_STATISTICS);
if (url != null) {
String time = DateUtil.formatDate(statistics.getCaptureTime());
Form form = new Form();
form.param("version", getClass().getPackage().getImplementationVersion());
form.param("captureTime", time);
form.param("activeUsers", String.valueOf(statistics.getActiveUsers()));
form.param("activeDevices", String.valueOf(statistics.getActiveDevices()));
form.param("requests", String.valueOf(statistics.getRequests()));
form.param("messagesReceived", String.valueOf(statistics.getMessagesReceived()));
form.param("messagesStored", String.valueOf(statistics.getMessagesStored()));
form.param("mailSent", String.valueOf(statistics.getMailSent()));
form.param("smsSent", String.valueOf(statistics.getSmsSent()));
form.param("geocoderRequests", String.valueOf(statistics.getGeocoderRequests()));
form.param("geolocationRequests", String.valueOf(statistics.getGeolocationRequests()));
if (statistics.getProtocols() != null) {
try {
form.param("protocols", objectMapper.writeValueAsString(statistics.getProtocols()));
} catch (JsonProcessingException e) {
LOGGER.warn("Failed to serialize protocols", e);
}
}
client.target(url).request().async().post(Entity.form(form));
}
}
}
use of org.traccar.model.Statistics in project traccar by traccar.
the class StatisticsManager method checkSplit.
private void checkSplit() {
int currentUpdate = Calendar.getInstance().get(SPLIT_MODE);
if (lastUpdate.getAndSet(currentUpdate) != currentUpdate) {
Statistics statistics = new Statistics();
synchronized (this) {
statistics.setCaptureTime(new Date());
statistics.setActiveUsers(users.size());
statistics.setActiveDevices(deviceProtocols.size());
statistics.setRequests(requests);
statistics.setMessagesReceived(messagesReceived);
statistics.setMessagesStored(messagesStored);
statistics.setMailSent(mailSent);
statistics.setSmsSent(smsSent);
statistics.setGeocoderRequests(geocoderRequests);
statistics.setGeolocationRequests(geolocationRequests);
if (!deviceProtocols.isEmpty()) {
Map<String, Integer> protocols = new HashMap<>();
for (String protocol : deviceProtocols.values()) {
protocols.compute(protocol, (key, count) -> count != null ? count + 1 : 1);
}
statistics.setProtocols(protocols);
}
users.clear();
deviceProtocols.clear();
requests = 0;
messagesReceived = 0;
messagesStored = 0;
mailSent = 0;
smsSent = 0;
geocoderRequests = 0;
geolocationRequests = 0;
}
try {
dataManager.addObject(statistics);
} catch (StorageException e) {
LOGGER.warn("Error saving statistics", e);
}
String url = config.getString(Keys.SERVER_STATISTICS);
if (url != null) {
String time = DateUtil.formatDate(statistics.getCaptureTime());
Form form = new Form();
form.param("version", getClass().getPackage().getImplementationVersion());
form.param("captureTime", time);
form.param("activeUsers", String.valueOf(statistics.getActiveUsers()));
form.param("activeDevices", String.valueOf(statistics.getActiveDevices()));
form.param("requests", String.valueOf(statistics.getRequests()));
form.param("messagesReceived", String.valueOf(statistics.getMessagesReceived()));
form.param("messagesStored", String.valueOf(statistics.getMessagesStored()));
form.param("mailSent", String.valueOf(statistics.getMailSent()));
form.param("smsSent", String.valueOf(statistics.getSmsSent()));
form.param("geocoderRequests", String.valueOf(statistics.getGeocoderRequests()));
form.param("geolocationRequests", String.valueOf(statistics.getGeolocationRequests()));
if (statistics.getProtocols() != null) {
try {
form.param("protocols", objectMapper.writeValueAsString(statistics.getProtocols()));
} catch (JsonProcessingException e) {
LOGGER.warn("Failed to serialize protocols", e);
}
}
client.target(url).request().async().post(Entity.form(form));
}
}
}
Aggregations