Skip to content

Commit

Permalink
extra fix for RestComm#234: Adding of CsvStatsPrinter
Browse files Browse the repository at this point in the history
  • Loading branch information
mniemiec authored and vetss committed May 10, 2017
1 parent 83b5848 commit 80eec49
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ image::images/GUI_Campaign_Management.png[]

Click on 'Create Statistics Campaign' button to create new campaign.
Select the stack from 'Counter Definition Set Name' drop down on which you want to define new campaign.
Next select the time period from 'Duration' drop down and enter unique 'Campaign Name'.
Next select the time period from 'Duration' drop down and enter unique 'Campaign Name'.
An 'Output format' field allows you to select a type of statistics logging: CSV, verbose or both of them.

IMPORTANT: The stack on which new campaign is defined must have set 'Statistics Enabled' property to true

Expand All @@ -36,7 +37,7 @@ Last tab also displays the 'Start Time' and 'End Time' representing time duratio


.GUI - Campaigns View
image::images/GUI_Campaign_Management_View.png[]
image::images/GUI_Campaign_Management_view.png[]

[NOTE]
====
Expand All @@ -59,16 +60,23 @@ If you wish to have stats logged, you must configure the settings in the file [p
If you are running the platform as standalone, then you should configure in [path]_log4j.xml_.

Logging stats to main server log file::
If you wish to have the stats logged in the main server log file located at [path]_jboss-5.1.0.GA/server/default/log/server.log_, then you must add a new category to the [path]_jboss-log4j.xml_ as shown below and set priority value to "DEBUG".
If you wish to have the stats logged in the main server log file located at [path]_jboss-5.1.0.GA/server/default/log/server.log_, then you must add a new category to the [path]_jboss-log4j.xml_ as shown below and set priority value to "DEBUG". For verbose stats:
----
<category name="org.mobicents.protocols.ss7.oam.common.statistics.StatsPrinter" additivity="false">
<priority value="DEBUG" />
</category>
----
and for a CSV stats:
----
<category name="org.mobicents.protocols.ss7.oam.common.statistics.CsvStatsPrinter" additivity="false">
<priority value="DEBUG" />
</category>
----

Logging stats to a separate stats log file::
If you wish to have the stats logged to a separate log file located at [path]_jboss-5.1.0.GA/server/default/log/stats.log_, then you must add a new appender to the [path]_jboss-log4j.xml_ and change category as shown below.
Logging stats to a separate stats log files::
If you wish to have the stats logged to a separate log files located at [path]_jboss-5.1.0.GA/server/default/log/stats.log_ and [path]_jboss-5.1.0.GA/server/default/log/csvstats.log_, then you must add a new appenders to the [path]_jboss-log4j.xml_ and change category as shown below.
You must set the priority value to "DEBUG".
----
Expand All @@ -90,6 +98,25 @@ You must set the priority value to "DEBUG".
<priority value="DEBUG" />
<appender-ref ref="STATS"/>
</category>
<appender name="CSVSTATS" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="$
{jboss.server.home.dir}
/log/csvstats.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="500KB" />
<param name="MaxBackupIndex" value="1" />
<param name="Threshold" value="DEBUG"/>
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<category name="org.mobicents.protocols.ss7.oam.common.statistics.CsvStatsPrinter" additivity="false">
<priority value="DEBUG" />
<appender-ref ref="CSVSTATS"/>
</category>
----

As of today {this-platform} {this-application} exposes statistics only for TCAP.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public interface CounterCampaign extends Serializable {
*/
int getDuration();

/**
* statistics output format
* @return
*/
int getOutputFormat();

/**
* Returns counters definitions
* @return
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* TeleStax, Open Source Cloud Communications Copyright 2012.
* and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.mobicents.protocols.ss7.oam.common.statistics.api;

/**
* Created by mniemiec on 08.05.17.
*/
public enum CounterOutputFormat {
CSV (0),
VERBOSE (1),
CSV_AND_VERBOSE (2);

private int code;

CounterOutputFormat(int code) {
this.code = code;
}

public int getCode() {
return this.code;
}

public static CounterOutputFormat getInstance(int code) {
switch (code) {
case 0:
return CounterOutputFormat.CSV;
case 1:
return CounterOutputFormat.VERBOSE;
case 2:
return CounterOutputFormat.CSV_AND_VERBOSE;
default:
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ public interface CounterProvider {
* been registered
* @param duration
* Duration in minutes (possible values: 5, 10, 15, 20, 30 and 60 minutes)
* @param outputFormat
* Output format (possible values: 0, 1, 2)
* 0 - CSV
* 1 - verbose
* 2 - CSV and verbose
*/
void createCampaign(String campaignName, String counterSetName, int duration) throws Exception;
void createCampaign(String campaignName, String counterSetName, int duration, int outputFormat) throws Exception;

/**
* creating a short Campaign, duration - interval in seconds (only predefined
Expand All @@ -85,8 +90,13 @@ public interface CounterProvider {
* been registered
* @param duration
* Duration in minutes (possible values: 5, 10, 15, 20, 30 and 60 seconds)
* @param outputFormat
* Output format (possible values: 0, 1, 2)
* 0 - CSV
* 1 -verbose
* 2 - CSV and verbose
*/
void createShortCampaign(String campaignName, String counterSetName, int duration) throws Exception;
void createShortCampaign(String campaignName, String counterSetName, int duration, int outputFormat) throws Exception;

/**
* destroying a Campaign
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ public class CounterCampaignImpl implements CounterCampaign {
private static final String NAME = "name";
private static final String COUNTER_SET_NAME = "counterSetName";
private static final String DURATION = "duration";
private static final String OUTPUT_FORMAT = "outputFormat";
private static final String SHORT_CAMPAIGN = "shortCampaign";

private String name;
private CounterDefSet counterSet;
private String counterSetName;
private int duration;
private int outputFormat;
private boolean shortCampaign;

private Date startTime;
Expand All @@ -60,11 +62,12 @@ public class CounterCampaignImpl implements CounterCampaign {
public CounterCampaignImpl() {
}

public CounterCampaignImpl(String name, String counterSetName, CounterDefSet counterSet, int duration, boolean shortCampaign) {
public CounterCampaignImpl(String name, String counterSetName, CounterDefSet counterSet, int duration, boolean shortCampaign, int outputFormat) {
this.name = name;
this.counterSetName = counterSetName;
this.counterSet = counterSet;
this.duration = duration;
this.outputFormat = outputFormat;
this.shortCampaign = shortCampaign;
}

Expand All @@ -83,6 +86,11 @@ public int getDuration() {
return duration;
}

@Override
public int getOutputFormat() {
return outputFormat;
}

@Override
public boolean isShortCampaign() {
return shortCampaign;
Expand Down Expand Up @@ -140,13 +148,15 @@ public void read(javolution.xml.XMLFormat.InputElement xml, CounterCampaignImpl
counterCampaign.counterSetName = xml.getAttribute(COUNTER_SET_NAME, "");
counterCampaign.shortCampaign = xml.getAttribute(SHORT_CAMPAIGN, false);
counterCampaign.duration = xml.getAttribute(DURATION, 60);
counterCampaign.outputFormat = xml.getAttribute(OUTPUT_FORMAT, 1);
}

public void write(CounterCampaignImpl counterCampaign, javolution.xml.XMLFormat.OutputElement xml) throws XMLStreamException {
xml.setAttribute(NAME, counterCampaign.getName());
xml.setAttribute(COUNTER_SET_NAME, counterCampaign.getCounterSetName());
xml.setAttribute(SHORT_CAMPAIGN, counterCampaign.isShortCampaign());
xml.setAttribute(DURATION, counterCampaign.getDuration());
xml.setAttribute(OUTPUT_FORMAT, counterCampaign.getOutputFormat());
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.mobicents.protocols.ss7.oam.common.statistics.api.CounterDef;
import org.mobicents.protocols.ss7.oam.common.statistics.api.CounterDefSet;
import org.mobicents.protocols.ss7.oam.common.statistics.api.CounterMediator;
import org.mobicents.protocols.ss7.oam.common.statistics.api.CounterOutputFormat;
import org.mobicents.protocols.ss7.oam.common.statistics.api.CounterType;
import org.mobicents.protocols.ss7.oam.common.statistics.api.CounterValueSet;
import org.mobicents.protocols.ss7.oam.common.statistics.api.SourceValueCounter;
Expand Down Expand Up @@ -228,16 +229,16 @@ public CounterDefSet getCounterDefSet(String counterDefSetName) {
}

@Override
public void createCampaign(String campaignName, String counterSetName, int duration) throws Exception {
this.doCreateCampaign(campaignName, counterSetName, duration, false);
public void createCampaign(String campaignName, String counterSetName, int duration, int outputFormat) throws Exception {
this.doCreateCampaign(campaignName, counterSetName, duration, false, outputFormat);
}

@Override
public void createShortCampaign(String campaignName, String counterSetName, int duration) throws Exception {
this.doCreateCampaign(campaignName, counterSetName, duration, true);
public void createShortCampaign(String campaignName, String counterSetName, int duration, int outputFormat) throws Exception {
this.doCreateCampaign(campaignName, counterSetName, duration, true, outputFormat);
}

private void doCreateCampaign(String campaignName, String counterSetName, int duration, boolean shortCampaign)
private void doCreateCampaign(String campaignName, String counterSetName, int duration, boolean shortCampaign, int outputFormat)
throws Exception {
if (campaignName == null) {
throw new Exception("Campaign Name cannot be null");
Expand All @@ -253,6 +254,9 @@ private void doCreateCampaign(String campaignName, String counterSetName, int du
if (duration != 5 && duration != 10 && duration != 15 && duration != 20 && duration != 30 && duration != 60)
throw new Exception("Duration may be only 5, 10, 15, 20, 30 or 60 minutes/seconds");

if (outputFormat != 0 && outputFormat != 1 && outputFormat != 2)
throw new Exception("Output format may be only CSV, verbose or CSV and verbose");

CounterMediator cm = lstCounterDefSet.get(counterSetName);
if (cm == null) {
throw new Exception("CounterMediator is null for counterSetName=" + counterSetName);
Expand All @@ -261,7 +265,7 @@ private void doCreateCampaign(String campaignName, String counterSetName, int du
synchronized (this) {
CounterDefSet counterSet = cm.getCounterDefSet(counterSetName);
CounterCampaignImpl camp = new CounterCampaignImpl(campaignName, counterSetName, counterSet, duration,
shortCampaign);
shortCampaign, outputFormat);
lstCounterCampaign.put(campaignName, camp);
this.store();
}
Expand Down Expand Up @@ -329,8 +333,24 @@ protected void processCampaign(CounterCampaignImpl cc, Date endTime) {
}
if (cm != null) {
SourceValueSet svs1 = cc.getLastSourceValueSet();
this.statsPrinter.printStats(cc);
this.csvStatsPrinter.printCsvStats(cc);
CounterOutputFormat outputFormat = CounterOutputFormat.getInstance(cc.getOutputFormat());
if (outputFormat != null) {
switch (outputFormat) {
case CSV:
this.csvStatsPrinter.printCsvStats(cc);
break;
case VERBOSE:
this.statsPrinter.printStats(cc);
break;
case CSV_AND_VERBOSE:
this.statsPrinter.printStats(cc);
this.csvStatsPrinter.printCsvStats(cc);
break;
}
} else {
logger.info("Output format not set for campaign: " + cc.getName() + ", using default");
this.statsPrinter.printStats(cc);
}

int durationInSeconds = cc.getDuration();
if (!cc.isShortCampaign()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ public void storingCampaignsTest() throws Exception {
CounterMediator cm = new CounterMediatorProxy();
counterProvider.registerCounterMediator(cm);

counterProvider.createCampaign("camp1", "counterSet1", 5);
counterProvider.createCampaign("camp2", "counterSet2", 60);
counterProvider.createCampaign("camp1", "counterSet1", 5, 1);
counterProvider.createCampaign("camp2", "counterSet2", 60, 1);
try {
counterProvider.createCampaign("camp1", "counterSet3", 60);
counterProvider.createCampaign("camp1", "counterSet3", 60, 1);
fail("Same campaignName must bring Exception");
} catch (Exception e) {
}
try {
counterProvider.createCampaign("camp3", "counterSet1", 59);
counterProvider.createCampaign("camp3", "counterSet1", 59, 1);
fail("Wrong duration must bring Exception");
} catch (Exception e) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void counterProviderStartsLastTest() throws Exception {
CounterMediator cm = counterProvider.getCounterMediatorLst().get(cmName);
assertEquals(cm, tcapManagement);

counterProvider.createCampaign("camp_01", csName, 10);
counterProvider.createCampaign("camp_01", csName, 10, 1);
assertEquals(counterProvider.getCampaignsList().length, 1);
CounterCampaign cc = counterProvider.getCampaign("camp_01");
assertEquals(cc.getCounterSetName(), csName);
Expand Down Expand Up @@ -152,7 +152,7 @@ public void counterProviderStartsLastTest() throws Exception {
assertEquals(cc.getCounterSet(), cds);
assertFalse(cc.isShortCampaign());

counterProvider.createShortCampaign("camp_02", csName, 20);
counterProvider.createShortCampaign("camp_02", csName, 20, 1);
assertEquals(counterProvider.getCampaignsList().length, 2);
cc = counterProvider.getCampaign("camp_02");
assertEquals(cc.getCounterSetName(), csName);
Expand Down Expand Up @@ -184,7 +184,7 @@ public void counterProviderStartsFirstTest() throws Exception {
CounterMediator cm = counterProvider.getCounterMediatorLst().get(cmName);
assertEquals(cm, tcapManagement);

counterProvider.createCampaign("camp_01", csName, 10);
counterProvider.createCampaign("camp_01", csName, 10, 1);
assertEquals(counterProvider.getCampaignsList().length, 1);
CounterCampaign cc = counterProvider.getCampaign("camp_01");
assertEquals(cc.getCounterSetName(), csName);
Expand Down Expand Up @@ -232,7 +232,7 @@ public void processingStatDataTest() throws Exception {
String cmName = tcapManagement.getCounterMediatorName();
CounterDefSet cds = tcapManagement.getCounterDefSet(csName);

counterProvider.createCampaign("camp_01", csName, 60);
counterProvider.createCampaign("camp_01", csName, 60, 1);
Date tm1 = new Date(2010, 1, 1, 10, 0, 0);
Date tm2 = new Date(2010, 1, 1, 11, 0, 0);

Expand Down
Loading

0 comments on commit 80eec49

Please sign in to comment.