summaryrefslogtreecommitdiffstats
path: root/src/zabbix_proxy/datasender
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/datasender
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/datasender')
-rw-r--r--src/zabbix_proxy/datasender/datasender.c85
1 files changed, 24 insertions, 61 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++;