Ad Widget

Collapse

Add key for DNS performance

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Add key for DNS performance

    Hello every one!
    I implemented net.dns.perf and I have deployed on my server.
    I wish this patch would accept by the community.

    https://github.com/yayo/zabbix/commi...2843f79a4f27ca


    diff --git a/frontends/php/include/classes/items/CHelpItems.php b/frontends/php/include/classes/items/CHelpItems.php
    index 07a419f..7fd419a 100644
    --- a/frontends/php/include/classes/items/CHelpItems.php
    +++ b/frontends/php/include/classes/items/CHelpItems.php
    @@ -88,6 +88,10 @@ class CHelpItems {
    'key' => 'net.dns.record[<ip>,name,<type>,<timeout>,<count>,<protocol>]',
    'description' => _('Performs a DNS query. Returns character string with the required type of information')
    ],
    + [
    + 'key' => 'net.dns.perf[<ip>,name,<type>,<timeout>,<count>,<protocol>]',
    + 'description' => _('Checks performance of DNS service. Returns 0 - service is down; seconds - the number of seconds spent waiting for response from the service')
    + ],
    [
    'key' => 'net.if.collisions[if]',
    'description' => _('Number of out-of-window collisions. Returns integer')
    @@ -398,6 +402,10 @@ class CHelpItems {
    'key' => 'net.dns.record[<ip>,name,<type>,<timeout>,<count>,<protocol>]',
    'description' => _('Performs a DNS query. Returns character string with the required type of information')
    ],
    + [
    + 'key' => 'net.dns.perf[<ip>,name,<type>,<timeout>,<count>,<protocol>]',
    + 'description' => _('Checks performance of DNS service. Returns 0 - service is down; seconds - the number of seconds spent waiting for response from the service')
    + ],
    [
    'key' => 'net.if.collisions[if]',
    'description' => _('Number of out-of-window collisions. Returns integer')
    diff --git a/src/libs/zbxsysinfo/common/common.c b/src/libs/zbxsysinfo/common/common.c
    index a6a6e7d..21bd3af 100644
    --- a/src/libs/zbxsysinfo/common/common.c
    +++ b/src/libs/zbxsysinfo/common/common.c
    @@ -69,6 +69,7 @@ ZBX_METRIC parameters_common[] =

    {"net.dns", CF_HAVEPARAMS, NET_DNS, ",zabbix.com"},
    {"net.dns.record", CF_HAVEPARAMS, NET_DNS_RECORD, ",zabbix.com"},
    + {"net.dns.perf", CF_HAVEPARAMS, NET_DNS_PERF, ",zabbix.com"},
    {"net.tcp.dns", CF_HAVEPARAMS, NET_DNS, ",zabbix.com"}, /* deprecated */
    {"net.tcp.dns.query", CF_HAVEPARAMS, NET_DNS_RECORD, ",zabbix.com"}, /* deprecated */
    {"net.tcp.port", CF_HAVEPARAMS, NET_TCP_PORT, ",80"},
    diff --git a/src/libs/zbxsysinfo/common/net.c b/src/libs/zbxsysinfo/common/net.c
    index 67ba3bd..65ecef7 100644
    --- a/src/libs/zbxsysinfo/common/net.c
    +++ b/src/libs/zbxsysinfo/common/net.c
    @@ -215,6 +215,7 @@ static int dns_query(AGENT_REQUEST *request, AGENT_RESULT *result, int short_ans
    int res, type, retrans, retry, use_tcp, i, ret = SYSINFO_RET_FAIL, ip_type = AF_INET;
    char *ip, zone[MAX_STRING_LEN], buffer[MAX_STRING_LEN], *zone_str, *param,
    tmp[MAX_STRING_LEN];
    + double check_time=zbx_time();
    struct in_addr inaddr;
    struct in6_addr in6addr;
    #ifndef _WINDOWS
    @@ -406,6 +407,21 @@ static int dns_query(AGENT_REQUEST *request, AGENT_RESULT *result, int short_ans
    goto clean_dns;
    }

    + if (2 == short_answer)
    + {
    + if (DNS_RCODE_NOERROR != res)
    + SET_DBL_RESULT(result, 0.0);
    + else
    + {
    + check_time = zbx_time() - check_time;
    + if (ZBX_FLOAT_PRECISION > check_time)
    + check_time = ZBX_FLOAT_PRECISION;
    + SET_DBL_RESULT(result, check_time);
    + }
    + ret = SYSINFO_RET_OK;
    + goto clean_dns;
    + }
    +
    if (DNS_RCODE_NOERROR != res)
    {
    SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot perform DNS query: [%d]", res));
    @@ -699,6 +715,20 @@ static int dns_query(AGENT_REQUEST *request, AGENT_RESULT *result, int short_ans
    return SYSINFO_RET_OK;
    }

    + if (2 == short_answer)
    + {
    + if (NOERROR != hp->rcode || 0 == ntohs(hp->ancount) || -1 == res)
    + SET_DBL_RESULT(result, 0.0);
    + else
    + {
    + check_time = zbx_time() - check_time;
    + if (ZBX_FLOAT_PRECISION > check_time)
    + check_time = ZBX_FLOAT_PRECISION;
    + SET_DBL_RESULT(result, check_time);
    + }
    + return SYSINFO_RET_OK;
    + }
    +
    if (NOERROR != hp->rcode || 0 == ntohs(hp->ancount) || -1 == res)
    {
    SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot perform DNS query."));
    @@ -994,3 +1024,7 @@ int NET_DNS_RECORD(AGENT_REQUEST *request, AGENT_RESULT *result)
    {
    return dns_query(request, result, 0);
    }
    +int NET_DNS_PERF(AGENT_REQUEST *request, AGENT_RESULT *result)
    +{
    + return dns_query(request, result, 2);
    +}
    diff --git a/src/libs/zbxsysinfo/common/net.h b/src/libs/zbxsysinfo/common/net.h
    index cf2fa0a..7aeae37 100644
    --- a/src/libs/zbxsysinfo/common/net.h
    +++ b/src/libs/zbxsysinfo/common/net.h
    @@ -100,6 +100,7 @@ int tcp_expect(const char *host, unsigned short port, int timeout, const char *r

    int NET_DNS(AGENT_REQUEST *request, AGENT_RESULT *result);
    int NET_DNS_RECORD(AGENT_REQUEST *request, AGENT_RESULT *result);
    +int NET_DNS_PERF(AGENT_REQUEST *request, AGENT_RESULT *result);
    int NET_TCP_PORT(AGENT_REQUEST *request, AGENT_RESULT *result);

    #endif /* ZABBIX_SYSINFO_COMMON_NET_H */
Working...
X