summaryrefslogtreecommitdiffstats
path: root/src/zabbix_proxy
diff options
context:
space:
mode:
authorsasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-07-29 09:43:53 +0000
committersasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-07-29 09:43:53 +0000
commitf7cd0be8cdcedcc34656ced6982dd7abadca01fc (patch)
treea6aa538b83fd84824e8a8431bd9c2ecc694dafc3 /src/zabbix_proxy
parente3248ce4bc1b34d8623359d5333cfa9712b5eb73 (diff)
downloadzabbix-f7cd0be8cdcedcc34656ced6982dd7abadca01fc.tar.gz
zabbix-f7cd0be8cdcedcc34656ced6982dd7abadca01fc.tar.xz
zabbix-f7cd0be8cdcedcc34656ced6982dd7abadca01fc.zip
- [DEV-196] improved performance of server module
git-svn-id: svn://svn.zabbix.com/trunk@5848 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_proxy')
-rw-r--r--src/zabbix_proxy/datasender/datasender.c85
-rw-r--r--src/zabbix_proxy/proxy.c7
-rw-r--r--src/zabbix_proxy/zlog.c25
3 files changed, 45 insertions, 72 deletions
diff --git a/src/zabbix_proxy/datasender/datasender.c b/src/zabbix_proxy/datasender/datasender.c
index b1f1898c..0e836259 100644
--- a/src/zabbix_proxy/datasender/datasender.c
+++ b/src/zabbix_proxy/datasender/datasender.c
@@ -33,6 +33,7 @@
struct history_field_t {
const char *field;
const char *tag;
+ zbx_json_type_t jt;
};
struct history_table_t {
@@ -48,13 +49,11 @@ struct last_ids {
static ZBX_HISTORY_TABLE ht[]={
{"proxy_history", "history_lastid",
{
- {"host", ZBX_PROTO_TAG_HOST},
- {"key_", ZBX_PROTO_TAG_KEY},
- {"clock", ZBX_PROTO_TAG_CLOCK},
- {"timestamp", ZBX_PROTO_TAG_LOGTIMESTAMP},
- {"source", ZBX_PROTO_TAG_LOGSOURCE},
- {"severity", ZBX_PROTO_TAG_LOGSEVERITY},
- {"value", ZBX_PROTO_TAG_VALUE},
+ {"clock", ZBX_PROTO_TAG_CLOCK, ZBX_JSON_TYPE_INT},
+ {"timestamp", ZBX_PROTO_TAG_LOGTIMESTAMP, ZBX_JSON_TYPE_INT},
+ {"source", ZBX_PROTO_TAG_LOGSOURCE, ZBX_JSON_TYPE_STRING},
+ {"severity", ZBX_PROTO_TAG_LOGSEVERITY, ZBX_JSON_TYPE_INT},
+ {"value", ZBX_PROTO_TAG_VALUE, ZBX_JSON_TYPE_STRING},
{NULL}
}
},
@@ -64,14 +63,14 @@ static ZBX_HISTORY_TABLE ht[]={
static ZBX_HISTORY_TABLE dht[]={
{"proxy_dhistory", "dhistory_lastid",
{
- {"clock", ZBX_PROTO_TAG_CLOCK},
- {"druleid", ZBX_PROTO_TAG_DRULE},
- {"type", ZBX_PROTO_TAG_TYPE},
- {"ip", ZBX_PROTO_TAG_IP},
- {"port", ZBX_PROTO_TAG_PORT},
- {"key_", ZBX_PROTO_TAG_KEY},
- {"value", ZBX_PROTO_TAG_VALUE},
- {"status", ZBX_PROTO_TAG_STATUS},
+ {"clock", ZBX_PROTO_TAG_CLOCK, ZBX_JSON_TYPE_INT},
+ {"druleid", ZBX_PROTO_TAG_DRULE, ZBX_JSON_TYPE_INT},
+ {"type", ZBX_PROTO_TAG_TYPE, ZBX_JSON_TYPE_INT},
+ {"ip", ZBX_PROTO_TAG_IP, ZBX_JSON_TYPE_STRING},
+ {"port", ZBX_PROTO_TAG_PORT, ZBX_JSON_TYPE_INT},
+ {"key_", ZBX_PROTO_TAG_KEY, ZBX_JSON_TYPE_STRING},
+ {"value", ZBX_PROTO_TAG_VALUE, ZBX_JSON_TYPE_STRING},
+ {"status", ZBX_PROTO_TAG_STATUS, ZBX_JSON_TYPE_INT},
{NULL}
}
},
@@ -187,9 +186,6 @@ static int get_history_data(struct zbx_json *j, const ZBX_HISTORY_TABLE *ht, zbx
char sql[MAX_STRING_LEN];
DB_RESULT result;
DB_ROW row;
- const ZBX_FIELD *field;
- const ZBX_TABLE *table;
- zbx_json_type_t jt;
zbx_uint64_t id;
zabbix_log(LOG_LEVEL_DEBUG, "In get_history_data() [table:%s]",
@@ -199,42 +195,28 @@ static int get_history_data(struct zbx_json *j, const ZBX_HISTORY_TABLE *ht, zbx
get_lastid(ht, &id);
- offset += zbx_snprintf(sql + offset, sizeof(sql) - offset, "select id");
+ offset += zbx_snprintf(sql + offset, sizeof(sql) - offset, "select p.id,h.host,i.key_");
for (f = 0; ht->fields[f].field != NULL; f ++)
- offset += zbx_snprintf(sql + offset, sizeof(sql) - offset, ",%s",
+ offset += zbx_snprintf(sql + offset, sizeof(sql) - offset, ",p.%s",
ht->fields[f].field);
- offset += zbx_snprintf(sql + offset, sizeof(sql) - offset, " from %s"
- " where id>" ZBX_FS_UI64 " order by id",
+ offset += zbx_snprintf(sql + offset, sizeof(sql) - offset, " from hosts h,items i,%s p"
+ " where h.hostid=i.hostid and i.itemid=p.itemid and p.id>" ZBX_FS_UI64 " order by p.id",
ht->table,
id);
result = DBselectN(sql, 1000);
- table = DBget_table(ht->table);
-
while (NULL != (row = DBfetch(result))) {
zbx_json_addobject(j, NULL);
*lastid = zbx_atoui64(row[0]);
+ zbx_json_addstring(j, ZBX_PROTO_TAG_HOST, row[1], ZBX_JSON_TYPE_STRING);
+ zbx_json_addstring(j, ZBX_PROTO_TAG_KEY, row[2], ZBX_JSON_TYPE_STRING);
- for (f = 0; ht->fields[f].field != NULL; f ++) {
- field = DBget_field(table, ht->fields[f].field);
-
- switch (field->type) {
- case ZBX_TYPE_ID:
- case ZBX_TYPE_INT:
- case ZBX_TYPE_UINT:
- jt = ZBX_JSON_TYPE_INT;
- break;
- default :
- jt = ZBX_JSON_TYPE_STRING;
- break;
- }
-
- zbx_json_addstring(j, ht->fields[f].tag, row[f + 1], jt);
- }
+ for (f = 0; ht->fields[f].field != NULL; f ++)
+ zbx_json_addstring(j, ht->fields[f].tag, row[f + 3], ht->fields[f].jt);
records++;
@@ -267,9 +249,6 @@ static int get_dhistory_data(struct zbx_json *j, const ZBX_HISTORY_TABLE *ht, zb
char sql[MAX_STRING_LEN];
DB_RESULT result;
DB_ROW row;
- const ZBX_FIELD *field;
- const ZBX_TABLE *table;
- zbx_json_type_t jt;
zbx_uint64_t id;
zabbix_log(LOG_LEVEL_DEBUG, "In get_dhistory_data() [table:%s]",
@@ -292,29 +271,13 @@ static int get_dhistory_data(struct zbx_json *j, const ZBX_HISTORY_TABLE *ht, zb
result = DBselectN(sql, 1000);
- table = DBget_table(ht->table);
-
while (NULL != (row = DBfetch(result))) {
zbx_json_addobject(j, NULL);
*lastid = zbx_atoui64(row[0]);
- for (f = 0; ht->fields[f].field != NULL; f ++) {
- field = DBget_field(table, ht->fields[f].field);
-
- switch (field->type) {
- case ZBX_TYPE_ID:
- case ZBX_TYPE_INT:
- case ZBX_TYPE_UINT:
- jt = ZBX_JSON_TYPE_INT;
- break;
- default :
- jt = ZBX_JSON_TYPE_STRING;
- break;
- }
-
- zbx_json_addstring(j, ht->fields[f].tag, row[f + 1], jt);
- }
+ for (f = 0; ht->fields[f].field != NULL; f ++)
+ zbx_json_addstring(j, ht->fields[f].tag, row[f + 1], ht->fields[f].jt);
records++;
diff --git a/src/zabbix_proxy/proxy.c b/src/zabbix_proxy/proxy.c
index df199b3c..eb7bc161 100644
--- a/src/zabbix_proxy/proxy.c
+++ b/src/zabbix_proxy/proxy.c
@@ -107,7 +107,7 @@ pid_t *threads=NULL;
int CONFIG_CONFSYNCER_FORKS = 1;
int CONFIG_DATASENDER_FORKS = 1;
-int CONFIG_DBSYNCER_FORKS = 0;//1;
+int CONFIG_DBSYNCER_FORKS = 1;
int CONFIG_DISCOVERER_FORKS = 1;
int CONFIG_HOUSEKEEPER_FORKS = 1;
int CONFIG_PINGER_FORKS = 1;
@@ -130,7 +130,7 @@ int CONFIG_HEARTBEAT_FREQUENCY = 60;
int CONFIG_PROXYCONFIG_FREQUENCY = 3600*24;
-int CONFIG_DATASENDER_FREQUENCY = 10;
+int CONFIG_DATASENDER_FREQUENCY = 1;
int CONFIG_SENDER_FREQUENCY = 30;
int CONFIG_DBSYNCER_FREQUENCY = 5;
@@ -199,6 +199,7 @@ void init_config(void)
{"ServerPort",&CONFIG_SERVER_PORT,0,TYPE_INT,PARM_OPT,1024,32768},
{"Hostname",&CONFIG_HOSTNAME,0,TYPE_STRING,PARM_OPT,0,0},
+ {"StartDBSyncers",&CONFIG_DBSYNCER_FORKS,0,TYPE_INT,PARM_OPT,0,16},
{"StartDiscoverers",&CONFIG_DISCOVERER_FORKS,0,TYPE_INT,PARM_OPT,0,255},
{"StartHTTPPollers",&CONFIG_HTTPPOLLER_FORKS,0,TYPE_INT,PARM_OPT,0,255},
{"StartPingers",&CONFIG_PINGER_FORKS,0,TYPE_INT,PARM_OPT,0,255},
@@ -350,7 +351,7 @@ int main(int argc, char **argv)
if(CONFIG_DBSYNCER_FORKS!=0)
{
- init_database_cache();
+ init_database_cache(ZBX_PROCESS_PROXY);
}
return daemon_start(CONFIG_ALLOW_ROOT);
diff --git a/src/zabbix_proxy/zlog.c b/src/zabbix_proxy/zlog.c
index 51570a02..6104e790 100644
--- a/src/zabbix_proxy/zlog.c
+++ b/src/zabbix_proxy/zlog.c
@@ -65,11 +65,14 @@ void __zbx_zabbix_syslog(const char *fmt, ...)
/* This is made to disable writing to database for watchdog */
if(CONFIG_ENABLE_LOG == 0) return;
- result = DBselect("select %s where h.hostid=i.hostid and i.key_='%s' and i.value_type=%d" DB_NODE,
- ZBX_SQL_ITEM_SELECT,
- SERVER_ZABBIXLOG_KEY,
- ITEM_VALUE_TYPE_STR,
- DBnode_local("h.hostid"));
+ result = DBselect("select %s where h.hostid=i.hostid and h.status=%d and i.status=%d"
+ " and h.proxy_hostid=0 and i.key_='%s' and i.value_type=%d" DB_NODE,
+ ZBX_SQL_ITEM_SELECT,
+ ITEM_STATUS_ACTIVE,
+ HOST_STATUS_MONITORED,
+ SERVER_ZABBIXLOG_KEY,
+ ITEM_VALUE_TYPE_STR,
+ DBnode_local("h.hostid"));
now = time(NULL);
@@ -84,10 +87,16 @@ void __zbx_zabbix_syslog(const char *fmt, ...)
init_result(&agent);
SET_STR_RESULT(&agent, strdup(value_str));
- process_new_value(&item, &agent, now);
- free_result(&agent);
- update_triggers(item.itemid);
+ if (0 == CONFIG_DBSYNCER_FORKS)
+ {
+ process_new_value(&item, &agent, now);
+ update_triggers(item.itemid);
+ }
+ else
+ process_new_value(&item, &agent, now);
+
+ free_result(&agent);
}
DBfree_result(result);