Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unique name for TopN metrics #183

Merged
4 commits merged into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,13 @@ class TopN final : public Metric
private:
datasketches::frequent_items_sketch<T> _fi;
size_t _top_count = 10;
std::string _schema_name;
This conversation was marked as resolved.
Show resolved Hide resolved

public:
TopN(std::string schema_key, std::initializer_list<std::string> names, std::string desc)
TopN(std::string schema_key, std::string schema_name, std::initializer_list<std::string> names, std::string desc)
: Metric(schema_key, names, std::move(desc))
, _fi(MAX_FI_MAP_SIZE, START_FI_MAP_SIZE)
, _schema_name(schema_name)
{
}

Expand Down Expand Up @@ -280,7 +282,7 @@ class TopN final : public Metric
out << "# HELP " << base_name_snake() << ' ' << _desc << std::endl;
out << "# TYPE " << base_name_snake() << " gauge" << std::endl;
for (uint64_t i = 0; i < std::min(_top_count, items.size()); i++) {
l["name"] = formatter(items[i].get_item());
l[_schema_name] = formatter(items[i].get_item());
out << name_snake({}, l) << ' ' << items[i].get_estimate() << std::endl;
}
}
Expand All @@ -306,7 +308,7 @@ class TopN final : public Metric
for (uint64_t i = 0; i < std::min(_top_count, items.size()); i++) {
std::stringstream name_text;
name_text << items[i].get_item();
l["name"] = name_text.str();
l[_schema_name] = name_text.str();
out << name_snake({}, l) << ' ' << items[i].get_estimate() << std::endl;
}
}
Expand Down
24 changes: 20 additions & 4 deletions src/handlers/dns/DnsStreamHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,16 @@ void DnsMetricsBucket::to_json(json &j) const
_dns_slowXactOut.to_json(j);

_dns_topUDPPort.to_json(j, [](const uint16_t &val) { return std::to_string(val); });
_dns_topQname2.to_json(j);
_dns_topQname3.to_json(j);
_dns_topQname2.to_json(j, [](std::string val) {
This conversation was marked as resolved.
Show resolved Hide resolved
std::transform(val.begin(), val.end(), val.begin(),
[](unsigned char c) { return std::tolower(c); });
return val;
});
_dns_topQname3.to_json(j, [](std::string val) {
std::transform(val.begin(), val.end(), val.begin(),
[](unsigned char c) { return std::tolower(c); });
return val;
});
_dns_topNX.to_json(j);
_dns_topREFUSED.to_json(j);
_dns_topSRVFAIL.to_json(j);
Expand Down Expand Up @@ -662,8 +670,16 @@ void DnsMetricsBucket::to_prometheus(std::stringstream &out, Metric::LabelMap ad
_dns_slowXactOut.to_prometheus(out, add_labels);

_dns_topUDPPort.to_prometheus(out, add_labels, [](const uint16_t &val) { return std::to_string(val); });
_dns_topQname2.to_prometheus(out, add_labels);
_dns_topQname3.to_prometheus(out, add_labels);
_dns_topQname2.to_prometheus(out, add_labels, [](std::string val) {
std::transform(val.begin(), val.end(), val.begin(),
[](unsigned char c) { return std::tolower(c); });
return val;
});
_dns_topQname3.to_prometheus(out, add_labels, [](std::string val) {
std::transform(val.begin(), val.end(), val.begin(),
[](unsigned char c) { return std::tolower(c); });
return val;
});
_dns_topNX.to_prometheus(out, add_labels);
_dns_topREFUSED.to_prometheus(out, add_labels);
_dns_topSRVFAIL.to_prometheus(out, add_labels);
Expand Down
22 changes: 11 additions & 11 deletions src/handlers/dns/DnsStreamHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include "PcapInputStream.h"
#include "StreamHandler.h"
#include "dns.h"
#include "querypairmgr.h"
#include "dnstap.pb.h"
#include "querypairmgr.h"
#include <Corrade/Utility/Debug.h>
#include <bitset>
#include <limits>
Expand Down Expand Up @@ -93,16 +93,16 @@ class DnsMetricsBucket final : public visor::AbstractMetricsBucket
: _dnsXactFromTimeUs("dns", {"xact", "out", "quantiles_us"}, "Quantiles of transaction timing (query/reply pairs) when host is client, in microseconds")
, _dnsXactToTimeUs("dns", {"xact", "in", "quantiles_us"}, "Quantiles of transaction timing (query/reply pairs) when host is server, in microseconds")
, _dns_qnameCard("dns", {"cardinality", "qname"}, "Cardinality of unique QNAMES, both ingress and egress")
, _dns_topQname2("dns", {"top_qname2"}, "Top QNAMES, aggregated at a depth of two labels")
, _dns_topQname3("dns", {"top_qname3"}, "Top QNAMES, aggregated at a depth of three labels")
, _dns_topNX("dns", {"top_nxdomain"}, "Top QNAMES with result code NXDOMAIN")
, _dns_topREFUSED("dns", {"top_refused"}, "Top QNAMES with result code REFUSED")
, _dns_topSRVFAIL("dns", {"top_srvfail"}, "Top QNAMES with result code SRVFAIL")
, _dns_topUDPPort("dns", {"top_udp_ports"}, "Top UDP source port on the query side of a transaction")
, _dns_topQType("dns", {"top_qtype"}, "Top query types")
, _dns_topRCode("dns", {"top_rcode"}, "Top result codes")
, _dns_slowXactIn("dns", {"xact", "in", "top_slow"}, "Top QNAMES in transactions where host is the server and transaction speed is slower than p90")
, _dns_slowXactOut("dns", {"xact", "out", "top_slow"}, "Top QNAMES in transactions where host is the client and transaction speed is slower than p90")
, _dns_topQname2("dns", "qname", {"top_qname2"}, "Top QNAMES, aggregated at a depth of two labels")
, _dns_topQname3("dns", "qname", {"top_qname3"}, "Top QNAMES, aggregated at a depth of three labels")
, _dns_topNX("dns", "nxdomain", {"top_nxdomain"}, "Top QNAMES with result code NXDOMAIN")
This conversation was marked as resolved.
Show resolved Hide resolved
, _dns_topREFUSED("dns", "refused", {"top_refused"}, "Top QNAMES with result code REFUSED")
This conversation was marked as resolved.
Show resolved Hide resolved
, _dns_topSRVFAIL("dns", "srvfail", {"top_srvfail"}, "Top QNAMES with result code SRVFAIL")
This conversation was marked as resolved.
Show resolved Hide resolved
, _dns_topUDPPort("dns", "udp_ports", {"top_udp_ports"}, "Top UDP source port on the query side of a transaction")
This conversation was marked as resolved.
Show resolved Hide resolved
, _dns_topQType("dns", "qtype", {"top_qtype"}, "Top query types")
, _dns_topRCode("dns", "rcode", {"top_rcode"}, "Top result codes")
, _dns_slowXactIn("dns", "xact", {"xact", "in", "top_slow"}, "Top QNAMES in transactions where host is the server and transaction speed is slower than p90")
This conversation was marked as resolved.
Show resolved Hide resolved
, _dns_slowXactOut("dns", "xact", {"xact", "out", "top_slow"}, "Top QNAMES in transactions where host is the client and transaction speed is slower than p90")
This conversation was marked as resolved.
Show resolved Hide resolved
{
set_event_rate_info("dns", {"rates", "total"}, "Rate of all DNS wire packets (combined ingress and egress) per second");
set_num_events_info("dns", {"wire_packets", "total"}, "Total DNS wire packets");
Expand Down
8 changes: 4 additions & 4 deletions src/handlers/net/NetStreamHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ class NetworkMetricsBucket final : public visor::AbstractMetricsBucket
NetworkMetricsBucket()
: _srcIPCard("packets", {"cardinality", "src_ips_in"}, "Source IP cardinality")
, _dstIPCard("packets", {"cardinality", "dst_ips_out"}, "Destination IP cardinality")
, _topGeoLoc("packets", {"top_geoLoc"}, "Top GeoIP locations")
, _topASN("packets", {"top_ASN"}, "Top ASNs by IP")
, _topIPv4("packets", {"top_ipv4"}, "Top IPv4 IP addresses")
, _topIPv6("packets", {"top_ipv6"}, "Top IPv6 IP addresses")
, _topGeoLoc("packets", "geo_loc", {"top_geoLoc"}, "Top GeoIP locations")
, _topASN("packets", "asn", {"top_ASN"}, "Top ASNs by IP")
, _topIPv4("packets", "ipv4", {"top_ipv4"}, "Top IPv4 IP addresses")
, _topIPv6("packets", "ipv6", {"top_ipv6"}, "Top IPv6 IP addresses")
, _rate_in("packets", {"rates", "pps_in"}, "Rate of ingress in packets per second")
, _rate_out("packets", {"rates", "pps_out"}, "Rate of egress in packets per second")
{
Expand Down