summary with total of events from ES and from DB

This commit is contained in:
Michele Artini 2021-02-17 12:19:20 +01:00
parent 1614002b5c
commit 504d42e96c
3 changed files with 27 additions and 5 deletions

View File

@ -4,8 +4,10 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -54,6 +56,9 @@ public class AjaxController extends AbstractDnetController {
@Autowired
private ThreadManager threadManager;
@Autowired
private JdbcTemplate jdbcTemplate;
@Value("${lbs.elastic.homepage}")
private String elasticSearchUiUrl;
@ -92,14 +97,24 @@ public class AjaxController extends AbstractDnetController {
currentStatus.setDispatchers(dispatchers);
currentStatus.setThreads(threads);
currentStatus.getTotals().put("topics", topicTypeRepo.count());
currentStatus.getTotals().put("events", eventRepository.count());
currentStatus.getTotals().put("events_es", eventRepository.count());
currentStatus.getTotals().put("events_db", countEventsInTheDb());
currentStatus.getTotals().put("subscriptions", subscriptionRepo.count());
currentStatus.getTotals().put("notifications", notificationRepository.count());
currentStatus.getTotals().put("notifications_es", notificationRepository.count());
return currentStatus;
}
}
private Long countEventsInTheDb() {
try {
final String sql = IOUtils.toString(getClass().getResourceAsStream("/sql/totalEvents.sql"));
return jdbcTemplate.queryForObject(sql, Long.class);
} catch (final Exception e) {
return 0l;
}
}
@GetMapping("/resetCounters")
public CurrentStatus resetCounters() {
dispatcherManager.getDispatchers().forEach(NotificationDispatcher::resetCount);

View File

@ -0,0 +1 @@
select sum(size) from oa_datasource_stats;

View File

@ -22,9 +22,15 @@
</td>
</tr>
<tr>
<th class="col-xs-6">n. events</th>
<th class="col-xs-6">n. events (total)</th>
<td class="col-xs-6 text-right">
{{summary.totals.events}}
{{summary.totals.events_db}}
</td>
</tr>
<tr>
<th class="col-xs-6">n. events (on ES)</th>
<td class="col-xs-6 text-right">
{{summary.totals.events_es}}
</td>
</tr>
<tr>
@ -36,7 +42,7 @@
<tr>
<th class="col-xs-6">n. notifications</th>
<td class="col-xs-6 text-right">
{{summary.totals.notifications}}
{{summary.totals.notifications_es}}
</td>
</tr>
</table>