Skip to content

Commit

Permalink
Merge pull request #8 from statusengine/watchdog
Browse files Browse the repository at this point in the history
Watchdog
  • Loading branch information
nook24 committed Sep 6, 2018
2 parents 9229784 + ae11fb1 commit fe0e8de
Show file tree
Hide file tree
Showing 115 changed files with 471 additions and 219 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.0
3.4.0
2 changes: 1 addition & 1 deletion bin/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?php
/**
* Statusengine Worker
* Copyright (C) 2016-2017 Daniel Ziegler
* Copyright (C) 2016-2018 Daniel Ziegler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
73 changes: 12 additions & 61 deletions bin/StatusengineWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?php
/**
* Statusengine Worker
* Copyright (C) 2016-2017 Daniel Ziegler
* Copyright (C) 2016-2018 Daniel Ziegler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -42,16 +42,11 @@
$pids = [];
$ParentPid = new \Statusengine\ValueObjects\Pid(getmypid());

$ChildFactory = new \Statusengine\ChildFactory($Config, $Syslog, $ParentPid);

if ($Config->isRedisEnabled() || $Config->storeLiveDateInArchive()) {
for ($i = 0; $i < $Config->getNumberOfHoststatusWorkers(); $i++) {
$Syslog->info('Fork new host status worker');
$HoststatusChild = new Statusengine\HoststatusChild(
$Config,
$ParentPid,
$Syslog
);
$hoststatusChildPid = $HoststatusChild->fork();
$pids[] = $hoststatusChildPid;
$pids[] = $ChildFactory->forkHoststatusChild();
}
}

Expand All @@ -70,74 +65,29 @@

if ($Config->isCrateEnabled() || $Config->isMysqlEnabled()) {
for ($i = 0; $i < $Config->getNumberOfLogentryWorkers(); $i++) {
$Syslog->info('Fork new log entry worker');
$LogentryChild = new Statusengine\LogentryChild(
$Config,
$ParentPid,
$Syslog
);
$logentryChildPid = $LogentryChild->fork();
$pids[] = $logentryChildPid;
$pids[] = $ChildFactory->forkLogentryChild();
}

for ($i = 0; $i < $Config->getNumberOfStatechangeWorkers(); $i++) {
$Syslog->info('Fork new state change worker');
$StatechangeConfig = new Statusengine\Config\Statechange();
$StatechangeSignalHandler = new \Statusengine\ChildSignalHandler();
$StatechangeStatistics = new \Statusengine\Redis\Statistics($Config, $Syslog);
$StatechangeChild = new Statusengine\StatechangeChild(
$Config,
$ParentPid,
$Syslog
);
$statechangeChildPid = $StatechangeChild->fork();
$pids[] = $statechangeChildPid;
$pids[] = $ChildFactory->forkStatechangeChild();
}

for ($i = 0; $i < $Config->getNumberOfHostcheckWorkers(); $i++) {
$Syslog->info('Fork new host check worker');
$HostcheckChild = new Statusengine\HostcheckChild(
$Config,
$ParentPid,
$Syslog
);
$hostcheckChildPid = $HostcheckChild->fork();
$pids[] = $hostcheckChildPid;
$pids[] = $ChildFactory->forkHostcheckChild();
}

for ($i = 0; $i < $Config->getNumberOfServicecheckWorkers(); $i++) {
$Syslog->info('Fork new service check worker');
$ServicecheckChild = new Statusengine\ServicecheckChild(
$Config,
$ParentPid,
$Syslog
);
$servicecheckChildPid = $ServicecheckChild->fork();
$pids[] = $servicecheckChildPid;
$pids[] = $ChildFactory->forkServicecheckChild();
}

for ($i = 0; $i < $Config->getNumberOfMiscWorkers(); $i++) {
$Syslog->info('Fork new misc worker');
$MiscChild = new Statusengine\MiscChild(
$Config,
$ParentPid,
$Syslog
);
$miscChildPid = $MiscChild->fork();
$pids[] = $miscChildPid;
$pids[] = $ChildFactory->forkMiscChild();
}
}

if ($Config->isProcessPerfdataEnabled() && $Config->isOnePerfdataBackendEnabled()) {
for ($i = 0; $i < $Config->getNumberOfPerfdataWorkers(); $i++) {
$Syslog->info('Fork new performance data worker');
$PerfdataChild = new Statusengine\PerfdataChild(
$Config,
$ParentPid,
$Syslog
);
$perfdataChildPid = $PerfdataChild->fork();
$pids[] = $perfdataChildPid;
$pids[] = $ChildFactory->forkPerfdataChild();
}
}

Expand All @@ -160,7 +110,8 @@
$TaskManager,
$Syslog,
$MonitoringRestartConfig,
$StorageBackend
$StorageBackend,
$ChildFactory
);
foreach ($pids as $Pid) {
$ParentProcess->addChildPid($Pid);
Expand Down
2 changes: 1 addition & 1 deletion bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Statusengine Worker
* Copyright (C) 2016-2017 Daniel Ziegler
* Copyright (C) 2016-2018 Daniel Ziegler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion src/BackendSelector.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Statusengine Worker
* Copyright (C) 2016-2017 Daniel Ziegler
* Copyright (C) 2016-2018 Daniel Ziegler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
71 changes: 37 additions & 34 deletions src/Backends/Crate/Crate.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Statusengine Worker
* Copyright (C) 2016-2017 Daniel Ziegler
* Copyright (C) 2016-2018 Daniel Ziegler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -91,11 +91,11 @@ public function __construct(Config $Config, BulkInsertObjectStore $BulkInsertObj
* @param null|int $startTime
*/
public function saveNodeName($nodeName = null, $startTime = null) {
if($nodeName === null){
if ($nodeName === null) {
$nodeName = $this->nodeName;
}

if($startTime === null){
if ($startTime === null) {
$startTime = time();
}

Expand All @@ -119,7 +119,7 @@ public function saveNodeName($nodeName = null, $startTime = null) {
/**
* @return array
*/
public function getNodes(){
public function getNodes() {
$this->connect();
$query = $this->Connection->prepare('SELECT * FROM statusengine_nodes ORDER BY node_name ASC');

Expand All @@ -131,7 +131,7 @@ public function getNodes(){
}
$this->disconnect();
$nodes = [];
foreach($result as $record){
foreach ($result as $record) {
$nodes[] = NodeName::fromCrateDb($record);
}
return $nodes;
Expand All @@ -140,7 +140,7 @@ public function getNodes(){
/**
* @param string $nodeName
*/
public function deleteNodeByName($nodeName){
public function deleteNodeByName($nodeName) {
$this->connect();
$query = $this->Connection->prepare('DELETE FROM statusengine_nodes WHERE node_name=?');
$query->bindValue(1, $nodeName);
Expand Down Expand Up @@ -172,14 +172,17 @@ public function connect() {
$this->Connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (\Exception $e) {
$this->Syslog->error($e->getMessage());

//rethrow exception that the parent process will not die.
throw $e;
}
return $this->Connection;
}

/**
* @param int $timeout in seconds
*/
public function setTimeout($timeout){
public function setTimeout($timeout) {
$this->Connection->setAttribute(PDO::ATTR_TIMEOUT, $timeout);
}

Expand Down Expand Up @@ -379,13 +382,13 @@ public function deleteTaskByUuids($uuids = []) {
public function deleteHostchecksOlderThan($timestamp) {
$partitions = $this->getPartitionsByTableName('statusengine_hostchecks');
$daysToDelete = [];
foreach($partitions as $record){
if(isset($record['values']['day']) && $record['values']['day'] < $timestamp){
foreach ($partitions as $record) {
if (isset($record['values']['day']) && $record['values']['day'] < $timestamp) {
$daysToDelete[] = $record['values']['day'];
}
}

foreach($daysToDelete as $partition){
foreach ($daysToDelete as $partition) {
$this->dropPartitionsFromTableByTableNameAndDayValue('statusengine_hostchecks', $partition);
}
}
Expand All @@ -408,13 +411,13 @@ public function deleteHostAcknowledgementsOlderThan($timestamp) {
public function deleteHostNotificationsOlderThan($timestamp) {
$partitions = $this->getPartitionsByTableName('statusengine_host_notifications');
$daysToDelete = [];
foreach($partitions as $record){
if(isset($record['values']['day']) && $record['values']['day'] < $timestamp){
foreach ($partitions as $record) {
if (isset($record['values']['day']) && $record['values']['day'] < $timestamp) {
$daysToDelete[] = $record['values']['day'];
}
}

foreach($daysToDelete as $partition){
foreach ($daysToDelete as $partition) {
$this->dropPartitionsFromTableByTableNameAndDayValue('statusengine_host_notifications', $partition);
}
}
Expand All @@ -425,13 +428,13 @@ public function deleteHostNotificationsOlderThan($timestamp) {
public function deleteHostStatehistoryOlderThan($timestamp) {
$partitions = $this->getPartitionsByTableName('statusengine_host_statehistory');
$daysToDelete = [];
foreach($partitions as $record){
if(isset($record['values']['day']) && $record['values']['day'] < $timestamp){
foreach ($partitions as $record) {
if (isset($record['values']['day']) && $record['values']['day'] < $timestamp) {
$daysToDelete[] = $record['values']['day'];
}
}

foreach($daysToDelete as $partition){
foreach ($daysToDelete as $partition) {
$this->dropPartitionsFromTableByTableNameAndDayValue('statusengine_host_statehistory', $partition);
}
}
Expand All @@ -454,13 +457,13 @@ public function deleteHostDowntimeHistoryOlderThan($timestamp) {
public function deleteServicechecksOlderThan($timestamp) {
$partitions = $this->getPartitionsByTableName('statusengine_servicechecks');
$daysToDelete = [];
foreach($partitions as $record){
if(isset($record['values']['day']) && $record['values']['day'] < $timestamp){
foreach ($partitions as $record) {
if (isset($record['values']['day']) && $record['values']['day'] < $timestamp) {
$daysToDelete[] = $record['values']['day'];
}
}

foreach($daysToDelete as $partition){
foreach ($daysToDelete as $partition) {
$this->dropPartitionsFromTableByTableNameAndDayValue('statusengine_servicechecks', $partition);
}
}
Expand All @@ -483,13 +486,13 @@ public function deleteServiceAcknowledgementsOlderThan($timestamp) {
public function deleteServiceNotificationsOlderThan($timestamp) {
$partitions = $this->getPartitionsByTableName('statusengine_service_notifications');
$daysToDelete = [];
foreach($partitions as $record){
if(isset($record['values']['day']) && $record['values']['day'] < $timestamp){
foreach ($partitions as $record) {
if (isset($record['values']['day']) && $record['values']['day'] < $timestamp) {
$daysToDelete[] = $record['values']['day'];
}
}

foreach($daysToDelete as $partition){
foreach ($daysToDelete as $partition) {
$this->dropPartitionsFromTableByTableNameAndDayValue('statusengine_service_notifications', $partition);
}
}
Expand Down Expand Up @@ -531,13 +534,13 @@ public function deleteServiceDowntimeHistoryOlderThan($timestamp) {
public function deleteLogentriesOlderThan($timestamp) {
$partitions = $this->getPartitionsByTableName('statusengine_logentries');
$daysToDelete = [];
foreach($partitions as $record){
if(isset($record['values']['day']) && $record['values']['day'] < $timestamp){
foreach ($partitions as $record) {
if (isset($record['values']['day']) && $record['values']['day'] < $timestamp) {
$daysToDelete[] = $record['values']['day'];
}
}

foreach($daysToDelete as $partition){
foreach ($daysToDelete as $partition) {
$this->dropPartitionsFromTableByTableNameAndDayValue('statusengine_logentries', $partition);
}
}
Expand All @@ -558,18 +561,18 @@ public function deleteTasksOlderThan($timestamp) {
* @param int $timestamp
* @return bool
*/
public function deletePerfdataOlderThan($timestamp){
public function deletePerfdataOlderThan($timestamp) {
$timestamp = $timestamp * 1000;

$partitions = $this->getPartitionsByTableName('statusengine_perfdata');
$daysToDelete = [];
foreach($partitions as $record){
if(isset($record['values']['day']) && $record['values']['day'] < $timestamp){
$daysToDelete[] = $record['values']['day'];
}
foreach ($partitions as $record) {
if (isset($record['values']['day']) && $record['values']['day'] < $timestamp) {
$daysToDelete[] = $record['values']['day'];
}
}

foreach($daysToDelete as $partition){
foreach ($daysToDelete as $partition) {
$this->dropPartitionsFromTableByTableNameAndDayValue('statusengine_perfdata', $partition);
}
}
Expand All @@ -578,7 +581,7 @@ public function deletePerfdataOlderThan($timestamp){
* @param string $tablename
* @return array
*/
public function getPartitionsByTableName($tablename){
public function getPartitionsByTableName($tablename) {
$query = $this->prepare(
'SELECT * FROM information_schema.table_partitions WHERE table_name=?'
);
Expand All @@ -592,7 +595,7 @@ public function getPartitionsByTableName($tablename){
* @param int $dayValue
* @return bool
*/
public function dropPartitionsFromTableByTableNameAndDayValue($tableName, $dayValue){
public function dropPartitionsFromTableByTableNameAndDayValue($tableName, $dayValue) {
$query = $this->prepare(sprintf('DELETE FROM %s WHERE DAY = ?', $tableName));
$query->bindValue(1, $dayValue);
return $query->execute();
Expand Down Expand Up @@ -626,7 +629,7 @@ public function getServiceScheduleddowntimeBackend() {
return new CrateServiceScheduleddowntime($this, $this->nodeName);
}

public function monitoringengineWasRestarted(){
public function monitoringengineWasRestarted() {
$this->connect();
$Hoststatus = new CrateHoststatus($this, $this->BulkInsertObjectStore, $this->nodeName);
$Hoststatus->truncate();
Expand Down
2 changes: 1 addition & 1 deletion src/Backends/Crate/CrateModel.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Statusengine Worker
* Copyright (C) 2016-2017 Daniel Ziegler
* Copyright (C) 2016-2018 Daniel Ziegler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion src/Backends/Crate/SqlObjects/CrateHostAcknowledgement.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Statusengine Worker
* Copyright (C) 2016-2017 Daniel Ziegler
* Copyright (C) 2016-2018 Daniel Ziegler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion src/Backends/Crate/SqlObjects/CrateHostDowntimehistory.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Statusengine Worker
* Copyright (C) 2016-2017 Daniel Ziegler
* Copyright (C) 2016-2018 Daniel Ziegler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
Loading

0 comments on commit fe0e8de

Please sign in to comment.