mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-15 15:27:00 +00:00
samples: add prometheus text file collector mustach template
Because prometheus needs timestamp information add that to mustach, and update manual page what tags are available. Reference: https://prometheus.io/docs/instrumenting/exposition_formats/ Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
eabaa8adc2
commit
e4f7259cf6
6 changed files with 78 additions and 6 deletions
|
|
@ -107,10 +107,11 @@ The default format is
|
|||
\fB\-\-mustach\fR=\fITEMPLATE\fR
|
||||
Output using mustach
|
||||
.I template
|
||||
file. Mustache tags in the template are same as json output without IP
|
||||
address information. When the native output formats controlled with
|
||||
file. This is useful when the native output formats controlled with
|
||||
.B \-\-format
|
||||
option do not provide what you need you should use mustach instead.
|
||||
option do not provide what you need. See below example mustach template
|
||||
that is using all available {{tags}} to demonstrate what can be displayed
|
||||
and how.
|
||||
.IP
|
||||
@bindir@/dhcpd-pools --config @docdir@/dhcpd.conf --leases
|
||||
@docdir@/dhcpd.leases --mustach @docdir@/mustach.template
|
||||
|
|
@ -286,6 +287,9 @@ ISC dhcpd configuration file.
|
|||
.TP
|
||||
@DHCPDLEASE_FILE@
|
||||
ISC dhcpd lease file.
|
||||
.TP
|
||||
@docdir@/prometheus.template
|
||||
Prometheus text file collector mustach template.
|
||||
.SH AUTHORS
|
||||
Original design by Sami Kerola.
|
||||
.br
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
dist_doc_DATA = \
|
||||
samples/dhcpd.conf \
|
||||
samples/dhcpd.leases \
|
||||
samples/mustach.template
|
||||
samples/mustach.template \
|
||||
samples/prometheus.template
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ Subnets:{{#subnets}}
|
|||
backup_count: {{backup_count}}
|
||||
backup_percent: {{backup_percent}}
|
||||
status: {{status}}
|
||||
gettimeofday: {{gettimeofday}}
|
||||
lease_file_mtime: {{lease_file_mtime}}
|
||||
{{/subnets}}
|
||||
|
||||
Shared-networks:{{#shared-networks}}
|
||||
|
|
@ -27,6 +29,8 @@ Shared-networks:{{#shared-networks}}
|
|||
backup_count: {{backup_count}}
|
||||
backup_percent: {{backup_percent}}
|
||||
status: {{status}}
|
||||
gettimeofday: {{gettimeofday}}
|
||||
lease_file_mtime: {{lease_file_mtime}}
|
||||
{{/shared-networks}}
|
||||
|
||||
Summary:{{#summary}}
|
||||
|
|
@ -41,4 +45,6 @@ Summary:{{#summary}}
|
|||
backup_count: {{backup_count}}
|
||||
backup_percent: {{backup_percent}}
|
||||
status: {{status}}
|
||||
gettimeofday: {{gettimeofday}}
|
||||
lease_file_mtime: {{lease_file_mtime}}
|
||||
{{/summary}}
|
||||
|
|
|
|||
30
samples/prometheus.template
Normal file
30
samples/prometheus.template
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# This mustach template can be used as Prometheus text file.
|
||||
# https://prometheus.io/
|
||||
|
||||
# HELP dhcpd_pools_ranges The range statistics.
|
||||
# TYPE dhcpd_pools_ranges gauge
|
||||
{{#subnets}}dhcpd_pools_ranges{range="{{first_ip}}",used="1"} {{used}} {{gettimeofday}}000
|
||||
dhcpd_pools_ranges{range="{{first_ip}}",touched="1"} {{touched}} {{gettimeofday}}000
|
||||
dhcpd_pools_ranges{range="{{first_ip}}",defined="1"} {{defined}} {{gettimeofday}}000
|
||||
dhcpd_pools_ranges{range="{{first_ip}}",free="1"} {{free}} {{gettimeofday}}000
|
||||
dhcpd_pools_ranges{range="{{first_ip}}",touch_count="1"} {{touch_count}} {{gettimeofday}}000
|
||||
dhcpd_pools_ranges{range="{{first_ip}}",status="1"} {{status}} {{gettimeofday}}000
|
||||
{{/subnets}}
|
||||
# HELP dhcpd_pools_shared_nets The shared networks statistics.
|
||||
# TYPE dhcpd_pools_shared_nets gauge
|
||||
{{#shared-networks}}dhcpd_pools_shared_nets{location="{{location}}",defined="1"} {{defined}} {{gettimeofday}}000
|
||||
dhcpd_pools_shared_nets{location="{{location}}",used="1"} {{used}} {{gettimeofday}}000
|
||||
dhcpd_pools_shared_nets{location="{{location}}",touched="1"} {{touched}} {{gettimeofday}}000
|
||||
dhcpd_pools_shared_nets{location="{{location}}",free="1"} {{free}} {{gettimeofday}}000
|
||||
dhcpd_pools_shared_nets{location="{{location}}",touch_count="1"} {{touch_count}} {{gettimeofday}}000
|
||||
dhcpd_pools_shared_nets{location="{{location}}",status="1"} {{status}} {{gettimeofday}}000
|
||||
{{/shared-networks}}
|
||||
# HELP dhcpd_pools_summary Statistics of the all networks.
|
||||
# TYPE dhcpd_pools_summary gauge
|
||||
{{#summary}}dhcpd_pools_summary{location="{{location}}",defined="1"} {{defined}} {{gettimeofday}}000
|
||||
dhcpd_pools_summary{location="{{location}}",used="1"} {{used}} {{gettimeofday}}000
|
||||
dhcpd_pools_summary{location="{{location}}",touched="1"} {{touched}} {{gettimeofday}}000
|
||||
dhcpd_pools_summary{location="{{location}}",free="1"} {{free}} {{gettimeofday}}000
|
||||
dhcpd_pools_summary{location="{{location}}",touch_count="1"} {{touch_count}} {{gettimeofday}}000
|
||||
dhcpd_pools_summary{location="{{location}}",status="1"} {{status}} {{gettimeofday}}000
|
||||
{{/summary}}
|
||||
|
|
@ -44,6 +44,7 @@
|
|||
#include <error.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "close-stream.h"
|
||||
|
|
@ -144,6 +145,20 @@ static int must_put_range(void *closure, const char *name, int escape
|
|||
fprintf(file, "%d", e->oh.status);
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(name, "gettimeofday")) {
|
||||
struct timeval tp;
|
||||
|
||||
gettimeofday(&tp, NULL);
|
||||
fprintf(file, "%ld", tp.tv_sec);
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(name, "lease_file_mtime")) {
|
||||
struct stat st;
|
||||
|
||||
stat(e->state->dhcpdlease_file, &st);
|
||||
fprintf(file, "%ld", st.st_mtime);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -198,6 +213,20 @@ static int must_put_shnet(void *closure, const char *name, int escape
|
|||
fprintf(file, "%d", e->oh.status);
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(name, "gettimeofday")) {
|
||||
struct timeval tp;
|
||||
|
||||
gettimeofday(&tp, NULL);
|
||||
fprintf(file, "%ld", tp.tv_sec);
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(name, "lease_file_mtime")) {
|
||||
struct stat st;
|
||||
|
||||
stat(e->state->dhcpdlease_file, &st);
|
||||
fprintf(file, "%ld", st.st_mtime);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,11 +9,13 @@ if [ ! -d tests/outputs ]; then
|
|||
fi
|
||||
|
||||
dhcpd-pools -c $top_srcdir/samples/dhcpd.conf -l $top_srcdir/samples/dhcpd.leases \
|
||||
--mustach $top_srcdir/samples/mustach.template -o tests/outputs/$IAM
|
||||
--mustach $top_srcdir/samples/mustach.template |
|
||||
sed '/gettimeofday:/d; /lease_file_mtime:/d' >| tests/outputs/$IAM
|
||||
|
||||
echo "--- skip ok ---" >> tests/outputs/$IAM
|
||||
dhcpd-pools -c $top_srcdir/samples/dhcpd.conf -l $top_srcdir/samples/dhcpd.leases \
|
||||
--mustach $top_srcdir/samples/mustach.template --skip-ok --warning 44 >> tests/outputs/$IAM
|
||||
--mustach $top_srcdir/samples/mustach.template --skip-ok --warning 44 |
|
||||
sed '/gettimeofday:/d; /lease_file_mtime:/d' >> tests/outputs/$IAM
|
||||
|
||||
diff -u $top_srcdir/tests/expected/$IAM tests/outputs/$IAM
|
||||
exit $?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue