Merge branch 'storageareas' into zma_to_thread
Conflicts: scripts/zmwatch.pl.in src/zm_ffmpeg_camera.cpp src/zm_monitor.cpp src/zmc.cpp
This commit is contained in:
commit
d8e4b0abfb
|
@ -224,10 +224,41 @@ CREATE TABLE `Events_Hour` (
|
||||||
`StartTime` datetime default NULL,
|
`StartTime` datetime default NULL,
|
||||||
`DiskSpace` bigint unsigned default NULL,
|
`DiskSpace` bigint unsigned default NULL,
|
||||||
PRIMARY KEY (`EventId`),
|
PRIMARY KEY (`EventId`),
|
||||||
KEY `Events_Hour_MonitorId_idx` (`MonitorId`)
|
KEY `Events_Hour_MonitorId_idx` (`MonitorId`),
|
||||||
KEY `Events_Hour_StartTime_idx` (`StartTime`)
|
KEY `Events_Hour_StartTime_idx` (`StartTime`)
|
||||||
) ENGINE=@ZM_MYSQL_ENGINE@;
|
) ENGINE=@ZM_MYSQL_ENGINE@;
|
||||||
|
|
||||||
|
delimiter //
|
||||||
|
DROP TRIGGER IF EXISTS Events_Hour_delete_trigger//
|
||||||
|
CREATE TRIGGER Events_Hour_delete_trigger BEFORE DELETE ON Events_Hour
|
||||||
|
FOR EACH ROW BEGIN
|
||||||
|
UPDATE Monitors SET
|
||||||
|
HourEvents = COALESCE(HourEvents,1)-1,
|
||||||
|
HourEventDiskSpace=COALESCE(HourEventDiskSpace)-COALESCE(OLD.DiskSpace,0)
|
||||||
|
WHERE Id=OLD.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Hour_update_trigger//
|
||||||
|
|
||||||
|
CREATE TRIGGER Events_Hour_update_trigger AFTER UPDATE ON Events_Hour
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
declare diff BIGINT default 0;
|
||||||
|
|
||||||
|
set diff = COALESCE(NEW.DiskSpace,0) - COALESCE(OLD.DiskSpace,0);
|
||||||
|
IF ( diff ) THEN
|
||||||
|
IF ( NEW.MonitorID != OLD.MonitorID ) THEN
|
||||||
|
UPDATE Monitors SET HourEventDiskSpace=COALESCE(DayEventDiskSpace,0)-OLD.DiskSpace WHERE Monitors.Id=OLD.MonitorId;
|
||||||
|
UPDATE Monitors SET HourEventDiskSpace=COALESCE(DayEventDiskSpace,0)+NEW.DiskSpace WHERE Monitors.Id=NEW.MonitorId;
|
||||||
|
ELSE
|
||||||
|
UPDATE Monitors SET HourEventDiskSpace=COALESCE(DayEventDiskSpace,0)+diff WHERE Monitors.Id=NEW.MonitorId;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
|
||||||
|
DELIMITER ;
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `Events_Day`;
|
DROP TABLE IF EXISTS `Events_Day`;
|
||||||
CREATE TABLE `Events_Day` (
|
CREATE TABLE `Events_Day` (
|
||||||
`EventId` int(10) unsigned NOT NULL,
|
`EventId` int(10) unsigned NOT NULL,
|
||||||
|
@ -235,11 +266,41 @@ CREATE TABLE `Events_Day` (
|
||||||
`StartTime` datetime default NULL,
|
`StartTime` datetime default NULL,
|
||||||
`DiskSpace` bigint unsigned default NULL,
|
`DiskSpace` bigint unsigned default NULL,
|
||||||
PRIMARY KEY (`EventId`),
|
PRIMARY KEY (`EventId`),
|
||||||
KEY `Events_Day_MonitorId_idx` (`MonitorId`)
|
KEY `Events_Day_MonitorId_idx` (`MonitorId`),
|
||||||
KEY `Events_Day_StartTime_idx` (`StartTime`)
|
KEY `Events_Day_StartTime_idx` (`StartTime`)
|
||||||
) ENGINE=@ZM_MYSQL_ENGINE@;
|
) ENGINE=@ZM_MYSQL_ENGINE@;
|
||||||
|
|
||||||
|
delimiter //
|
||||||
|
DROP TRIGGER IF EXISTS Events_Day_delete_trigger//
|
||||||
|
CREATE TRIGGER Events_Day_delete_trigger BEFORE DELETE ON Events_Day
|
||||||
|
FOR EACH ROW BEGIN
|
||||||
|
UPDATE Monitors SET
|
||||||
|
DayEvents = COALESCE(DayEvents,1)-1,
|
||||||
|
DayEventDiskSpace=COALESCE(DayEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
|
WHERE Id=OLD.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Day_update_trigger;
|
||||||
|
CREATE TRIGGER Events_Day_update_trigger AFTER UPDATE ON Events_Day
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
declare diff BIGINT default 0;
|
||||||
|
|
||||||
|
set diff = COALESCE(NEW.DiskSpace,0) - COALESCE(OLD.DiskSpace,0);
|
||||||
|
IF ( diff ) THEN
|
||||||
|
IF ( NEW.MonitorID != OLD.MonitorID ) THEN
|
||||||
|
UPDATE Monitors SET DayEventDiskSpace=COALESCE(DayEventDiskSpace,0)-OLD.DiskSpace WHERE Monitors.Id=OLD.MonitorId;
|
||||||
|
UPDATE Monitors SET DayEventDiskSpace=COALESCE(DayEventDiskSpace,0)+NEW.DiskSpace WHERE Monitors.Id=NEW.MonitorId;
|
||||||
|
ELSE
|
||||||
|
UPDATE Monitors SET DayEventDiskSpace=COALESCE(DayEventDiskSpace,0)+diff WHERE Monitors.Id=NEW.MonitorId;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
DELIMITER ;
|
||||||
DROP TABLE IF EXISTS `Events_Week`;
|
DROP TABLE IF EXISTS `Events_Week`;
|
||||||
CREATE TABLE `Events_Week` (
|
CREATE TABLE `Events_Week` (
|
||||||
`EventId` int(10) unsigned NOT NULL,
|
`EventId` int(10) unsigned NOT NULL,
|
||||||
|
@ -247,10 +308,41 @@ CREATE TABLE `Events_Week` (
|
||||||
`StartTime` datetime default NULL,
|
`StartTime` datetime default NULL,
|
||||||
`DiskSpace` bigint unsigned default NULL,
|
`DiskSpace` bigint unsigned default NULL,
|
||||||
PRIMARY KEY (`EventId`),
|
PRIMARY KEY (`EventId`),
|
||||||
KEY `Events_Week_MonitorId_idx` (`MonitorId`)
|
KEY `Events_Week_MonitorId_idx` (`MonitorId`),
|
||||||
KEY `Events_Week_StartTime_idx` (`StartTime`)
|
KEY `Events_Week_StartTime_idx` (`StartTime`)
|
||||||
) ENGINE=@ZM_MYSQL_ENGINE@;
|
) ENGINE=@ZM_MYSQL_ENGINE@;
|
||||||
|
|
||||||
|
delimiter //
|
||||||
|
DROP TRIGGER IF EXISTS Events_Week_delete_trigger//
|
||||||
|
CREATE TRIGGER Events_Week_delete_trigger BEFORE DELETE ON Events_Week
|
||||||
|
FOR EACH ROW BEGIN
|
||||||
|
UPDATE Monitors SET
|
||||||
|
WeekEvents = COALESCE(WeekEvents,1)-1,
|
||||||
|
WeekEventDiskSpace=COALESCE(WeekEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
|
WHERE Id=OLD.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Week_update_trigger;
|
||||||
|
CREATE TRIGGER Events_Week_update_trigger AFTER UPDATE ON Events_Week
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
declare diff BIGINT default 0;
|
||||||
|
|
||||||
|
set diff = COALESCE(NEW.DiskSpace,0) - COALESCE(OLD.DiskSpace,0);
|
||||||
|
IF ( diff ) THEN
|
||||||
|
IF ( NEW.MonitorID != OLD.MonitorID ) THEN
|
||||||
|
UPDATE Monitors SET WeekEventDiskSpace=COALESCE(WeekEventDiskSpace,0)-OLD.DiskSpace WHERE Monitors.Id=OLD.MonitorId;
|
||||||
|
UPDATE Monitors SET WeekEventDiskSpace=COALESCE(WeekEventDiskSpace,0)+NEW.DiskSpace WHERE Monitors.Id=NEW.MonitorId;
|
||||||
|
ELSE
|
||||||
|
UPDATE Monitors SET WeekEventDiskSpace=COALESCE(WeekEventDiskSpace,0)+diff WHERE Monitors.Id=NEW.MonitorId;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DELIMITER ;
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `Events_Month`;
|
DROP TABLE IF EXISTS `Events_Month`;
|
||||||
CREATE TABLE `Events_Month` (
|
CREATE TABLE `Events_Month` (
|
||||||
`EventId` int(10) unsigned NOT NULL,
|
`EventId` int(10) unsigned NOT NULL,
|
||||||
|
@ -258,10 +350,42 @@ CREATE TABLE `Events_Month` (
|
||||||
`StartTime` datetime default NULL,
|
`StartTime` datetime default NULL,
|
||||||
`DiskSpace` bigint unsigned default NULL,
|
`DiskSpace` bigint unsigned default NULL,
|
||||||
PRIMARY KEY (`EventId`),
|
PRIMARY KEY (`EventId`),
|
||||||
KEY `Events_Month_MonitorId_idx` (`MonitorId`)
|
KEY `Events_Month_MonitorId_idx` (`MonitorId`),
|
||||||
KEY `Events_Month_StartTime_idx` (`StartTime`)
|
KEY `Events_Month_StartTime_idx` (`StartTime`)
|
||||||
) ENGINE=@ZM_MYSQL_ENGINE@;
|
) ENGINE=@ZM_MYSQL_ENGINE@;
|
||||||
|
|
||||||
|
delimiter //
|
||||||
|
DROP TRIGGER IF EXISTS Events_Month_delete_trigger//
|
||||||
|
CREATE TRIGGER Events_Month_delete_trigger BEFORE DELETE ON Events_Month
|
||||||
|
FOR EACH ROW BEGIN
|
||||||
|
UPDATE Monitors SET
|
||||||
|
MonthEvents = COALESCE(MonthEvents,1)-1,
|
||||||
|
MonthEventDiskSpace=COALESCE(MonthEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
|
WHERE Id=OLD.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Month_update_trigger;
|
||||||
|
CREATE TRIGGER Events_Month_update_trigger AFTER UPDATE ON Events_Month
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
declare diff BIGINT default 0;
|
||||||
|
|
||||||
|
set diff = COALESCE(NEW.DiskSpace,0) - COALESCE(OLD.DiskSpace,0);
|
||||||
|
IF ( diff ) THEN
|
||||||
|
IF ( NEW.MonitorID != OLD.MonitorID ) THEN
|
||||||
|
UPDATE Monitors SET MonthEventDiskSpace=COALESCE(MonthEventDiskSpace,0)-OLD.DiskSpace WHERE Monitors.Id=OLD.MonitorId;
|
||||||
|
UPDATE Monitors SET MonthEventDiskSpace=COALESCE(MonthEventDiskSpace,0)+NEW.DiskSpace WHERE Monitors.Id=NEW.MonitorId;
|
||||||
|
ELSE
|
||||||
|
UPDATE Monitors SET MonthEventDiskSpace=COALESCE(MonthEventDiskSpace,0)+diff WHERE Monitors.Id=NEW.MonitorId;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
DELIMITER ;
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `Events_Archived`;
|
DROP TABLE IF EXISTS `Events_Archived`;
|
||||||
CREATE TABLE `Events_Archived` (
|
CREATE TABLE `Events_Archived` (
|
||||||
|
@ -346,27 +470,30 @@ delimiter ;
|
||||||
DROP TRIGGER IF EXISTS event_insert_trigger;
|
DROP TRIGGER IF EXISTS event_insert_trigger;
|
||||||
|
|
||||||
delimiter //
|
delimiter //
|
||||||
create trigger event_insert_trigger after insert on Events
|
/* The assumption is that when an Event is inserted, it has no size yet, so don't bother updating the DiskSpace, just the count.
|
||||||
for each row
|
* The DiskSpace will get update in the Event Update Trigger
|
||||||
begin
|
*/
|
||||||
|
CREATE TRIGGER event_insert_trigger AFTER INSERT ON Events
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
|
||||||
INSERT INTO Events_Hour (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
INSERT INTO Events_Hour (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
||||||
INSERT INTO Events_Day (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
INSERT INTO Events_Day (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
||||||
INSERT INTO Events_Week (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
INSERT INTO Events_Week (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
||||||
INSERT INTO Events_Month (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
INSERT INTO Events_Month (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
||||||
UPDATE Monitors SET TotalEvents = COALESCE(TotalEvents,0)+1 WHERE Id=NEW.MonitorId;
|
UPDATE Monitors SET
|
||||||
end;
|
HourEvents = COALESCE(DayEvents,0)+1,
|
||||||
|
DayEvents = COALESCE(DayEvents,0)+1,
|
||||||
|
WeekEvents = COALESCE(DayEvents,0)+1,
|
||||||
|
MonthEvents = COALESCE(DayEvents,0)+1,
|
||||||
|
TotalEvents = COALESCE(TotalEvents,0)+1
|
||||||
|
WHERE Id=NEW.MonitorId;
|
||||||
|
END;
|
||||||
//
|
//
|
||||||
|
|
||||||
delimiter ;
|
DROP TRIGGER IF EXISTS event_delete_trigger//
|
||||||
|
|
||||||
|
|
||||||
drop trigger if exists event_delete_trigger;
|
|
||||||
|
|
||||||
delimiter //
|
|
||||||
|
|
||||||
CREATE TRIGGER event_delete_trigger BEFORE DELETe on Events
|
|
||||||
|
|
||||||
|
CREATE TRIGGER event_delete_trigger BEFORE DELETE ON Events
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
call update_storage_stats(OLD.StorageId, -OLD.DiskSpace);
|
call update_storage_stats(OLD.StorageId, -OLD.DiskSpace);
|
||||||
|
@ -378,14 +505,14 @@ BEGIN
|
||||||
DELETE FROM Events_Archived WHERE EventId=OLD.Id;
|
DELETE FROM Events_Archived WHERE EventId=OLD.Id;
|
||||||
UPDATE Monitors SET
|
UPDATE Monitors SET
|
||||||
ArchivedEvents = ArchivedEvents - 1,
|
ArchivedEvents = ArchivedEvents - 1,
|
||||||
ArchivedEventDiskSpace = ArchivedEventDiskSpace - OLD.DiskSpace,
|
ArchivedEventDiskSpace = COALESCE(ArchivedEventDiskSpace,0) - COALESCE(OLD.DiskSpace,0),
|
||||||
TotalEvents = TotalEvents - 1,
|
TotalEvents = TotalEvents - 1,
|
||||||
TotalEventDiskSpace = TotalEventDiskSpace - OLD.DiskSpace
|
TotalEventDiskSpace = COALESCE(TotalEventDiskSpace,0) - COALESCE(OLD.DiskSpace,0)
|
||||||
WHERE Id=OLD.MonitorId;
|
WHERE Id=OLD.MonitorId;
|
||||||
ELSE
|
ELSE
|
||||||
UPDATE Monitors SET
|
UPDATE Monitors SET
|
||||||
TotalEvents = TotalEvents-1,
|
TotalEvents = TotalEvents-1,
|
||||||
TotalEventDiskSpace=TotalEventDiskSpace-OLD.DiskSpace
|
TotalEventDiskSpace=COALESCE(TotalEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
WHERE Id=OLD.MonitorId;
|
WHERE Id=OLD.MonitorId;
|
||||||
END IF;
|
END IF;
|
||||||
END;
|
END;
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
drop trigger if exists event_delete_trigger;
|
||||||
|
|
||||||
|
delimiter //
|
||||||
|
|
||||||
|
CREATE TRIGGER event_delete_trigger BEFORE DELETe on Events
|
||||||
|
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
call update_storage_stats(OLD.StorageId, -OLD.DiskSpace);
|
||||||
|
DELETE FROM Events_Hour WHERE EventId=OLD.Id;
|
||||||
|
DELETE FROM Events_Day WHERE EventId=OLD.Id;
|
||||||
|
DELETE FROM Events_Week WHERE EventId=OLD.Id;
|
||||||
|
DELETE FROM Events_Month WHERE EventId=OLD.Id;
|
||||||
|
IF ( OLD.Archived ) THEN
|
||||||
|
DELETE FROM Events_Archived WHERE EventId=OLD.Id;
|
||||||
|
UPDATE Monitors SET
|
||||||
|
ArchivedEvents = ArchivedEvents - 1,
|
||||||
|
ArchivedEventDiskSpace = COALESCE(ArchivedEventDiskSpace,0) - COALESCE(OLD.DiskSpace,0),
|
||||||
|
TotalEvents = TotalEvents - 1,
|
||||||
|
TotalEventDiskSpace = COALESCE(TotalEventDiskSpace,0) - COALESCE(OLD.DiskSpace,0)
|
||||||
|
WHERE Id=OLD.MonitorId;
|
||||||
|
ELSE
|
||||||
|
UPDATE Monitors SET
|
||||||
|
TotalEvents = TotalEvents-1,
|
||||||
|
TotalEventDiskSpace=COALESCE(TotalEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
|
WHERE Id=OLD.MonitorId;
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
|
||||||
|
//
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
delimiter //
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Hour_delete_trigger//
|
||||||
|
CREATE TRIGGER Events_Hour_delete_trigger BEFORE DELETE ON Events_Hour
|
||||||
|
FOR EACH ROW BEGIN
|
||||||
|
UPDATE Monitors SET
|
||||||
|
HourEvents = COALESCE(HourEvents,1)-1,
|
||||||
|
HourEventDiskSpace=COALESCE(HourEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
|
WHERE Id=OLD.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Day_delete_trigger//
|
||||||
|
CREATE TRIGGER Events_Day_delete_trigger BEFORE DELETE ON Events_Day
|
||||||
|
FOR EACH ROW BEGIN
|
||||||
|
UPDATE Monitors SET
|
||||||
|
DayEvents = COALESCE(DayEvents,1)-1,
|
||||||
|
DayEventDiskSpace=COALESCE(DayEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
|
WHERE Id=OLD.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Week_delete_trigger//
|
||||||
|
CREATE TRIGGER Events_Week_delete_trigger BEFORE DELETE ON Events_Week
|
||||||
|
FOR EACH ROW BEGIN
|
||||||
|
UPDATE Monitors SET
|
||||||
|
WeekEvents = COALESCE(WeekEvents,1)-1,
|
||||||
|
WeekEventDiskSpace=COALESCE(WeekEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
|
WHERE Id=OLD.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Month_delete_trigger//
|
||||||
|
CREATE TRIGGER Events_Month_delete_trigger BEFORE DELETE ON Events_Month
|
||||||
|
FOR EACH ROW BEGIN
|
||||||
|
UPDATE Monitors SET
|
||||||
|
MonthEvents = COALESCE(MonthEvents,1)-1,
|
||||||
|
MonthEventDiskSpace=COALESCE(MonthEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
|
WHERE Id=OLD.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS event_insert_trigger//
|
||||||
|
|
||||||
|
CREATE TRIGGER event_insert_trigger AFTER INSERT ON Events
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO Events_Hour (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
||||||
|
INSERT INTO Events_Day (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
||||||
|
INSERT INTO Events_Week (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
||||||
|
INSERT INTO Events_Month (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
||||||
|
UPDATE Monitors SET
|
||||||
|
HourEvents = COALESCE(HourEvents,0)+1,
|
||||||
|
DayEvents = COALESCE(DayEvents,0)+1,
|
||||||
|
WeekEvents = COALESCE(WeekEvents,0)+1,
|
||||||
|
MonthEvents = COALESCE(MonthEvents,0)+1,
|
||||||
|
TotalEvents = COALESCE(TotalEvents,0)+1
|
||||||
|
WHERE Id=NEW.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,140 @@
|
||||||
|
delimiter //
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Hour_delete_trigger//
|
||||||
|
CREATE TRIGGER Events_Hour_delete_trigger BEFORE DELETE ON Events_Hour
|
||||||
|
FOR EACH ROW BEGIN
|
||||||
|
UPDATE Monitors SET
|
||||||
|
HourEvents = COALESCE(HourEvents,1)-1,
|
||||||
|
HourEventDiskSpace=COALESCE(HourEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
|
WHERE Id=OLD.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Hour_update_trigger;
|
||||||
|
CREATE TRIGGER Events_Hour_update_trigger AFTER UPDATE ON Events_Hour
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
declare diff BIGINT default 0;
|
||||||
|
|
||||||
|
set diff = COALESCE(NEW.DiskSpace,0) - COALESCE(OLD.DiskSpace,0);
|
||||||
|
IF ( diff ) THEN
|
||||||
|
UPDATE Monitors SET HourEventDiskSpace=COALESCE(HourEventDiskSpace,0)+diff WHERE Monitors.Id=MonitorId;
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Day_delete_trigger//
|
||||||
|
CREATE TRIGGER Events_Day_delete_trigger BEFORE DELETE ON Events_Day
|
||||||
|
FOR EACH ROW BEGIN
|
||||||
|
UPDATE Monitors SET
|
||||||
|
DayEvents = COALESCE(DayEvents,1)-1,
|
||||||
|
DayEventDiskSpace=COALESCE(DayEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
|
WHERE Id=OLD.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Day_update_trigger;
|
||||||
|
CREATE TRIGGER Events_Day_update_trigger AFTER UPDATE ON Events_Day
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
declare diff BIGINT default 0;
|
||||||
|
|
||||||
|
set diff = COALESCE(NEW.DiskSpace,0) - COALESCE(OLD.DiskSpace,0);
|
||||||
|
IF ( diff ) THEN
|
||||||
|
UPDATE Monitors SET DayEventDiskSpace=COALESCE(DayEventDiskSpace,0)+diff WHERE Monitors.Id=MonitorId;
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Week_delete_trigger//
|
||||||
|
CREATE TRIGGER Events_Week_delete_trigger BEFORE DELETE ON Events_Week
|
||||||
|
FOR EACH ROW BEGIN
|
||||||
|
UPDATE Monitors SET
|
||||||
|
WeekEvents = COALESCE(WeekEvents,1)-1,
|
||||||
|
WeekEventDiskSpace=COALESCE(WeekEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
|
WHERE Id=OLD.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Week_update_trigger;
|
||||||
|
CREATE TRIGGER Events_Week_update_trigger AFTER UPDATE ON Events_Week
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
declare diff BIGINT default 0;
|
||||||
|
|
||||||
|
set diff = COALESCE(NEW.DiskSpace,0) - COALESCE(OLD.DiskSpace,0);
|
||||||
|
IF ( diff ) THEN
|
||||||
|
UPDATE Monitors SET WeekEventDiskSpace=COALESCE(WeekEventDiskSpace,0)+diff WHERE Monitors.Id=MonitorId;
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Month_delete_trigger//
|
||||||
|
CREATE TRIGGER Events_Month_delete_trigger BEFORE DELETE ON Events_Month
|
||||||
|
FOR EACH ROW BEGIN
|
||||||
|
UPDATE Monitors SET
|
||||||
|
MonthEvents = COALESCE(MonthEvents,1)-1,
|
||||||
|
MonthEventDiskSpace=COALESCE(MonthEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
|
WHERE Id=OLD.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Month_update_trigger;
|
||||||
|
CREATE TRIGGER Events_Month_update_trigger AFTER UPDATE ON Events_Month
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
declare diff BIGINT default 0;
|
||||||
|
|
||||||
|
set diff = COALESCE(NEW.DiskSpace,0) - COALESCE(OLD.DiskSpace,0);
|
||||||
|
IF ( diff ) THEN
|
||||||
|
UPDATE Monitors SET MonthEventDiskSpace=COALESCE(MonthEventDiskSpace,0)+diff WHERE Monitors.Id=MonitorId;
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS event_insert_trigger//
|
||||||
|
|
||||||
|
CREATE TRIGGER event_insert_trigger AFTER INSERT ON Events
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO Events_Hour (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
||||||
|
INSERT INTO Events_Day (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
||||||
|
INSERT INTO Events_Week (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
||||||
|
INSERT INTO Events_Month (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
||||||
|
UPDATE Monitors SET
|
||||||
|
HourEvents = COALESCE(HourEvents,0)+1,
|
||||||
|
DayEvents = COALESCE(DayEvents,0)+1,
|
||||||
|
WeekEvents = COALESCE(WeekEvents,0)+1,
|
||||||
|
MonthEvents = COALESCE(MonthEvents,0)+1,
|
||||||
|
TotalEvents = COALESCE(TotalEvents,0)+1
|
||||||
|
WHERE Id=NEW.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
delimiter ;
|
||||||
|
SET @s = (SELECT IF(
|
||||||
|
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE()
|
||||||
|
AND table_name = 'Events'
|
||||||
|
AND column_name = 'Scheme'
|
||||||
|
) > 0,
|
||||||
|
"SELECT 'Column Scheme already exists in Events'",
|
||||||
|
"ALTER TABLE Events ADD `Scheme` enum('Deep','Medium','Shallow') NOT NULL default 'Deep' AFTER `DiskSpace`"
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE stmt FROM @s;
|
||||||
|
EXECUTE stmt;
|
||||||
|
|
||||||
|
|
||||||
|
UPDATE Monitors SET
|
||||||
|
TotalEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id),
|
||||||
|
TotalEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND DiskSpace IS NOT NULL),
|
||||||
|
HourEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB( NOW(), INTERVAL 1 hour) ),
|
||||||
|
HourEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB(NOW(), INTERVAL 1 hour) AND DiskSpace IS NOT NULL),
|
||||||
|
DayEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB(NOW(), INTERVAL 1 day)),
|
||||||
|
DayEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB(NOW(), INTERVAL 1 day) AND DiskSpace IS NOT NULL),
|
||||||
|
WeekEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB(NOW(), INTERVAL 1 week)),
|
||||||
|
WeekEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB(NOW(), INTERVAL 1 week) AND DiskSpace IS NOT NULL),
|
||||||
|
MonthEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB( NOW(), INTERVAL 1 month)),
|
||||||
|
MonthEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB(NOW(), INTERVAL 1 month) AND DiskSpace IS NOT NULL),
|
||||||
|
ArchivedEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id AND Archived=1),
|
||||||
|
ArchivedEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND Archived=1 AND DiskSpace IS NOT NULL)
|
|
@ -0,0 +1,148 @@
|
||||||
|
delimiter //
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Hour_delete_trigger//
|
||||||
|
CREATE TRIGGER Events_Hour_delete_trigger BEFORE DELETE ON Events_Hour
|
||||||
|
FOR EACH ROW BEGIN
|
||||||
|
UPDATE Monitors SET
|
||||||
|
HourEvents = COALESCE(HourEvents,1)-1,
|
||||||
|
HourEventDiskSpace=COALESCE(HourEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
|
WHERE Id=OLD.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Hour_update_trigger;
|
||||||
|
CREATE TRIGGER Events_Hour_update_trigger AFTER UPDATE ON Events_Hour
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
declare diff BIGINT default 0;
|
||||||
|
|
||||||
|
set diff = COALESCE(NEW.DiskSpace,0) - COALESCE(OLD.DiskSpace,0);
|
||||||
|
IF ( diff ) THEN
|
||||||
|
IF ( NEW.MonitorID != OLD.MonitorID ) THEN
|
||||||
|
UPDATE Monitors SET HourEventDiskSpace=COALESCE(DayEventDiskSpace,0)-OLD.DiskSpace WHERE Monitors.Id=OLD.MonitorId;
|
||||||
|
UPDATE Monitors SET HourEventDiskSpace=COALESCE(DayEventDiskSpace,0)+NEW.DiskSpace WHERE Monitors.Id=NEW.MonitorId;
|
||||||
|
ELSE
|
||||||
|
UPDATE Monitors SET HourEventDiskSpace=COALESCE(DayEventDiskSpace,0)+diff WHERE Monitors.Id=NEW.MonitorId;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Day_delete_trigger//
|
||||||
|
CREATE TRIGGER Events_Day_delete_trigger BEFORE DELETE ON Events_Day
|
||||||
|
FOR EACH ROW BEGIN
|
||||||
|
UPDATE Monitors SET
|
||||||
|
DayEvents = COALESCE(DayEvents,1)-1,
|
||||||
|
DayEventDiskSpace=COALESCE(DayEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
|
WHERE Id=OLD.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Day_update_trigger;
|
||||||
|
CREATE TRIGGER Events_Day_update_trigger AFTER UPDATE ON Events_Day
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
declare diff BIGINT default 0;
|
||||||
|
|
||||||
|
set diff = COALESCE(NEW.DiskSpace,0) - COALESCE(OLD.DiskSpace,0);
|
||||||
|
IF ( diff ) THEN
|
||||||
|
IF ( NEW.MonitorID != OLD.MonitorID ) THEN
|
||||||
|
UPDATE Monitors SET DayEventDiskSpace=COALESCE(DayEventDiskSpace,0)-OLD.DiskSpace WHERE Monitors.Id=OLD.MonitorId;
|
||||||
|
UPDATE Monitors SET DayEventDiskSpace=COALESCE(DayEventDiskSpace,0)+NEW.DiskSpace WHERE Monitors.Id=NEW.MonitorId;
|
||||||
|
ELSE
|
||||||
|
UPDATE Monitors SET DayEventDiskSpace=COALESCE(DayEventDiskSpace,0)+diff WHERE Monitors.Id=NEW.MonitorId;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Week_delete_trigger//
|
||||||
|
CREATE TRIGGER Events_Week_delete_trigger BEFORE DELETE ON Events_Week
|
||||||
|
FOR EACH ROW BEGIN
|
||||||
|
UPDATE Monitors SET
|
||||||
|
WeekEvents = COALESCE(WeekEvents,1)-1,
|
||||||
|
WeekEventDiskSpace=COALESCE(WeekEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
|
WHERE Id=OLD.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Week_update_trigger;
|
||||||
|
CREATE TRIGGER Events_Week_update_trigger AFTER UPDATE ON Events_Week
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
declare diff BIGINT default 0;
|
||||||
|
|
||||||
|
set diff = COALESCE(NEW.DiskSpace,0) - COALESCE(OLD.DiskSpace,0);
|
||||||
|
IF ( diff ) THEN
|
||||||
|
IF ( NEW.MonitorID != OLD.MonitorID ) THEN
|
||||||
|
UPDATE Monitors SET WeekEventDiskSpace=COALESCE(WeekEventDiskSpace,0)-OLD.DiskSpace WHERE Monitors.Id=OLD.MonitorId;
|
||||||
|
UPDATE Monitors SET WeekEventDiskSpace=COALESCE(WeekEventDiskSpace,0)+NEW.DiskSpace WHERE Monitors.Id=NEW.MonitorId;
|
||||||
|
ELSE
|
||||||
|
UPDATE Monitors SET WeekEventDiskSpace=COALESCE(WeekEventDiskSpace,0)+diff WHERE Monitors.Id=NEW.MonitorId;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Month_delete_trigger//
|
||||||
|
CREATE TRIGGER Events_Month_delete_trigger BEFORE DELETE ON Events_Month
|
||||||
|
FOR EACH ROW BEGIN
|
||||||
|
UPDATE Monitors SET
|
||||||
|
MonthEvents = COALESCE(MonthEvents,1)-1,
|
||||||
|
MonthEventDiskSpace=COALESCE(MonthEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0)
|
||||||
|
WHERE Id=OLD.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS Events_Month_update_trigger;
|
||||||
|
CREATE TRIGGER Events_Month_update_trigger AFTER UPDATE ON Events_Month
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
declare diff BIGINT default 0;
|
||||||
|
|
||||||
|
set diff = COALESCE(NEW.DiskSpace,0) - COALESCE(OLD.DiskSpace,0);
|
||||||
|
IF ( diff ) THEN
|
||||||
|
IF ( NEW.MonitorID != OLD.MonitorID ) THEN
|
||||||
|
UPDATE Monitors SET MonthEventDiskSpace=COALESCE(MonthEventDiskSpace,0)-OLD.DiskSpace WHERE Monitors.Id=OLD.MonitorId;
|
||||||
|
UPDATE Monitors SET MonthEventDiskSpace=COALESCE(MonthEventDiskSpace,0)+NEW.DiskSpace WHERE Monitors.Id=NEW.MonitorId;
|
||||||
|
ELSE
|
||||||
|
UPDATE Monitors SET MonthEventDiskSpace=COALESCE(MonthEventDiskSpace,0)+diff WHERE Monitors.Id=NEW.MonitorId;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS event_insert_trigger//
|
||||||
|
|
||||||
|
CREATE TRIGGER event_insert_trigger AFTER INSERT ON Events
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO Events_Hour (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
||||||
|
INSERT INTO Events_Day (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
||||||
|
INSERT INTO Events_Week (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
||||||
|
INSERT INTO Events_Month (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0);
|
||||||
|
UPDATE Monitors SET
|
||||||
|
HourEvents = COALESCE(HourEvents,0)+1,
|
||||||
|
DayEvents = COALESCE(DayEvents,0)+1,
|
||||||
|
WeekEvents = COALESCE(WeekEvents,0)+1,
|
||||||
|
MonthEvents = COALESCE(MonthEvents,0)+1,
|
||||||
|
TotalEvents = COALESCE(TotalEvents,0)+1
|
||||||
|
WHERE Id=NEW.MonitorId;
|
||||||
|
END;
|
||||||
|
//
|
||||||
|
|
||||||
|
delimiter ;
|
||||||
|
|
||||||
|
UPDATE Monitors SET
|
||||||
|
TotalEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id),
|
||||||
|
TotalEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND DiskSpace IS NOT NULL),
|
||||||
|
HourEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB( NOW(), INTERVAL 1 hour) ),
|
||||||
|
HourEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB(NOW(), INTERVAL 1 hour) AND DiskSpace IS NOT NULL),
|
||||||
|
DayEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB(NOW(), INTERVAL 1 day)),
|
||||||
|
DayEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB(NOW(), INTERVAL 1 day) AND DiskSpace IS NOT NULL),
|
||||||
|
WeekEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB(NOW(), INTERVAL 1 week)),
|
||||||
|
WeekEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB(NOW(), INTERVAL 1 week) AND DiskSpace IS NOT NULL),
|
||||||
|
MonthEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB( NOW(), INTERVAL 1 month)),
|
||||||
|
MonthEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB(NOW(), INTERVAL 1 month) AND DiskSpace IS NOT NULL),
|
||||||
|
ArchivedEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id AND Archived=1),
|
||||||
|
ArchivedEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND Archived=1 AND DiskSpace IS NOT NULL)
|
|
@ -647,17 +647,17 @@ MAIN: while( $loop ) {
|
||||||
# Number of rows
|
# Number of rows
|
||||||
my $selectLogRowCountSql = 'SELECT count(*) AS Rows FROM Logs';
|
my $selectLogRowCountSql = 'SELECT count(*) AS Rows FROM Logs';
|
||||||
my $selectLogRowCountSth = $dbh->prepare_cached( $selectLogRowCountSql )
|
my $selectLogRowCountSth = $dbh->prepare_cached( $selectLogRowCountSql )
|
||||||
or Fatal( "Can't prepare '$selectLogRowCountSql': ".$dbh->errstr() );
|
or Fatal( "Can't prepare '$selectLogRowCountSql': ".$dbh->errstr() );
|
||||||
$res = $selectLogRowCountSth->execute()
|
$res = $selectLogRowCountSth->execute()
|
||||||
or Fatal( "Can't execute: ".$selectLogRowCountSth->errstr() );
|
or Fatal( "Can't execute: ".$selectLogRowCountSth->errstr() );
|
||||||
my $row = $selectLogRowCountSth->fetchrow_hashref();
|
my $row = $selectLogRowCountSth->fetchrow_hashref();
|
||||||
my $logRows = $row->{Rows};
|
my $logRows = $row->{Rows};
|
||||||
if ( $logRows > $Config{ZM_LOG_DATABASE_LIMIT} ) {
|
if ( $logRows > $Config{ZM_LOG_DATABASE_LIMIT} ) {
|
||||||
my $deleteLogByRowsSql = 'DELETE low_priority FROM Logs ORDER BY TimeKey ASC LIMIT ?';
|
my $deleteLogByRowsSql = 'DELETE low_priority FROM Logs ORDER BY TimeKey ASC LIMIT ?';
|
||||||
my $deleteLogByRowsSth = $dbh->prepare_cached( $deleteLogByRowsSql )
|
my $deleteLogByRowsSth = $dbh->prepare_cached( $deleteLogByRowsSql )
|
||||||
or Fatal( "Can't prepare '$deleteLogByRowsSql': ".$dbh->errstr() );
|
or Fatal( "Can't prepare '$deleteLogByRowsSql': ".$dbh->errstr() );
|
||||||
$res = $deleteLogByRowsSth->execute( $logRows - $Config{ZM_LOG_DATABASE_LIMIT} )
|
$res = $deleteLogByRowsSth->execute( $logRows - $Config{ZM_LOG_DATABASE_LIMIT} )
|
||||||
or Fatal( "Can't execute: ".$deleteLogByRowsSth->errstr() );
|
or Fatal( "Can't execute: ".$deleteLogByRowsSth->errstr() );
|
||||||
if ( $deleteLogByRowsSth->rows() ) {
|
if ( $deleteLogByRowsSth->rows() ) {
|
||||||
aud_print( 'Deleted '.$deleteLogByRowsSth->rows() ." log table entries by count\n" );
|
aud_print( 'Deleted '.$deleteLogByRowsSth->rows() ." log table entries by count\n" );
|
||||||
}
|
}
|
||||||
|
@ -668,9 +668,9 @@ MAIN: while( $loop ) {
|
||||||
'DELETE low_priority FROM Logs
|
'DELETE low_priority FROM Logs
|
||||||
WHERE TimeKey < unix_timestamp(now() - interval '.$Config{ZM_LOG_DATABASE_LIMIT}.')';
|
WHERE TimeKey < unix_timestamp(now() - interval '.$Config{ZM_LOG_DATABASE_LIMIT}.')';
|
||||||
my $deleteLogByTimeSth = $dbh->prepare_cached( $deleteLogByTimeSql )
|
my $deleteLogByTimeSth = $dbh->prepare_cached( $deleteLogByTimeSql )
|
||||||
or Fatal( "Can't prepare '$deleteLogByTimeSql': ".$dbh->errstr() );
|
or Fatal( "Can't prepare '$deleteLogByTimeSql': ".$dbh->errstr() );
|
||||||
$res = $deleteLogByTimeSth->execute()
|
$res = $deleteLogByTimeSth->execute()
|
||||||
or Fatal( "Can't execute: ".$deleteLogByTimeSth->errstr() );
|
or Fatal( "Can't execute: ".$deleteLogByTimeSth->errstr() );
|
||||||
if ( $deleteLogByTimeSth->rows() ){
|
if ( $deleteLogByTimeSth->rows() ){
|
||||||
aud_print( 'Deleted '.$deleteLogByTimeSth->rows()
|
aud_print( 'Deleted '.$deleteLogByTimeSth->rows()
|
||||||
." log table entries by time\n" );
|
." log table entries by time\n" );
|
||||||
|
@ -680,7 +680,7 @@ MAIN: while( $loop ) {
|
||||||
$loop = $continuous;
|
$loop = $continuous;
|
||||||
|
|
||||||
my $eventcounts_sql = q`
|
my $eventcounts_sql = q`
|
||||||
UPDATE Monitors SET
|
UPDATE Monitors SET
|
||||||
TotalEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id),
|
TotalEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id),
|
||||||
TotalEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND DiskSpace IS NOT NULL),
|
TotalEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND DiskSpace IS NOT NULL),
|
||||||
HourEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB( NOW(), INTERVAL 1 hour) ),
|
HourEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB( NOW(), INTERVAL 1 hour) ),
|
||||||
|
@ -693,12 +693,56 @@ UPDATE Monitors SET
|
||||||
MonthEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB(NOW(), INTERVAL 1 month) AND DiskSpace IS NOT NULL),
|
MonthEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND StartTime > DATE_SUB(NOW(), INTERVAL 1 month) AND DiskSpace IS NOT NULL),
|
||||||
ArchivedEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id AND Archived=1),
|
ArchivedEvents=(SELECT COUNT(Id) FROM Events WHERE MonitorId=Monitors.Id AND Archived=1),
|
||||||
ArchivedEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND Archived=1 AND DiskSpace IS NOT NULL)
|
ArchivedEventDiskSpace=(SELECT SUM(DiskSpace) FROM Events WHERE MonitorId=Monitors.Id AND Archived=1 AND DiskSpace IS NOT NULL)
|
||||||
`;
|
`;
|
||||||
|
|
||||||
my $eventcounts_sth = $dbh->prepare_cached( $eventcounts_sql );
|
my $eventcounts_sth = $dbh->prepare_cached( $eventcounts_sql );
|
||||||
$eventcounts_sth->execute();
|
$eventcounts_sth->execute();
|
||||||
$eventcounts_sth->finish();
|
$eventcounts_sth->finish();
|
||||||
|
|
||||||
|
my $eventcounts_hour_sql = q`
|
||||||
|
UPDATE Monitors INNER JOIN (
|
||||||
|
SELECT MonitorId, COUNT(*) AS HourEvents, SUM(COALESCE(DiskSpace,0)) AS HourEventDiskSpace
|
||||||
|
FROM Events_Hour GROUP BY MonitorId
|
||||||
|
) AS E ON E.MonitorId=Monitors.Id SET
|
||||||
|
Monitors.HourEvents = E.HourEvents,
|
||||||
|
Monitors.HourEventDiskSpace = E.HourEventDiskSpace
|
||||||
|
`;
|
||||||
|
|
||||||
|
|
||||||
|
my $eventcounts_day_sql = q`
|
||||||
|
UPDATE Monitors INNER JOIN (
|
||||||
|
SELECT MonitorId, COUNT(*) AS DayEvents, SUM(COALESCE(DiskSpace,0)) AS DayEventDiskSpace
|
||||||
|
FROM Events_Day GROUP BY MonitorId
|
||||||
|
) AS E ON E.MonitorId=Monitors.Id SET
|
||||||
|
Monitors.DayEvents = E.DayEvents,
|
||||||
|
Monitors.DayEventDiskSpace = E.DayEventDiskSpace
|
||||||
|
`;
|
||||||
|
|
||||||
|
my $eventcounts_week_sql = q`
|
||||||
|
UPDATE Monitors INNER JOIN (
|
||||||
|
SELECT MonitorId, COUNT(*) AS WeekEvents, SUM(COALESCE(DiskSpace,0)) AS WeekEventDiskSpace
|
||||||
|
FROM Events_Week GROUP BY MonitorId
|
||||||
|
) AS E ON E.MonitorId=Monitors.Id SET
|
||||||
|
Monitors.WeekEvents = E.WeekEvents,
|
||||||
|
Monitors.WeekEventDiskSpace = E.WeekEventDiskSpace
|
||||||
|
`;
|
||||||
|
|
||||||
|
my $eventcounts_month_sql = q`
|
||||||
|
UPDATE Monitors INNER JOIN (
|
||||||
|
SELECT MonitorId, COUNT(*) AS MonthEvents, SUM(COALESCE(DiskSpace,0)) AS MonthEventDiskSpace
|
||||||
|
FROM Events_Month GROUP BY MonitorId
|
||||||
|
) AS E ON E.MonitorId=Monitors.Id SET
|
||||||
|
Monitors.MonthEvents = E.MonthEvents,
|
||||||
|
Monitors.MonthEventDiskSpace = E.MonthEventDiskSpace
|
||||||
|
`;
|
||||||
|
my $eventcounts_hour_sth = $dbh->prepare_cached( $eventcounts_hour_sql );
|
||||||
|
my $eventcounts_day_sth = $dbh->prepare_cached( $eventcounts_day_sql );
|
||||||
|
my $eventcounts_week_sth = $dbh->prepare_cached( $eventcounts_week_sql );
|
||||||
|
my $eventcounts_month_sth = $dbh->prepare_cached( $eventcounts_month_sql );
|
||||||
|
$eventcounts_hour_sth->execute( ) or Error( "Can't execute: ".$eventcounts_sth->errstr() );
|
||||||
|
$eventcounts_day_sth->execute( ) or Error( "Can't execute: ".$eventcounts_sth->errstr() );
|
||||||
|
$eventcounts_week_sth->execute( ) or Error( "Can't execute: ".$eventcounts_sth->errstr() );
|
||||||
|
$eventcounts_month_sth->execute( ) or Error( "Can't execute: ".$eventcounts_sth->errstr() );
|
||||||
sleep( $Config{ZM_AUDIT_CHECK_INTERVAL} ) if $continuous;
|
sleep( $Config{ZM_AUDIT_CHECK_INTERVAL} ) if $continuous;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -76,81 +76,6 @@ my $sql = $Config{ZM_SERVER_ID} ? 'SELECT * FROM Monitors WHERE ServerId=?' : 'S
|
||||||
my $sth = $dbh->prepare_cached( $sql )
|
my $sth = $dbh->prepare_cached( $sql )
|
||||||
or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
|
or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||||
|
|
||||||
my $eventcounts_sql = q`
|
|
||||||
UPDATE Monitors INNER JOIN (
|
|
||||||
SELECT MonitorId,
|
|
||||||
COUNT(Id) AS TotalEvents,
|
|
||||||
SUM(DiskSpace) AS TotalEventDiskSpace,
|
|
||||||
SUM(IF(Archived,1,0)) AS ArchivedEvents,
|
|
||||||
SUM(IF(Archived,DiskSpace,0)) AS ArchivedEventDiskSpace,
|
|
||||||
SUM(IF(StartTime > DATE_SUB(NOW(), INTERVAL 1 hour),1,0)) AS HourEvents,
|
|
||||||
SUM(IF(StartTime > DATE_SUB(NOW(), INTERVAL 1 hour),DiskSpace,0)) AS HourEventDiskSpace,
|
|
||||||
SUM(IF(StartTime > DATE_SUB(NOW(), INTERVAL 1 day),1,0)) AS DayEvents,
|
|
||||||
SUM(IF(StartTime > DATE_SUB(NOW(), INTERVAL 1 day),DiskSpace,0)) AS DayEventDiskSpace,
|
|
||||||
SUM(IF(StartTime > DATE_SUB(NOW(), INTERVAL 1 week),1,0)) AS WeekEvents,
|
|
||||||
SUM(IF(StartTime > DATE_SUB(NOW(), INTERVAL 1 week),DiskSpace,0)) AS WeekEventDiskSpace,
|
|
||||||
SUM(IF(StartTime > DATE_SUB(NOW(), INTERVAL 1 month),1,0)) AS MonthEvents,
|
|
||||||
SUM(IF(StartTime > DATE_SUB(NOW(), INTERVAL 1 month),DiskSpace,0)) AS MonthEventDiskSpace
|
|
||||||
FROM Events GROUP BY MonitorId
|
|
||||||
) AS E ON E.MonitorId=Monitors.Id SET
|
|
||||||
Monitors.TotalEvents = E.TotalEvents,
|
|
||||||
Monitors.TotalEventDiskSpace = E.TotalEventDiskSpace,
|
|
||||||
Monitors.ArchivedEvents = E.ArchivedEvents,
|
|
||||||
Monitors.ArchivedEventDiskSpace = E.ArchivedEventDiskSpace,
|
|
||||||
Monitors.HourEvents = E.HourEvents,
|
|
||||||
Monitors.HourEventDiskSpace = E.HourEventDiskSpace,
|
|
||||||
Monitors.DayEvents = E.DayEvents,
|
|
||||||
Monitors.DayEventDiskSpace = E.DayEventDiskSpace,
|
|
||||||
Monitors.WeekEvents = E.WeekEvents,
|
|
||||||
Monitors.WeekEventDiskSpace = E.WeekEventDiskSpace,
|
|
||||||
Monitors.MonthEvents = E.MonthEvents,
|
|
||||||
Monitors.MonthEventDiskSpace = E.MonthEventDiskSpace
|
|
||||||
`;
|
|
||||||
|
|
||||||
|
|
||||||
my $eventcounts_hour_sql = q`
|
|
||||||
UPDATE Monitors INNER JOIN (
|
|
||||||
SELECT MonitorId, COUNT(*) AS HourEvents, SUM(COALESCE(DiskSpace,0)) AS HourEventDiskSpace
|
|
||||||
FROM Events_Hour GROUP BY MonitorId
|
|
||||||
) AS E ON E.MonitorId=Monitors.Id SET
|
|
||||||
Monitors.HourEvents = E.HourEvents,
|
|
||||||
Monitors.HourEventDiskSpace = E.HourEventDiskSpace
|
|
||||||
`;
|
|
||||||
|
|
||||||
|
|
||||||
my $eventcounts_day_sql = q`
|
|
||||||
UPDATE Monitors INNER JOIN (
|
|
||||||
SELECT MonitorId, COUNT(*) AS DayEvents, SUM(COALESCE(DiskSpace,0)) AS DayEventDiskSpace
|
|
||||||
FROM Events_Day GROUP BY MonitorId
|
|
||||||
) AS E ON E.MonitorId=Monitors.Id SET
|
|
||||||
Monitors.DayEvents = E.DayEvents,
|
|
||||||
Monitors.DayEventDiskSpace = E.DayEventDiskSpace
|
|
||||||
`;
|
|
||||||
|
|
||||||
my $eventcounts_week_sql = q`
|
|
||||||
UPDATE Monitors INNER JOIN (
|
|
||||||
SELECT MonitorId, COUNT(*) AS WeekEvents, SUM(COALESCE(DiskSpace,0)) AS WeekEventDiskSpace
|
|
||||||
FROM Events_Week GROUP BY MonitorId
|
|
||||||
) AS E ON E.MonitorId=Monitors.Id SET
|
|
||||||
Monitors.WeekEvents = E.WeekEvents,
|
|
||||||
Monitors.WeekEventDiskSpace = E.WeekEventDiskSpace
|
|
||||||
`;
|
|
||||||
|
|
||||||
my $eventcounts_month_sql = q`
|
|
||||||
UPDATE Monitors INNER JOIN (
|
|
||||||
SELECT MonitorId, COUNT(*) AS MonthEvents, SUM(COALESCE(DiskSpace,0)) AS MonthEventDiskSpace
|
|
||||||
FROM Events_Month GROUP BY MonitorId
|
|
||||||
) AS E ON E.MonitorId=Monitors.Id SET
|
|
||||||
Monitors.MonthEvents = E.MonthEvents,
|
|
||||||
Monitors.MonthEventDiskSpace = E.MonthEventDiskSpace
|
|
||||||
`;
|
|
||||||
|
|
||||||
|
|
||||||
my $eventcounts_sth = $dbh->prepare_cached( $eventcounts_sql );
|
|
||||||
my $eventcounts_hour_sth = $dbh->prepare_cached( $eventcounts_hour_sql );
|
|
||||||
my $eventcounts_day_sth = $dbh->prepare_cached( $eventcounts_day_sql );
|
|
||||||
my $eventcounts_week_sth = $dbh->prepare_cached( $eventcounts_week_sql );
|
|
||||||
my $eventcounts_month_sth = $dbh->prepare_cached( $eventcounts_month_sql );
|
|
||||||
|
|
||||||
while( 1 ) {
|
while( 1 ) {
|
||||||
while ( ! ( $dbh and $dbh->ping() ) ) {
|
while ( ! ( $dbh and $dbh->ping() ) ) {
|
||||||
|
@ -162,10 +87,6 @@ while( 1 ) {
|
||||||
$dbh->do('DELETE FROM Events_Day WHERE StartTime < DATE_SUB(NOW(), INTERVAL 1 day)');
|
$dbh->do('DELETE FROM Events_Day WHERE StartTime < DATE_SUB(NOW(), INTERVAL 1 day)');
|
||||||
$dbh->do('DELETE FROM Events_Week WHERE StartTime < DATE_SUB(NOW(), INTERVAL 1 week)');
|
$dbh->do('DELETE FROM Events_Week WHERE StartTime < DATE_SUB(NOW(), INTERVAL 1 week)');
|
||||||
$dbh->do('DELETE FROM Events_Month WHERE StartTime < DATE_SUB(NOW(), INTERVAL 1 month)');
|
$dbh->do('DELETE FROM Events_Month WHERE StartTime < DATE_SUB(NOW(), INTERVAL 1 month)');
|
||||||
$eventcounts_hour_sth->execute( ) or Error( "Can't execute: ".$eventcounts_sth->errstr() );
|
|
||||||
$eventcounts_day_sth->execute( ) or Error( "Can't execute: ".$eventcounts_sth->errstr() );
|
|
||||||
$eventcounts_week_sth->execute( ) or Error( "Can't execute: ".$eventcounts_sth->errstr() );
|
|
||||||
$eventcounts_month_sth->execute( ) or Error( "Can't execute: ".$eventcounts_sth->errstr() );
|
|
||||||
|
|
||||||
sleep( $Config{ZM_STATS_UPDATE_INTERVAL} );
|
sleep( $Config{ZM_STATS_UPDATE_INTERVAL} );
|
||||||
} # end while (1)
|
} # end while (1)
|
||||||
|
|
|
@ -107,7 +107,6 @@ FfmpegCamera::FfmpegCamera( int p_id, const std::string &p_path, const std::stri
|
||||||
mRawFrame = NULL;
|
mRawFrame = NULL;
|
||||||
mFrame = NULL;
|
mFrame = NULL;
|
||||||
frameCount = 0;
|
frameCount = 0;
|
||||||
mIsOpening = false;
|
|
||||||
mCanCapture = false;
|
mCanCapture = false;
|
||||||
mOpenStart = 0;
|
mOpenStart = 0;
|
||||||
|
|
||||||
|
@ -122,6 +121,7 @@ FfmpegCamera::~FfmpegCamera() {
|
||||||
|
|
||||||
int FfmpegCamera::PrimeCapture() {
|
int FfmpegCamera::PrimeCapture() {
|
||||||
if ( mCanCapture ) {
|
if ( mCanCapture ) {
|
||||||
|
Info( "Priming capture from %s", mPath.c_str() );
|
||||||
CloseFfmpeg();
|
CloseFfmpeg();
|
||||||
}
|
}
|
||||||
mVideoStreamId = -1;
|
mVideoStreamId = -1;
|
||||||
|
@ -185,7 +185,6 @@ int FfmpegCamera::OpenFfmpeg() {
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
mOpenStart = time(NULL);
|
mOpenStart = time(NULL);
|
||||||
mIsOpening = true;
|
|
||||||
|
|
||||||
// Open the input, not necessarily a file
|
// Open the input, not necessarily a file
|
||||||
#if !LIBAVFORMAT_VERSION_CHECK(53, 2, 0, 4, 0)
|
#if !LIBAVFORMAT_VERSION_CHECK(53, 2, 0, 4, 0)
|
||||||
|
@ -224,7 +223,6 @@ int FfmpegCamera::OpenFfmpeg() {
|
||||||
if ( avformat_open_input( &mFormatContext, mPath.c_str(), NULL, &opts ) != 0 )
|
if ( avformat_open_input( &mFormatContext, mPath.c_str(), NULL, &opts ) != 0 )
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
mIsOpening = false;
|
|
||||||
Error("Unable to open input %s due to: %s", mPath.c_str(), strerror(errno));
|
Error("Unable to open input %s due to: %s", mPath.c_str(), strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -236,8 +234,7 @@ int FfmpegCamera::OpenFfmpeg() {
|
||||||
|
|
||||||
monitor->GetLastEventId() ;
|
monitor->GetLastEventId() ;
|
||||||
|
|
||||||
mIsOpening = false;
|
Debug(1, "Opened input");
|
||||||
Debug ( 1, "Opened input" );
|
|
||||||
|
|
||||||
Info( "Stream open %s, parsing streams...", mPath.c_str() );
|
Info( "Stream open %s, parsing streams...", mPath.c_str() );
|
||||||
|
|
||||||
|
@ -246,7 +243,10 @@ int FfmpegCamera::OpenFfmpeg() {
|
||||||
#else
|
#else
|
||||||
if ( avformat_find_stream_info( mFormatContext, 0 ) < 0 )
|
if ( avformat_find_stream_info( mFormatContext, 0 ) < 0 )
|
||||||
#endif
|
#endif
|
||||||
Fatal("Unable to find stream info from %s due to: %s", mPath.c_str(), strerror(errno));
|
{
|
||||||
|
Error("Unable to find stream info from %s due to: %s", mPath.c_str(), strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
Debug(4, "Got stream info");
|
Debug(4, "Got stream info");
|
||||||
|
|
||||||
|
|
|
@ -1226,12 +1226,16 @@ void Monitor::UpdateAnalysisFPS() {
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
gettimeofday( &now, NULL );
|
gettimeofday( &now, NULL );
|
||||||
if ( analysis_image_count && fps_report_interval && !(analysis_image_count%fps_report_interval) ) {
|
if ( analysis_image_count && fps_report_interval && !(analysis_image_count%fps_report_interval) ) {
|
||||||
analysis_fps = double(fps_report_interval)/(now.tv_sec - last_analysis_fps_time);
|
double new_analysis_fps = double(fps_report_interval)/(now.tv_sec - last_analysis_fps_time);
|
||||||
Info( "%s: %d - Analysing at %.2f fps", name, image_count, analysis_fps );
|
Info("%s: %d - Analysing at %.2f fps", name, image_count, new_analysis_fps);
|
||||||
static char sql[ZM_SQL_SML_BUFSIZ];
|
if ( new_analysis_fps != analysis_fps ) {
|
||||||
snprintf( sql, sizeof(sql), "INSERT INTO Monitor_Status (MonitorId,AnalysisFPS) VALUES (%d, %.2lf) ON DUPLICATE KEY UPDATE AnalysisFPS = %.2lf", id, analysis_fps, analysis_fps );
|
analysis_fps = new_analysis_fps;
|
||||||
if ( mysql_query( &dbconn, sql ) ) {
|
|
||||||
Error( "Can't run query: %s", mysql_error( &dbconn ) );
|
static char sql[ZM_SQL_SML_BUFSIZ];
|
||||||
|
snprintf( sql, sizeof(sql), "INSERT INTO Monitor_Status (MonitorId,AnalysisFPS) VALUES (%d, %.2lf) ON DUPLICATE KEY UPDATE AnalysisFPS = %.2lf", id, analysis_fps, analysis_fps );
|
||||||
|
if ( mysql_query( &dbconn, sql ) ) {
|
||||||
|
Error("Can't run query: %s", mysql_error(&dbconn));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
last_analysis_fps_time = now.tv_sec;
|
last_analysis_fps_time = now.tv_sec;
|
||||||
}
|
}
|
||||||
|
@ -2935,16 +2939,18 @@ int Monitor::Capture() {
|
||||||
// If we are too fast, we get div by zero. This seems to happen in the case of audio packets.
|
// If we are too fast, we get div by zero. This seems to happen in the case of audio packets.
|
||||||
if ( now != last_fps_time ) {
|
if ( now != last_fps_time ) {
|
||||||
// # of images per interval / the amount of time it took
|
// # of images per interval / the amount of time it took
|
||||||
capture_fps = double(fps_report_interval)/(now-last_fps_time);
|
double new_capture_fps = double(fps_report_interval)/(now-last_fps_time);
|
||||||
//Info( "%d -> %d -> %d", fps_report_interval, now, last_fps_time );
|
//Info( "%d -> %d -> %d", fps_report_interval, now, last_fps_time );
|
||||||
//Info( "%d -> %d -> %lf -> %lf", now-last_fps_time, fps_report_interval/(now-last_fps_time), double(fps_report_interval)/(now-last_fps_time), fps );
|
//Info( "%d -> %d -> %lf -> %lf", now-last_fps_time, fps_report_interval/(now-last_fps_time), double(fps_report_interval)/(now-last_fps_time), fps );
|
||||||
Info( "%s: %d - Capturing at %.2lf fps", name, image_count, capture_fps );
|
Info("%s: %d - Capturing at %.2lf fps", name, image_count, capture_fps);
|
||||||
last_fps_time = now;
|
if ( new_capture_fps != capture_fps ) {
|
||||||
static char sql[ZM_SQL_SML_BUFSIZ];
|
last_fps_time = now;
|
||||||
snprintf( sql, sizeof(sql), "INSERT INTO Monitor_Status (MonitorId,CaptureFPS) VALUES (%d, %.2lf) ON DUPLICATE KEY UPDATE CaptureFPS = %.2lf", id, capture_fps, capture_fps );
|
static char sql[ZM_SQL_SML_BUFSIZ];
|
||||||
if ( mysql_query( &dbconn, sql ) ) {
|
snprintf(sql, sizeof(sql), "INSERT INTO Monitor_Status (MonitorId,CaptureFPS) VALUES (%d, %.2lf) ON DUPLICATE KEY UPDATE CaptureFPS = %.2lf", id, capture_fps, capture_fps);
|
||||||
Error( "Can't run query: %s", mysql_error( &dbconn ) );
|
if ( mysql_query(&dbconn, sql) ) {
|
||||||
}
|
Error("Can't run query: %s", mysql_error(&dbconn));
|
||||||
|
}
|
||||||
|
} // end if fps has changed
|
||||||
}
|
}
|
||||||
} // end if report fps
|
} // end if report fps
|
||||||
} else { // result == 0
|
} else { // result == 0
|
||||||
|
|
|
@ -144,12 +144,12 @@ int RemoteCameraHttp::Connect() {
|
||||||
|
|
||||||
if ( p == NULL ) {
|
if ( p == NULL ) {
|
||||||
Error("Unable to connect to the remote camera, aborting");
|
Error("Unable to connect to the remote camera, aborting");
|
||||||
return( -1 );
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug( 3, "Connected to host, socket = %d", sd );
|
Debug(3, "Connected to host, socket = %d", sd);
|
||||||
return( sd );
|
return sd;
|
||||||
}
|
} // end int RemoteCameraHttp::Connect()
|
||||||
|
|
||||||
int RemoteCameraHttp::Disconnect() {
|
int RemoteCameraHttp::Disconnect() {
|
||||||
close( sd );
|
close( sd );
|
||||||
|
@ -1006,8 +1006,8 @@ int RemoteCameraHttp::PreCapture() {
|
||||||
if ( sd < 0 ) {
|
if ( sd < 0 ) {
|
||||||
Connect();
|
Connect();
|
||||||
if ( sd < 0 ) {
|
if ( sd < 0 ) {
|
||||||
Error( "Unable to connect to camera" );
|
Error("Unable to connect to camera");
|
||||||
return( -1 );
|
return -1;
|
||||||
}
|
}
|
||||||
mode = SINGLE_IMAGE;
|
mode = SINGLE_IMAGE;
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
|
|
|
@ -241,6 +241,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
while( ! zm_terminate ) {
|
while( ! zm_terminate ) {
|
||||||
|
result = 0;
|
||||||
for ( int i = 0; i < n_monitors; i ++ ) {
|
for ( int i = 0; i < n_monitors; i ++ ) {
|
||||||
time_t now = (time_t)time(NULL);
|
time_t now = (time_t)time(NULL);
|
||||||
monitors[i]->setStartupTime(now);
|
monitors[i]->setStartupTime(now);
|
||||||
|
@ -371,6 +372,7 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
} // end foreach monitor
|
} // end foreach monitor
|
||||||
delete [] analysis_threads;
|
delete [] analysis_threads;
|
||||||
|
sleep(10);
|
||||||
} // end while ! zm_terminate outer connection loop
|
} // end while ! zm_terminate outer connection loop
|
||||||
delete [] monitors;
|
delete [] monitors;
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ function deleteEvents( element, name ) {
|
||||||
}
|
}
|
||||||
if ( count > 0 ) {
|
if ( count > 0 ) {
|
||||||
if ( confirm( confirmDeleteEventsString ) ) {
|
if ( confirm( confirmDeleteEventsString ) ) {
|
||||||
form.action.value = 'delete';
|
form.elements['action'].value = 'delete';
|
||||||
form.submit();
|
form.submit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,13 +120,13 @@ function viewEvents( element, name ) {
|
||||||
|
|
||||||
function archiveEvents( element, name ) {
|
function archiveEvents( element, name ) {
|
||||||
var form = element.form;
|
var form = element.form;
|
||||||
form.action.value = 'archive';
|
form.elements['action'].value = 'archive';
|
||||||
form.submit();
|
form.submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
function unarchiveEvents( element, name ) {
|
function unarchiveEvents(element, name) {
|
||||||
var form = element.form;
|
var form = element.form;
|
||||||
form.action.value = 'unarchive';
|
form.elements['action'].value = 'unarchive';
|
||||||
form.submit();
|
form.submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue