我们正在使用Grafana和Influx测量吞吐量。当然,我们想用每秒(rps)大约发生多少个请求来衡量吞吐量。 典型的请求是:
CREATE OR REPLACE TYPE F_NUMBER AS OBJECT (
F1 NUMBER,
F2 NUMBER
);
CREATE OR REPLACE TYPE F_NUMBER_TABLE AS TABLE OF F_NUMBER;
DECLARE
number_table F_NUMBER_TABLE;
number_table_new F_NUMBER_TABLE;
F1 NUMBER;
F2 NUMBER;
TYPE f_array_type IS TABLE OF NUMBER;
f1_array f_array_type;
f2_array f_array_type;
BEGIN
number_table := F_NUMBER_TABLE(F_NUMBER(2,3));
SELECT *
INTO f1, f2
FROM TABLE(number_table);
DBMS_OUTPUT.PUT_LINE ( 'f1 = ' || F1 );
DBMS_OUTPUT.PUT_LINE ( 'f2 = ' || F2 );
EXECUTE IMMEDIATE 'select * from TABLE(:t)' INTO F1, F2 USING number_table;
DBMS_OUTPUT.PUT_LINE ( 'f1 = ' || f1 );
DBMS_OUTPUT.PUT_LINE ( 'f2 = ' || f2 );
number_table := F_NUMBER_TABLE(F_NUMBER(2,3), F_NUMBER(22,33));
EXECUTE IMMEDIATE 'select * from TABLE(:t)' BULK COLLECT INTO f1_array, f2_array USING number_table;
DBMS_OUTPUT.PUT_LINE ( 'f1_array(*) = ' || f1_array(1) ||','|| f1_array(2) );
DBMS_OUTPUT.PUT_LINE ( 'f2_array(*) = ' || f2_array(1) ||','|| f2_array(2) );
SELECT F_NUMBER(F1, F2)
BULK COLLECT INTO number_table_new
FROM TABLE(number_table);
DBMS_OUTPUT.PUT_LINE ( 'number_table_new(1) = ' || number_table_new(1).F1 ||','|| number_table_new(1).F2 );
DBMS_OUTPUT.PUT_LINE ( 'number_table_new(2) = ' || number_table_new(2).F1 ||','|| number_table_new(2).F2 );
EXECUTE IMMEDIATE 'select F_NUMBER(F1, F2) from TABLE(:t)' BULK COLLECT INTO number_table_new USING number_table;
DBMS_OUTPUT.PUT_LINE ( 'number_table_new(1) = ' || number_table_new(1).F1 ||','|| number_table_new(1).F2 );
DBMS_OUTPUT.PUT_LINE ( 'number_table_new(2) = ' || number_table_new(2).F1 ||','|| number_table_new(2).F2 );
END;
但是,我们失去了使用惊人的动态SELECT sum("count") / 10 FROM "http_requests" GROUP BY time(10s)
的可能性,当图表范围很大时(例如一周中的一天),此功能非常有用。当我们更改间隔时,应将 divider 更改为$__interval
表达式。
SELECT
但是这种方法行不通,因为返回的结果为空。
如何使用动态SELECT sum("count") / $__interval FROM "http_requests" GROUP BY time($__interval)
创建请求以进行吞吐量测量?
答案 0 :(得分:3)
未得到任何结果的原因是$__interval
不是数字,而是诸如10s
,1m
等的字符串,influxdb将其理解为时间范围。因此,无法按您尝试的方式使用它。
但是,您要计算的是mean
,它可以作为InfluxQL中的函数使用。获得所需行为的方法就是这样。
SELECT mean("count") FROM "http_requests" GROUP BY time($__interval)
编辑:第二个想法并不是您想要的。
您可能需要使用derivative
。稍后,我会再与您联系。
Edit2:您认为这可以回答您有Calculating request per second using InfluxDB on Grafana
的问题 Edit3:第三次编辑很有魅力。
我们使用您的开始查询,并将其包装在另一个查询中,例如:
SELECT sum("rps") from (SELECT sum("count") / 10 as rps FROM "http_requests" GROUP BY time(10s)) GROUP BY time($__interval)