Prometheus not able to divide 2 values [duplicate] - windows

We need to add results of two queries in Prometheus. Snippet is below:
(probe_ssl_earliest_cert_expiry{job="SSL-expiry"} - time() < 86400 * 738 )*1000 + (node_time_seconds*1000)
but the result says no data as shown below:

You will get an empty result if the metrics do not match. The reason is that for binary operator vector1 <op> vector2
vector1 and vector2 results in a vector consisting of the elements of
vector1 for which there are elements in vector2 with exactly matching
label sets. Other elements are dropped.
You must at least add a on() or ignoring() vector matching keyword specifying the labels (names) on which the (name and) value match. You may have to add grouping instruction if you have one to many matching.
Fill the ??? in the following expression such that label match:
(probe_ssl_earliest_cert_expiry{job="SSL-expiry"} - time() < 86400 * 738 )*1000 + ON(???) (node_time_seconds*1000)

Related

Filtering by Length of Values in Cell using Custom Formula

I have a column D named "body", containing text. I want to filter (show) only values that are greater than 1000 characters, so that rows with small values < 1000 are not shown. How do I address that in the custom formula ?
Use D2 or D:D as your argument to LEN. (This list is non-exhaustive.)
=LEN(D2) >= 1000
=LEN(D:D) >= 1000
I used >= since you said you don't want to show anything less than 1000.

Adding two values in Prometheus

We need to add results of two queries in Prometheus. Snippet is below:
(probe_ssl_earliest_cert_expiry{job="SSL-expiry"} - time() < 86400 * 738 )*1000 + (node_time_seconds*1000)
but the result says no data as shown below:
You will get an empty result if the metrics do not match. The reason is that for binary operator vector1 <op> vector2
vector1 and vector2 results in a vector consisting of the elements of
vector1 for which there are elements in vector2 with exactly matching
label sets. Other elements are dropped.
You must at least add a on() or ignoring() vector matching keyword specifying the labels (names) on which the (name and) value match. You may have to add grouping instruction if you have one to many matching.
Fill the ??? in the following expression such that label match:
(probe_ssl_earliest_cert_expiry{job="SSL-expiry"} - time() < 86400 * 738 )*1000 + ON(???) (node_time_seconds*1000)

What does this mathcad line mean?

A is a set of real numbers. Really confused as to what this line does. The numerator looks like its taking the subset of A that does not contain the smallest value. The denominator appears to be the range. How can you divide the resulting subset by the range? Or perhaps that is not what the numerator is doing?
A <- (A - min(A)) * (max(A) - min(A))^-1
^-1 means take the matrix inverse not the reciprocal
Assuming A is an matrix of real numbers, then the expression can be broken down as follows:
let mna = min(A) : Scalar - the minimum value of A
let mxa = max(A) : Scalar - the maximum value of A
let N = (A-min(A)) = Array - Scalar - each element of A minus mna
let X = (A-max(A)) ... minus mxa
so we have
N*inverse(X)
... Which would be true if I had put my glasses on and read the expression properly instead of as A <- (A - min(A)) * (A - max(A))^-1
However, as the expression is actually A <- (A - min(A)) * (max(A) - min(A))^-1, the explanation is different.
The expression for N is the same (although I note parenthetically that an expression of the form (array - scalar/conformable-array) means subtract; it is not an array element deletion operation).
However, (max(A) - min(A)) is what it looks like, the maximum value of A minus it's minimum value, and the ^-1 in this instance does mean divide.
The expression therefore returns A with all values scaled to lie between 0 (==min(A)) and 1 (==max(A)).
The <- at the start of the expression is Mathcad's local definition operator (used to assign values in a Mathcad "program") and simply assigns the normalized value of A back to A.

How to get histogram data object from matlab

Lets say I have a matrix x=[ 1 2 1 2 1 2 1 2 3 4 5 ]. To look at its histogram, I can do h=hist(x).
Now, h with retrieve a matrix consisting only the number of occurrences and does not store the original value to which it occurred.
What I want is something like a function which takes a value from x and returns number of occurrences of it. Having said that, what one thing histeq does should we admire is, it automatically scales nearest values according!
How should solve this issue? How exactly people do it?
My reason of interest is in images:
Lets say I have an image. I want to find all number of occurrences of a chrominance value of image.
I'm not really shure what you are looking for, but if you ant to use hist to count the number of occurences, use:
[h,c]=hist(x,sort(unique(x)))
Otherwise hist uses ranges defined by centers. The second output argument returns the corresponding number.
hist has a second return value that will be the bin centers xc corresponding to the counts n returned in form of the first return value: [n, xc] = hist(x). You should have a careful look at the reference which describes a large number of optional arguments that control the behavior of hist. However, hist is way too mighty for your specific problem.
To simply count the number of occurrences of a specific value, you could simply use something like sum(x(:) == 42). The colon operator will linearize your image matrix, the equals operator will yield a list of boolean values with 1 for each element of x that was 42, and thus sum will yield the total number of these occurrences.
An alternative to hist / histc is to use bsxfun:
n = unique(x(:)).'; %'// values contained in x. x can have any number of dims
y = sum(bsxfun(#eq, x(:), n)); %// count for each value

Find similar records in dataset

I have a dataset of 25 integer fields and 40k records, e.g.
1:
field1: 0
field2: 3
field3: 1
field4: 2
[...]
field25: 1
2:
field1: 2
field2: 1
field3: 4
field4: 0
[...]
field25: 2
etc.
I'm testing with MySQL but am not tied to it.
Given a single record, I need to retrieve the records most similar to it; something like the lowest average difference of the fields. I started looking at the following, but I don't know how to map this onto the problem of searching for similarities in a large dataset.
https://en.wikipedia.org/wiki/Euclidean_distance
https://en.wikipedia.org/wiki/S%C3%B8rensen_similarity_index
https://en.wikipedia.org/wiki/Similarity_matrix
I know it's an old post, but for anyone who comes by it seeking similar algorithms, one that works particularly well is Cosine Similarity. Find a way to vectorize your records, then look for vectors with minimum angle between them. If vectorizing a record is not trivial, then you can vectorize similarity between them via some known algorithm, and then look at cosine similarity of the similarity vectors to the perfect match vector (assuming perfect matches aren't the goal since they're easy to find anyway). I get tremendous results with this matching even comparing things like lists of people in various countries working on a particular project with various contributions to the project. Vectorization implies looking at number of country matches, country mismatches, ratio of people in a matching country between two datasets, etc etc etc. I use string edit distance functions like Levenshtein distance for getting numeric value from string dissimilarities, but one could use phonetic matching, etc. As long as the target number is not 0 (vector [0 0 ... 0] is the subspace of ANY vector and thus its angle would be undefined. Sometimes to get away from the problem, such as the case of edit distance, I give a perfect match (e.d. 0) a negative weight, so that perfect matches are really emphasized. -1 and 1 are farther away than 1 and 2, which makes a lot of sense - perfect match is better than anything with even 1 misspelling.
Cos(theta) = (A dot B) / (Norm(A)*Norm(B)) where dot is the dot-product, and Norm is the Euclidian magnitude of the vector.
Good luck!
Here's a possibility with straight average distance between each of the fields (the value after each minus is from the given record needing a match):
SELECT id,
(
ABS(field1-2)
+ ABS(field2-2)
+ ABS(field3-3)
+ ABS(field4-1)
+ ABS(field5-0)
+ ABS(field6-3)
+ ABS(field7-2)
+ ABS(field8-0)
+ ABS(field9-1)
+ ABS(field10-0)
+ ABS(field11-2)
+ ABS(field12-2)
+ ABS(field13-3)
+ ABS(field14-2)
+ ABS(field15-0)
+ ABS(field16-1)
+ ABS(field17-0)
+ ABS(field18-2)
+ ABS(field19-3)
+ ABS(field20-1)
+ ABS(field21-0)
+ ABS(field22-1)
+ ABS(field23-3)
+ ABS(field24-2)
+ ABS(field25-2)
)/25
AS distance
FROM mytable
ORDER BY distance ASC
LIMIT 20;

Resources