Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd label manipulation functions #959
Comments
This comment has been minimized.
This comment has been minimized.
|
Set and copy can be done with replace, so we could have just join and replace. |
This comment has been minimized.
This comment has been minimized.
|
I'm going to implement |
This comment has been minimized.
This comment has been minimized.
|
dest first is also the order of Go's builtin |
This comment has been minimized.
This comment has been minimized.
|
Yeah, that order is common in some contexts. Ok, will keep it like that then. |
This comment has been minimized.
This comment has been minimized.
Yes |
juliusv
added a commit
that referenced
this issue
Aug 18, 2015
This comment has been minimized.
This comment has been minimized.
varunpatro
commented
Oct 5, 2015
|
Hi what's the status of this PR? Only |
This comment has been minimized.
This comment has been minimized.
|
That's correct. |
This comment has been minimized.
This comment has been minimized.
varunpatro
commented
Oct 5, 2015
|
Alright thanks. I'll work on |
This comment has been minimized.
This comment has been minimized.
|
Awesome, you can file that PR straight to master. On Mon, Oct 5, 2015 at 6:54 PM Varun Patro notifications@github.com wrote:
|
This comment has been minimized.
This comment has been minimized.
|
To answer your question on IRC: https://github.com/prometheus/prometheus/blob/master/promql/functions.go#L819 Allow for up to say 8 labels to be specified, that should be more than enough. |
brian-brazil
added
the
feature-request
label
Dec 16, 2015
fabxc
added
kind/enhancement
and removed
feature request
labels
Apr 28, 2016
This comment has been minimized.
This comment has been minimized.
hryamzik
commented
May 19, 2016
•
|
How about P.S.: the scenario as a bit complicated. |
This comment has been minimized.
This comment has been minimized.
|
That's not something that should be handled at the PromQL level. You should either exclude |
This comment has been minimized.
This comment has been minimized.
hryamzik
commented
May 19, 2016
|
I can't do this as other metrics are instance-related. But I've found a way to do this:
|
This comment has been minimized.
This comment has been minimized.
|
May I suggest using the blackbox exporter for this? It exports SSL cert expiry dates, and the labels should be nicer to work with. |
This comment has been minimized.
This comment has been minimized.
hryamzik
commented
May 19, 2016
|
@brian-brazil good point, I didn't mention this exporter, thank you! But I can't see a way to check domain expiration and ssl certificates on multiple hosts. |
This comment has been minimized.
This comment has been minimized.
|
It does support multiple hosts, but doesn't do domain expiration currently. Would need to be careful on that one, don't want to overwhelm Whois. |
This comment has been minimized.
This comment has been minimized.
hryamzik
commented
May 19, 2016
|
I simply run cron scripts once an hour. Whois is a nightmare with it's format so I had to implement failing on parse error. #!/bin/bash
# Scipt checks domain expiration dates.
# Checked with reg.ru and GoDaddy.com
# whois is required
scriptname=${0##*/}
metricname=${scriptname%.*}
function get_date_from_string {
if exp_date=$(date -d $2 +%s)
then
printf 'domain_check_expiration_date{name="%s"} %s\ndomain_check_success{name="%s"} 1\n' $1 $exp_date $1
else
echo "invalid date '$2'" > /dev/stderr
printf 'domain_check_expiration_date{name="%s"} 0\ndomain_check_success{name="%s"} 0\n' $1 $1
fi
}
function check_expiration {
whois=$(whois $1)
if exp_date_raw=$(echo "$whois"|egrep -i 'Registry Expiry Date|Registrar Registration Expiration Date')
then
# generic & godaddy
# echo "godaddy or generic" > /dev/stderr
get_date_from_string $1 $(echo $exp_date_raw|awk -F ': ' {'print $2'})
elif exp_date_raw=$(echo "$whois"|egrep -i 'free-date')
then
# reg.ru
# echo "reg.ru" > /dev/stderr
get_date_from_string $1 $(echo $exp_date_raw|awk -F ': ' {'print $2'}|tr '.' '-')
else
echo "Unsupported whois format for $1" > /dev/stderr
printf 'domain_check_expiration_date{name="\s"} 0\ndomain_check_success{name="\s"} 0\n' $1 $1
fi
}
echo -n '' > /tmp/${metricname}.prom.$$
{% for domain in check_domains %}
check_expiration {{ domain }} >> /tmp/${metricname}.prom.$$
{% endfor %}
cat <<EOF>> /tmp/${metricname}.prom.$$
${metricname}_completion_time $(date +%s)
EOF
mv -v /tmp/${metricname}.prom.$$ /var/lib/node_exporter/${metricname}.prom |
This comment has been minimized.
This comment has been minimized.
leonerd
commented
Nov 11, 2016
•
|
Would there be any mileage in allowing multiple destination labels somehow too? E.g. if you wanted to split an "address" label into separate host + port fields. Or to specifically remove a label by setting its value to the empty string. Also another thing is I quite often I end up doing a simple match of
with the added effect of removing the old label name at the same time. |
brian-brazil
referenced this issue
Jan 16, 2017
Closed
Feature request: label_drop(v instant-vector, label) method #2343
This comment has been minimized.
This comment has been minimized.
|
We have join and replace now which are the minimal set of functions. |
brian-brazil
closed this
Jun 16, 2017
This comment has been minimized.
This comment has been minimized.
bric3
commented
Mar 26, 2018
|
Adding a label don't work if there is no label. I'm trying to integrate a metric into a table of existing values. However the
Prom 1.8 |
This comment has been minimized.
This comment has been minimized.
|
It makes more sense to ask questions like this on the prometheus-users mailing list rather than in a GitHub issue. On the mailing list, more people are available to potentially respond to your question, and the whole community can benefit from the answers provided. |
gouthamve
pushed a commit
to gouthamve/promql
that referenced
this issue
Mar 28, 2018
This comment has been minimized.
This comment has been minimized.
lock
bot
commented
Mar 22, 2019
|
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
brian-brazil commentedAug 3, 2015
We need functions in promql to allow playing around with labels, to allow for more advanced use cases such as dealing with mismatched label names.
I propose the following functions:
label_set(vector, labelname, labelvalue)label_copy(vector, dest_labelname, src_labelname)label_join(vector, dest_labelname, separator, src_labelname...)label_replace(vector, dest_labelname, replacement, src_labelame, regex)Combining
label_joinandlabel_replaceyou can do any merging and mixing you want of labels. The alternative to having two functions would be to offer a way to use go templates, which I don't think is wise for performance reasons.