Skip to content

Commit

Permalink
Change the action to a prefix
Browse files Browse the repository at this point in the history
 The prefix can instantaneously be used in log.php to increment a
service. It save a check of the action to determine the prefix.
  • Loading branch information
jorianvo committed Jun 23, 2015
1 parent 12d82e5 commit a86e197
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class OC_esLog_Hooks {

// This function is called every time a file is read
static public function read($path) {
OC_esLog::sendToStatsd($path,'File read');
OC_esLog::sendToStatsd($path,'browser.reads.');
}

// This function is called every time a file is written
static public function write($path) {
OC_esLog::sendToStatsd($path,'File write');
OC_esLog::sendToStatsd($path,'browser.uploads.');
}

// This function is called every time a file is written using webdav
Expand All @@ -39,7 +39,7 @@ static public function webdav($vars) {
// Get the request method
if($protocol=='webdav'){
if ($action=='put') {
OC_esLog::sendToStatsd(NULL,'File write');
OC_esLog::sendToStatsd(NULL,'webdav.putrequests.');
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions lib/log.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ public function __construct(){

// This function will gather the stats and send them statsd
// The path is the path of the file that is read or written
// currently this is not used. The action is either 'File read'
// or 'File write' and determines what value to send to statsd
public static function sendToStatsd($path,$action){
// currently this is not used. The action tells us the action
// performed e.g. 'Webdav put request' and the prefix is the
// statsd prefix we give to the metric in order to easily find
// it in graphite
public static function sendToStatsd($path,$prefix){
// Get host and port from gui (admin)
$host = OC_Appconfig::getValue('eslog', 'eslog_host', '127.0.0.1');
$port = OC_Appconfig::getValue('eslog', 'eslog_port', '8125');
Expand Down Expand Up @@ -58,11 +60,7 @@ public static function sendToStatsd($path,$action){
//throw new \Exception("country of origin = $country");

// Check if file is read or written
if ($action == "File read"){
$service->increment('read');
} elseif ($action == "File write"){
$service->increment("files.writes.".$locator);
}
$service->increment($prefix.$locator);

// Send the data over the socket to statsd
$service->flush();
Expand Down

0 comments on commit a86e197

Please sign in to comment.