Added column in stat ua command.
This commit is contained in:
parent
8e38a03eb0
commit
1d5179a5c3
7 changed files with 136 additions and 38 deletions
|
@ -237,7 +237,7 @@ public class StatoolInfos
|
|||
|
||||
for (UserAgentStat stat : stator.getUserAgentStats().sortByLabel())
|
||||
{
|
||||
System.out.println(stat.getValue());
|
||||
System.out.println(stat.getUserAgent());
|
||||
}
|
||||
|
||||
System.err.println(String.format("%s %10d", "UserAgent count: ", stator.getUserAgentStats().size()));
|
||||
|
@ -351,6 +351,7 @@ public class StatoolInfos
|
|||
}
|
||||
}
|
||||
|
||||
System.err.println("IpCount Ip");
|
||||
for (IpStat stat : stator.getIps().sortByCount().reverse())
|
||||
{
|
||||
System.out.println(stat.getCount() + " " + stat.getValue());
|
||||
|
@ -401,9 +402,10 @@ public class StatoolInfos
|
|||
}
|
||||
}
|
||||
|
||||
System.err.println("LogCount IpCount VisitCount UserAgent");
|
||||
for (UserAgentStat stat : stator.getUserAgentStats().sortByCount().reverse())
|
||||
{
|
||||
System.out.println(stat.getCount() + " " + stat.getValue());
|
||||
System.out.println(String.format("%d %d %d %s", stat.getLogCount(), stat.getIpCount(), stat.getVisitCount(), stat.getUserAgent()));
|
||||
}
|
||||
|
||||
System.err.println(String.format("%s %10d", "User Agent count: ", stator.getUserAgentStats().size()));
|
||||
|
@ -451,6 +453,7 @@ public class StatoolInfos
|
|||
}
|
||||
}
|
||||
|
||||
System.err.println("VisitCount LogCount VisitDuration VisitDuration Ip UserAgent");
|
||||
for (VisitorStat stat : stator.getVisitorStats().sortByVisitCount().reverse())
|
||||
{
|
||||
System.out.println(
|
||||
|
|
41
src/fr/devinsy/statoolinfos/stats/useragent/IpSet.java
Normal file
41
src/fr/devinsy/statoolinfos/stats/useragent/IpSet.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
|
||||
*
|
||||
* This file is part of StatoolInfos, simple service statistics tool.
|
||||
*
|
||||
* StatoolInfos is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* StatoolInfos 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package fr.devinsy.statoolinfos.stats.useragent;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class IpSet.
|
||||
*/
|
||||
public final class IpSet extends HashSet<String>
|
||||
{
|
||||
private static final long serialVersionUID = 8883849089810229045L;
|
||||
private static Logger logger = LoggerFactory.getLogger(IpSet.class);
|
||||
|
||||
/**
|
||||
* Instantiates a new ip set.
|
||||
*/
|
||||
public IpSet()
|
||||
{
|
||||
super();
|
||||
}
|
||||
}
|
|
@ -21,6 +21,11 @@ package fr.devinsy.statoolinfos.stats.useragent;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.statoolinfos.metrics.http.HttpAccessLog;
|
||||
import fr.devinsy.statoolinfos.metrics.http.HttpStatusCategory;
|
||||
import fr.devinsy.statoolinfos.stats.visitor.VisitorStat;
|
||||
import fr.devinsy.statoolinfos.stats.visitor.VisitorStatSet;
|
||||
|
||||
/**
|
||||
* The Class UserAgentStat.
|
||||
*/
|
||||
|
@ -28,9 +33,10 @@ public final class UserAgentStat
|
|||
{
|
||||
private static Logger logger = LoggerFactory.getLogger(UserAgentStat.class);
|
||||
|
||||
private String value;
|
||||
private long count;
|
||||
private long ipLinkCount;
|
||||
private String userAgent;
|
||||
private long logCount;
|
||||
private IpSet ips;
|
||||
private VisitorStatSet visitors;
|
||||
|
||||
/**
|
||||
* Instantiates a new user agent stat.
|
||||
|
@ -42,34 +48,62 @@ public final class UserAgentStat
|
|||
*/
|
||||
public UserAgentStat(final String userAgent)
|
||||
{
|
||||
this.value = userAgent;
|
||||
this.count = 0;
|
||||
this.ipLinkCount = 0;
|
||||
this.userAgent = userAgent;
|
||||
this.logCount = 0;
|
||||
this.ips = new IpSet();
|
||||
this.visitors = new VisitorStatSet();
|
||||
}
|
||||
|
||||
public long getCount()
|
||||
public long getIpCount()
|
||||
{
|
||||
return this.count;
|
||||
return this.ips.size();
|
||||
}
|
||||
|
||||
public long getIpLinkCount()
|
||||
public long getLogCount()
|
||||
{
|
||||
return this.ipLinkCount;
|
||||
return this.logCount;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
public String getUserAgent()
|
||||
{
|
||||
return this.value;
|
||||
return this.userAgent;
|
||||
}
|
||||
|
||||
public void inc()
|
||||
/**
|
||||
* Gets the visit count.
|
||||
*
|
||||
* @return the visit count
|
||||
*/
|
||||
public long getVisitCount()
|
||||
{
|
||||
this.count += 1;
|
||||
long result;
|
||||
|
||||
result = this.visitors.getVisitCount();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setIpLinkCount(final long ipLinkCount)
|
||||
public void incLogCount()
|
||||
{
|
||||
this.ipLinkCount = ipLinkCount;
|
||||
this.logCount += 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put log.
|
||||
*
|
||||
* @param log
|
||||
* the log
|
||||
*/
|
||||
public void putLog(final HttpAccessLog log)
|
||||
{
|
||||
incLogCount();
|
||||
this.ips.add(log.getIp());
|
||||
|
||||
if (log.getStatus().getCategory() == HttpStatusCategory.SUCCESS)
|
||||
{
|
||||
VisitorStat stat = this.visitors.put(log.getIp(), log.getUserAgent().toString());
|
||||
stat.getVisits().add(log.getTime());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -106,7 +106,7 @@ public class UserAgentStatComparator implements Comparator<UserAgentStat>
|
|||
}
|
||||
else
|
||||
{
|
||||
result = (long) source.getCount();
|
||||
result = (long) source.getLogCount();
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -130,7 +130,7 @@ public class UserAgentStatComparator implements Comparator<UserAgentStat>
|
|||
}
|
||||
else
|
||||
{
|
||||
result = source.getValue();
|
||||
result = source.getUserAgent();
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -23,6 +23,9 @@ import java.util.HashMap;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.statoolinfos.metrics.http.HttpAccessLog;
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Class UserAgents.
|
||||
*/
|
||||
|
@ -40,27 +43,26 @@ public final class UserAgentStatSet extends HashMap<String, UserAgentStat>
|
|||
super();
|
||||
}
|
||||
|
||||
public void put(final String userAgent)
|
||||
{
|
||||
UserAgentStat stat = get(userAgent);
|
||||
if (stat == null)
|
||||
{
|
||||
stat = new UserAgentStat(userAgent);
|
||||
this.put(userAgent, stat);
|
||||
}
|
||||
|
||||
stat.inc();
|
||||
}
|
||||
|
||||
/**
|
||||
* Put.
|
||||
*
|
||||
* @param ip
|
||||
* the ip
|
||||
* @param userAgent
|
||||
* the user agent
|
||||
*/
|
||||
public void put(final UserAgentStat userAgent)
|
||||
public void put(final HttpAccessLog log)
|
||||
{
|
||||
this.put(userAgent.getValue(), userAgent);
|
||||
String key = log.getUserAgent().toString().trim();
|
||||
|
||||
UserAgentStat stat = get(key);
|
||||
if (stat == null)
|
||||
{
|
||||
stat = new UserAgentStat(log.getUserAgent().toString());
|
||||
this.put(key, stat);
|
||||
}
|
||||
|
||||
stat.putLog(log);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -70,9 +70,7 @@ public final class UserAgentStator
|
|||
*/
|
||||
public void putLog(final HttpAccessLog log)
|
||||
{
|
||||
String userAgent = log.getUserAgent().toString().trim();
|
||||
|
||||
this.logCount += 1;
|
||||
this.userAgents.put(userAgent);
|
||||
this.userAgents.put(log);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,6 +60,26 @@ public final class VisitorStatSet extends HashMap<String, VisitorStat>
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the visit count.
|
||||
*
|
||||
* @return the visit count
|
||||
*/
|
||||
public long getVisitCount()
|
||||
{
|
||||
long result;
|
||||
|
||||
result = 0;
|
||||
|
||||
for (VisitorStat stat : this.values())
|
||||
{
|
||||
result += stat.getVisitCount();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put.
|
||||
*
|
||||
|
@ -93,7 +113,7 @@ public final class VisitorStatSet extends HashMap<String, VisitorStat>
|
|||
*/
|
||||
public void put(final String ip, final UserAgentStat userAgent)
|
||||
{
|
||||
this.put(userAgent.getValue(), userAgent);
|
||||
this.put(userAgent.getUserAgent(), userAgent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue