Last active
February 27, 2018 14:07
-
-
Save analogic/95b37faa3d754936e836074c10237063 to your computer and use it in GitHub Desktop.
FreeRADIUS Accounting per month
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE IF NOT EXISTS `data_month` ( | |
`calledstationid` VARCHAR(50), | |
`in_octets` BIGINT(20) DEFAULT 0, | |
`out_octets` BIGINT(20) DEFAULT 0, | |
`year` INT(4), | |
`month` INT(2), | |
`last_update` DATETIME, | |
PRIMARY KEY (`calledstationid`, `year`, `month`) | |
) ENGINE MyISAM; | |
CREATE TRIGGER `monthDataStatistics` BEFORE UPDATE ON `radacct` FOR EACH ROW | |
INSERT INTO data_month ( | |
`calledstationid`, | |
`in_octets`, | |
`out_octets`, | |
`year`, | |
`month`, | |
`last_update`) | |
VALUES ( | |
old.calledstationid, | |
new.acctinputoctets - old.acctinputoctets, | |
new.acctoutputoctets - old.acctoutputoctets, | |
YEAR(CURDATE()), | |
MONTH(CURDATE()), | |
CURRENT_TIMESTAMP() | |
) | |
ON DUPLICATE KEY UPDATE | |
`in_octets` = (`in_octets` + (new.acctinputoctets - old.acctinputoctets)), | |
`out_octets` = (`out_octets` + (new.acctoutputoctets - old.acctoutputoctets)), | |
`last_update` = CURRENT_TIMESTAMP(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment