Revize 1651
Přidáno uživatelem Ondřej Fibich před asi 12 roky(ů)
freenetis/branches/testing/db_upgrades/upgrade_1.0.0~rc9.php | ||
---|---|---|
$db = Database::instance();
|
||
|
||
// this should not happend, but...
|
||
if (!$db->table_exists('members_traffics'))
|
||
if (!$db->table_exists('members_traffics') ||
|
||
version_compare(ORM::factory('user')->get_mysql_version(), '5.1.0', '<'))
|
||
{
|
||
Settings::set('ulogd_enabled', 0);
|
||
return true;
|
freenetis/branches/testing/application/models/members_traffic.php | ||
---|---|---|
class Members_traffic_Model extends Model
|
||
{
|
||
/**
|
||
* Creates tables (daily, monthly, yearly)
|
||
* Creates tables (daily, monthly, yearly) with parttitons for current date/month
|
||
*
|
||
* @param boolean $create_first_partition enable creating of first partitions?
|
||
*/
|
||
public static function create_tables()
|
||
public static function create_tables($create_first_partition = FALSE)
|
||
{
|
||
$db = Database::instance();
|
||
|
||
$first_partition_daily = '';
|
||
$first_partition_monthly = '';
|
||
|
||
if ($create_first_partition === TRUE)
|
||
{
|
||
// next month
|
||
$i = strtotime($db->query("
|
||
SELECT DATE_ADD('" . date('Y-m-d', time()) . "', INTERVAL 1 MONTH) AS t
|
||
")->current()->t);
|
||
|
||
// sql
|
||
$first_partition_daily = ", PARTITION p_" . date('Y_m_d')
|
||
. " VALUES LESS THAN (TO_DAYS('"
|
||
. date('Y-m-d', time() + 86400) . "')) ENGINE = InnoDB";
|
||
|
||
$first_partition_monthly = ", PARTITION p_" . date('Y_m_01')
|
||
. " VALUES LESS THAN (TO_DAYS('"
|
||
. date('Y-m-01', $i) . "')) ENGINE = InnoDB";
|
||
}
|
||
|
||
// daily
|
||
$db->query("CREATE TABLE IF NOT EXISTS `members_traffics_daily` (
|
||
`member_id` int(11) NOT NULL,
|
||
`upload` bigint unsigned NOT NULL,
|
||
... | ... | |
KEY `date` (`date`)
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci
|
||
PARTITION BY RANGE (TO_DAYS(`date`))
|
||
(PARTITION p_first VALUES LESS THAN (TO_DAYS('1970-01-01')) ENGINE = InnoDB);
|
||
(PARTITION p_first VALUES LESS THAN (TO_DAYS('1970-01-01')) ENGINE = InnoDB
|
||
$first_partition_daily);
|
||
");
|
||
|
||
// monthly
|
||
$db->query("CREATE TABLE IF NOT EXISTS `members_traffics_monthly` (
|
||
`member_id` int(11) NOT NULL,
|
||
`upload` bigint unsigned NOT NULL,
|
||
... | ... | |
KEY `date` (`date`)
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci
|
||
PARTITION BY RANGE (TO_DAYS(`date`))
|
||
(PARTITION p_first VALUES LESS THAN (TO_DAYS('1970-01-01')) ENGINE = InnoDB);
|
||
(PARTITION p_first VALUES LESS THAN (TO_DAYS('1970-01-01')) ENGINE = InnoDB
|
||
$first_partition_monthly);
|
||
");
|
||
|
||
// yearly
|
||
$db->query("CREATE TABLE IF NOT EXISTS `members_traffics_yearly` (
|
||
`member_id` int(11) NOT NULL,
|
||
`upload` bigint unsigned NOT NULL,
|
||
... | ... | |
}
|
||
|
||
/**
|
||
* Remove partitions for members_traffics_daily which are more than year old
|
||
* Remove partitions for members_traffics_daily which are more than 2 month old
|
||
*
|
||
* @author Ondřej Fibich
|
||
*/
|
||
... | ... | |
}
|
||
|
||
/**
|
||
* Remove partitions for members_traffics_monthly which are more than year old
|
||
* Remove partitions for members_traffics_monthly which are more than 2 years old
|
||
*
|
||
* @author Ondřej Fibich
|
||
*/
|
freenetis/branches/testing/application/controllers/settings.php | ||
---|---|---|
if (!$this->acl_check_edit(get_class($this), 'system'))
|
||
Controller::error(ACCESS);
|
||
|
||
$user_model = new User_Model();
|
||
|
||
// creating of new forge
|
||
$this->form = new Forge('settings/logging');
|
||
|
||
... | ... | |
->value('1')
|
||
->label('Enable ulogd');
|
||
|
||
$this->form->input('ulogd_update_interval')
|
||
->label(__('Interval of update') . ': ' .
|
||
help::hint('ulogd_update_interval'))
|
||
->rules('required|valid_numeric')
|
||
->value(Settings::get('ulogd_update_interval'));
|
||
if (version_compare($user_model->get_mysql_version(), '5.1.0', '<'))
|
||
{
|
||
$this->form->ulogd_enabled->label(
|
||
__('Enable ulogd') . ' - <span class="error">' .
|
||
__('require MySQL %s and higher', array('5.1')) . '</span>')
|
||
->disabled('disabled');
|
||
}
|
||
else
|
||
{
|
||
$this->form->input('ulogd_update_interval')
|
||
->label(__('Interval of update') . ': ' .
|
||
help::hint('ulogd_update_interval'))
|
||
->rules('required|valid_numeric')
|
||
->value(Settings::get('ulogd_update_interval'));
|
||
|
||
$this->form->group('')
|
||
->label(__('Active members') . ' ' .
|
||
help::hint('ulogd_active'));
|
||
|
||
$this->form->input('ulogd_active_count')
|
||
->label(__('Base') . ': ' .
|
||
help::hint('ulogd_active_count'))
|
||
->rules('required|valid_ulogd_active_count')
|
||
->value(Settings::get('ulogd_active_count'));
|
||
|
||
$this->form->dropdown('ulogd_active_type')
|
||
->label(__('Type of traffic') . ': ' .
|
||
help::hint('ulogd_active_type'))
|
||
->rules('required')
|
||
->options(array
|
||
(
|
||
0 => '----- ' . __('Select type') . ' -----',
|
||
'upload' => __('upload'),
|
||
'download' => __('download'),
|
||
'total' => __('both') . ' (' . __('upload') . ' + ' . __('download') . ')'
|
||
))->selected(Settings::get('ulogd_active_type'))
|
||
->style('width:200px');
|
||
|
||
$this->form->input('ulogd_active_min')
|
||
->label(__('Minimum of traffic') . ': ' .
|
||
help::hint('ulogd_active_min'))
|
||
->rules('valid_byte_size')
|
||
->value(Settings::get('ulogd_active_min'));
|
||
}
|
||
|
||
$this->form->group('')
|
||
->label(__('Active members') . ' ' .
|
||
help::hint('ulogd_active'));
|
||
|
||
$this->form->input('ulogd_active_count')
|
||
->label(__('Base') . ': ' .
|
||
help::hint('ulogd_active_count'))
|
||
->rules('required|valid_ulogd_active_count')
|
||
->value(Settings::get('ulogd_active_count'));
|
||
|
||
$this->form->dropdown('ulogd_active_type')
|
||
->label(__('Type of traffic') . ': ' .
|
||
help::hint('ulogd_active_type'))
|
||
->rules('required')
|
||
->options(array
|
||
(
|
||
0 => '----- ' . __('Select type') . ' -----',
|
||
'upload' => __('upload'),
|
||
'download' => __('download'),
|
||
'total' => __('both') . ' (' . __('upload') . ' + ' . __('download') . ')'
|
||
))->selected(Settings::get('ulogd_active_type'))
|
||
->style('width:200px');
|
||
|
||
$this->form->input('ulogd_active_min')
|
||
->label(__('Minimum of traffic') . ': ' .
|
||
help::hint('ulogd_active_min'))
|
||
->rules('valid_byte_size')
|
||
->value(Settings::get('ulogd_active_min'));
|
||
|
||
$this->form->group(__('Syslog NG MySQL API').' '.help::hint('syslog_ng_mysql_api'));
|
||
|
||
$this->form->checkbox('syslog_ng_mysql_api_enabled')
|
||
... | ... | |
->label('Enable action logs');
|
||
|
||
$this->form->submit('Save');
|
||
|
||
$user_model = new User_Model();
|
||
|
||
if (version_compare($user_model->get_mysql_version(), '5.1.0', '<'))
|
||
{
|
||
... | ... | |
{
|
||
try
|
||
{
|
||
Members_traffic_Model::create_tables();
|
||
Members_traffic_Model::create_tables(TRUE);
|
||
Ulog2_ct_Model::create_functions();
|
||
}
|
||
catch (Exception $e)
|
Také k dispozici: Unified diff
Opravy:
- pri vytvoreni tabulek pro traffic se prida i partition pro aktualni den
- odchyceni chyby vytvareni tabulek provozu na Lennym (MySQL v <5.1 neumi partitions nezbytne pro traffic)