diff --git a/clickhouse/dictionaries/dns_responce.tsv b/clickhouse/dictionaries/dns_response.tsv similarity index 100% rename from clickhouse/dictionaries/dns_responce.tsv rename to clickhouse/dictionaries/dns_response.tsv diff --git a/clickhouse/dns_dictionary.xml b/clickhouse/dns_dictionary.xml index f85265b..c5a6b9e 100644 --- a/clickhouse/dns_dictionary.xml +++ b/clickhouse/dns_dictionary.xml @@ -1,14 +1,14 @@ - dns_responce + dns_response - /opt/dictionaries/dns_responce.tsv + /opt/dictionaries/dns_response.tsv TabSeparated diff --git a/clickhouse/tables.sql b/clickhouse/tables.sql index fc588a3..c6538de 100644 --- a/clickhouse/tables.sql +++ b/clickhouse/tables.sql @@ -11,7 +11,7 @@ CREATE TABLE IF NOT EXISTS DNS_LOG ( Type UInt16, Edns0Present UInt8, DoBit UInt8, - ResponceCode UInt8, + ResponseCode UInt8, Question String, Size UInt16 ) engine=MergeTree partition by toYYYYMM(DnsDate) @@ -59,9 +59,9 @@ ENGINE=SummingMergeTree(DnsDate, (timestamp, Server, Class), 8192, c) AS SELECT DnsDate, timestamp, Server, Class, count(*) as c FROM DNS_LOG WHERE QR=0 GROUP BY Server, DnsDate, timestamp, Class; -- View with query responses -CREATE MATERIALIZED VIEW IF NOT EXISTS DNS_RESPONCECODE -ENGINE=SummingMergeTree(DnsDate, (timestamp, Server, ResponceCode), 8192, c) AS - SELECT DnsDate, timestamp, Server, ResponceCode, count(*) as c FROM DNS_LOG WHERE QR=1 GROUP BY Server, DnsDate, timestamp, ResponceCode; +CREATE MATERIALIZED VIEW IF NOT EXISTS DNS_RESPONSECODE +ENGINE=SummingMergeTree(DnsDate, (timestamp, Server, ResponseCode), 8192, c) AS + SELECT DnsDate, timestamp, Server, ResponseCode, count(*) as c FROM DNS_LOG WHERE QR=1 GROUP BY Server, DnsDate, timestamp, ResponseCode; -- View with IP Prefix CREATE MATERIALIZED VIEW IF NOT EXISTS DNS_IP_MASK diff --git a/grafana/panel.json b/grafana/panel.json index dfb855b..3ad3fe5 100644 --- a/grafana/panel.json +++ b/grafana/panel.json @@ -1108,19 +1108,19 @@ "steppedLine": false, "targets": [ { - "compiledQuery": "SELECT t, groupArray((dictGetString('dns_responce', 'Name', toUInt64(ResponceCode)), count/2)) FROM (SELECT (intDiv(toUInt32(timestamp), 2) * 2) * 1000 as t, ResponceCode, sum(c) as count FROM DNS_RESPONCECODE WHERE DnsDate >= toDate(1506625902) AND timestamp >= toDateTime(1506625902) AND Server IN('default','valparaiso') group by t, ResponceCode ORDER BY t) group by t\n order by t", + "compiledQuery": "SELECT t, groupArray((dictGetString('dns_response', 'Name', toUInt64(ResponseCode)), count/2)) FROM (SELECT (intDiv(toUInt32(timestamp), 2) * 2) * 1000 as t, ResponseCode, sum(c) as count FROM DNS_RESPONSECODE WHERE DnsDate >= toDate(1506625902) AND timestamp >= toDateTime(1506625902) AND Server IN('default','valparaiso') group by t, ResponseCode ORDER BY t) group by t\n order by t", "database": "default", "dateColDataType": "DnsDate", "dateLoading": false, "dateTimeColDataType": "timestamp", "datetimeLoading": false, - "formattedQuery": "SELECT t, groupArray((dictGetString('dns_responce', 'Name', toUInt64(ResponceCode)), count/$interval)) FROM (SELECT $timeSeries as t, ResponceCode, sum(c) as count FROM $table WHERE $timeFilter AND Server IN($ServerName) group by t, ResponceCode ORDER BY t) group by t
order by t", + "formattedQuery": "SELECT t, groupArray((dictGetString('dns_response', 'Name', toUInt64(ResponseCode)), count/$interval)) FROM (SELECT $timeSeries as t, ResponseCode, sum(c) as count FROM $table WHERE $timeFilter AND Server IN($ServerName) group by t, ResponseCode ORDER BY t) group by t
order by t", "intervalFactor": 1, - "query": "SELECT t, groupArray((dictGetString('dns_responce', 'Name', toUInt64(ResponceCode)), count/$interval)) FROM (SELECT $timeSeries as t, ResponceCode, sum(c) as count FROM DNS_RESPONCECODE WHERE $timeFilter group by t, ResponceCode ORDER BY t) group by t\n order by t", - "rawQuery": "SELECT t, groupArray((dictGetString('dns_responce', 'Name', toUInt64(ResponceCode)), count/2)) FROM (SELECT (intDiv(toUInt32(timestamp), 2) * 2) * 1000 as t, ResponceCode, sum(c) as count FROM default.DNS_RESPONCECODE WHERE DnsDate >= toDate(1506436944) AND timestamp >= toDateTime(1506436944) AND Server IN('valparaiso') group by t, ResponceCode ORDER BY t) group by t order by t", + "query": "SELECT t, groupArray((dictGetString('dns_response', 'Name', toUInt64(ResponseCode)), count/$interval)) FROM (SELECT $timeSeries as t, ResponseCode, sum(c) as count FROM DNS_RESPONSECODE WHERE $timeFilter group by t, ResponseCode ORDER BY t) group by t\n order by t", + "rawQuery": "SELECT t, groupArray((dictGetString('dns_response', 'Name', toUInt64(ResponseCode)), count/2)) FROM (SELECT (intDiv(toUInt32(timestamp), 2) * 2) * 1000 as t, ResponseCode, sum(c) as count FROM default.DNS_RESPONSECODE WHERE DnsDate >= toDate(1506436944) AND timestamp >= toDateTime(1506436944) AND Server IN('valparaiso') group by t, ResponseCode ORDER BY t) group by t order by t", "refId": "A", "resultFormat": "time_series", - "table": "DNS_RESPONCECODE", + "table": "DNS_RESPONSECODE", "tableLoading": false, "tags": [], "targetLists": [ diff --git a/src/clickhouse.go b/src/clickhouse.go index 9d4cf13..a9170dc 100644 --- a/src/clickhouse.go +++ b/src/clickhouse.go @@ -94,7 +94,7 @@ func SendData(connect clickhouse.Clickhouse, batch []DNSResult, server []byte) e return err } - _, err = connect.Prepare("INSERT INTO DNS_LOG (DnsDate, timestamp, Server, IPVersion, IPPrefix, Protocol, QR, OpCode, Class, Type, ResponceCode, Question, Size, Edns0Present, DoBit) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)") + _, err = connect.Prepare("INSERT INTO DNS_LOG (DnsDate, timestamp, Server, IPVersion, IPPrefix, Protocol, QR, OpCode, Class, Type, ResponseCode, Question, Size, Edns0Present, DoBit) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)") if err != nil { return err }