StatisticsConfig.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.monitor.engine.statistic;

  21. import org.openspcoop2.monitor.engine.exceptions.EngineException;

  22. import java.util.Arrays;
  23. import java.util.List;
  24. import java.util.Set;
  25. import java.util.stream.Collectors;

  26. import org.apache.commons.lang.StringUtils;
  27. import org.openspcoop2.monitor.engine.config.MonitorProperties;
  28. import org.openspcoop2.monitor.engine.constants.CostantiConfigurazione;

  29. import org.openspcoop2.utils.LoggerWrapperFactory;
  30. import org.openspcoop2.utils.UtilsException;
  31. import org.openspcoop2.utils.transport.http.HttpRequestConfig;
  32. import org.slf4j.Logger;

  33. /**
  34.  * StatisticsConfig
  35.  *
  36.  * @author Poli Andrea (apoli@link.it)
  37.  * @author $Author$
  38.  * @version $Rev$, $Date$
  39.  */
  40. public class StatisticsConfig {

  41.     private Logger logCore = null;
  42.     private Logger logSql = null;

  43.     /** Indicazione se deve essere effettuato il log delle query */
  44.     private boolean debug = false;  
  45.    
  46.     /** Indicazione se deve essere usata la union per calcolare i tempi di latenza */
  47.     private boolean useUnionForLatency = false;
  48.    
  49.     /** Indicazione se devono essere generate le statistiche custom */
  50.     private boolean generazioneStatisticheCustom = false;
  51.    
  52.     /** Indicazione se devono analizzate le transazioni custom */
  53.     private boolean analisiTransazioniCustom = false;
  54.    
  55.     /** Intervallo di attesa prima di passare al prossimo intervallo */
  56.     private long waitMsBeforeNextInterval = -1;
  57.    
  58.     /** Attesa che tutte le transazioni siano state consegnate con successo prima di passare al prossimo intervallo */
  59.     private boolean waitStatiInConsegna = false;
  60.    
  61.     /** Tipologie di statistiche */
  62.     private boolean statisticheOrarie = false;
  63.     private boolean statisticheGiornaliere = false;
  64.     private boolean statisticheSettimanali = false;
  65.     private boolean statisticheMensili = false;
  66.    
  67.     /** Tipologie di statistiche: gestione ultimo intervallo */
  68.     private boolean statisticheOrarieGestioneUltimoIntervallo = false;
  69.     private boolean statisticheGiornaliereGestioneUltimoIntervallo = false;
  70.     private boolean statisticheSettimanaliGestioneUltimoIntervallo = false;
  71.     private boolean statisticheMensiliGestioneUltimoIntervallo = false;
  72.        
  73.     /** Lista di indici forzati */
  74.     private StatisticsForceIndexConfig forceIndexConfig = null;
  75.    
  76.     /** PDND Tracing **/
  77.     private boolean pdndTracciamentoGenerazione = false;
  78.     private boolean pdndTracciamentoPubblicazione = false;
  79.     private HttpRequestConfig pdndTracciamentoRequestConfig;
  80.     private boolean pdndTracciamentoSoggettiDisabled = false;
  81.     private Set<String> pdndTracciamentoSoggettiEnabled;
  82.     private Integer pdndTracciamentoMaxAttempt = null;
  83.     private List<Integer> pdndTracciamentoPendingCheck = null;
  84.     private boolean pdndTracciamentoErogazioniEnabled = true;
  85.     private boolean pdndTracciamentoFruizioniEnabled = true;
  86.    
  87.     private static final String FALSE = "false";
  88.    
  89.     /** Costruttore */
  90.     public StatisticsConfig(boolean readPropertiesFromFile) throws EngineException{
  91.    
  92.         try{
  93.             if(readPropertiesFromFile){
  94.                
  95.                 this.logCore = LoggerWrapperFactory.getLogger("org.openspcoop2.monitor.engine.statistic");
  96.                 this.logSql = LoggerWrapperFactory.getLogger("org.openspcoop2.monitor.engine.statistic.sql");
  97.                
  98.                 MonitorProperties props = MonitorProperties.getInstance(this.logCore);
  99.    
  100.                 if ("true".equals(props.getProperty(CostantiConfigurazione.STAT_DEBUG, FALSE, true))) {
  101.                     this.debug = true;
  102.                 } else {
  103.                     this.debug = false;
  104.                 }
  105.                
  106.                 if ("true".equals(props.getProperty(CostantiConfigurazione.STAT_USE_UNION_FOR_LATENCY, FALSE, true))) {
  107.                     this.useUnionForLatency = true;
  108.                 } else {
  109.                     this.useUnionForLatency = false;
  110.                 }
  111.                
  112.                 if ("true".equals(props.getProperty(CostantiConfigurazione.STAT_CUSTOM_STATISTICS, FALSE, true))) {
  113.                     this.generazioneStatisticheCustom = true;
  114.                 } else {
  115.                     this.generazioneStatisticheCustom = false;
  116.                 }
  117.                
  118.                 if ("true".equals(props.getProperty(CostantiConfigurazione.STAT_CUSTOM_TRANSACTION_STATISTICS, FALSE, true))) {
  119.                     this.analisiTransazioniCustom = true;
  120.                 } else {
  121.                     this.analisiTransazioniCustom = false;
  122.                 }
  123.        
  124.                 if ("true".equals(props.getProperty(CostantiConfigurazione.STAT_HOURLY, "true", true))) {
  125.                     this.statisticheOrarie = true;
  126.                 } else {
  127.                     this.statisticheOrarie = false;
  128.                 }
  129.                
  130.                 if ("true".equals(props.getProperty(CostantiConfigurazione.STAT_DAILY, "true", true))) {
  131.                     this.statisticheGiornaliere = true;
  132.                 } else {
  133.                     this.statisticheGiornaliere = false;
  134.                 }
  135.        
  136.                 if ("true".equals(props.getProperty(CostantiConfigurazione.STAT_WEEKLY, "true", true))) {
  137.                     this.statisticheSettimanali = true;
  138.                 } else {
  139.                     this.statisticheSettimanali = false;
  140.                 }
  141.        
  142.                 if ("true".equals(props.getProperty(CostantiConfigurazione.STAT_MONTHLY, "true", true))) {
  143.                     this.statisticheMensili = true;
  144.                 } else {
  145.                     this.statisticheMensili = false;
  146.                 }
  147.                
  148.                 this.pdndTracciamentoGenerazione = parsePdndGenerazioneTracciamentoProperty(props);
  149.                 this.pdndTracciamentoPubblicazione = parsePdndPubblicazioneTracciamentoProperty(props);
  150.                 this.pdndTracciamentoRequestConfig = parsePdndTracingRequestConfig(props);
  151.                 this.pdndTracciamentoSoggettiEnabled = parsePdndTracingSoggettiEnabled(props);
  152.                 this.pdndTracciamentoSoggettiDisabled = parsePdndTracingSoggettiDisabled(props);
  153.                 this.pdndTracciamentoErogazioniEnabled = parsePdndTracingErogazioniEnabled(props);
  154.                 this.pdndTracciamentoFruizioniEnabled = parsePdndTracingFruizioniEnabled(props);
  155.                 this.pdndTracciamentoPendingCheck = parsePdndTracciamentoPendingCheck(props);
  156.                 this.pdndTracciamentoMaxAttempt = parsePdndTracciamentoMaxAttempts(props);
  157.                
  158.                 if ("true".equals(props.getProperty(CostantiConfigurazione.PDND_PUBBLICAZIONE_TRACCIAMENTO_ENABLED, "true", true))) {
  159.                     this.pdndTracciamentoPubblicazione = true;
  160.                 } else {
  161.                     this.pdndTracciamentoPubblicazione = false;
  162.                 }
  163.        
  164.                 if ("true".equals(props.getProperty(CostantiConfigurazione.STAT_HOURLY_LASTINT, "true", true))) {
  165.                     this.statisticheOrarieGestioneUltimoIntervallo = true;
  166.                 } else {
  167.                     this.statisticheOrarieGestioneUltimoIntervallo = false;
  168.                 }
  169.                
  170.                 if ("true".equals(props.getProperty(CostantiConfigurazione.STAT_DAILY_LASTINT, "true", true))) {
  171.                     this.statisticheGiornaliereGestioneUltimoIntervallo = true;
  172.                 } else {
  173.                     this.statisticheGiornaliereGestioneUltimoIntervallo = false;
  174.                 }
  175.        
  176.                 if ("true".equals(props.getProperty(CostantiConfigurazione.STAT_WEEKLY_LASTINT, "true", true))) {
  177.                     this.statisticheSettimanaliGestioneUltimoIntervallo = true;
  178.                 } else {
  179.                     this.statisticheSettimanaliGestioneUltimoIntervallo = false;
  180.                 }
  181.        
  182.                 if ("true".equals(props.getProperty(CostantiConfigurazione.STAT_MONTHLY_LASTINT, "true", true))) {
  183.                     this.statisticheMensiliGestioneUltimoIntervallo = true;
  184.                 } else {
  185.                     this.statisticheMensiliGestioneUltimoIntervallo = false;
  186.                 }
  187.                
  188.             }
  189.            
  190.         }catch(Exception e){
  191.             throw new EngineException(e.getMessage(),e);
  192.         }
  193.     }
  194.    
  195.     private static boolean parsePdndGenerazioneTracciamentoProperty(MonitorProperties props) throws UtilsException {
  196.         String propId = CostantiConfigurazione.PDND_GENERAZIONE_TRACCIAMENTO_ENABLED;
  197.         return "true".equals(props.getProperty(propId, "true", true));
  198.     }
  199.    
  200.     private static boolean parsePdndPubblicazioneTracciamentoProperty(MonitorProperties props) throws UtilsException {
  201.         String propId = CostantiConfigurazione.PDND_PUBBLICAZIONE_TRACCIAMENTO_ENABLED;
  202.         return "true".equals(props.getProperty(propId, "true", true));
  203.     }
  204.    
  205.     private static boolean parsePdndTracingErogazioniEnabled(MonitorProperties props) throws UtilsException {
  206.         String propId = CostantiConfigurazione.PDND_PUBBLICAZIONE_TRACCIAMENTO_EROGAZIONI_ENABLED;
  207.         return "true".equals(props.getProperty(propId, "true", true));
  208.     }
  209.    
  210.     private static boolean parsePdndTracingFruizioniEnabled(MonitorProperties props) throws UtilsException {
  211.         String propId = CostantiConfigurazione.PDND_PUBBLICAZIONE_TRACCIAMENTO_FRUIZIONI_ENABLED;
  212.         return "true".equals(props.getProperty(propId, "true", true));
  213.     }
  214.    
  215.     private static HttpRequestConfig parsePdndTracingRequestConfig(MonitorProperties props) {
  216.         return new HttpRequestConfig("pdnd.tracciamento", str -> {
  217.             try {
  218.                 return props.getProperty(str, false, true);
  219.             } catch (UtilsException e) {
  220.                 return null;
  221.             }
  222.         });
  223.     }
  224.    
  225.     private static Set<String> parsePdndTracingSoggettiEnabled(MonitorProperties props) throws UtilsException {
  226.         String propId = CostantiConfigurazione.PDND_PUBBLICAZIONE_TRACCIAMENTO_SOGGETTI_ENABLED;
  227.         String value = props.getProperty(propId, "", false);
  228.         if (value == null || StringUtils.isEmpty(value.trim()) || "*".equals(value.trim()))
  229.             return Set.of();
  230.         return Arrays.stream(value.split(","))
  231.                 .map(String::trim)
  232.                 .collect(Collectors.toSet());
  233.     }
  234.     private boolean parsePdndTracingSoggettiDisabled(MonitorProperties props) throws UtilsException {
  235.         String propId = CostantiConfigurazione.PDND_PUBBLICAZIONE_TRACCIAMENTO_SOGGETTI_ENABLED;
  236.         String value = props.getProperty(propId, "", false);
  237.         return value==null || StringUtils.isEmpty(value.trim());
  238.     }
  239.    
  240.     private List<Integer> parsePdndTracciamentoPendingCheck(MonitorProperties props) throws UtilsException {
  241.         String propId = CostantiConfigurazione.PDND_TRACCIAMENTO_PUBBLICAZIONE_PENDING_CHECK;
  242.         String value = props.getProperty(propId, "", false);
  243.         return value == null || StringUtils.isEmpty(value.trim()) ? List.of(0) : Arrays.stream(value.split(","))
  244.                 .map(Integer::valueOf)
  245.                 .collect(Collectors.toList());
  246.     }
  247.    
  248.     private Integer parsePdndTracciamentoMaxAttempts(MonitorProperties props) throws UtilsException {
  249.         String propId = CostantiConfigurazione.PDND_TRACCIAMENTO_PUBBLICAZIONE_MAX_ATTEMPTS;
  250.         String value = props.getProperty(propId, "", false);
  251.         return value == null || StringUtils.isEmpty(value.trim()) ? null : Integer.valueOf(value);
  252.     }
  253.    
  254.     public Logger getLogCore() {
  255.         return this.logCore;
  256.     }
  257.    
  258.     public void setLogCore(Logger logCore) {
  259.         this.logCore = logCore;
  260.     }

  261.     public Logger getLogSql() {
  262.         return this.logSql;
  263.     }

  264.     public void setLogSql(Logger logSql) {
  265.         this.logSql = logSql;
  266.     }
  267.    
  268.     public boolean isDebug() {
  269.         return this.debug;
  270.     }

  271.     public void setDebug(boolean debug) {
  272.         this.debug = debug;
  273.     }

  274.     public boolean isUseUnionForLatency() {
  275.         return this.useUnionForLatency;
  276.     }

  277.     public void setUseUnionForLatency(boolean useUnionForLatency) {
  278.         this.useUnionForLatency = useUnionForLatency;
  279.     }
  280.    
  281.     public boolean isGenerazioneStatisticheCustom() {
  282.         return this.generazioneStatisticheCustom;
  283.     }

  284.     public void setGenerazioneStatisticheCustom(boolean generazioneStatisticheCustom) {
  285.         this.generazioneStatisticheCustom = generazioneStatisticheCustom;
  286.     }

  287.     public boolean isStatisticheOrarie() {
  288.         return this.statisticheOrarie;
  289.     }

  290.     public void setStatisticheOrarie(boolean statisticheOrarie) {
  291.         this.statisticheOrarie = statisticheOrarie;
  292.     }

  293.     public boolean isStatisticheGiornaliere() {
  294.         return this.statisticheGiornaliere;
  295.     }

  296.     public void setStatisticheGiornaliere(boolean statisticheGiornaliere) {
  297.         this.statisticheGiornaliere = statisticheGiornaliere;
  298.     }

  299.     public boolean isStatisticheSettimanali() {
  300.         return this.statisticheSettimanali;
  301.     }

  302.     public void setStatisticheSettimanali(boolean statisticheSettimanali) {
  303.         this.statisticheSettimanali = statisticheSettimanali;
  304.     }

  305.     public boolean isStatisticheMensili() {
  306.         return this.statisticheMensili;
  307.     }

  308.     public void setStatisticheMensili(boolean statisticheMensili) {
  309.         this.statisticheMensili = statisticheMensili;
  310.     }

  311.     public boolean isStatisticheOrarieGestioneUltimoIntervallo() {
  312.         return this.statisticheOrarieGestioneUltimoIntervallo;
  313.     }
  314.    

  315.     public void setStatisticheOrarieGestioneUltimoIntervallo(
  316.             boolean statisticheOrarieGestioneUltimoIntervallo) {
  317.         this.statisticheOrarieGestioneUltimoIntervallo = statisticheOrarieGestioneUltimoIntervallo;
  318.     }

  319.     public boolean isStatisticheGiornaliereGestioneUltimoIntervallo() {
  320.         return this.statisticheGiornaliereGestioneUltimoIntervallo;
  321.     }

  322.     public void setStatisticheGiornaliereGestioneUltimoIntervallo(
  323.             boolean statisticheGiornaliereGestioneUltimoIntervallo) {
  324.         this.statisticheGiornaliereGestioneUltimoIntervallo = statisticheGiornaliereGestioneUltimoIntervallo;
  325.     }

  326.     public boolean isStatisticheSettimanaliGestioneUltimoIntervallo() {
  327.         return this.statisticheSettimanaliGestioneUltimoIntervallo;
  328.     }

  329.     public void setStatisticheSettimanaliGestioneUltimoIntervallo(
  330.             boolean statisticheSettimanaliGestioneUltimoIntervallo) {
  331.         this.statisticheSettimanaliGestioneUltimoIntervallo = statisticheSettimanaliGestioneUltimoIntervallo;
  332.     }

  333.     public boolean isStatisticheMensiliGestioneUltimoIntervallo() {
  334.         return this.statisticheMensiliGestioneUltimoIntervallo;
  335.     }

  336.     public void setStatisticheMensiliGestioneUltimoIntervallo(
  337.             boolean statisticheMensiliGestioneUltimoIntervallo) {
  338.         this.statisticheMensiliGestioneUltimoIntervallo = statisticheMensiliGestioneUltimoIntervallo;
  339.     }
  340.    
  341.     public boolean isAnalisiTransazioniCustom() {
  342.         return this.analisiTransazioniCustom;
  343.     }

  344.     public void setAnalisiTransazioniCustom(boolean analisiTransazioniCustom) {
  345.         this.analisiTransazioniCustom = analisiTransazioniCustom;
  346.     }
  347.    
  348.     public StatisticsForceIndexConfig getForceIndexConfig() {
  349.         return this.forceIndexConfig;
  350.     }

  351.     public void setForceIndexConfig(StatisticsForceIndexConfig forceIndexConfig) {
  352.         this.forceIndexConfig = forceIndexConfig;
  353.     }
  354.    
  355.     public long getWaitMsBeforeNextInterval() {
  356.         return this.waitMsBeforeNextInterval;
  357.     }

  358.     public void setWaitMsBeforeNextInterval(long waitMsBeforeNextInterval) {
  359.         this.waitMsBeforeNextInterval = waitMsBeforeNextInterval;
  360.     }

  361.     public boolean isWaitStatiInConsegna() {
  362.         return this.waitStatiInConsegna;
  363.     }

  364.     public void setWaitStatiInConsegna(boolean waitStatiInConsegna) {
  365.         this.waitStatiInConsegna = waitStatiInConsegna;
  366.     }
  367.    
  368.     public boolean isPdndTracciamentoPubblicazione() {
  369.         return this.pdndTracciamentoPubblicazione;
  370.     }

  371.     public void setPdndTracciamentoPubblicazione(boolean pdndPubblicazioneTracciamento) {
  372.         this.pdndTracciamentoPubblicazione = pdndPubblicazioneTracciamento;
  373.     }
  374.    
  375.     public boolean isPdndTracciamentoGenerazione() {
  376.         return this.pdndTracciamentoGenerazione;
  377.     }

  378.     public void setPdndTracciamentoGenerazione(boolean pdndGenerazioneTracciamento) {
  379.         this.pdndTracciamentoGenerazione = pdndGenerazioneTracciamento;
  380.     }
  381.    
  382.     public HttpRequestConfig getPdndTracciamentoRequestConfig() {
  383.         return this.pdndTracciamentoRequestConfig;
  384.     }

  385.     public void setPdndTracciamentoRequestConfig(HttpRequestConfig pdndTracingRequestConfig) {
  386.         this.pdndTracciamentoRequestConfig = pdndTracingRequestConfig;
  387.     }
  388.    
  389.     public void setPdndTracciamentoMaxAttempt(Integer maxAttempt) {
  390.         this.pdndTracciamentoMaxAttempt = maxAttempt;
  391.     }
  392.    
  393.     public Integer getPdndTracciamentoMaxAttempt() {
  394.         return this.pdndTracciamentoMaxAttempt;
  395.     }
  396.    
  397.     public void setPdndTracciamentoPendingCheck(List<Integer> pdndTracciamentoPendingCheck) {
  398.         this.pdndTracciamentoPendingCheck = pdndTracciamentoPendingCheck;
  399.     }
  400.    
  401.     public List<Integer> getPdndTracciamentoPendingCheck() {
  402.         return this.pdndTracciamentoPendingCheck;
  403.     }
  404.    
  405.     public void setPdndTracciamentoSoggettiEnabled(Set<String> pdndTracingSoggettiEnabled) {
  406.         this.pdndTracciamentoSoggettiEnabled = pdndTracingSoggettiEnabled;
  407.     }
  408.    
  409.     public Set<String> getPdndTracciamentoSoggettiEnabled() {
  410.         return this.pdndTracciamentoSoggettiEnabled;
  411.     }

  412.     public boolean isPdndTracciamentoSoggettiDisabled() {
  413.         return this.pdndTracciamentoSoggettiDisabled;
  414.     }

  415.     public void setPdndTracciamentoSoggettiDisabled(boolean pdndTracciamentoSoggettiDisabled) {
  416.         this.pdndTracciamentoSoggettiDisabled = pdndTracciamentoSoggettiDisabled;
  417.     }
  418.    
  419.     public boolean isPdndTracciamentoErogazioniEnabled() {
  420.         return this.pdndTracciamentoErogazioniEnabled;
  421.     }

  422.     public void setPdndTracciamentoErogazioniEnabled(boolean pdndTracingErogazioniEnabled) {
  423.         this.pdndTracciamentoErogazioniEnabled = pdndTracingErogazioniEnabled;
  424.     }

  425.     public boolean isPdndTracciamentoFruizioniEnabled() {
  426.         return this.pdndTracciamentoFruizioniEnabled;
  427.     }

  428.     public void setPdndTracciamentoFruizioniEnabled(boolean pdndTracingFruizioniEnabled) {
  429.         this.pdndTracciamentoFruizioniEnabled = pdndTracingFruizioniEnabled;
  430.     }
  431. }