I'm trying to do something for my website, to be specific, I'm trying to do a script for uptime.
I have the reader, a scri开发者_StackOverflowpt which read the percents from a table.
This is not a very efficient way to use a Relational Database. I would, instead, suggest (at least with the SQL side), the following:
CREATE TABLE `servers` (
`srv_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
-- Additional Fields Omitted here.
PRIMARY KEY (`srv_id`)
)
ENGINE = InnoDB;
CREATE TABLE `stats` (
`stat_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`srv_id` INTEGER UNSIGNED NOT NULL,
`date` TIMESTAMP NOT NULL,
`uptime` INTEGER UNSIGNED NOT NULL,
PRIMARY KEY (`stat_id`)
)
ENGINE = InnoDB;
This way you can record as many measures as you like, against as many servers as you like, and then use SQL to either delete old content or keep the old content and use WHERE
arguments to filter the data used in the interface displaying these stats.
$day = int(strftime("%j") % 5);
$key = 'day' . $day;
if($row[$key] == 0)
{
if($checkls && $checkgs) //if server is online update the percent
mysql_query("UPDATE s_stats SET ${key}=".($stats_row[$key] + 0.5)." WHERE srv_id=".$r[id]." ") or die(mysql_error()); //every 7.2 minutes add 0.5 percent
else echo "error day $day";
}
精彩评论