|
| 1 | +-- FUNCTION: fintrack.collectcomponentperformance(integer) |
| 2 | + |
| 3 | +-- DROP FUNCTION fintrack.collectcomponentperformance(integer); |
| 4 | + |
| 5 | +CREATE OR REPLACE FUNCTION fintrack.collectcomponentperformance( |
| 6 | + inuserid integer) |
| 7 | + RETURNS text |
| 8 | + LANGUAGE 'plpgsql' |
| 9 | + |
| 10 | + COST 100 |
| 11 | + VOLATILE |
| 12 | +AS $BODY$ |
| 13 | + |
| 14 | +DECLARE |
| 15 | + |
| 16 | +/* |
| 17 | +* FinTP - Financial Transactions Processing Application |
| 18 | +* Copyright (C) 2013 Business Information Systems (Allevo) S.R.L. |
| 19 | +* |
| 20 | +* This program is free software: you can redistribute it and/or modify |
| 21 | +* it under the terms of the GNU General Public License as published by |
| 22 | +* the Free Software Foundation, either version 3 of the License, or |
| 23 | +* (at your option) any later version. |
| 24 | +* |
| 25 | +* This program is distributed in the hope that it will be useful, |
| 26 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 | +* GNU General Public License for more details. |
| 29 | +* |
| 30 | +* You should have received a copy of the GNU General Public License |
| 31 | +* along with this program. If not, see <http://www.gnu.org/licenses/> |
| 32 | +* or contact Allevo at : 031281 Bucuresti, 23C Calea Vitan, Romania, |
| 33 | +* phone +40212554577, office@allevo.ro <office@allevo.ro>, www.allevo.ro. |
| 34 | +*/ |
| 35 | +/************************************************ |
| 36 | + Change history: |
| 37 | + Created: 01.Feb.2019 - DanielC - 13036 |
| 38 | + Description: Component performance report |
| 39 | + Parameters: inuserid - the user who required the report |
| 40 | + Returns: n/a |
| 41 | + Used: FinTP/BASE/RE |
| 42 | +***********************************************/ |
| 43 | +v_processingtime integer; |
| 44 | +v_totalprocmsg integer; |
| 45 | +v_timenow timestamp without time zone; |
| 46 | +v_cmpthread character varying; |
| 47 | +v_cmpname character varying; |
| 48 | +v_cmpcategory character varying; |
| 49 | +v_noofevents integer; |
| 50 | +v_nooferrevents integer; |
| 51 | +v_noofmngevents integer; |
| 52 | +v_idletime integer; |
| 53 | +v_procrate numeric(8,2); |
| 54 | +v_prechour text; |
| 55 | +v_precnosec double precision; |
| 56 | +v_intervals text default ''; |
| 57 | +rec fintrack.service_class_pair; |
| 58 | +xdate fintrack.date_secno_pair; |
| 59 | + |
| 60 | + |
| 61 | +BEGIN |
| 62 | + v_timenow := current_timestamp::timestamp(0); |
| 63 | + v_cmpthread := null; |
| 64 | + |
| 65 | + --iterate trough unique pairs of service-class |
| 66 | + for rec in select distinct service, class from findata.status where service in (select id from fincfg.servicemaps) |
| 67 | + loop |
| 68 | + -- calculate processingtime and the total number or processed messages |
| 69 | + select count(distinct(date_part('second', insertdate))), count(distinct(correlationid)) |
| 70 | + into v_processingtime, v_totalprocmsg |
| 71 | + from findata.status |
| 72 | + where trim(type) = 'Info' and insertdate::date = v_timenow::date and service = rec.service and class = rec.class; |
| 73 | + |
| 74 | + -- find component name and component category |
| 75 | + select name, partner into v_cmpname, v_cmpcategory from fincfg.servicemaps |
| 76 | + where id = rec.service; |
| 77 | + |
| 78 | + -- find component thread |
| 79 | + if (rec.class = 'Transaction.Fetch') then |
| 80 | + v_cmpthread := 'Fetch'; |
| 81 | + elsif (rec.class = 'Transaction.Publish') then |
| 82 | + v_cmpthread := 'Publish'; |
| 83 | + end if; |
| 84 | + |
| 85 | + -- calculate number of events for Info/Error/Management |
| 86 | + select coalesce(sum(case when trim(type) = 'Info' then 1 else 0 end), 0), |
| 87 | + coalesce(sum(case when trim(type) = 'Error' or trim(type) = 'Warning' then 1 else 0 end), 0), |
| 88 | + coalesce(sum(case when trim(type) = 'Management' then 1 else 0 end), 0) |
| 89 | + into v_noofevents, v_nooferrevents, v_noofmngevents |
| 90 | + from findata.status |
| 91 | + where insertdate::date = v_timenow::date and service = rec.service and class = rec.class; |
| 92 | + |
| 93 | + -- calculate idletime and processing rate |
| 94 | + v_idletime := 24 * 60 * 60 - v_processingtime; |
| 95 | + if (v_totalprocmsg = 0) then |
| 96 | + v_procrate := 0; |
| 97 | + else |
| 98 | + v_procrate := (v_totalprocmsg::numeric) / (v_processingtime::numeric); |
| 99 | + end if; |
| 100 | + |
| 101 | + --calculate intervals |
| 102 | + v_intervals := ''; |
| 103 | + v_precnosec := 0; |
| 104 | + v_prechour := ''; |
| 105 | + |
| 106 | + for xdate in select substring(cast(insertdate as character varying), 12, 8) as insdate, |
| 107 | + extract(hour from insertdate)*60*60 + extract(minute from insertdate)*60 + trunc(extract(second from insertdate)) as conv |
| 108 | + from findata.status |
| 109 | + where insertdate::date = v_timenow::date and service = rec.service and class = rec.class and trim(type) = 'Info' |
| 110 | + order by conv |
| 111 | + loop |
| 112 | + if (xdate.conv - v_precnosec > 1) then |
| 113 | + if (v_precnosec = 0) then |
| 114 | + v_intervals := v_intervals || xdate.insdate || '-'; |
| 115 | + else |
| 116 | + v_intervals := v_intervals || v_prechour || '; '; |
| 117 | + v_intervals := v_intervals || xdate.insdate || '-'; |
| 118 | + end if; |
| 119 | + end if; |
| 120 | + |
| 121 | + v_prechour := xdate.insdate; |
| 122 | + v_precnosec := xdate.conv; |
| 123 | + end loop; |
| 124 | + |
| 125 | + v_intervals := v_intervals || v_prechour || '; '; |
| 126 | + |
| 127 | + -- insert results |
| 128 | + insert into fintrack.componentperformance |
| 129 | + values (v_timenow::date, to_char(v_timenow::time, 'HH:MI:SS'),v_cmpname, v_cmpthread, v_cmpcategory, |
| 130 | + v_idletime, v_processingtime, v_procrate, v_noofevents, v_nooferrevents, v_noofmngevents, v_intervals, inuserid); |
| 131 | + end loop; |
| 132 | + |
| 133 | + -- stop trace |
| 134 | + v_idletime := fintrack.stoptrace(inuserid); |
| 135 | + |
| 136 | + RETURN to_char(v_timenow, 'YYYY-MM-DD HH24:MI:SS'); |
| 137 | + |
| 138 | +EXCEPTION |
| 139 | +WHEN OTHERS THEN |
| 140 | + RAISE EXCEPTION 'Unexpected error occured while configuring queue: %', SQLERRM; |
| 141 | +END; |
| 142 | + |
| 143 | +$BODY$; |
| 144 | + |
| 145 | +ALTER FUNCTION fintrack.collectcomponentperformance(integer) |
| 146 | + OWNER TO fintrack; |
| 147 | + |
0 commit comments