Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #97 from Schibsted-Tech-Polska/add-memory-graph-wi…
Browse files Browse the repository at this point in the history
…dget

Add memory graph widget
  • Loading branch information
domeq authored Jan 11, 2017
2 parents 0f58dfc + 82d7815 commit b6ac1a5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions module/Dashboard/config/autoload/dao/NewRelicDao.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
final class NewRelicAddresses {
const TOTAL_MEMORY = 'fetchTotalMemory';
const AVG_HOST_MEMORY = 'fetchMemoryAvg';
const HOST_MEMORY = 'fetchMemoryUsage';
}

return [
Expand Down Expand Up @@ -45,6 +46,10 @@ final class NewRelicAddresses {
'https://api.newrelic.com/v2/applications/:appId:/metrics/data.json'
. '?names[]=Memory/Physical&values[]=total_used_mb&summarize=true'
. '&from=:beginDateTime:&end=:endDateTime:',
NewRelicAddresses::HOST_MEMORY =>
'https://api.newrelic.com/v2/applications/:appId:/metrics/data.json'
. '?names[]=Memory/Physical&values[]=used_mb_by_host&summarize=false'
. '&from=:beginDateTime:&end=:endDateTime:',
'fetchServerCpuUsageForGraphWidget' =>
'https://api.newrelic.com/v2/servers/:serverId:/metrics/data.json'
. '?names[]=System/CPU/System/percent&names[]=System/CPU/User/percent'
Expand Down
21 changes: 21 additions & 0 deletions module/Dashboard/src/Dashboard/Model/Dao/NewRelicDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,27 @@ public function fetchTotalMemoryForIncrementalGraphWidget(array $params = [])
];
}

/**
* Fetches memory usage by your app
*
* @param array $params - array with appId and other optional parameters for endpoint URL
* @return float
*/
public function fetchMemoryUsageForGraphWidget(array $params = [])
{
$response = $this->request($this->getEndpointUrl(NewRelicAddresses::HOST_MEMORY), $params, self::RESPONSE_IN_JSON);
return array_map(
function ($timeslice) use ($params) {
return [
'x' => 1000 * Utils::dateStringToLocalSeconds($timeslice['to']),
'y' => $timeslice['values']['used_mb_by_host'],
'events' => $this->fetchDeploymentEvents($params),
];
},
$response['metric_data']['metrics'][0]['timeslices']
);
}

/**
* @param array $params
*
Expand Down

0 comments on commit b6ac1a5

Please sign in to comment.