function statusRow($row) { global $db, $i, $jsend, $lbjs, $provider; if ($row['provider'] != $provider) { echo '<tr><td colspan="7" style="text-align: left; vertical-align: middle; font-weight: bold; font-size: 10px; padding-left: 5px;">'. $row['provider'] .'</td></tr>'; $provider = $row['provider']; } if ($row['status'] == "0") { echo '<tr style="text-align: center" class="offline">'; } elseif ($row['uptime'] == "n/a") { echo '<tr style="text-align: center" class="online-but-no-data">'; } else { echo '<tr style="text-align: center">'; } $dbq = $db->prepare('SELECT COUNT(*) FROM processes WHERE uid = ?'); $dbr = $dbq->execute(array($row['uid'])); $servicecount = $dbq->fetch(); $numrows = 1; if ($row['note'] != "") { $numrows++; } if ($servicecount[0] > 0) { $numrows++; } echo '<td rowspan="'.$numrows.'"><a href="history.php?uid='. $row['uid'].'">'. $row['hostname'] .'</a></td>'; echo '<td><span id="time-'.$i.'"></span></td>'; $jsend .= '$(function () { $(\'#time-'.$i.'\').countdown({since: "-'.(time()-$row['time']).'S", compact: true}); });'; echo '<td>'. $row['uptime'] .'</td>'; echo '<td class="5pad">'; if(empty($row['mtotal'])) { echo "N/A"; } else { $mp = ($row['mused'])/$row['mtotal']*100; $used = $row['mused']; echo '<div class="progress-container"><div class="progress-container-percent" style="width:'. $mp .'%"><div class="bartext">'. $used .'/'. $row['mtotal'] .'MB</div></div></div>'; } echo '<br /><a href="grapher.php?uid='.$row['uid'].'&type=memory&interval=1h" rel="lightbox-'.$row['uid'].'-memory">1h</a> <a href="grapher.php?uid='.$row['uid'].'&type=memory&interval=3h" rel="lightbox-'.$row['uid'].'-memory">3h</a> <a href="grapher.php?uid='.$row['uid'].'&type=memory&interval=6h" rel="lightbox-'.$row['uid'].'-memory">6h</a> <a href="grapher.php?uid='.$row['uid'].'&type=memory&interval=12h" rel="lightbox-'.$row['uid'].'-memory">12h</a> <a href="grapher.php?uid='.$row['uid'].'&type=memory&interval=1d" rel="lightbox-'.$row['uid'].'-memory">1d</a></td>'; echo '<td class="5pad">'; if(isset($row['diskused'])) { $mp = ($row['diskused']/$row['disktotal'])*100; echo '<div class="progress-container"><div class="progress-container-percent" style="width:'. $mp .'%"><div class="bartext">'. format_kbytes($row['diskused']) .'/'. format_kbytes($row['disktotal']) .'GB</div></div></div>'; } else { echo 'N/A'; } echo '<br /><a href="grapher.php?uid='.$row['uid'].'&type=disk&interval=1h" rel="lightbox-'.$row['uid'].'-disk">1h</a> <a href="grapher.php?uid='.$row['uid'].'&type=disk&interval=3h" rel="lightbox-'.$row['uid'].'-disk">3h</a> <a href="grapher.php?uid='.$row['uid'].'&type=disk&interval=6h" rel="lightbox-'.$row['uid'].'-disk">6h</a> <a href="grapher.php?uid='.$row['uid'].'&type=disk&interval=12h" rel="lightbox-'.$row['uid'].'-disk">12h</a> <a href="grapher.php?uid='.$row['uid'].'&type=disk&interval=1d" rel="lightbox-'.$row['uid'].'-disk">1d</a></td>'; echo '<td class="5pad"><div style="display:block; margin: 3px; padding: 2px;">'; echo '<span class="loadavg" style="background-color: #'.gen_color($row['load1']).'">'. sprintf('%.02f', $row['load1']) .'</span> '; echo '<span class="loadavg" style="background-color: #'.gen_color($row['load5']).'">'. sprintf('%.02f', $row['load5']) .'</span> '; echo '<span class="loadavg" style="background-color: #'.gen_color($row['load15']).'">'. sprintf('%.02f', $row['load15']) .'</span> '; echo '</div><a href="grapher.php?uid='.$row['uid'].'&type=loadavg&interval=1h" rel="lightbox-'.$row['uid'].'-load">1h</a> <a href="grapher.php?uid='.$row['uid'].'&type=loadavg&interval=3h" rel="lightbox-'.$row['uid'].'-load">3h</a> <a href="grapher.php?uid='.$row['uid'].'&type=loadavg&interval=6h" rel="lightbox-'.$row['uid'].'-load">6h</a> <a href="grapher.php?uid='.$row['uid'].'&type=loadavg&interval=12h" rel="lightbox-'.$row['uid'].'-load">12h</a> <a href="grapher.php?uid='.$row['uid'].'&type=loadavg&interval=1d" rel="lightbox-'.$row['uid'].'-load">1d</a>'; echo '</td>'; echo '<td>Rx: '.format_bytes($row['rx']).'/s<br />Tx: '.format_bytes($row['tx']).'/s<br />'; echo '<a href="grapher.php?uid='.$row['uid'].'&type=transfer&interval=1h" rel="lightbox-'.$row['uid'].'-transfer">1h</a> <a href="grapher.php?uid='.$row['uid'].'&type=transfer&interval=3h" rel="lightbox-'.$row['uid'].'-transfer">3h</a> <a href="grapher.php?uid='.$row['uid'].'&type=transfer&interval=6h" rel="lightbox-'.$row['uid'].'-transfer">6h</a> <a href="grapher.php?uid='.$row['uid'].'&type=transfer&interval=12h" rel="lightbox-'.$row['uid'].'-transfer">12h</a> <a href="grapher.php?uid='.$row['uid'].'&type=transfer&interval=1d" rel="lightbox-'.$row['uid'].'-transfer">1d</a>'; echo '</td>'; // echo '<td>Rx: '.(round($row['rx']/1024, 2)).' KB/s<br />Tx: '.(round($row['tx']/1024, 2)).' KB/s</td>'; echo '</tr>'; if ($servicecount[0] > 0) { $dbq = $db->prepare('SELECT * FROM processes WHERE uid = ? ORDER BY name ASC'); $dbr = $dbq->execute(array($row['uid'])); echo '<tr>'; echo '<td colspan="6" style="text-align: left; line-height: 22px;"><strong>Services:</strong><ul class="services">'; while ($service = $dbq->fetch(PDO::FETCH_ASSOC)) { switch ($service['status']) { case 0: $class = "service-up"; break; case 1: $class = "service-warning"; break; case 2: $class = "service-critical"; break; case -1: $class = "service-unknown"; break; } echo '<li class="'.$class.'">'. $service['name'] .'</li>'; } echo '</ul>'; echo '</td>'; echo '</tr>'; } if ($row['note'] != "") { echo '<tr><td colspan="6" style="text-align:left;"><strong>Notes: </strong>'.$row['note'].'</td></tr>'; } $i++; $lbjs .= " $(function() { $('a[rel=lightbox-".$row['uid']."-load]').lightBox({fixedNavigation:true}); }); $(function() { $('a[rel=lightbox-".$row['uid']."-disk]').lightBox({fixedNavigation:true}); }); $(function() { $('a[rel=lightbox-".$row['uid']."-memory]').lightBox({fixedNavigation:true}); }); $(function() { $('a[rel=lightbox-".$row['uid']."-transfer]').lightBox({fixedNavigation:true}); }); "; }
<?php if (!empty($diskinfo)) { foreach ($diskinfo as $disk) { ?> <script> $(document).ready(function(){ var data = [ ["used(<?php echo format_kbytes($disk['used_size']); ?> )", <?php echo $disk['used_size']; ?> ], ["avail(<?php echo format_kbytes($disk['avail_size']); ?> )",<?php echo $disk['avail_size']; ?> ], ]; var plot1 = jQuery.jqplot ("disk_<?php echo $disk['id']; ?> ", [data], { seriesColors: [ "#4bb2c5", "#EAA228", "#579575", "#839557", "#958c12", "#953579", "#4b5de4", "#d8b83f", "#ff5800", "#0085cc"], // 默认显示的分类颜色 title: { text: "<?php
function send_report_mail() { //Overview $mysql_servers_up = $this->db->query("select count(*) as num from mysql_status where connect=1")->row()->num; $mysql_servers_down = $this->db->query("select count(*) as num from mysql_status where connect!=1")->row()->num; $mongodb_servers_up = $this->db->query("select count(*) as num from mongodb_status where ok=1")->row()->num; $mongodb_servers_down = $this->db->query("select count(*) as num from mongodb_status where ok!=1")->row()->num; $os_snmp_up = $this->db->query("select count(*) as num from os_resource where snmp=1")->row()->num; $os_snmp_down = $this->db->query("select count(*) as num from os_resource where snmp!=1")->row()->num; $table_overview = "\n <table border=1 bgcolor=#dae8fb style='font-size: 12px;' >\n <tr>\n <th colspan=6>数据库概况</th>\n </tr>\n <tr>\n <td> MySQL Up </td>\n <td> MySQL Down </td>\n <td> MongoDB Up </td>\n <td> MongoDB Down </td>\n <td> OS SNMP Up </td>\n <td> OS SNMP Down </td>\n </tr>\n <tr>\n <td>" . $mysql_servers_up . "</td>\n <td>" . $mysql_servers_down . "</td> \n <td>" . $mongodb_servers_up . " </td> \n <td>" . $mongodb_servers_down . "</td> \n <td>" . $os_snmp_up . " </td>\n <td>" . $os_snmp_down . " </td> \n \n </tr>\n </table>\n "; //last alarm $last_alarm = $this->db->query("select * from alarm_history order by id desc limit 10;")->result_array(); $table_header = "<table border=1 bgcolor=#dae8fb style='font-size: 12px;' >\n <tr>\n <th colspan=7>最新告警</th>\n </tr>\n <tr>\n <td>host</td>\n <td>application</td>\n <td>db_type</td>\n <td>level</td>\n <td>message</td>\n <td>value</td>\n <td>monitor_time</td>\n </tr>\n "; $table_content = ''; foreach ($last_alarm as $record) { $table_record = "\n \n <tr>\n <td> " . $record['host'] . ":" . $record['port'] . "</td>\n <td> " . $record['application'] . " </td> \n <td> " . $record['db_type'] . "</td> \n <td> " . $record['level'] . "</td>\n <td> " . $record['message'] . "</td> \n <td> " . $record['alarm_value'] . "</td> \n <td> " . $record['create_time'] . "</td> \n </tr>\n "; $table_content = $table_content . $table_record; } $table_footer = "</table>"; $table_content_alarm = $table_header . $table_content . $table_footer; //mysql thread top 10 $top_mysql_thread = $this->db->query("select server.host,server.port,status.threads_running,`status`.threads_connected,queries_persecond,transaction_persecond,app.`name` appname from mysql_status status left join db_servers_mysql server\non `status`.server_id=`server`.id join db_application app where `server`.application_id=app.id order by threads_running desc limit 10;")->result_array(); $table_header = "<table border=1 bgcolor=#dae8fb style='font-size: 12px;' >\n <tr>\n <th colspan=6>MySQL性能Top10</th>\n </tr>\n <tr>\n <td>host</td>\n <td>app</td>\n <td>threads_running</td>\n <td>threads_connected</td>\n <td>queries_persecond</td>\n <td>transaction_persecond</td>\n </tr>\n "; $table_content = ''; foreach ($top_mysql_thread as $record) { $table_record = "\n \n <tr>\n <td> " . $record['host'] . ":" . $record['port'] . " </td>\n <td> " . $record['appname'] . " </td>\t\n <td> " . $record['threads_running'] . " </td>\t\n <td> " . $record['threads_connected'] . " </td>\t\n <td> " . $record['queries_persecond'] . " </td>\n <td> " . $record['transaction_persecond'] . " </td>\t\n \t\t\n\t </tr>\n "; $table_content = $table_content . $table_record; } $table_footer = "</table>"; $table_content_mysql_thread = $table_header . $table_content . $table_footer; //mongodb connection top 10 $top_mongodb_connections = $this->db->query("select server.host,server.port,`status`.connections_current,`status`.connections_available,`status`.opcounters_query_persecond,\n`status`.opcounters_insert_persecond,`status`.opcounters_update_persecond,`status`.opcounters_delete_persecond,app.name appname from mongodb_status status left join db_servers_mongodb server\non `status`.server_id=`server`.id join db_application app where `server`.application_id=app.id order by connections_current desc limit 10;")->result_array(); $table_header = "<table border=1 bgcolor=#dae8fb style='font-size: 12px;' >\n <tr>\n <th colspan=8>MongoDB性能Top10</th>\n </tr>\n <tr>\n <td>host</td>\n <td>app</td>\n <td>connections_current</td>\n <td>connections_available</td>\n <td>query</td>\n <td>insert</td>\n <td>update</td>\n <td>delete</td>\n </tr>\n "; $table_content = ''; foreach ($top_mongodb_connections as $record) { $table_record = "\n \n <tr>\n <td> " . $record['host'] . ":" . $record['port'] . " </td>\n <td> " . $record['appname'] . " </td>\t\n <td> " . $record['connections_current'] . " </td>\t\n <td> " . $record['connections_available'] . " </td>\t\n <td> " . $record['opcounters_query_persecond'] . " </td>\n <td> " . $record['opcounters_insert_persecond'] . " </td>\n <td> " . $record['opcounters_update_persecond'] . " </td>\n <td> " . $record['opcounters_delete_persecond'] . " </td>\t\n \t\t\n\t </tr>\n "; $table_content = $table_content . $table_record; } $table_footer = "</table>"; $table_content_mongodb = $table_header . $table_content . $table_footer; //cupload top 10 $top_cpuload = $this->db->query("select ip,load_1,load_5,load_15,process,cpu_idle_time from os_resource order by load_1 desc limit 10;")->result_array(); $table_header = "<table border=1 bgcolor=#dae8fb style='font-size: 12px;' >\n <tr>\n <th colspan=6>系统CPU负载Top10</th>\n </tr>\n <tr>\n <td>ip</td>\n <td>load_1</td>\n <td>load_5</td>\n <td>load_15</td>\n <td>process</td>\n <td>cpu idle</td>\n </tr>\n "; $table_content = ''; foreach ($top_cpuload as $record) { $table_record = "\n \n <tr>\n <td> " . $record['ip'] . " </td>\t\n <td> " . $record['load_1'] . " </td>\t\n <td> " . $record['load_5'] . " </td>\t\n <td> " . $record['load_15'] . " </td>\n <td> " . $record['process'] . " </td>\t\n <td> " . $record['cpu_idle_time'] . "% </td>\t\t\n\t </tr>\n "; $table_content = $table_content . $table_record; } $table_footer = "</table>"; $table_content_cpuload = $table_header . $table_content . $table_footer; //disk top 10 $top_diskusage = $this->db->query("select ip,mounted,total_size,used_size,avail_size,used_rate from os_diskinfo group by CONCAT(ip,mounted) order by cast(SUBSTRING_INDEX(used_rate,'%',1) as unsigned) desc limit 10;")->result_array(); $table_header = "<table border=1 bgcolor=#dae8fb style='font-size: 12px;' >\n <tr>\n <th colspan=6>系统磁盘使用率Top10</th>\n </tr>\n <tr>\n <td>ip</td>\n <td>mounted</td>\n <td>total_size</td>\n <td>used_size</td>\n <td>avail_size</td>\n <td>used_rate</td>\n </tr>\n "; $table_content = ''; foreach ($top_diskusage as $record) { $table_record = "\n \n <tr>\n <td> " . $record['ip'] . " </td>\t\n <td> " . $record['mounted'] . " </td>\t\n <td> " . format_kbytes($record['total_size']) . " </td>\t\n <td> " . format_kbytes($record['used_size']) . " </td>\t\n <td> " . format_kbytes($record['avail_size']) . " </td>\t\n <td> " . $record['used_rate'] . " </td>\t\t\n\t </tr>\n "; $table_content = $table_content . $table_record; } $table_footer = "</table>"; $table_content_disk = $table_header . $table_content . $table_footer; //echo $table_overview."</p>".$table_content_alarm."</p>".$table_content_mysql_thread."</p>".$table_content_mongodb."</p>".$table_content_cpuload."</p>".$table_content_disk; $title = "数据库服务器健康检查报告"; $content = $table_overview . "</p>" . $table_content_alarm . "</p>" . $table_content_mysql_thread . "</p>" . $table_content_mongodb . "</p>" . $table_content_cpuload . "</p>" . $table_content_disk; $this->load->library('email'); $this->email->clear(); $config['protocol'] = 'smtp'; $config['mailtype'] = 'html'; $config['charset'] = 'utf-8'; $config['smtp_host'] = $this->settings->get_option_item('smtp_host'); $config['smtp_port'] = $this->settings->get_option_item('smtp_port'); $config['smtp_user'] = $this->settings->get_option_item('smtp_user'); $config['smtp_pass'] = $this->settings->get_option_item('smtp_pass'); $config['smtp_timeout'] = $this->settings->get_option_item('smtp_timeout'); $mailfrom = $this->settings->get_option_item('mailfrom'); $report_mail_to_list = $this->settings->get_option_item('report_mail_to_list'); $this->email->initialize($config); $this->email->from($mailfrom); $this->email->to($report_mail_to_list); $this->email->subject($title); $this->email->message($content); if (!$this->email->send()) { echo " Send report mail Fail!</br>"; } else { echo " Send report mail seccess!</br>"; } }
echo '<td>' . $row['uptime'] . '</td>'; echo '<td class="5pad">'; if (empty($row['mtotal'])) { echo "n/a"; } else { $mp = ($row['mused'] - $row['mbuffers']) / $row['mtotal'] * 100; $used = $row['mused'] - $row['mbuffers']; echo '<div class="progress-container"><div class="progress-container-percent" style="width:' . $mp . '%"><div class="bartext">' . $used . '/' . $row['mtotal'] . 'MB</div></div></div>'; } echo '</td>'; echo '<td class="5pad">'; if (empty($row['diskused'])) { echo 'n/a'; } else { $mp = $row['diskused'] / $row['disktotal'] * 100; echo '<div class="progress-container"><div class="progress-container-percent" style="width:' . $mp . '%"><div class="bartext">' . format_kbytes($row['diskused']) . '/' . format_kbytes($row['disktotal']) . 'GB</div></div></div>'; } echo '</td>'; echo '<td class="5pad">'; if ($row['os'] == 0) { echo '<span class="loadavg" style="background-color: #' . gen_color($row['load1']) . '">' . sprintf('%.02f', $row['load1']) . '</span> '; echo '<span class="loadavg" style="background-color: #' . gen_color($row['load5']) . '">' . sprintf('%.02f', $row['load5']) . '</span> '; echo '<span class="loadavg" style="background-color: #' . gen_color($row['load15']) . '">' . sprintf('%.02f', $row['load15']) . '</span> '; } else { echo 'Unknown'; } echo '</td>'; echo '</tr>'; } function format_kbytes($size) {
?> </td> <td><?php echo $item['mounted']; ?> </td> <td><?php echo format_kbytes($item['total_size']); ?> </td> <td><?php echo format_kbytes($item['used_size']); ?> </td> <td><?php echo format_kbytes($item['avail_size']); ?> </td> <td><?php echo $item['used_rate']; ?> </td> <td><a href="<?php echo site_url('os/cpu_chart/' . $item['ip']); ?> "><img src="./images/chart.gif"/></a></a></td> </tr> <?php } } else { ?>
<td><?php echo $item['tags']; ?> </td> <td> <?php if (!empty($item['diskinfo'])) { ?> <?php foreach ($item['diskinfo'] as $disk) { ?> <div style="margin-right:40px; float:left;">[<?php echo $disk['mounted']; ?> Total:<?php echo format_kbytes($disk['total_size']); ?> Used_Rate:<?php echo $disk['used_rate']; ?> ]</div> <?php } ?> <?php } ?> </td> <td><a href="<?php echo site_url('os/disk_chart/' . $item['ip']); ?>
?> </td> <td><?php echo check_active(check_value($item['threads_running'])); ?> </td> <td><?php echo check_active(check_value($item['threads_waits'])); ?> </td> <td><?php echo format_kbytes($item['bytes_received_persecond']); ?> </td> <td><?php echo format_kbytes($item['bytes_sent_persecond']); ?> </td> <td><?php echo check_value($item['queries_persecond']); ?> </td> <td><?php echo check_value($item['transaction_persecond']); ?> </td> <td><?php if ($item['connect'] == '1') { ?> <a href="<?php echo site_url('mysql/chart/' . $item['server_id']);