From bf3d05eca2e2e75a19e9cb1abc19488d073fc0ca Mon Sep 17 00:00:00 2001 From: mattf Date: Fri, 21 Apr 2023 15:01:04 +0000 Subject: [PATCH] Added agent screen latency logging, viewable in the Real-Time Report and the new Agent Latency Report. git-svn-id: svn://192.168.202.10@3712 3d104415-ff17-0410-8863-d5cf3c621b8a --- agc_2-X/trunk/UPGRADE | 9 + agc_2-X/trunk/bin/ADMIN_archive_log_tables.pl | 53 +++ agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl | 191 +++++++- agc_2-X/trunk/docs/AGENT_SCREEN_LOGGING.txt | 117 +++++ .../trunk/extras/MySQL_AST_CREATE_tables.sql | 43 +- agc_2-X/trunk/extras/upgrade_2.14.sql | 43 ++ agc_2-X/trunk/www/agc/conf_exten_check.php | 35 +- agc_2-X/trunk/www/agc/vicidial.php | 24 +- .../trunk/www/vicidial/AST_timeonVDADall.php | 224 ++++++++-- agc_2-X/trunk/www/vicidial/admin.php | 11 +- .../trunk/www/vicidial/help_documentation.txt | 3 +- .../trunk/www/vicidial/options-example.php | 2 + .../trunk/www/vicidial/realtime_report.php | 41 +- .../www/vicidial/user_latency_report.php | 420 ++++++++++++++++++ 14 files changed, 1148 insertions(+), 68 deletions(-) create mode 100644 agc_2-X/trunk/docs/AGENT_SCREEN_LOGGING.txt create mode 100644 agc_2-X/trunk/www/vicidial/user_latency_report.php diff --git a/agc_2-X/trunk/UPGRADE b/agc_2-X/trunk/UPGRADE index b608b35e..09628020 100644 --- a/agc_2-X/trunk/UPGRADE +++ b/agc_2-X/trunk/UPGRADE @@ -783,6 +783,15 @@ OTHER CHANGES: 219. Added "Asterisk Restart URL" to the Modify Servers page, this can send a URL request any time Asterisk is auto-restarted on that server. +220. Added Agent API "send_notification" function, allowing you to send + notifications to agents by User, User Group or Campaign. + +221. Added "AMD Agent Route Options" flag to allow immediately hangup and dispo + of calls with no audio data. This is a campaign feature. + +222. Added agent screen latency logging, viewable in the Real-Time Report and + the new Agent Latency Report. + diff --git a/agc_2-X/trunk/bin/ADMIN_archive_log_tables.pl b/agc_2-X/trunk/bin/ADMIN_archive_log_tables.pl index f288eeb8..4c71b9cb 100644 --- a/agc_2-X/trunk/bin/ADMIN_archive_log_tables.pl +++ b/agc_2-X/trunk/bin/ADMIN_archive_log_tables.pl @@ -66,6 +66,7 @@ # 220309-2246 - Added --api-archive-days=X and --api-archive-only flags # 220312-0859 - Added vicidial_dial_cid_log table archiving, same as vicidial_dial_log # 230418-1341 - Added vicidial_user_dial_log archiving, same as vicidial_dial_log +# 230421-0057 - Added vicidial_agent_latency_summary_log archiving # $CALC_TEST=0; @@ -3200,6 +3201,58 @@ if (!$T) } + ##### vicidial_agent_latency_summary_log + $stmtA = "SELECT count(*) from vicidial_agent_latency_summary_log;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $vicidial_agent_latency_summary_log_count = $aryA[0]; + } + $sthA->finish(); + + $stmtA = "SELECT count(*) from vicidial_agent_latency_summary_log_archive;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + if ($sthArows > 0) + { + @aryA = $sthA->fetchrow_array; + $vicidial_agent_latency_summary_log_archive_count = $aryA[0]; + } + $sthA->finish(); + + if (!$Q) {print "\nProcessing vicidial_agent_latency_summary_log table... ($vicidial_agent_latency_summary_log_count|$vicidial_agent_latency_summary_log_archive_count)\n";} + $stmtA = "INSERT IGNORE INTO vicidial_agent_latency_summary_log_archive SELECT * from vicidial_agent_latency_summary_log;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows = $sthA->rows; + if (!$Q) {print "$sthArows rows inserted into vicidial_agent_latency_summary_log_archive table \n";} + + $rv = $sthA->err(); + if (!$rv) + { + if ($wipe_all > 0) + {$stmtA = "DELETE FROM vicidial_agent_latency_summary_log;";} + else + {$stmtA = "DELETE FROM vicidial_agent_latency_summary_log WHERE db_time < '$del_time';";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows = $sthA->rows; + if (!$Q) {print "$sthArows rows deleted from vicidial_agent_latency_summary_log table \n";} + + $stmtA = "optimize table vicidial_agent_latency_summary_log;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + + $stmtA = "optimize table vicidial_agent_latency_summary_log_archive;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + } + + ##### vicidial_carrier_log $stmtA = "SELECT count(*) from vicidial_carrier_log;"; $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; diff --git a/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl b/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl index 65c059b7..ea240bb9 100644 --- a/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl +++ b/agc_2-X/trunk/bin/ADMIN_keepalive_ALL.pl @@ -162,9 +162,10 @@ # 230309-0926 - Added ara_url for server asterisk reboots, daily rolling of vicidial_abandon_check_queue table # 230331-2155 - Fix for issue #1458 # 230412-1405 - Added daily rolling of vicidial_agent_notifications table, truncating of vicidial_agent_notifications_queue table +# 230420-2321 - Added latency live agent detail updates and log rolling nightly # -$build = '230412-1405'; +$build = '230420-2321'; $DB=0; # Debug flag $teodDB=0; # flag to log Timeclock End of Day processes to log file @@ -2152,6 +2153,107 @@ if ($timeclock_end_of_day_NOW > 0) ##### END vicidial_lead_24hour_calls end of day process removing records older than 1 day ##### + ##### START latency log summary log inserts + + ##### gather vicidial_agent_latency_log ##### + $stmtA = "SELECT user,web_ip,count(*),max(latency),avg(latency) FROM vicidial_agent_latency_log where log_date >= \"$RMSQLdate\" and log_date < \"$now_date\" group by user,web_ip order by user,web_ip;"; + if ($DBX) {print "$stmtA\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $i=0; + while ($sthArows > $i) + { + @aryA = $sthA->fetchrow_array; + $VLADuser[$i] = $aryA[0]; + $VLADweb_ip[$i] = $aryA[1]; + $VLADcount_latency[$i] = $aryA[2]; + $VLADmax_latency[$i] = $aryA[3]; + $VLADavg_latency[$i] = $aryA[4]; + $i++; + } + $sthA->finish(); + + if ($DB) {print " past day vicidial_agent_latency_log user/ip entries to insert: $i\n";} + + if ($i > 0) + { + $i=0; + $sum_inserts=0; + while ($sthArows > $i) + { + $stmtA = "INSERT INTO vicidial_agent_latency_summary_log SET user='$VLADuser[$i]',log_date='$RMSQLdate',web_ip='$VLADweb_ip[$i]',latency_avg='$VLADavg_latency[$i]',latency_peak='$VLADmax_latency[$i]',latency_count='$VLADcount_latency[$i]';"; + $affected_rows = $dbhA->do($stmtA) or die "Couldn't execute query: |$stmtA|\n"; + $sum_inserts = ($sum_inserts + $affected_rows); + $event_string = "vicidial_agent_latency_summary_log insert query: $sum_inserts|$affected_rows|$stmtA|"; + if ($DBX) {print "$event_string\n";} + if ($teodDB) {&teod_logger;} + + $i++; + } + + if ($sum_inserts > 0) + { + $stmtA = "INSERT INTO vicidial_agent_latency_summary_log(user,log_date,web_ip,latency_count,latency_peak,latency_avg) SELECT user,'$RMSQLdate','---ALL---',sum(latency_count),max(latency_peak),sum(latency_avg * latency_count) / sum(latency_count) from vicidial_agent_latency_summary_log where log_date = \"$RMSQLdate\" group by user order by user;;"; + $affected_rows = $dbhA->do($stmtA) or die "Couldn't execute query: |$stmtA|\n"; + $event_string = "vicidial_agent_latency_summary_log ALL insert query: |$affected_rows|$stmtA|"; + if ($DBX) {print "$event_string\n";} + if ($teodDB) {&teod_logger;} + } + + # remove non-active records from vicidial_live_agents_details table and optimize + $stmtA = "DELETE FROM vicidial_live_agents_details where update_date < (NOW()-INTERVAL 5 MINUTE);"; + $affected_rows = $dbhA->do($stmtA) or die "Couldn't execute query: |$stmtA|\n"; + $event_string = "vicidial_live_agents_details delete query: |$affected_rows|$stmtA|"; + if ($DBX) {print "$event_string\n";} + if ($teodDB) {&teod_logger;} + + $stmtA = "optimize table vicidial_live_agents_details;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + + # archive vicidial_agent_latency_log table every night + if (!$Q) {print "\nProcessing vicidial_agent_latency_log table...\n";} + $stmtA = "INSERT IGNORE INTO vicidial_agent_latency_log_archive SELECT * from vicidial_agent_latency_log;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows = $sthA->rows; + $event_string = "$sthArows rows inserted into vicidial_agent_latency_log_archive table"; + if (!$Q) {print "$event_string \n";} + if ($teodDB) {&teod_logger;} + + $rv = $sthA->err(); + if (!$rv) + { + $stmtA = "DELETE FROM vicidial_agent_latency_log WHERE log_date < \"$now_date\";"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows = $sthA->rows; + $event_string = "$sthArows rows deleted from in vicidial_agent_latency_log table"; + if (!$Q) {print "$event_string \n";} + if ($teodDB) {&teod_logger;} + + $stmtA = "optimize table vicidial_agent_latency_log;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + } + + # delete vicidial_agent_latency_log_archive records older than 7 days old + $stmtA = "DELETE FROM vicidial_agent_latency_log_archive WHERE log_date < \"$SDSQLdate\";"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows = $sthA->rows; + $event_string = "$sthArows old rows deleted from in vicidial_agent_latency_log_archive table ($SDSQLdate)"; + if (!$Q) {print "$event_string \n";} + if ($teodDB) {&teod_logger;} + + $stmtA = "optimize table vicidial_agent_latency_log_archive;"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + } + ##### END latency log summary log inserts + + ##### BEGIN usacan_phone_dialcode_fix funciton ##### if ($usacan_phone_dialcode_fix > 0) { @@ -5375,6 +5477,93 @@ if ( ($active_voicemail_server =~ /$server_ip/) && ((length($active_voicemail_se +################################################################################ +##### START latency log live agent details updates +################################################################################ +# only run this on active voicemail server +if ( ($active_voicemail_server =~ /$server_ip/) && ((length($active_voicemail_server)) eq (length($server_ip))) ) + { + ##### gather vicidial_live_agents_details ##### + $stmtA = "SELECT user,web_ip FROM vicidial_live_agents_details where update_date > (NOW()-INTERVAL 5 MINUTE);"; + if ($DBX) {print "$stmtA\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArows=$sthA->rows; + $i=0; + while ($sthArows > $i) + { + @aryA = $sthA->fetchrow_array; + $VLADuser[$i] = $aryA[0]; + $VLADweb_ip[$i] = $aryA[1]; + $i++; + } + $sthA->finish(); + + if ($DB) {print " recent vicidial_live_agents_details entries to update: $i\n";} + + $i=0; + while ($sthArows > $i) + { + $VALLmin_count_latency=0; $VALLmin_max_latency=0; $VALLmin_avg_latency=0; + $stmtA = "SELECT count(*),max(latency),avg(latency) from vicidial_agent_latency_log where user='$VLADuser[$i]' and log_date >= (NOW()-INTERVAL 1 MINUTE);"; + if ($DBX) {print "$stmtA\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArowsX=$sthA->rows; + if ($sthArowsX > 0) + { + @aryA = $sthA->fetchrow_array; + $VALLmin_count_latency = $aryA[0]; + $VALLmin_max_latency = $aryA[1]; + $VALLmin_avg_latency = $aryA[2]; + } + $sthA->finish(); + + if ($VALLmin_count_latency > 0) + { + $VALLhour_count_latency=0; $VALLhour_max_latency=0; $VALLhour_avg_latency=0; + $stmtA = "SELECT count(*),max(latency),avg(latency) from vicidial_agent_latency_log where user='$VLADuser[$i]' and log_date >= (NOW()-INTERVAL 60 MINUTE);"; + if ($DBX) {print "$stmtA\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArowsX=$sthA->rows; + if ($sthArowsX > 0) + { + @aryA = $sthA->fetchrow_array; + $VALLhour_count_latency = $aryA[0]; + $VALLhour_max_latency = $aryA[1]; + $VALLhour_avg_latency = $aryA[2]; + } + $sthA->finish(); + + $VALLtoday_count_latency=0; $VALLtoday_max_latency=0; $VALLtoday_avg_latency=0; + $stmtA = "SELECT count(*),max(latency),avg(latency) from vicidial_agent_latency_log where user='$VLADuser[$i]' and log_date >= \"$today_start\";"; + if ($DBX) {print "$stmtA\n";} + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArowsX=$sthA->rows; + if ($sthArowsX > 0) + { + @aryA = $sthA->fetchrow_array; + $VALLtoday_count_latency = $aryA[0]; + $VALLtoday_max_latency = $aryA[1]; + $VALLtoday_avg_latency = $aryA[2]; + } + $sthA->finish(); + + $stmtA = "UPDATE vicidial_live_agents_details SET latency_min_avg='$VALLmin_avg_latency',latency_min_peak='$VALLmin_max_latency',latency_hour_avg='$VALLhour_avg_latency',latency_hour_peak='$VALLhour_max_latency',latency_today_avg='$VALLtoday_avg_latency',latency_today_peak='$VALLtoday_max_latency' where user='$VLADuser[$i]';"; + $affected_rows = $dbhA->do($stmtA) or die "Couldn't execute query: |$stmtA|\n"; + if ($DBX) {print "vicidial_live_agents_details update query: |$affected_rows|$stmtA|\n";} + } + $i++; + } + } +################################################################################ +##### END latency log live agent details updates +################################################################################ + + + ################################################################################ ##### BEGIN Audio Store sync diff --git a/agc_2-X/trunk/docs/AGENT_SCREEN_LOGGING.txt b/agc_2-X/trunk/docs/AGENT_SCREEN_LOGGING.txt new file mode 100644 index 00000000..17abfaad --- /dev/null +++ b/agc_2-X/trunk/docs/AGENT_SCREEN_LOGGING.txt @@ -0,0 +1,117 @@ +AGENT SCREEN LOGGING Started: 2023-04-20 Updated: 2023-04-21 + + + +This document covers some of the various data points that are collected related to usage of the VICIdial Agent Screen. + + + +Agent Screen Usage Logging Items: +- Agent IP Addresses Viewable in the User Stats page and the User Logins Report and others +- Agent Screen Visibility Viewable in the User Stats page +- Agent Screen Latency Viewable in the Real-Time Report, the Agent Latency Report and the Agent Debug Log Report +- Agent Screen Debug Viewable in the Agent Debug Log Report + + + +AGENT IP ADDRESSES: + +Both the agent web IP Address and the agent phone IP address that are used to connect to the VICIdial servers can be logged. The web IP Address is logged by default in several places, and the phone IP Address can be logged by putting the "AST_phone_update.pl" script in the crontab on each of the dialer servers in your cluster. + +These IP addresses are viewable in the "User Stats" page, the "User Logins Report", the "Agent LAGGED Report", the "User Group Login Report" and other reports. + + + +AGENT SCREEN VISIBILITY: + +This metric tells you when the agent is viewing the Agent Screen and when they have hidden that web browser window, as well as how long it was visible or hidden. + +This data is viewable in the "User Stats" page and the "Agent Debug Log Report". + + + +AGENT SCREEN LATENCY: + +This metric measures the amount of time in milliseconds that it takes for the agent's web browser to send a request and receive data back from the VICIdial web server. This data is logged about every second. + +This data is viewable in the Real-Time Report, the Agent Latency Report and the Agent Debug Log Report. + +In the "Real-Time Report", the LATENCY column can appear on the AGENTS table if you enable one of the "Agent Latency" options in the "Report Display Options" panel. The 4 active options for this setting are: + YES = show only the 1 minute average latency + ALL = show the 1-minute average and 1 minute peak latencies + DAY = show the 1-minute, 60-minute and current-day averages and peak latencies + NOW = show only the current latency in real-time + +The "Agent Latency Report" will show either the current day latencies for all active agents, or it will show the archival daily summary history for a single agent as far back as the daily latency log summaries go. + +The "Agent Debug Log Report" will show this data as a part of the "refresh" function log entry data records. + +On the back-end, the 'vicidial_agent_latency_log' database table stores the per-second data. This table is archived and truncated every night and the archives are only stored for 7 days before they are purged. The 'vicidial_live_agents_details' database table stores the real-time data for agents that have logged in during the current day. The 'vicidial_agent_latency_summary_log' database table stores the archival daily summaries of the latency data for each user/IP set and it is generated every night before the vicidial_agent_latency_log is archived(in the "ADMIN_keepalive_ALL.pl" script on the Active Voicemail Server at the Timeclock End of Day). + + + +AGENT SCREEN DEBUG: + +This metric is really a collection of all of the available agent screen debug data put together. This metric is not enabled by default, to use it you need to enable the "Agent Screen Debug Logging" option in System Settings. The data that is collected is only stored on your system for 7 days. + +The "Agent Debug Log Report" will show all of this data, including the back-end communication between the agent screen and the webserver, every active element that the agent clicks on, and the time it takes to perform many of the agent screen functions. + + + + + + + + + + +------------------------------------------------------------------------------------------------- +Database Tables (FOR REFERENCE ONLY!): + +CREATE TABLE vicidial_agent_visibility_log ( +db_time DATETIME NOT NULL, +event_start_epoch INT(10) UNSIGNED, +event_end_epoch INT(10) UNSIGNED, +user VARCHAR(20), +length_in_sec INT(10), +visibility ENUM('VISIBLE','HIDDEN','LOGIN','NONE') default 'NONE', +agent_log_id INT(9) UNSIGNED, +index (db_time), +index (agent_log_id), +unique index visibleuser (user, visibility, event_end_epoch) +) ENGINE=MyISAM; + +CREATE TABLE vicidial_live_agents_details ( +user VARCHAR(20) NOT NULL PRIMARY KEY, +update_date DATETIME, +web_ip VARCHAR(45) default '', +latency MEDIUMINT(7) default '0', +latency_min_avg MEDIUMINT(7) default '0', +latency_min_peak MEDIUMINT(7) default '0', +latency_hour_avg MEDIUMINT(7) default '0', +latency_hour_peak MEDIUMINT(7) default '0', +latency_today_avg MEDIUMINT(7) default '0', +latency_today_peak MEDIUMINT(7) default '0', +index (user), +index (update_date) +) ENGINE=MyISAM; + +CREATE TABLE vicidial_agent_latency_log ( +user VARCHAR(20) NOT NULL, +log_date DATETIME, +latency MEDIUMINT(7) default '0', +web_ip VARCHAR(45) default '', +index (user), +index (log_date) +) ENGINE=MyISAM; + +CREATE TABLE vicidial_agent_latency_summary_log ( +user VARCHAR(20) NOT NULL, +log_date DATETIME, +web_ip VARCHAR(45) default '', +latency_avg MEDIUMINT(7) default '0', +latency_peak MEDIUMINT(7) default '0', +latency_count SMALLINT(4) default '0', +index (user), +index (log_date) +) ENGINE=MyISAM; diff --git a/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql b/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql index b44b0460..dd4baf96 100644 --- a/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql +++ b/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql @@ -4934,6 +4934,41 @@ index (user), index (call_date) ) ENGINE=MyISAM; +CREATE TABLE vicidial_live_agents_details ( +user VARCHAR(20) NOT NULL PRIMARY KEY, +update_date DATETIME, +web_ip VARCHAR(45) default '', +latency MEDIUMINT(7) default '0', +latency_min_avg MEDIUMINT(7) default '0', +latency_min_peak MEDIUMINT(7) default '0', +latency_hour_avg MEDIUMINT(7) default '0', +latency_hour_peak MEDIUMINT(7) default '0', +latency_today_avg MEDIUMINT(7) default '0', +latency_today_peak MEDIUMINT(7) default '0', +index (user), +index (update_date) +) ENGINE=MyISAM; + +CREATE TABLE vicidial_agent_latency_log ( +user VARCHAR(20) NOT NULL, +log_date DATETIME, +latency MEDIUMINT(7) default '0', +web_ip VARCHAR(45) default '', +index (user), +index (log_date) +) ENGINE=MyISAM; + +CREATE TABLE vicidial_agent_latency_summary_log ( +user VARCHAR(20) NOT NULL, +log_date DATETIME, +web_ip VARCHAR(45) default '', +latency_avg MEDIUMINT(7) default '0', +latency_peak MEDIUMINT(7) default '0', +latency_count SMALLINT(4) default '0', +index (user), +index (log_date) +) ENGINE=MyISAM; + ALTER TABLE vicidial_email_list MODIFY message text character set utf8; @@ -5207,6 +5242,12 @@ ALTER TABLE vicidial_agent_notifications_archive MODIFY notification_id INT(10) CREATE TABLE vicidial_user_dial_log_archive LIKE vicidial_user_dial_log; CREATE UNIQUE INDEX vdudl on vicidial_user_dial_log_archive (caller_code,call_date,user); +CREATE TABLE vicidial_agent_latency_log_archive LIKE vicidial_agent_latency_log; +CREATE UNIQUE INDEX vdalla on vicidial_agent_latency_log_archive (user,log_date); + +CREATE TABLE vicidial_agent_latency_summary_log_archive LIKE vicidial_agent_latency_summary_log; +CREATE UNIQUE INDEX vdalsla on vicidial_agent_latency_summary_log_archive (user,log_date,web_ip); + GRANT RELOAD ON *.* TO cron@'%'; GRANT RELOAD ON *.* TO cron@localhost; @@ -5301,4 +5342,4 @@ INSERT INTO `wallboard_reports` VALUES ('AGENTS_AND_QUEUES','Agents and Queues', UPDATE system_settings set vdc_agent_api_active='1'; -UPDATE system_settings SET db_schema_version='1681',db_schema_update_date=NOW(),reload_timestamp=NOW(); +UPDATE system_settings SET db_schema_version='1682',db_schema_update_date=NOW(),reload_timestamp=NOW(); diff --git a/agc_2-X/trunk/extras/upgrade_2.14.sql b/agc_2-X/trunk/extras/upgrade_2.14.sql index b1e37a17..77281766 100644 --- a/agc_2-X/trunk/extras/upgrade_2.14.sql +++ b/agc_2-X/trunk/extras/upgrade_2.14.sql @@ -2226,3 +2226,46 @@ CREATE TABLE vicidial_user_dial_log_archive LIKE vicidial_user_dial_log; CREATE UNIQUE INDEX vdudl on vicidial_user_dial_log_archive (caller_code,call_date,user); UPDATE system_settings SET db_schema_version='1681',db_schema_update_date=NOW() where db_schema_version < 1681; + +CREATE TABLE vicidial_live_agents_details ( +user VARCHAR(20) NOT NULL PRIMARY KEY, +update_date DATETIME, +web_ip VARCHAR(45) default '', +latency MEDIUMINT(7) default '0', +latency_min_avg MEDIUMINT(7) default '0', +latency_min_peak MEDIUMINT(7) default '0', +latency_hour_avg MEDIUMINT(7) default '0', +latency_hour_peak MEDIUMINT(7) default '0', +latency_today_avg MEDIUMINT(7) default '0', +latency_today_peak MEDIUMINT(7) default '0', +index (user), +index (update_date) +) ENGINE=MyISAM; + +CREATE TABLE vicidial_agent_latency_log ( +user VARCHAR(20) NOT NULL, +log_date DATETIME, +latency MEDIUMINT(7) default '0', +web_ip VARCHAR(45) default '', +index (user), +index (log_date) +) ENGINE=MyISAM; + +CREATE TABLE vicidial_agent_latency_summary_log ( +user VARCHAR(20) NOT NULL, +log_date DATETIME, +web_ip VARCHAR(45) default '', +latency_avg MEDIUMINT(7) default '0', +latency_peak MEDIUMINT(7) default '0', +latency_count SMALLINT(4) default '0', +index (user), +index (log_date) +) ENGINE=MyISAM; + +CREATE TABLE vicidial_agent_latency_log_archive LIKE vicidial_agent_latency_log; +CREATE UNIQUE INDEX vdalla on vicidial_agent_latency_log_archive (user,log_date); + +CREATE TABLE vicidial_agent_latency_summary_log_archive LIKE vicidial_agent_latency_summary_log; +CREATE UNIQUE INDEX vdalsla on vicidial_agent_latency_summary_log_archive (user,log_date,web_ip); + +UPDATE system_settings SET db_schema_version='1682',db_schema_update_date=NOW() where db_schema_version < 1682; diff --git a/agc_2-X/trunk/www/agc/conf_exten_check.php b/agc_2-X/trunk/www/agc/conf_exten_check.php index 50c2d8f8..034f252e 100644 --- a/agc_2-X/trunk/www/agc/conf_exten_check.php +++ b/agc_2-X/trunk/www/agc/conf_exten_check.php @@ -94,10 +94,11 @@ # 220310-0934 - Added more time-sync detailed logging # 230220-1759 - Fix for In-Group manual dial issue # 230412-1020 - Added code for send_notification API function +# 230420-2020 - Added latency logging # -$version = '2.14-68'; -$build = '230412-1020'; +$version = '2.14-69'; +$build = '230420-2020'; $php_script = 'conf_exten_check.php'; $mel=1; # Mysql Error Log enabled = 1 $mysql_log_count=51; @@ -106,6 +107,7 @@ $DB=0; $VD_login=0; $SSagent_debug_logging=0; $startMS = microtime(); +$ip = getenv("REMOTE_ADDR"); require_once("dbconnect_mysqli.php"); require_once("functions.php"); @@ -159,6 +161,8 @@ if (isset($_GET["visibility"])) {$visibility=$_GET["visibility"];} elseif (isset($_POST["visibility"])) {$visibility=$_POST["visibility"];} if (isset($_GET["active_ingroup_dial"])) {$active_ingroup_dial=$_GET["active_ingroup_dial"];} elseif (isset($_POST["active_ingroup_dial"])) {$active_ingroup_dial=$_POST["active_ingroup_dial"];} +if (isset($_GET["latency"])) {$latency=$_GET["latency"];} + elseif (isset($_POST["latency"])) {$latency=$_POST["latency"];} $DB=preg_replace("/[^0-9a-zA-Z]/","",$DB); @@ -234,6 +238,7 @@ $client = preg_replace("/[^-_0-9a-zA-Z]/","",$client); $campagentstdisp = preg_replace("/[^-_0-9a-zA-Z]/","",$campagentstdisp); $phone_number = preg_replace("/[^-_0-9a-zA-Z]/","",$phone_number); $xferchannel = preg_replace("/\'|\"|\\\\|;/","",$xferchannel); +$latency = preg_replace("/[^-_0-9a-zA-Z]/","",$latency); if ($non_latin < 1) { @@ -832,6 +837,18 @@ if ($ACTION == 'refresh') $retry_count++; } + ### update the vicidial_live_agents_details record + $stmt="UPDATE vicidial_live_agents_details set latency='$latency',web_ip='$ip',update_date=NOW() where user='$user';"; + if ($format=='debug') {echo "\n";} + $rslt=mysql_to_mysqli($stmt, $link); + if ($mel > 0) {$errno = mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'03XXX',$user,$server_ip,$session_name,$one_mysql_log);} + + ### insert a vicidial_agent_latency_log record + $stmt="INSERT INTO vicidial_agent_latency_log SET latency='$latency',web_ip='$ip',user='$user',log_date=NOW();"; + if ($format=='debug') {echo "\n";} + $rslt=mysql_to_mysqli($stmt, $link); + if ($mel > 0) {$errno = mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'03XXX',$user,$server_ip,$session_name,$one_mysql_log);} + if ( ( ($Acomments != 'CHAT') and ($Acomments != 'EMAIL') and (strlen($active_ingroup_dial) < 1) ) or ($live_call_seconds > 4) ) { ##### BEGIN DEAD logging section ##### @@ -919,6 +936,18 @@ if ($ACTION == 'refresh') $retry_count++; } + ### update the vicidial_live_agents_details record + $stmt="UPDATE vicidial_live_agents_details set latency='$latency',web_ip='$ip',update_date=NOW() where user='$user';"; + if ($format=='debug') {echo "\n";} + $rslt=mysql_to_mysqli($stmt, $link); + if ($mel > 0) {$errno = mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'03XXX',$user,$server_ip,$session_name,$one_mysql_log);} + + ### insert a vicidial_agent_latency_log record + $stmt="INSERT INTO vicidial_agent_latency_log SET latency='$latency',web_ip='$ip',user='$user',log_date=NOW();"; + if ($format=='debug') {echo "\n";} + $rslt=mysql_to_mysqli($stmt, $link); + if ($mel > 0) {$errno = mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'03XXX',$user,$server_ip,$session_name,$one_mysql_log);} + ##### BEGIN DEAD logging section ##### if ($Acomments != 'EMAIL') { @@ -1478,7 +1507,7 @@ if ($ACTION == 'refresh') } echo "$countecho\n"; - $stage = "$Astatus|$Aagent_log_id$DEADlog"; + $stage = "$Astatus|$Aagent_log_id|".$latency."ms|$DEADlog"; } diff --git a/agc_2-X/trunk/www/agc/vicidial.php b/agc_2-X/trunk/www/agc/vicidial.php index 34d194c2..b614e4df 100644 --- a/agc_2-X/trunk/www/agc/vicidial.php +++ b/agc_2-X/trunk/www/agc/vicidial.php @@ -717,10 +717,11 @@ # 230407-1839 - Fix for input variable filter issue # 230412-1018 - Added code for send_notification API function # 230418-1425 - Added vicidial_user_dial_log logging +# 230420-2015 - Added latency calculation and logging, Issue #1457 # -$version = '2.14-685c'; -$build = '230418-1425'; +$version = '2.14-686c'; +$build = '230420-2015'; $php_script = 'vicidial.php'; $mel=1; # Mysql Error Log enabled = 1 $mysql_log_count=102; @@ -4389,6 +4390,11 @@ else $affected_rows = mysqli_affected_rows($link); echo "\n"; + $stmt="INSERT IGNORE INTO vicidial_live_agents_details set latency='0',web_ip='$ip',update_date=NOW(),user='$VD_login';"; + if ($format=='debug') {echo "\n";} + $rslt=mysql_to_mysqli($stmt, $link); + if ($mel > 0) {$errno = mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'03XXX',$user,$server_ip,$session_name,$one_mysql_log);} + if ($enable_queuemetrics_logging > 0) { $QM_LOGIN = 'AGENTLOGIN'; @@ -6076,7 +6082,7 @@ if ($enable_fast_refresh < 1) {echo "\tvar refresh_interval = 1000;\n";} var image_LB_mute_recording_ON = new Image(); image_LB_mute_recording_ON.src="./images/"; var set_timeout_audio_loop = false; - + var latency = 0; 0) { @@ -7144,11 +7150,12 @@ function set_length(SLnumber,SLlength_goal,SLdirection) //alert ("1"); if (!xmlhttprequestcheckconf && typeof XMLHttpRequest!='undefined') { + var request_start_time = Date.now(); xmlhttprequestcheckconf = new XMLHttpRequest(); } if (xmlhttprequestcheckconf) { - checkconf_query = "server_ip=" + server_ip + "&session_name=" + session_name + "&user=" + user + "&pass=" + pass + "&client=vdc&conf_exten=" + taskconfnum + "&auto_dial_level=" + auto_dial_level + "&campagentstdisp=" + campagentstdisp + "&customer_chat_id=" + document.vicidial_form.customer_chat_id.value + "&live_call_seconds=" + VD_live_call_secondS + "&active_ingroup_dial=" + active_ingroup_dial + "&xferchannel=" + document.vicidial_form.xferchannel.value + "&check_for_answer=" + MDcheck_for_answer + "&MDnextCID=" + MDnextCID + "&campaign=" + campaign + "&phone_number=" + dialed_number + "&visibility=" + visibility_log + "&clicks=" + button_click_log; + checkconf_query = "server_ip=" + server_ip + "&session_name=" + session_name + "&user=" + user + "&pass=" + pass + "&client=vdc&conf_exten=" + taskconfnum + "&auto_dial_level=" + auto_dial_level + "&campagentstdisp=" + campagentstdisp + "&customer_chat_id=" + document.vicidial_form.customer_chat_id.value + "&live_call_seconds=" + VD_live_call_secondS + "&active_ingroup_dial=" + active_ingroup_dial + "&xferchannel=" + document.vicidial_form.xferchannel.value + "&check_for_answer=" + MDcheck_for_answer + "&MDnextCID=" + MDnextCID + "&campaign=" + campaign + "&phone_number=" + dialed_number + "&visibility=" + visibility_log + "&latency=" + latency + "&clicks=" + button_click_log; button_click_log=''; visibility_log=''; xmlhttprequestcheckconf.open('POST', 'conf_exten_check.php'); @@ -7158,6 +7165,10 @@ function set_length(SLnumber,SLlength_goal,SLdirection) { if (xmlhttprequestcheckconf && xmlhttprequestcheckconf.readyState == 4 && xmlhttprequestcheckconf.status == 200) { + var request_end_time = Date.now(); + // Calculate latency + latency = parseInt(request_end_time) - parseInt(request_start_time); + var check_conf = null; var LMAforce = taskforce; check_conf = xmlhttprequestcheckconf.responseText; @@ -7970,8 +7981,8 @@ function set_length(SLnumber,SLlength_goal,SLdirection) {blind_monitoring_now=0;} } } - delete xmlhttprequestcheckconf; - xmlhttprequestcheckconf = undefined; + delete xmlhttprequestcheckconf; + xmlhttprequestcheckconf = undefined; } else if (xmlhttprequestcheckconf && xmlhttprequestcheckconf.readyState == 4 && xmlhttprequestcheckconf.status != 200) { @@ -8955,7 +8966,6 @@ function set_length(SLnumber,SLlength_goal,SLdirection) { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { - var AlerTrslt = xmlhttp.responseText; if (AlerTrslt.length>0) { diff --git a/agc_2-X/trunk/www/vicidial/AST_timeonVDADall.php b/agc_2-X/trunk/www/vicidial/AST_timeonVDADall.php index 02e279b1..81e1ff7b 100644 --- a/agc_2-X/trunk/www/vicidial/AST_timeonVDADall.php +++ b/agc_2-X/trunk/www/vicidial/AST_timeonVDADall.php @@ -128,10 +128,11 @@ # 220217-2045 - Added input variable filters # 220221-1535 - Added allow_web_debug system setting # 230308-0215 - Added option to show customer phone code +# 230421-0107 - Added AGENTlatency display # -$version = '2.14-113'; -$build = '230308-0215'; +$version = '2.14-114'; +$build = '230421-0107'; $php_script='AST_timeonVDADall.php'; require("dbconnect_mysqli.php"); @@ -234,6 +235,8 @@ if (isset($_GET["PRESETstats"])) {$PRESETstats=$_GET["PRESETstats"];} elseif (isset($_POST["PRESETstats"])) {$PRESETstats=$_POST["PRESETstats"];} if (isset($_GET["AGENTtimeSTATS"])) {$AGENTtimeSTATS=$_GET["AGENTtimeSTATS"];} elseif (isset($_POST["AGENTtimeSTATS"])) {$AGENTtimeSTATS=$_POST["AGENTtimeSTATS"];} +if (isset($_GET["AGENTlatency"])) {$AGENTlatency=$_GET["AGENTlatency"];} + elseif (isset($_POST["AGENTlatency"])) {$AGENTlatency=$_POST["AGENTlatency"];} if (isset($_GET["INGROUPcolorOVERRIDE"])) {$INGROUPcolorOVERRIDE=$_GET["INGROUPcolorOVERRIDE"];} elseif (isset($_POST["INGROUPcolorOVERRIDE"])) {$INGROUPcolorOVERRIDE=$_POST["INGROUPcolorOVERRIDE"];} if (isset($_GET["RTajax"])) {$RTajax=$_GET["RTajax"];} @@ -451,6 +454,7 @@ $ShowCustPhoneCode = preg_replace('/[^-_0-9a-zA-Z]/', '', $ShowCustPhoneCode); $CARRIERstats = preg_replace('/[^-_0-9a-zA-Z]/', '', $CARRIERstats); $PRESETstats = preg_replace('/[^-_0-9a-zA-Z]/', '', $PRESETstats); $AGENTtimeSTATS = preg_replace('/[^-_0-9a-zA-Z]/', '', $AGENTtimeSTATS); +$AGENTlatency = preg_replace('/[^-_0-9a-zA-Z]/', '', $AGENTlatency); $parkSTATS = preg_replace('/[^-_0-9a-zA-Z]/', '', $parkSTATS); $SLAinSTATS = preg_replace('/[^-_0-9a-zA-Z]/', '', $SLAinSTATS); $INGROUPcolorOVERRIDE = preg_replace('/[^-_0-9a-zA-Z]/', '', $INGROUPcolorOVERRIDE); @@ -1074,6 +1078,25 @@ $select_list .= "