_processObservation(); } /** * Adds additional editor fields to the Contentserv interface * * @param CSGuiEditor $editor * @param CSMonitorObserver $observer */ public function prepareEditor(CSGuiEditor $editor, CSMonitorObserver $observer) { $this->_observer = $observer; $editor->addField('SearchWord', CS::translate('CSALIVE_MONITOR_SEARCH_WORD', 'csalive'), '', '', FALSE, array( 'PaneTitle' => CS::translate('REST_GUI_EDIT_SETTINGS') )); } ///// PROTECTED METHODS ////////////////////////////////////////////////////// /** * Measures the time needed for a specific process and stores it in the database */ protected function _processObservation() { $strUrl = '../admin/rest/opensearch/search?q=' . $this->getSearchWord() . '&f=json&l=de&a=&p=1&c=10' . CSUser::getPIN(); $intStartTime = $this->microtimeFloat(); //START $strResult = Curl::GET($strUrl); $arrResult = json_decode($strResult, true); $floatMeasuredTime = $this->getDuration($intStartTime); //STOP $this->saveSearchedValue($floatMeasuredTime, 's', 'Core.' . $this->getServiceName()); if ($strResult !== NULL) { $this->saveSearchedValue($arrResult['totalResults'], 'items', 'Core.' . $this->getServiceName() . 'Value'); } } ///// PRIVATE METHODS ////////////////////////////////////////////////////// /** * Returns a the current time as microtime. * * Helper function to measure script durations * * @return float returns current microtime */ private function microtimeFloat() { list($usec, $sec) = explode(" ", microtime()); return ((float) $usec + (float) $sec); } /** * Returns the time difference between current time and given time in seconds. * * Helper function to measure script durations * * @return float returns current microtime */ private function getDuration($intStartTime) { return number_format((self::microtimeFloat() - $intStartTime), 4); } /** * Receives the name of the service * * @return String Name of the service */ private function getServiceName() { $strServiceName = 'Searchperformance'; return $strServiceName; } /** * Receives the entered word in the editor * * @return String Searched Word */ private function getSearchWord() { $strSearchWord = $this->_observer->getValue('SearchWord'); return $strSearchWord; } /** * Saves the searched values in the database * * @param mixed $mixedSearchedValue * @param String $strUnit * @param String $strService */ private function saveSearchedValue($mixedSearchedValue, $strUnit, $strService) { $observation = CSMonitor::createObservation($this->_observer->getID(), $strService); $observation->setMeasuredValue($mixedSearchedValue); $observation->setTimestamp(CS::getDate()); $observation->setUnit($strUnit); $state = CSMonitor::MONITOR_GUI_NOTIFICATION_NONE_ID; $observation->setState($state); $observation->setWarningValue(1); $observation->setCriticalValue(2); $observation->store(); } }