diff options
author | sasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-07-29 12:32:01 +0000 |
---|---|---|
committer | sasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-07-29 12:32:01 +0000 |
commit | 3cbda6423e731d63f3b2892e3065ed65203e68de (patch) | |
tree | 3d996291de25f71a60d82a7820776f4b5222973f /src | |
parent | f7cd0be8cdcedcc34656ced6982dd7abadca01fc (diff) | |
download | zabbix-3cbda6423e731d63f3b2892e3065ed65203e68de.tar.gz zabbix-3cbda6423e731d63f3b2892e3065ed65203e68de.tar.xz zabbix-3cbda6423e731d63f3b2892e3065ed65203e68de.zip |
- [DEV-196] improved performance of server module
git-svn-id: svn://svn.zabbix.com/trunk@5849 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/zbxdb/db.c | 4 | ||||
-rw-r--r-- | src/libs/zbxdbcache/dbcache.c | 90 | ||||
-rw-r--r-- | src/zabbix_server/pinger/pinger.c | 38 |
3 files changed, 74 insertions, 58 deletions
diff --git a/src/libs/zbxdb/db.c b/src/libs/zbxdb/db.c index 61dad9fd..ccd5c403 100644 --- a/src/libs/zbxdb/db.c +++ b/src/libs/zbxdb/db.c @@ -477,8 +477,8 @@ int zbx_db_vexecute(const char *fmt, va_list args) /* more results? -1 = no, >0 = error, 0 = yes (keep looping) */ if ((status = mysql_next_result(conn)) > 0) - zabbix_log(LOG_LEVEL_ERR, "Error: %s [%d]", - mysql_error(conn), mysql_errno(conn)); + zabbix_log(LOG_LEVEL_ERR, "Query failed: [%s] %s [%d]", + sql, mysql_error(conn), mysql_errno(conn)); } while (status == 0); } } diff --git a/src/libs/zbxdbcache/dbcache.c b/src/libs/zbxdbcache/dbcache.c index 82866151..78e56f34 100644 --- a/src/libs/zbxdbcache/dbcache.c +++ b/src/libs/zbxdbcache/dbcache.c @@ -512,7 +512,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) char value_esc[MAX_STRING_LEN], *value_esc_dyn; int history_text_num, history_log_num; zbx_uint64_t id; -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL int tmp_offset; #endif @@ -525,7 +525,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) /* * history */ -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL tmp_offset = sql_offset; zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 64, "insert into history values "); @@ -535,7 +535,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) { if (history[i].value_type == ITEM_VALUE_TYPE_FLOAT) { -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 512, "(" ZBX_FS_UI64 ",%d," ZBX_FS_DBL "),", history[i].itemid, @@ -552,7 +552,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) } } -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL if (sql[sql_offset - 1] == ',') { sql_offset--; @@ -564,7 +564,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) if (CONFIG_NODE_NOHISTORY == 0 && CONFIG_MASTER_NODEID > 0) { -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL tmp_offset = sql_offset; zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 64, "insert into history_sync (nodeid,itemid,clock,value) values "); @@ -574,7 +574,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) { if (history[i].value_type == ITEM_VALUE_TYPE_FLOAT) { -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 512, "(%d," ZBX_FS_UI64 ",%d," ZBX_FS_DBL "),", get_nodeid_by_id(history[i].itemid), @@ -593,7 +593,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) } } -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL if (sql[sql_offset - 1] == ',') { sql_offset--; @@ -607,7 +607,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) /* * history_uint */ -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL tmp_offset = sql_offset; zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 64, "insert into history_uint values "); @@ -617,7 +617,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) { if (history[i].value_type == ITEM_VALUE_TYPE_UINT64) { -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 512, "(" ZBX_FS_UI64 ",%d," ZBX_FS_UI64 "),", history[i].itemid, @@ -634,7 +634,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) } } -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL if (sql[sql_offset - 1] == ',') { sql_offset--; @@ -646,7 +646,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) if (CONFIG_NODE_NOHISTORY == 0 && CONFIG_MASTER_NODEID > 0) { -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL tmp_offset = sql_offset; zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 64, "insert into history_uint_sync (nodeid,itemid,clock,value) values "); @@ -656,7 +656,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) { if (history[i].value_type == ITEM_VALUE_TYPE_UINT64) { -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 512, "(%d," ZBX_FS_UI64 ",%d," ZBX_FS_UI64 "),", get_nodeid_by_id(history[i].itemid), @@ -675,7 +675,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) } } -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL if (sql[sql_offset - 1] == ',') { sql_offset--; @@ -689,7 +689,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) /* * history_str */ -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL tmp_offset = sql_offset; zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 64, "insert into history_str values "); @@ -700,7 +700,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) if (history[i].value_type == ITEM_VALUE_TYPE_STR) { DBescape_string(history[i].value.value_str, value_esc, sizeof(value_esc)); -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 512, "(" ZBX_FS_UI64 ",%d,'%s'),", history[i].itemid, @@ -717,7 +717,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) } } -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL if (sql[sql_offset - 1] == ',') { sql_offset--; @@ -729,7 +729,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) if (CONFIG_NODE_NOHISTORY == 0 && CONFIG_MASTER_NODEID > 0) { -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL tmp_offset = sql_offset; zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 64, "insert into history_str_sync (nodeid,itemid,clock,value) values "); @@ -740,7 +740,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) if (history[i].value_type == ITEM_VALUE_TYPE_STR) { DBescape_string(history[i].value.value_str, value_esc, sizeof(value_esc)); -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 512, "(%d," ZBX_FS_UI64 ",%d,'%s'),", get_nodeid_by_id(history[i].itemid), @@ -759,7 +759,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) } } -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL if (sql[sql_offset - 1] == ',') { sql_offset--; @@ -786,7 +786,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) { id = DBget_maxid_num("history_text", "id", history_text_num); -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL tmp_offset = sql_offset; zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 64, "insert into history_text values "); @@ -797,7 +797,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) if (history[i].value_type == ITEM_VALUE_TYPE_TEXT) { value_esc_dyn = DBdyn_escape_string(history[i].value.value_str); -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 4096, "(" ZBX_FS_UI64 "," ZBX_FS_UI64 ",%d,'%s'),", id, @@ -818,7 +818,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) } } -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL if (sql[sql_offset - 1] == ',') { sql_offset--; @@ -836,7 +836,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) { id = DBget_maxid_num("history_log", "id", history_log_num); -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL tmp_offset = sql_offset; zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 64, "insert into history_log values "); @@ -847,7 +847,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) if (history[i].value_type == ITEM_VALUE_TYPE_LOG) { value_esc_dyn = DBdyn_escape_string(history[i].value.value_str); -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 4096, "(" ZBX_FS_UI64 "," ZBX_FS_UI64 ",%d,%d,'%s',%d,'%s'),", id, @@ -874,7 +874,7 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) } } -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL if (sql[sql_offset - 1] == ',') { sql_offset--; @@ -885,6 +885,10 @@ static void DCmass_add_history(ZBX_DC_HISTORY *history, int history_num) #endif } +#ifdef HAVE_MYSQL + sql[sql_offset] = '\0'; +#endif + #ifdef HAVE_ORACLE zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 8, "end;\n"); #endif @@ -911,7 +915,7 @@ static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num) { int sql_offset = 0, i; char value_esc[MAX_STRING_LEN], *value_esc_dyn; -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL int tmp_offset; #endif @@ -921,7 +925,7 @@ static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num) zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 8, "begin\n"); #endif -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL tmp_offset = sql_offset; zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 64, "insert into proxy_history (itemid,clock,value) values "); @@ -931,7 +935,7 @@ static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num) { if (history[i].value_type == ITEM_VALUE_TYPE_FLOAT) { -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 512, "(" ZBX_FS_UI64 ",%d,'" ZBX_FS_DBL "'),", history[i].itemid, @@ -948,7 +952,7 @@ static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num) } } -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL if (sql[sql_offset - 1] == ',') { sql_offset--; @@ -958,7 +962,7 @@ static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num) sql_offset = tmp_offset; #endif -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL tmp_offset = sql_offset; zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 64, "insert into proxy_history (itemid,clock,value) values "); @@ -968,7 +972,7 @@ static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num) { if (history[i].value_type == ITEM_VALUE_TYPE_UINT64) { -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 512, "(" ZBX_FS_UI64 ",%d,'" ZBX_FS_UI64 "'),", history[i].itemid, @@ -985,7 +989,7 @@ static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num) } } -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL if (sql[sql_offset - 1] == ',') { sql_offset--; @@ -995,7 +999,7 @@ static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num) sql_offset = tmp_offset; #endif -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL tmp_offset = sql_offset; zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 64, "insert into proxy_history (itemid,clock,value) values "); @@ -1006,7 +1010,7 @@ static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num) if (history[i].value_type == ITEM_VALUE_TYPE_STR) { DBescape_string(history[i].value.value_str, value_esc, sizeof(value_esc)); -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 512, "(" ZBX_FS_UI64 ",%d,'%s'),", history[i].itemid, @@ -1023,7 +1027,7 @@ static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num) } } -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL if (sql[sql_offset - 1] == ',') { sql_offset--; @@ -1033,7 +1037,7 @@ static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num) sql_offset = tmp_offset; #endif -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL tmp_offset = sql_offset; zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 64, "insert into proxy_history (itemid,clock,value) values "); @@ -1044,7 +1048,7 @@ static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num) if (history[i].value_type == ITEM_VALUE_TYPE_TEXT) { value_esc_dyn = DBdyn_escape_string(history[i].value.value_str); -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 4096, "(" ZBX_FS_UI64 ",%d,'%s'),", history[i].itemid, @@ -1062,7 +1066,7 @@ static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num) } } -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL if (sql[sql_offset - 1] == ',') { sql_offset--; @@ -1072,7 +1076,7 @@ static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num) sql_offset = tmp_offset; #endif -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL tmp_offset = sql_offset; zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 64, "insert into proxy_history (itemid,clock,timestamp,source,severity,value) values "); @@ -1083,7 +1087,7 @@ static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num) if (history[i].value_type == ITEM_VALUE_TYPE_LOG) { value_esc_dyn = DBdyn_escape_string(history[i].value.value_str); -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 4096, "(" ZBX_FS_UI64 "," ZBX_FS_UI64 ",%d,%d,'%s',%d,'%s'),", history[i].itemid, @@ -1107,7 +1111,7 @@ static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num) } } -#if defined(HAVE_MYSQL) +#ifdef HAVE_MYSQL if (sql[sql_offset - 1] == ',') { sql_offset--; @@ -1117,6 +1121,10 @@ static void DCmass_proxy_add_history(ZBX_DC_HISTORY *history, int history_num) sql_offset = tmp_offset; #endif +#ifdef HAVE_MYSQL + sql[sql_offset] = '\0'; +#endif + #ifdef HAVE_ORACLE zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 8, "end;\n"); #endif diff --git a/src/zabbix_server/pinger/pinger.c b/src/zabbix_server/pinger/pinger.c index 8796347d..a84f6b52 100644 --- a/src/zabbix_server/pinger/pinger.c +++ b/src/zabbix_server/pinger/pinger.c @@ -51,11 +51,14 @@ static int pinger_num; * Comments: can be done in process_data() * * * ******************************************************************************/ -static void process_value(char *key, ZBX_FPING_HOST *host, AGENT_RESULT *value, int now, int *items) +static void process_value(char *key, ZBX_FPING_HOST *host, zbx_uint64_t *value_ui64, double *value_dbl, int now, int *items) { DB_RESULT result; DB_ROW row; DB_ITEM item; + AGENT_RESULT value; + + assert(value_ui64 || value_dbl); zabbix_log(LOG_LEVEL_DEBUG, "In process_value(%s@%s)", key, @@ -80,26 +83,39 @@ static void process_value(char *key, ZBX_FPING_HOST *host, AGENT_RESULT *value, while (NULL != (row = DBfetch(result))) { DBget_item_from_db(&item, row); + init_result(&value); + + if (NULL != value_ui64) + { + SET_UI64_RESULT(&value, *value_ui64); + } + else + { + SET_DBL_RESULT(&value, *value_dbl); + } + if (0 == CONFIG_DBSYNCER_FORKS) { DBbegin(); switch (zbx_process) { case ZBX_PROCESS_SERVER: - process_new_value(&item, value, now); + process_new_value(&item, &value, now); update_triggers(item.itemid); break; case ZBX_PROCESS_PROXY: - proxy_process_new_value(&item, value, now); + proxy_process_new_value(&item, &value, now); break; } DBcommit(); } else { - process_new_value(&item, value, now); + process_new_value(&item, &value, now); DCadd_nextcheck(&item, now, NULL); } + free_result(&value); + (*items)++; } DBfree_result(result); @@ -123,7 +139,6 @@ static void process_value(char *key, ZBX_FPING_HOST *host, AGENT_RESULT *value, static int process_values(ZBX_FPING_HOST *hosts, int hosts_count, int now) { int i, items = 0; - AGENT_RESULT value; zabbix_log(LOG_LEVEL_DEBUG, "In process_values()"); @@ -131,20 +146,13 @@ static int process_values(ZBX_FPING_HOST *hosts, int hosts_count, int now) DCinit_nextchecks(); for (i = 0; i < hosts_count; i++) { - zabbix_log(LOG_LEVEL_DEBUG, "Host [%s] alive [%d] " ZBX_FS_DBL " sec.", + zabbix_log(LOG_LEVEL_DEBUG, "Host [%s] alive [" ZBX_FS_UI64 "] " ZBX_FS_DBL " sec.", hosts[i].addr, hosts[i].alive, hosts[i].sec); - init_result(&value); - SET_UI64_RESULT(&value, hosts[i].alive); - process_value(SERVER_ICMPPING_KEY, &hosts[i], &value, now, &items); - free_result(&value); - - init_result(&value); - SET_DBL_RESULT(&value, hosts[i].sec); - process_value(SERVER_ICMPPINGSEC_KEY, &hosts[i], &value, now, &items); - free_result(&value); + process_value(SERVER_ICMPPING_KEY, &hosts[i], &hosts[i].alive, NULL, now, &items); + process_value(SERVER_ICMPPINGSEC_KEY, &hosts[i], NULL, &hosts[i].sec, now, &items); } if (0 != CONFIG_DBSYNCER_FORKS) |