/**
 * setup the options that can only appear on the command-line
 */
int chassis_options_set_cmdline_only_options(chassis_options_t *opts,
		int *print_version,
		char **config_file) {

	chassis_options_add(opts,
		"version", 'V', 0, G_OPTION_ARG_NONE, print_version, "Show version", NULL);

	chassis_options_add(opts,
		"defaults-file", 0, 0, G_OPTION_ARG_STRING, config_file, "configuration file", "<file>");

	return 0;
}
/**
 * setup the options of the chassis
 */
int chassis_frontend_set_chassis_options(chassis_frontend_t *frontend, chassis_options_t *opts) {
	chassis_options_add(opts,
		"verbose-shutdown",         0, 0, G_OPTION_ARG_NONE, &(frontend->verbose_shutdown), "Always log the exit code when shutting down", NULL);

	chassis_options_add(opts,
		"daemon",                   0, 0, G_OPTION_ARG_NONE, &(frontend->daemon_mode), "Start in daemon-mode", NULL);

	chassis_options_add(opts,
		"conn_log",                 0, 0, G_OPTION_ARG_NONE, &(frontend->conn_log), "Record user login log", NULL);
	chassis_options_add(opts,
		"query_response_time_stats",0, 0, G_OPTION_ARG_NONE, &(frontend->query_response_time_stats), "Record query_response_time", NULL);
	chassis_options_add(opts,
		"ignore-user",                 0, 0, G_OPTION_ARG_STRING_ARRAY, &(frontend->ignore_user), "not to record user", "<user>");

#ifndef _WIN32
	chassis_options_add(opts,
		"user",                     0, 0, G_OPTION_ARG_STRING, &(frontend->user), "Run mysql-proxy as user", "<user>");
#endif

	chassis_options_add(opts,
		"basedir",                  0, 0, G_OPTION_ARG_STRING, &(frontend->base_dir), "Base directory to prepend to relative paths in the config", "<absolute path>");

	chassis_options_add(opts,
		"pid-file",                 0, 0, G_OPTION_ARG_STRING, &(frontend->pid_file), "PID file in case we are started as daemon", "<file>");

	chassis_options_add(opts,
		"plugin-dir",               0, 0, G_OPTION_ARG_STRING, &(frontend->plugin_dir), "path to the plugins", "<path>");

	chassis_options_add(opts,
		"plugins",                  0, 0, G_OPTION_ARG_STRING_ARRAY, &(frontend->plugin_names), "plugins to load", "<name>");

	chassis_options_add(opts,
		"log-level",                0, 0, G_OPTION_ARG_STRING, &(frontend->log_level), "log all messages of level ... or higher", "(error|warning|info|message|debug)");

	chassis_options_add(opts,
		"log-file",                 0, 0, G_OPTION_ARG_STRING, &(frontend->log_filename), "log all messages in a file", "<file>");

	chassis_options_add(opts,
		"log-use-syslog",           0, 0, G_OPTION_ARG_NONE, &(frontend->use_syslog), "log all messages to syslog", NULL);

	chassis_options_add(opts,
		"log-backtrace-on-crash",   0, 0, G_OPTION_ARG_NONE, &(frontend->invoke_dbg_on_crash), "try to invoke debugger on crash", NULL);

#ifndef _WIN32
	chassis_options_add(opts,
		"keepalive",                0, 0, G_OPTION_ARG_NONE, &(frontend->auto_restart), "try to restart the proxy if it crashed", NULL);
#endif

	chassis_options_add(opts,
		"max-open-files",           0, 0, G_OPTION_ARG_INT, &(frontend->max_files_number), "maximum number of open files (ulimit -n)", NULL);

	chassis_options_add(opts,
		"event-threads",            0, 0, G_OPTION_ARG_INT, &(frontend->event_thread_count), "number of event-handling threads (default: 1)", NULL);

	chassis_options_add(opts,
		"lua-path",                 0, 0, G_OPTION_ARG_STRING, &(frontend->lua_path), "set the LUA_PATH", "<...>");

	chassis_options_add(opts,
		"lua-cpath",                0, 0, G_OPTION_ARG_STRING, &(frontend->lua_cpath), "set the LUA_CPATH", "<...>");

	return 0;	
}
Beispiel #3
0
/**
 * setup the options of the chassis
 */
int chassis_frontend_set_chassis_options(chassis_frontend_t *frontend, chassis_options_t *opts) {
	chassis_options_add(opts,
		"verbose-shutdown",         0, 0, G_OPTION_ARG_NONE, &(frontend->verbose_shutdown), "Always log the exit code when shutting down", NULL);

	chassis_options_add(opts,
		"daemon",                   0, 0, G_OPTION_ARG_NONE, &(frontend->daemon_mode), "Start in daemon-mode", NULL);

#ifndef _WIN32
	chassis_options_add(opts,
		"user",                     0, 0, G_OPTION_ARG_STRING, &(frontend->user), "Run mysql-proxy as user", "<user>");
#endif

	chassis_options_add(opts,
		"basedir",                  0, 0, G_OPTION_ARG_STRING, &(frontend->base_dir), "Base directory to prepend to relative paths in the config", "<absolute path>");

	chassis_options_add(opts,
		"pid-file",                 0, 0, G_OPTION_ARG_STRING, &(frontend->pid_file), "PID file in case we are started as daemon", "<file>");

	chassis_options_add(opts,
		"plugin-dir",               0, 0, G_OPTION_ARG_STRING, &(frontend->plugin_dir), "path to the plugins", "<path>");

	chassis_options_add(opts,
		"plugins",                  0, 0, G_OPTION_ARG_STRING_ARRAY, &(frontend->plugin_names), "plugins to load", "<name>");

	chassis_options_add(opts,
		"log-level",                0, 0, G_OPTION_ARG_STRING, &(frontend->log_level), "log all messages of level ... or higher", "(error|warning|message|debug)");

	chassis_options_add(opts,
		"log-file",                 0, 0, G_OPTION_ARG_STRING, &(frontend->log_filename), "log all messages in a file", "<file>");

	chassis_options_add(opts,
		"log-config-file",          0, 0, G_OPTION_ARG_FILENAME, &(frontend->log_config_filename), "Use domain specific logging configuration", "<file>");

	chassis_options_add(opts,
		"log-use-syslog",           0, 0, G_OPTION_ARG_NONE, &(frontend->use_syslog), "log all messages to syslog", NULL);

	chassis_options_add(opts,
		"log-backtrace-on-crash",   0, 0, G_OPTION_ARG_NONE, &(frontend->invoke_dbg_on_crash), "try to invoke debugger on crash", NULL);

#ifndef _WIN32
	chassis_options_add(opts,
		"keepalive",                0, 0, G_OPTION_ARG_NONE, &(frontend->auto_restart), "try to restart the proxy if it crashed", NULL);
#endif

	chassis_options_add(opts,
		"max-open-files",           0, 0, G_OPTION_ARG_INT, &(frontend->max_files_number), "maximum number of open files (ulimit -n)", NULL);

	chassis_options_add(opts,
		"event-threads",            0, 0, G_OPTION_ARG_INT, &(frontend->event_thread_count), "number of event-handling threads (default: 1)", NULL);

	chassis_options_add(opts,
		"lua-path",                 0, 0, G_OPTION_ARG_STRING, &(frontend->lua_path), "set the LUA_PATH", "<...>");

	chassis_options_add(opts,
		"lua-cpath",                0, 0, G_OPTION_ARG_STRING, &(frontend->lua_cpath), "set the LUA_CPATH", "<...>");

	chassis_options_add(opts,
		"network-timeout",          0, 0, G_OPTION_ARG_INT,
		&(frontend->network_timeout), "sets timeout in seconds for detection "
		"of broken network connections (default: 10s)", 0);

	chassis_options_add(opts,
		"network-retries",          0, 0, G_OPTION_ARG_INT,
		&(frontend->network_retries), "sets number of retries before a "
		"connection is considered dead (default: 3)", 0);

	return 0;	
}
Beispiel #4
0
/**
 * setup the options of the chassis
 */
int chassis_frontend_set_chassis_options(chassis_frontend_t *frontend, chassis_options_t *opts) {
    chassis_options_add(opts, "verbose-shutdown", 0, 0, G_OPTION_ARG_NONE, &(frontend->verbose_shutdown), "Always log the exit code when shutting down", NULL, NULL, NULL, 0);
    chassis_options_add(opts, "daemon", 0, 0, G_OPTION_ARG_NONE, &(frontend->daemon_mode), "Start in daemon-mode", NULL, NULL, show_daemon, SHOW_OPTS_PROPERTY);
    chassis_options_add(opts, "user", 0, 0, G_OPTION_ARG_STRING, &(frontend->user), "Run mysql-proxy as user", "<user>", NULL, show_user, SHOW_OPTS_PROPERTY);
    chassis_options_add(opts, "basedir", 0, 0, G_OPTION_ARG_STRING, &(frontend->base_dir), "Base directory to prepend to relative paths in the config", "<absolute path>", assign_basedir, show_basedir, SHOW_OPTS_PROPERTY);
    chassis_options_add(opts, "plugin-dir", 0, 0, G_OPTION_ARG_STRING, &(frontend->plugin_dir), "path to the plugins", "<path>", NULL, NULL, ASSIGN_SHOW);
    chassis_options_add(opts, "plugins", 0, 0, G_OPTION_ARG_STRING_ARRAY, &(frontend->plugin_names), "plugins to load", "<name>", NULL, show_plugins, SHOW_OPTS_PROPERTY);
    chassis_options_add(opts, "log-level", 0, 0, G_OPTION_ARG_STRING, &(frontend->log_level), "log all messages of level ... or higher", "(error|warning|info|message|debug)", assign_log_level, show_log_level, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "log-path", 0, 0, G_OPTION_ARG_STRING, &(frontend->log_path), "log all messages in a path", "<path>", assign_log_path, show_log_path, SHOW_SAVE);
    chassis_options_add(opts, "log-use-syslog", 0, 0, G_OPTION_ARG_NONE, &(frontend->use_syslog), "log all messages to syslog", NULL, NULL, NULL, 0);
    chassis_options_add(opts, "log-backtrace-on-crash", 0, 0, G_OPTION_ARG_NONE, &(frontend->invoke_dbg_on_crash), "try to invoke debugger on crash", NULL, assign_log_bt_on_crash, show_log_bt_on_crash, 0);
    chassis_options_add(opts, "keepalive", 0, 0, G_OPTION_ARG_NONE, &(frontend->auto_restart), "try to restart the proxy if it crashed", NULL, NULL, show_keepalive, SHOW_OPTS_PROPERTY);
    chassis_options_add(opts, "max-open-files", 0, 0, G_OPTION_ARG_INT, &(frontend->max_files_number), "maximum number of open files (ulimit -n)", NULL, NULL, show_max_open_files, SHOW_OPTS_PROPERTY);
    chassis_options_add(opts, "max-connections", 0, 0, G_OPTION_ARG_INT, &(frontend->max_connections), "maximum connections", NULL, assign_max_connections, show_max_connections, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "long-wait-time", 0, 0, G_OPTION_ARG_INT, &(frontend->long_wait_time), "if a sync waiting takes longer than the specified time, it will be considered to be long (ms)", NULL, assign_long_wait_time, show_long_wait_time, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "long-query-time", 0, 0, G_OPTION_ARG_INT, &(frontend->long_query_time), "if a query takes longer than the specified time, it will be considered to be long (ms)", NULL, assign_long_query_time, show_long_query_time, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "query-response-time-range-base", 0, 0, G_OPTION_ARG_INT,
                                                &(frontend->query_response_time_range_base), "the logarithm base for the scale of query times' statistics(default: 2)",
                                                NULL, assign_time_range_base, show_time_range_base, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "query-response-time-stats", 0, 0, G_OPTION_ARG_INT, &(frontend->query_response_time_stats),
                                                "whether to enable collection of query times(0: none statistics, 1: slow query statistics, 2: histogram statistics)(default: 1)", NULL,
                                               assign_time_stats, show_time_stats, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "event-threads", 0, 0, G_OPTION_ARG_INT, &(frontend->event_thread_count), "number of event-handling threads (default: 1)", NULL, NULL, show_event_threads, SHOW_OPTS_PROPERTY);
    chassis_options_add(opts, "lua-path", 0, 0, G_OPTION_ARG_STRING, &(frontend->lua_path), "set the LUA_PATH", "<...>", NULL, NULL, 0);
    chassis_options_add(opts, "lua-cpath", 0, 0, G_OPTION_ARG_STRING, &(frontend->lua_cpath), "set the LUA_CPATH", "<...>", NULL, NULL, 0);
    chassis_options_add(opts, "instance", 0, 0, G_OPTION_ARG_STRING, &(frontend->instance_name), "instance name", "<name>", NULL, show_instance, SHOW_OPTS_PROPERTY);
    chassis_options_add(opts, "wait-timeout", 0, 0, G_OPTION_ARG_INT, &(frontend->wait_timeout), "the number of seconds which dbproxy waits for activity on a connection before closing it (default:0)", NULL,
                                                    assign_wait_timeout, show_wait_timeout, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "shutdown-timeout", 0, 0, G_OPTION_ARG_INT, &(frontend->shutdown_timeout), "the number of seconds which dbproxy waits for activity on a connection before closing it during shutdown process(default:1)", NULL,
                                                    assign_shutdown_timeout, show_shutdown_timeout, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "db-connection-idle-timeout", 0, 0, G_OPTION_ARG_INT, &(frontend->db_connection_idle_timeout), "the number of seconds which dbproxy will close a backend's idle connection after  (default:3600s)", NULL,
                                                    assign_db_connetion_idle_timeout, show_db_connection_idle_timeout, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "db-connection-max-age", 0, 0, G_OPTION_ARG_INT, &(frontend->db_connection_max_age), "the number of seconds which dbproxy will close a backend's connection after  (default:7200s), 0 means no maximum absolute age is enforced", NULL,
                                                    assign_db_connection_max_age, show_db_connection_max_age, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "mysql-version", 0, 0, G_OPTION_ARG_STRING, &(frontend->mysql_version), "the version of the backends  (default:5.5)", NULL, assign_mysql_version, show_mysql_version, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "lastest-query-num", 0, 0, G_OPTION_ARG_INT, &(frontend->lastest_query_num), "number of lastest queries (default:0, don't save lastest queries)", NULL, assign_lastest_query_num, show_lastest_query_num, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "query-filter-time-threshold", 0, 0, G_OPTION_ARG_INT, &(frontend->query_filter_time_threshold), "the threshold of query executing time when adding to filter (default: -1, no threshold)", NULL,
                                                    assign_time_threshold, show_time_threshold, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "query-filter-frequent-threshold", 0, 0, G_OPTION_ARG_DOUBLE, &(frontend->query_filter_frequent_threshold), "the threshold of query executing frequency(access times per-second) when adding to filter (default: = 0)", NULL,
                                                    assign_freq_threshold, show_freq_threshold, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "access-num-per-time-window", 0, 0, G_OPTION_ARG_INT, &(frontend->access_num_per_time_window), "the threshold of query executing times when calculating frequency (default: 5)", NULL,
                                                    assign_access_ratio, show_access_ratio, ALL_OPTS_PROPERTY);
//    chassis_options_add(opts, "backend-max-thread-running", 0, 0, G_OPTION_ARG_INT, &(frontend->max_backend_tr), "the default value of blacklist's filter flag (default: 0, close)", NULL,
//                                                    assign_backend_max_thread_running, show_backend_max_thread_running, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "thread-running-sleep-delay", 0, 0, G_OPTION_ARG_INT, &(frontend->thread_running_sleep_delay), "the thread running wait time_out(ms)", NULL,
                                                    assign_thread_running_sleep_delay, show_thread_running_sleep_delay, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "auto-filter-flag", 0, 0, G_OPTION_ARG_STRING, &(frontend->auto_filter_flag), "the default flag of auto added filter", NULL,
                                                    assign_auto_filter_flag, show_auto_filter_flag, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "manual-filter-flag", 0, 0, G_OPTION_ARG_STRING, &(frontend->manual_filter_flag), "the default flag of manual added filter", NULL,
                                                    assign_manual_filter_flag, show_manual_filter_flag, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "blacklist-file", 0, 0, G_OPTION_ARG_STRING, &(frontend->blacklist_file), "the blacklist file name", NULL,
                                                    assign_blacklist_file, show_blacklist_file, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "remove-backend-timeout", 0, 0, G_OPTION_ARG_INT, &(frontend->remove_backend_timeout), "the number of seconds which dbproxy waits for removing backend success", NULL,
                                                    assign_remove_backend_timeout, show_remove_backend_timeout, ALL_OPTS_PROPERTY);

    chassis_options_add(opts, "log-trace-modules", 0, 0, G_OPTION_ARG_INT, &(frontend->log_trace_modules), "moudles which want to trace the process,"
                                                                                                            " none: 0x00 connection_pool:0x01 event:0x02 sql: 0x04 con_status:0x08 all:0x0F", NULL,
                                                    assign_log_trace_modules, show_log_trace_modules, ALL_OPTS_PROPERTY);

    chassis_options_add(opts, "backend-monitor-pwds", 0, 0, G_OPTION_ARG_STRING, &(frontend->backend_pwds), "the user and password to to check the backends health status", "user:pwd", assign_backend_monitor_pwds, show_assign_backend_monitor_pwds, ALL_OPTS_PROPERTY);
    chassis_options_add(opts, "version", 0, 0, G_OPTION_ARG_INT, &(frontend->print_version), "print dbproxy version", NULL, NULL, show_version, SHOW_OPTS_PROPERTY);

    chassis_options_add(opts, "db-connect-timeout", 0, 0, G_OPTION_ARG_DOUBLE, &(frontend->db_connect_timeout), "connect mysql's timeout (default 3.0 s). value == 0, means don't set timeout.", NULL, assign_db_connect_timeout, show_db_connect_timeout, ALL_OPTS_PROPERTY);

    return 0;   
}