<commit_before>
/*
* Tigase Jabber/XMPP Server
* Copyright (C) 2004-2010 "<NAME>" <<EMAIL>>
*
* This program 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, version 3 of the License.
*
* This program 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 this program. Look for COPYING file in the top folder.
* If not, see http://www.gnu.org/licenses/.
*
* $Rev$
* Last modified by $Author$
* $Date$
 */
package tigase.stats;

//~--- non-JDK imports --------------------------------------------------------

import tigase.db.DBInitException;
import tigase.db.DataRepository;
import tigase.db.RepositoryFactory;
import tigase.db.TigaseDBException;

//~--- JDK imports ------------------------------------------------------------

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

//~--- classes ----------------------------------------------------------------

/**
 * Created: Apr 20, 2010 6:39:05 PM
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Rev$
 */
public class CounterDataLogger implements StatisticsArchivizerIfc {
	private static final Logger log = Logger.getLogger(CounterDataLogger.class.getName());

	/** Field description */
	public static final String DB_URL_PROP_KEY = "db-url";

	/** Field description */
	public static final String STATS_TABLE = "tig_stats_log";

	/**
	 * SQL float UNSIGNED
	 */
	public static final String CPU_USAGE_COL = "cpu_usage";

	/**
	 * SQL float UNSIGNED
	 */
	public static final String MEM_USAGE_COL = "mem_usage";

	/**
	 * SQL BIGINT
	 */
	public static final String UPTIME_COL = "uptime";

	/**
	 * SQL INT UNSIGNED
	 */
	public static final String VHOSTS_COL = "vhosts";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String SM_PACKETS_COL = "sm_packets";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String MUC_PACKETS_COL = "muc_packets";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String PUBSUB_PACKETS_COL = "pubsub_packets";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String C2S_PACKETS_COL = "c2s_packets";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String S2S_PACKETS_COL = "s2s_packets";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String EXT_PACKETS_COL = "ext_packets";

	/**
	 * SQL INT UNSIGNED
	 */
	public static final String C2S_CONNS_COL = "c2s_conns";

	/**
	 * SQL INT UNSIGNED
	 */
	public static final String S2S_CONNS_COL = "s2s_conns";

	/**
	 * SQL INT UNSIGNED
	 */
	public static final String BOSH_CONNS_COL = "bosh_conns";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String PRESENCES_COL = "presences";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String MESSAGES_COL = "messages";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String IQS_COL = "iqs";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String REGISTERED_COL = "registered";
	private static final String CREATE_STATS_TABLE = "create table " + STATS_TABLE + " ( "
		+ " lid serial," + " ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP," + " " + CPU_USAGE_COL
		+ " float unsigned not null default 0," + " " + MEM_USAGE_COL
		+ " float unsigned not null default 0," + " " + UPTIME_COL + " bigint not null default 0,"
		+ " " + VHOSTS_COL + " int unsigned not null default 0," + " " + SM_PACKETS_COL
		+ " bigint unsigned not null default 0," + " " + MUC_PACKETS_COL
		+ " bigint unsigned not null default 0," + " " + PUBSUB_PACKETS_COL
		+ " bigint unsigned not null default 0," + " " + C2S_PACKETS_COL
		+ " bigint unsigned not null default 0," + " " + S2S_PACKETS_COL
		+ " bigint unsigned not null default 0," + " " + EXT_PACKETS_COL
		+ " bigint unsigned not null default 0," + " " + PRESENCES_COL
		+ " bigint unsigned not null default 0," + " " + MESSAGES_COL
		+ " bigint unsigned not null default 0," + " " + IQS_COL
		+ " bigint unsigned not null default 0," + " " + REGISTERED_COL
		+ " bigint unsigned not null default 0," + " " + C2S_CONNS_COL
		+ " int unsigned not null default 0," + " " + S2S_CONNS_COL
		+ " int unsigned not null default 0," + " " + BOSH_CONNS_COL
		+ " int unsigned not null default 0," + " primary key(ts))";
	private static final String STATS_INSERT_QUERY = "insert into " + STATS_TABLE + "("
		+ CPU_USAGE_COL + ", " + MEM_USAGE_COL + ", " + UPTIME_COL + ", " + VHOSTS_COL + ", "
		+ SM_PACKETS_COL + ", " + MUC_PACKETS_COL + ", " + PUBSUB_PACKETS_COL + ", " + C2S_PACKETS_COL
		+ ", " + S2S_PACKETS_COL + ", " + EXT_PACKETS_COL + ", " + PRESENCES_COL + ", " + MESSAGES_COL
		+ ", " + IQS_COL + ", " + REGISTERED_COL + ", " + C2S_CONNS_COL + ", " + S2S_CONNS_COL + ", "
		+ BOSH_CONNS_COL + ") values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

	//~--- fields ---------------------------------------------------------------

	private DataRepository data_repo = null;
	private long last_c2s_packets = 0;
	private long last_ext_packets = 0;
	private long last_iqs = 0;
	private long last_messages = 0;
	private long last_muc_packets = 0;
	private long last_presences = 0;
	private long last_pubsub_packets = 0;
	private long last_s2s_packets = 0;
	private long last_sm_packets = 0;

	//~--- methods --------------------------------------------------------------

	/**
	 * Method description
	 *<commit_msg>Minor code formatting changes.<commit_after>
/*
* Tigase Jabber/XMPP Server
* Copyright (C) 2004-2010 "<NAME>" <<EMAIL>>
*
* This program 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, version 3 of the License.
*
* This program 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 this program. Look for COPYING file in the top folder.
* If not, see http://www.gnu.org/licenses/.
*
* $Rev$
* Last modified by $Author$
* $Date$
 */
package tigase.stats;

//~--- non-JDK imports --------------------------------------------------------

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import tigase.db.DBInitException;
import tigase.db.DataRepository;
import tigase.db.RepositoryFactory;

//~--- classes ----------------------------------------------------------------

/**
 * Created: Apr 20, 2010 6:39:05 PM
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Rev$
 */
public class CounterDataLogger implements StatisticsArchivizerIfc {
	private static final Logger log = Logger.getLogger(CounterDataLogger.class.getName());

	/** Field description */
	public static final String DB_URL_PROP_KEY = "db-url";

	/** Field description */
	public static final String STATS_TABLE = "tig_stats_log";

	/**
	 * SQL float UNSIGNED
	 */
	public static final String CPU_USAGE_COL = "cpu_usage";

	/**
	 * SQL float UNSIGNED
	 */
	public static final String MEM_USAGE_COL = "mem_usage";

	/**
	 * SQL BIGINT
	 */
	public static final String UPTIME_COL = "uptime";

	/**
	 * SQL INT UNSIGNED
	 */
	public static final String VHOSTS_COL = "vhosts";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String SM_PACKETS_COL = "sm_packets";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String MUC_PACKETS_COL = "muc_packets";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String PUBSUB_PACKETS_COL = "pubsub_packets";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String C2S_PACKETS_COL = "c2s_packets";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String S2S_PACKETS_COL = "s2s_packets";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String EXT_PACKETS_COL = "ext_packets";

	/**
	 * SQL INT UNSIGNED
	 */
	public static final String C2S_CONNS_COL = "c2s_conns";

	/**
	 * SQL INT UNSIGNED
	 */
	public static final String S2S_CONNS_COL = "s2s_conns";

	/**
	 * SQL INT UNSIGNED
	 */
	public static final String BOSH_CONNS_COL = "bosh_conns";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String PRESENCES_COL = "presences";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String MESSAGES_COL = "messages";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String IQS_COL = "iqs";

	/**
	 * SQL BIGINT UNSIGNED
	 */
	public static final String REGISTERED_COL = "registered";
	/* @formatter:off */
	private static final String CREATE_STATS_TABLE = "create table " + STATS_TABLE + " ( "
		+ " lid serial," + " ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP," + " " + CPU_USAGE_COL
		+ " float unsigned not null default 0," + " " + MEM_USAGE_COL
		+ " float unsigned not null default 0," + " " + UPTIME_COL + " bigint not null default 0,"
		+ " " + VHOSTS_COL + " int unsigned not null default 0," + " " + SM_PACKETS_COL
		+ " bigint unsigned not null default 0," + " " + MUC_PACKETS_COL
		+ " bigint unsigned not null default 0," + " " + PUBSUB_PACKETS_COL
		+ " bigint unsigned not null default 0," + " " + C2S_PACKETS_COL
		+ " bigint unsigned not null default 0," + " " + S2S_PACKETS_COL
		+ " bigint unsigned not null default 0," + " " + EXT_PACKETS_COL
		+ " bigint unsigned not null default 0," + " " + PRESENCES_COL
		+ " bigint unsigned not null default 0," + " " + MESSAGES_COL
		+ " bigint unsigned not null default 0," + " " + IQS_COL
		+ " bigint unsigned not null default 0," + " " + REGISTERED_COL
		+ " bigint unsigned not null default 0," + " " + C2S_CONNS_COL
		+ " int unsigned not null default 0," + " " + S2S_CONNS_COL
		+ " int unsigned not null default 0," + " " + BOSH_CONNS_COL
		+ " int unsigned not null default 0," + " primary key(ts))";
	private static final String STATS_INSERT_QUERY = "insert into " + STATS_TABLE + "("
		+ CPU_USAGE_COL + ", " + MEM_USAGE_COL + ", " + UPTIME_COL + ", " + VHOSTS_COL + ", "
		+ SM_PACKETS_COL + ", " + MUC_PACKETS_COL + ", " + PUBSUB_PACKETS_COL + ", " + C2S_PACKETS_COL
		+ ", " + S2S_PACKETS_COL + ", " + EXT_PACKETS_COL + ", " + PRESENCES_COL + ", " + MESSAGES_COL
		+ ", " + IQS_COL + ", " + REGISTERED_COL + ", " + C2S_CONNS_COL + ", " + S2S_CONNS_COL + ", "
		+ BOSH_CONNS_COL + ") values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
	/* @formatter:on */

	private DataRepository data_repo = null;
	private long last_c2s_packets = 0;
	private long last_ext_packets = 0;
	private long last_iqs = 0;
	private long last_messages = 0;
	private long last_muc_packets = 0;
	private long last_presences = 0;
	private long last_pubsub_packets = 0;
	private long last_s2s_packets = 0;
	private long last_sm_packets = 0;

	//~--- methods --------------------------------------------------------------

	/**
	 * Method description
	 *
{'fraction_non_alphanumeric': 0.16181947153750664, 'fraction_numerical': 0.011349530058521014, 'mean_word_length': 2.9644991212653777, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5210677', 'n_tokens_mistral': 4052, 'n_tokens_neox': 3674, 'n_words': 1070}