Returning the nodename as a label
This commit is contained in:
parent
9b65111a7a
commit
4c02456cd0
40
knot-prom.py
40
knot-prom.py
@ -33,22 +33,30 @@ def gen_metrics():
|
||||
Return them as a list
|
||||
'''
|
||||
metrics = [
|
||||
Gauge('server_zone_count', 'Number of zones'),
|
||||
Gauge('mod_rrl', 'Queries that were truncated or dropped because of response rate limiting', ['type']),
|
||||
Gauge('mod_stats_request_protocol', 'requests via udp or tcp in ipv4', ['protocol']),
|
||||
Gauge('mod_stats_server_operation', 'Total number of incoming queries', ['type']),
|
||||
Gauge('mod_stats_request_bytes', 'Bytes received responding to queries', ['type']),
|
||||
Gauge('mod_stats_response_bytes', 'Bytes sent responding to queries', ['type']),
|
||||
Gauge('mod_stats_edns_presence', 'DNS Extension (EDNS) present in request or response', ['type']),
|
||||
Gauge('mod_stats_flag_presence', 'Flag present in request', ['flag']),
|
||||
Gauge('mod_stats_response_code', 'outgoing response code', ['code']),
|
||||
Gauge('mod_stats_request_edns_option', 'Extended DNS (EDNS) option in request', ['option']),
|
||||
Gauge('mod_stats_response_edns_option', 'Extended DNS (EDNS) option in response', ['option']),
|
||||
Gauge('mod_stats_reply_nodata', 'RFC 2308 Nodata in reply', ['type']),
|
||||
Gauge('mod_stats_query_type', 'Number of queries by type', ['type']),
|
||||
Gauge('server_zone_count', 'Number of zones', ['node']),
|
||||
Gauge('mod_rrl', 'Queries that were truncated or dropped because of response rate limiting', ['type', 'node']),
|
||||
Gauge('mod_stats_request_protocol', 'requests via udp or tcp in ipv4', ['protocol', 'node']),
|
||||
Gauge('mod_stats_server_operation', 'Total number of incoming queries', ['type', 'node']),
|
||||
Gauge('mod_stats_request_bytes', 'Bytes received responding to queries', ['type', 'node']),
|
||||
Gauge('mod_stats_response_bytes', 'Bytes sent responding to queries', ['type', 'node']),
|
||||
Gauge('mod_stats_edns_presence', 'DNS Extension (EDNS) present in request or response', ['type', 'node']),
|
||||
Gauge('mod_stats_flag_presence', 'Flag present in request', ['flag', 'node']),
|
||||
Gauge('mod_stats_response_code', 'outgoing response code', ['code', 'node']),
|
||||
Gauge('mod_stats_request_edns_option', 'Extended DNS (EDNS) option in request', ['option', 'node']),
|
||||
Gauge('mod_stats_response_edns_option', 'Extended DNS (EDNS) option in response', ['option', 'node']),
|
||||
Gauge('mod_stats_reply_nodata', 'RFC 2308 Nodata in reply', ['type', 'node']),
|
||||
Gauge('mod_stats_query_type', 'Number of queries by type', ['type', 'node']),
|
||||
]
|
||||
return metrics
|
||||
|
||||
def get_nodename():
|
||||
'''
|
||||
Returns the hostname.
|
||||
'''
|
||||
from socket import gethostname
|
||||
hostname = gethostname()
|
||||
return str(hostname)
|
||||
|
||||
def populate_metrics(stats, metrics):
|
||||
'''
|
||||
Take dict of stats and list of metrics (all summaries)
|
||||
@ -56,10 +64,11 @@ def populate_metrics(stats, metrics):
|
||||
Return the metrics
|
||||
'''
|
||||
#These metrics don't use labels
|
||||
nolabel_metrics = ["server_zone_count"]
|
||||
nolabel_metrics = []
|
||||
|
||||
for statname in stats:
|
||||
statvalue = stats[statname]
|
||||
nodename = get_nodename()
|
||||
if statname not in nolabel_metrics:
|
||||
#Getting the statname, its label's value, and corresponding metric to set to it
|
||||
#A metrics label value is implied by the last field in the stats name
|
||||
@ -75,8 +84,9 @@ def populate_metrics(stats, metrics):
|
||||
if statname == metric._name and label != "Nolabel":
|
||||
labelname = metric._labelnames
|
||||
for i in labelname:
|
||||
if i != "node":
|
||||
labelname = i
|
||||
metric.labels(label).set(statvalue)
|
||||
metric.labels(label, nodename).set(statvalue)
|
||||
elif statname == metric._name and label == "Nolabel":
|
||||
metric.set(statvalue)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user