promql example with related fields but different labels - grafana

I'm using Prometheus and Grafana, and I'm trying to track a web server app.
I want to graph the average duration in ms of a particular query. I think I can get there from the data below, but I'm struggling.
My two sets of values:
rate(http_server_request_duration_seconds_sum[5m])
Element Value
{instance="dbserver:5000",job="control-tower",method="get",path="/api/control/v1/node/config.json"} 0.0010491088980113385
{instance="dbserver:5000",job="control-tower",method="get",path="/api/schedule/v1/programs/:id.json"} 0
{instance="dbserver:5000",job="control-tower",method="get",path="/api/schedule/v1/users.json"} 0
{instance="dbserver:5000",job="control-tower",method="get",path="/metrics"} 0.00009133616130826839
{instance="dbserver:5000",job="control-tower",method="post",path="/api/caption/v1/messages.json"} 0
{instance="dbserver:5000",job="control-tower",method="post",path="/api/caption/v1/sessions.json"} 0
{instance="dbserver:5000",job="control-tower",method="post",path="/api/schedule/v1/programs.json"} 0
{instance="dbserver:5000",job="control-tower",method="put",path="/api/caption/v1/sessions/captioners.json"} 0
{instance="dbserver:5000",job="control-tower",method="put",path="/api/control/v1/agents/:id.json"}
rate(http_server_requests_total[5m])
Element Value
{code="200",host="dbserver:5000",instance="dbserver:5000",job="control-tower",method="get",path="/api/control/v1/node/config.json"} 0.03511075688258612
{code="200",host="dbserver:5000",instance="dbserver:5000",job="control-tower",method="get",path="/api/schedule/v1/programs/:id.json"} 0
{code="200",host="dbserver:5000",instance="dbserver:5000",job="control-tower",method="get",path="/api/schedule/v1/users.json"} 0
{code="200",host="dbserver:5000",instance="dbserver:5000",job="control-tower",method="get",path="/metrics"} 0.06671043807691363
{code="200",host="dbserver:5000",instance="dbserver:5000",job="control-tower",method="post",path="/api/caption/v1/sessions.json"} 0
{code="200",host="dbserver:5000",instance="dbserver:5000",job="control-tower",method="post",path="/api/schedule/v1/programs.json"} 0
{code="200",host="dbserver:5000",instance="dbserver:5000",job="control-tower",method="put",path="/api/caption/v1/sessions/captioners.json"} 0
{code="200",host="dbserver:5000",instance="dbserver:5000",job="control-tower",method="put",path="/api/control/v1/agents/:id.json"} 0
{code="422",host="dbserver:5000",instance="dbserver:5000",job="control-tower",method="post",path="/api/schedule/v1/programs.json"} 0
{code="502",host="dbserver:5000",instance="dbserver:5000",job="control-tower",method="post",path="/api/caption/v1/messages.json"}
They have different labels. For this, I only care where path="/api/caption/v1/messages.json".
I think I need to use a combination of rate, sum, and "on" or "ignore", but I haven't been able to get on or ignore to work at all.
I can get the numerator (in seconds) with:
rate( http_server_request_duration_seconds_sum { path="/api/caption/v1/messages.json" }[5m])
And that returns:
{instance="dbserver:5000", job="control-tower", method="post", path="/api/caption/v1/messages.json"}
But the denominator can have different return codes, so I have to sum those, and I need to do some ignore or on or something, but I haven't found an example that helps me out, and I'm really new at this.
Anyone?

Okay, I continued to play. Because I only have one path I worry about, i figured out I could sum the rates. I think this works:
sum( rate( http_server_request_duration_seconds_sum {path="/api/caption/v1/messages.json"}[2h])) / sum( rate( http_server_requests_total{ path="/api/caption/v1/messages.json"}[2h]))
I changed the sample rate as my sample data fell off my 5-minute window, and I had zeros.
I THINK what this is doing is summing the rates, which gets rid of all the labels. And I THINK what it's also doing is using 2 hours of data. I think the rate value is how quickly the value changed over that 2 hour period.
I would love comments.
This solution won't work if I want one chart to include other paths, and I'm still not sure what to do about that, so this solves my current problem but still doesn't help me figure out how to do something similar with ignore or on.

Related

Changing amount of resource sets in Seize-block programmatically

So the problem is:
How can I change the amount in "Resource Sets" programmatically? I'am planning on changing this value back and forth from 1 and 2 given some conditions during the simulation run.
Amount I want to change is marked in yellow below.
Emile answer is right, but if you insist in using what you are using, you can click on the equal sign and make it a function:
and in the function (which i made take a random number between 1 and 2, but you can do what you want), you use the following (the function returns a type ResourcePool[][])
ResourcePool[][] rp = new ResourcePool[1][num];
for(int i=0;i<num;i++){
rp[0][i]=resourcePool;
}
return rp;
In your case, it seems you are using one resource alternative only.
Why don't you choose units of the same pool, then the number of units to be seized becomes dynamic.

How can I get statements within functions to execute in a randomly chosen order?

I'm relatively new to Matlab, and I've been trying to solve my problem for ages but I'm just continuously arriving at a dead end.
I have a code which should, in theory, play 3 sounds in a random order (each order being different for each trial). Upon each sound playing the participant will be asked which sound they heard and then given feedback. I have all the code complete and working up until the random order part. I have created code that on each trial will randomly order 1,2 and 3.
Order = [1, 2, 3];
PhonemeOrder = randperm (numel(Order));
I then have a function which plays the sound/asks the questions etc. within this I have attempted switch cases statements and if else statements depending on the number that PhonemeOrder produces but the order doesnt change even when phoneme order does. I believe my problem is however that PhonemeOrder comes out like [1,2,3] or [3,1,2] which is what i wanted. but Im not sure how to get my sounds to play in the order that it shows because I am using code like...
if/ PhonemeOrder = 1;
then do this...
elseif phonemeorder = 2;
then do this...
else
do this...
Or I've tried code like
switch cases
case 1
do this
case 2
do this
case 3
do this
I'm guessing this is where i am going wrong, but i just dont know how to change it and make it work! I hope this makes sense? I just need it to play in the order that phonemeorder specifies, with the order changing on each trial.
Any help will be greatly appreciated :D
bexG,
I think you are on the right track.
The only thing you need is to use a "for-loop" to go through the array of PhonemeOrder.
for i=1:length(PhonemeOrder)
switch PhonemeOrder(i)
case 1
play the first song
case 2
play the second song
case 3
play the thrid song
end
end
I hope this will help.
Please let me know if you have any further question.

Editing Timeline from CCB file in cocos

I did some research into this and couldn't really find anything, so if this is a repetitive question I apologize. but anyway I have made a CCB file in CocosBuilder and I would like to start the timeline, for example, at one second instead of playing from the beginning. Is there a way to do this? Thanks for the help guys.
Edit: i would like this to be done in the code.
I am using 2.2.1 Cocos2DX version. I think there is no option to play it from given interval. But you can tweak yourself to get it done. (Not simple one)
You have to go to CCBAnimationManager and there you get "mNodeSequences".
It is dictionary and you get difference properties there like "rotation position etc..."
values there.
Internally AnimationManager reads this value (These values are specified in your CCB)
and puts in runAction queue.
So you have to break it as you want.(Ex. 5 min timeline you have. But you want to start
from 1 min then you have run first 1 min Actions without delay and for remaining you
have properly calculate tween intervals.
It's long procedure and needs calculation. If you don't know any other simpler way try this. If you know pls let us know (Post it).

How many iterations are saved by JAGS/BUGS when burnin and thinning are specified?

I have a quick question about the details of running a model in JAGS and BUGS.
Say I run a model with n.burnin=5000, n.iter=5000 and thin=2. Does this mean that the program will:
Run 5,000 iterations, and discard results; and then
Run another 10,000 iterations, only keeping every second result?
If I save these simulations as a CODA object, are all 10,000 saved, or only the thinned 5,000? I'm just trying to understand which set of iterations are used to make the ACF plot?
With JAGS, n.burnin=5000, n.iter=5000 and thin=2, means you keep nothing. You run 5000, discard the first 5000 of these 5000 and then only keep a half of the remaining values of the chain (keep 1 value and discard the next one ..).
Use for example n.burnin=2000, n.iter=7000, thin=50, n.chains=5 : so you have (7000-2000)/50 * 5 = 500 values.
Could you be more specific which software you're talking about? It looks like you're referring to the arguments of the function bugs() in the R2WinBUGS package (except that the argument is called n.thin not thin). Looking at help(bugs) it just says n.burnin is the "number of iterations to discard at the beginning". Which doesn't specifically answer your question, but looking at the source for bugs.script() in that package suggests to me that it would run 5000 iterations burn in, as you suspected. You could send a suggestion to the maintainers of that package to clarify their documentation.
In your example, bugs() would then run 0 further iterations after the burn-in. Here the documentation is clearer - n.iter is the total number of iterations including the burn-in.
For your second question, the CODA output from WinBUGS (and any software which calls WinBUGS or OpenBUGS) will only include the thinned sample.

Finding a Range in CoffeeScript

I understand how to define an array range in CoffeeScript
lng[1..10]
However if I have
data = 10
What's the best way to find if 10 is within a range of 1 and 11?
if data is between(1..11)
return true
There is no "between" keyword, but you can utilize a normal array-range:
if data in [1..11]
alert 'yay'
But that's a bit of an overkill, so in simple cases I'd recommend a normal comparison:
if 1 <= data <= 11
alert 'yay'
If you don't mind polluting the native prototypes, you can add a between method to the Number objects:
Number::between = (min, max) ->
min <= this <= max
if 10.between(1, 11)
alert 'yay'
Although i personally wouldn't use it. if 1 <= something <= 11 is more direct and everyone will understand it. The between method, instead, has to be looked up if you want to know what it does (or you'd have to guess), and i think it doesn't add that much.