Skip to content

Commit 3d72019

Browse files
committed
Prometheus metric prefix
- `output/prometheus`: Close #93: Add module option to set prefix on all metric names
1 parent dd57b2b commit 3d72019

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

dsc_datatool/output/prometheus.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ class Prometheus(Output):
3232
show_timestamp = True
3333
start_timestamp = True
3434
fh = None
35-
type_def = ""
35+
type_def = ''
3636
type_printed = False
37+
prefix = ''
3738

3839

3940
def __init__(self, opts):
@@ -57,6 +58,7 @@ def __init__(self, opts):
5758
atexit.register(self.close)
5859
else:
5960
self.fh = sys.stdout
61+
self.prefix = opts.get('prefix', '')
6062

6163

6264
def close(self):
@@ -96,7 +98,7 @@ def process(self, datasets):
9698
for dataset in datasets:
9799
self.type_def = '# TYPE %s gauge' % _key(dataset.name.lower())
98100
self.type_printed = False
99-
tags = '%s{server=%s,node=%s' % (_key(dataset.name.lower()), _val(args.server), _val(args.node))
101+
tags = '%s%s{server=%s,node=%s' % (self.prefix, _key(dataset.name.lower()), _val(args.server), _val(args.node))
100102
if self.start_timestamp:
101103
timestamp = dataset.start_time * 1000
102104
else:

man/man7/dsc-datatool-output-prometheus.7

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Specify a file to output to instead of stdout.
4444
.BR append
4545
If given, the output will be appended to the file specified rather then
4646
overwritten.
47+
.TP
48+
.BR prefix =<string>
49+
Use the given string as prefix on all metric names.
4750
.LP
4851
.SH "SEE ALSO"
4952
.BR dsc-datatool (1)

0 commit comments

Comments
 (0)