root/sql/sprocs/noit.mark_metric_numeric_rollup_buffer.sql

Revision 1cb12d1bd5a9021a4249d44f0a80de3a36e848c9, 1.1 kB (checked in by Denish Patel <denish@omniti.com>, 5 years ago)

updated noit.mark_metric_numeric_rollup_buffer

  • Property mode set to 100644
Line 
1 -- formerly stratcon.loading_dock_metric_numeric_s_whence_log
2
3 CREATE OR REPLACE FUNCTION noit.mark_metric_numeric_rollup_buffer()
4   RETURNS trigger AS
5 $BODY$
6 DECLARE
7 v_whence timestamptz;
8 v_whence_5 timestamptz;
9 v_sid integer;
10 v_name text;
11 BEGIN
12 IF TG_OP = 'INSERT' THEN
13  
14  v_whence_5:=date_trunc('H',NEW.WHENCE) + (round(extract('minute' from NEW.WHENCE)/5)*5) * '1 minute'::interval;
15  
16    SELECT whence FROM noit.metric_numeric_rollup_queue WHERE whence=v_whence_5 and interval='5 minutes'
17      INTO v_whence;
18      
19    IF NOT FOUND THEN
20       BEGIN
21        INSERT INTO  noit.metric_numeric_rollup_queue VALUES(v_whence_5,'5 minutes');
22        EXCEPTION
23         WHEN UNIQUE_VIOLATION THEN
24         -- do nothing
25       END;
26     END IF;
27
28    SELECT sid,metric_name FROM noit.metric_name_summary WHERE sid=NEW.sid  and metric_name=NEW.name
29      INTO v_sid,v_name;
30    IF NOT FOUND THEN
31        INSERT INTO  noit.metric_name_summary VALUES(NEW.sid,NEW.name,'numeric');
32     END IF;
33
34 END IF;
35     RETURN NULL;
36 END
37 $BODY$
38   LANGUAGE 'plpgsql'   SECURITY DEFINER;
39
40 GRANT EXECUTE ON FUNCTION noit.mark_metric_numeric_rollup_buffer() TO stratcon;
Note: See TracBrowser for help on using the browser.