Get distinct values of metric












1














in my setup I have a java component reading data from YARN manager and exposing results of various jobs as metrics. For example I have a metrics with job duration which just holds duration of last app run. It may look like this:



duration_time_millis{job="probe",app_name="import-results",app_type="MAPREDUCE",status="SUCCEEDED"}
1991392 @1542770979.823
1991392 @1542770994.823
1991392 @1542771009.823
...
265722 @1542781554.823
265722 @1542781569.823
265722 @1542781584.823
...


The thing is I am scraping the expose server every 15s or so, but the jobs runs irregulary once per several hours. That means over past 6 hours I am getting 563x the first value and 520x the second value. As there is only one change in the interval.



Is there a way how to compute avg or stddev only on distinct values? Getting the number of distinct values would also mean better handling in histograms and heatmaps in grafana where count_values does not seem to be a good solution.



Thanks for any help on this!










share|improve this question


















  • 1




    You seem to be on the right track with count_values. To get the current number of distinct values for a metric you could use something like count(count_values("hi there stack overflow", up)). I don't think there is currently any Promql function that would do anything like count_values_over_time so there is not a way that I am aware of to be able to calculate avg or avg_over_time based on unique values. Sorry to break it to ya :(
    – wbh1
    Nov 21 '18 at 15:41










  • What a pity. If I check only one time series count_values always returns 1 as there is only one value at a time. And since there is no such function working with range vector, I cannot get much useful data for selected interval. Though I am a bit surprised there is no workaround at least for such simple query.
    – Milano Nicolum
    Nov 22 '18 at 8:51


















1














in my setup I have a java component reading data from YARN manager and exposing results of various jobs as metrics. For example I have a metrics with job duration which just holds duration of last app run. It may look like this:



duration_time_millis{job="probe",app_name="import-results",app_type="MAPREDUCE",status="SUCCEEDED"}
1991392 @1542770979.823
1991392 @1542770994.823
1991392 @1542771009.823
...
265722 @1542781554.823
265722 @1542781569.823
265722 @1542781584.823
...


The thing is I am scraping the expose server every 15s or so, but the jobs runs irregulary once per several hours. That means over past 6 hours I am getting 563x the first value and 520x the second value. As there is only one change in the interval.



Is there a way how to compute avg or stddev only on distinct values? Getting the number of distinct values would also mean better handling in histograms and heatmaps in grafana where count_values does not seem to be a good solution.



Thanks for any help on this!










share|improve this question


















  • 1




    You seem to be on the right track with count_values. To get the current number of distinct values for a metric you could use something like count(count_values("hi there stack overflow", up)). I don't think there is currently any Promql function that would do anything like count_values_over_time so there is not a way that I am aware of to be able to calculate avg or avg_over_time based on unique values. Sorry to break it to ya :(
    – wbh1
    Nov 21 '18 at 15:41










  • What a pity. If I check only one time series count_values always returns 1 as there is only one value at a time. And since there is no such function working with range vector, I cannot get much useful data for selected interval. Though I am a bit surprised there is no workaround at least for such simple query.
    – Milano Nicolum
    Nov 22 '18 at 8:51
















1












1








1







in my setup I have a java component reading data from YARN manager and exposing results of various jobs as metrics. For example I have a metrics with job duration which just holds duration of last app run. It may look like this:



duration_time_millis{job="probe",app_name="import-results",app_type="MAPREDUCE",status="SUCCEEDED"}
1991392 @1542770979.823
1991392 @1542770994.823
1991392 @1542771009.823
...
265722 @1542781554.823
265722 @1542781569.823
265722 @1542781584.823
...


The thing is I am scraping the expose server every 15s or so, but the jobs runs irregulary once per several hours. That means over past 6 hours I am getting 563x the first value and 520x the second value. As there is only one change in the interval.



Is there a way how to compute avg or stddev only on distinct values? Getting the number of distinct values would also mean better handling in histograms and heatmaps in grafana where count_values does not seem to be a good solution.



Thanks for any help on this!










share|improve this question













in my setup I have a java component reading data from YARN manager and exposing results of various jobs as metrics. For example I have a metrics with job duration which just holds duration of last app run. It may look like this:



duration_time_millis{job="probe",app_name="import-results",app_type="MAPREDUCE",status="SUCCEEDED"}
1991392 @1542770979.823
1991392 @1542770994.823
1991392 @1542771009.823
...
265722 @1542781554.823
265722 @1542781569.823
265722 @1542781584.823
...


The thing is I am scraping the expose server every 15s or so, but the jobs runs irregulary once per several hours. That means over past 6 hours I am getting 563x the first value and 520x the second value. As there is only one change in the interval.



Is there a way how to compute avg or stddev only on distinct values? Getting the number of distinct values would also mean better handling in histograms and heatmaps in grafana where count_values does not seem to be a good solution.



Thanks for any help on this!







prometheus prometheus-java






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 12:30









Milano Nicolum

615




615








  • 1




    You seem to be on the right track with count_values. To get the current number of distinct values for a metric you could use something like count(count_values("hi there stack overflow", up)). I don't think there is currently any Promql function that would do anything like count_values_over_time so there is not a way that I am aware of to be able to calculate avg or avg_over_time based on unique values. Sorry to break it to ya :(
    – wbh1
    Nov 21 '18 at 15:41










  • What a pity. If I check only one time series count_values always returns 1 as there is only one value at a time. And since there is no such function working with range vector, I cannot get much useful data for selected interval. Though I am a bit surprised there is no workaround at least for such simple query.
    – Milano Nicolum
    Nov 22 '18 at 8:51
















  • 1




    You seem to be on the right track with count_values. To get the current number of distinct values for a metric you could use something like count(count_values("hi there stack overflow", up)). I don't think there is currently any Promql function that would do anything like count_values_over_time so there is not a way that I am aware of to be able to calculate avg or avg_over_time based on unique values. Sorry to break it to ya :(
    – wbh1
    Nov 21 '18 at 15:41










  • What a pity. If I check only one time series count_values always returns 1 as there is only one value at a time. And since there is no such function working with range vector, I cannot get much useful data for selected interval. Though I am a bit surprised there is no workaround at least for such simple query.
    – Milano Nicolum
    Nov 22 '18 at 8:51










1




1




You seem to be on the right track with count_values. To get the current number of distinct values for a metric you could use something like count(count_values("hi there stack overflow", up)). I don't think there is currently any Promql function that would do anything like count_values_over_time so there is not a way that I am aware of to be able to calculate avg or avg_over_time based on unique values. Sorry to break it to ya :(
– wbh1
Nov 21 '18 at 15:41




You seem to be on the right track with count_values. To get the current number of distinct values for a metric you could use something like count(count_values("hi there stack overflow", up)). I don't think there is currently any Promql function that would do anything like count_values_over_time so there is not a way that I am aware of to be able to calculate avg or avg_over_time based on unique values. Sorry to break it to ya :(
– wbh1
Nov 21 '18 at 15:41












What a pity. If I check only one time series count_values always returns 1 as there is only one value at a time. And since there is no such function working with range vector, I cannot get much useful data for selected interval. Though I am a bit surprised there is no workaround at least for such simple query.
– Milano Nicolum
Nov 22 '18 at 8:51






What a pity. If I check only one time series count_values always returns 1 as there is only one value at a time. And since there is no such function working with range vector, I cannot get much useful data for selected interval. Though I am a bit surprised there is no workaround at least for such simple query.
– Milano Nicolum
Nov 22 '18 at 8:51



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412081%2fget-distinct-values-of-metric%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412081%2fget-distinct-values-of-metric%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'