de.tblsoft.solr.log.parser.RequestCounter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of solr-cmd-utils Show documentation
Show all versions of solr-cmd-utils Show documentation
A command line util for solr.
The newest version!
package de.tblsoft.solr.log.parser;
import com.google.common.base.Strings;
import com.google.common.util.concurrent.AtomicLongMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.SimpleDateFormat;
import java.util.*;
public class RequestCounter extends LogParser {
private static Logger LOG = LoggerFactory.getLogger(RequestCounter.class);
private AtomicLongMap count = AtomicLongMap.create();
private static Map aggregationOptions = new HashMap();
static {
aggregationOptions.put("second", "yyyy-MM-dd-kk:mm:ss");
aggregationOptions.put("minute", "yyyy-MM-dd-kk:mm");
aggregationOptions.put("hour", "yyyy-MM-dd-kk");
aggregationOptions.put("day", "yyyy-MM-dd");
aggregationOptions.put("month", "yyyy-MM");
aggregationOptions.put("year", "yyyy");
}
private String aggregationOption = "second";
private long maxOutput = 150;
public RequestCounter(String file) {
super(file);
}
@Override
protected void line(Date date, String line) {
SimpleDateFormat sdf = new SimpleDateFormat(
aggregationOptions.get(aggregationOption));
String aggregatedDate = sdf.format(date);
count.incrementAndGet(aggregatedDate);
}
public void print() {
SortedSet keys = new TreeSet(count.asMap().keySet());
long maxValue = Collections.max(count.asMap().values());
LOG.info("max: " + maxValue);
for (String key : keys) {
long value = count.get(key);
long scaledValue = scale(value,maxOutput, maxValue);
LOG.info(key + " : " + value + print(scaledValue));
}
}
private String print(long n) {
int i = 0;
StringBuilder buffer = new StringBuilder(" ");
while (i++ < n) {
//http://www.key-shortcut.com/zeichentabellen/utf-8-unicode-tabelle-2/
//buffer.append('\u2588');
//'\u2B1B'
char icon = '\u2B1B';
buffer.append(icon);
}
return buffer.toString();
}
private long scale(long value, long scale, long max) {
long f = (value * scale) / max;
return f;
}
public void setAggregationOption(String aggregationOption) {
if(!Strings.isNullOrEmpty(aggregationOption)) {
this.aggregationOption = aggregationOption;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy