org.graylog2.indexer.DeflectorInformation Maven / Gradle / Ivy
/**
* This file is part of Graylog.
*
* Graylog is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Graylog is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Graylog. If not, see .
*/
package org.graylog2.indexer;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.elasticsearch.action.admin.indices.stats.IndexShardStats;
import org.elasticsearch.action.admin.indices.stats.IndexStats;
import org.elasticsearch.action.admin.indices.stats.ShardStats;
import org.graylog2.indexer.cluster.Cluster;
import org.graylog2.plugin.Tools;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* @author Lennart Koopmann
*/
public class DeflectorInformation {
private final Cluster cluster;
private Map indices = Maps.newHashMap();
private String deflectorTarget;
private int maxMessagesPerIndex;
private String serverId;
public DeflectorInformation(Cluster cluster) {
this.cluster = cluster;
}
public void addIndex(IndexStats index) {
indices.put(index.getIndex(), index);
}
public void addIndices(Map indices) {
this.indices.putAll(indices);
}
public void setDeflectorTarget(String target) {
this.deflectorTarget = target;
}
public void setConfiguredMaximumMessagesPerIndex(int max) {
this.maxMessagesPerIndex = max;
}
public void setCallingNode(String serverId) {
this.serverId = serverId;
}
public Map getAsDatabaseObject() {
Map result = Maps.newHashMap();
Map> indexInformation = Maps.newHashMap();
for (Map.Entry e : indices.entrySet()) {
indexInformation.put(e.getKey(), getIndexInformation(e.getValue()));
}
result.put("server_id", serverId);
result.put("deflector_target", deflectorTarget);
result.put("max_messages_per_index", maxMessagesPerIndex);
result.put("indices", indexInformation);
result.put("timestamp", Tools.getUTCTimestamp());
return result;
}
private Map getIndexInformation(IndexStats stats) {
Map info = Maps.newHashMap();
info.put("docs", stats.getPrimaries().getDocs().getCount());
info.put("size", stats.getPrimaries().getStore().getSize().getKb());
info.put("time_index", stats.getPrimaries().getIndexing().getTotal().getIndexTime().getSeconds());
info.put("time_query", stats.getPrimaries().getSearch().getTotal().getQueryTime().getSeconds());
info.put("time_fetch", stats.getPrimaries().getSearch().getTotal().getFetchTime().getSeconds());
info.put("time_get", stats.getPrimaries().getGet().getTime().getSeconds());
info.put("shards", getShardInformation(stats));
return info;
}
private List