queryCtrl.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. define([
  2. 'angular',
  3. 'lodash',
  4. 'kbn',
  5. ],
  6. function (angular, _, kbn) {
  7. 'use strict';
  8. var module = angular.module('grafana.controllers');
  9. var supportedMetrics = {
  10. "AWS/AutoScaling": [
  11. "GroupMinSize", "GroupMaxSize", "GroupDesiredCapacity", "GroupInServiceInstances", "GroupPendingInstances", "GroupStandbyInstances", "GroupTerminatingInstances", "GroupTotalInstances"
  12. ],
  13. "AWS/Billing": [
  14. "EstimatedCharges"
  15. ],
  16. "AWS/CloudFront": [
  17. "Requests", "BytesDownloaded", "BytesUploaded", "TotalErrorRate", "4xxErrorRate", "5xxErrorRate"
  18. ],
  19. "AWS/CloudSearch": [
  20. "SuccessfulRequests", "SearchableDocuments", "IndexUtilization", "Partitions"
  21. ],
  22. "AWS/DynamoDB": [
  23. "ConditionalCheckFailedRequests", "ConsumedReadCapacityUnits", "ConsumedWriteCapacityUnits", "OnlineIndexConsumedWriteCapacity", "OnlineIndexPercentageProgress", "OnlineIndexThrottleEvents", "ProvisionedReadCapacityUnits", "ProvisionedWriteCapacityUnits", "ReadThrottleEvents", "ReturnedItemCount", "SuccessfulRequestLatency", "SystemErrors", "ThrottledRequests", "UserErrors", "WriteThrottleEvents"
  24. ],
  25. "AWS/ElastiCache": [
  26. "CPUUtilization", "SwapUsage", "FreeableMemory", "NetworkBytesIn", "NetworkBytesOut",
  27. "BytesUsedForCacheItems", "BytesReadIntoMemcached", "BytesWrittenOutFromMemcached", "CasBadval", "CasHits", "CasMisses", "CmdFlush", "CmdGet", "CmdSet", "CurrConnections", "CurrItems", "DecrHits", "DecrMisses", "DeleteHits", "DeleteMisses", "Evictions", "GetHits", "GetMisses", "IncrHits", "IncrMisses", "Reclaimed",
  28. "CurrConnections", "Evictions", "Reclaimed", "NewConnections", "BytesUsedForCache", "CacheHits", "CacheMisses", "ReplicationLag", "GetTypeCmds", "SetTypeCmds", "KeyBasedCmds", "StringBasedCmds", "HashBasedCmds", "ListBasedCmds", "SetBasedCmds", "SortedSetBasedCmds", "CurrItems"
  29. ],
  30. "AWS/EBS": [
  31. "VolumeReadBytes", "VolumeWriteBytes", "VolumeReadOps", "VolumeWriteOps", "VolumeTotalReadTime", "VolumeTotalWriteTime", "VolumeIdleTime", "VolumeQueueLength", "VolumeThroughputPercentage", "VolumeConsumedReadWriteOps",
  32. ],
  33. "AWS/EC2": [
  34. "CPUCreditUsage", "CPUCreditBalance", "CPUUtilization", "DiskReadOps", "DiskWriteOps", "DiskReadBytes", "DiskWriteBytes", "NetworkIn", "NetworkOut", "StatusCheckFailed", "StatusCheckFailed_Instance", "StatusCheckFailed_System"
  35. ],
  36. "AWS/ELB": [
  37. "HealthyHostCount", "UnHealthyHostCount", "RequestCount", "Latency", "HTTPCode_ELB_4XX", "HTTPCode_ELB_5XX", "HTTPCode_Backend_2XX", "HTTPCode_Backend_3XX", "HTTPCode_Backend_4XX", "HTTPCode_Backend_5XX", "BackendConnectionErrors", "SurgeQueueLength", "SpilloverCount"
  38. ],
  39. "AWS/ElasticMapReduce": [
  40. "CoreNodesPending", "CoreNodesRunning", "HBaseBackupFailed", "HBaseMostRecentBackupDuration", "HBaseTimeSinceLastSuccessfulBackup", "HDFSBytesRead", "HDFSBytesWritten", "HDFSUtilization", "IsIdle", "JobsFailed", "JobsRunning", "LiveDataNodes", "LiveTaskTrackers", "MapSlotsOpen", "MissingBlocks", "ReduceSlotsOpen", "RemainingMapTasks", "RemainingMapTasksPerSlot", "RemainingReduceTasks", "RunningMapTasks", "RunningReduceTasks", "S3BytesRead", "S3BytesWritten", "TaskNodesPending", "TaskNodesRunning", "TotalLoad"
  41. ],
  42. "AWS/Kinesis": [
  43. "PutRecord.Bytes", "PutRecord.Latency", "PutRecord.Success", "PutRecords.Bytes", "PutRecords.Latency", "PutRecords.Records", "PutRecords.Success", "IncomingBytes", "IncomingRecords", "GetRecords.Bytes", "GetRecords.IteratorAgeMilliseconds", "GetRecords.Latency", "GetRecords.Success"
  44. ],
  45. "AWS/ML": [
  46. "PredictCount", "PredictFailureCount"
  47. ],
  48. "AWS/OpsWorks": [
  49. "cpu_idle", "cpu_nice", "cpu_system", "cpu_user", "cpu_waitio", "load_1", "load_5", "load_15", "memory_buffers", "memory_cached", "memory_free", "memory_swap", "memory_total", "memory_used", "procs"
  50. ],
  51. "AWS/Redshift": [
  52. "CPUUtilization", "DatabaseConnections", "HealthStatus", "MaintenanceMode", "NetworkReceiveThroughput", "NetworkTransmitThroughput", "PercentageDiskSpaceUsed", "ReadIOPS", "ReadLatency", "ReadThroughput", "WriteIOPS", "WriteLatency", "WriteThroughput"
  53. ],
  54. "AWS/RDS": [
  55. "BinLogDiskUsage", "CPUUtilization", "DatabaseConnections", "DiskQueueDepth", "FreeableMemory", "FreeStorageSpace", "ReplicaLag", "SwapUsage", "ReadIOPS", "WriteIOPS", "ReadLatency", "WriteLatency", "ReadThroughput", "WriteThroughput", "NetworkReceiveThroughput", "NetworkTransmitThroughput"
  56. ],
  57. "AWS/Route53": [
  58. "HealthCheckStatus", "HealthCheckPercentageHealthy"
  59. ],
  60. "AWS/SNS": [
  61. "NumberOfMessagesPublished", "PublishSize", "NumberOfNotificationsDelivered", "NumberOfNotificationsFailed"
  62. ],
  63. "AWS/SQS": [
  64. "NumberOfMessagesSent", "SentMessageSize", "NumberOfMessagesReceived", "NumberOfEmptyReceives", "NumberOfMessagesDeleted", "ApproximateNumberOfMessagesDelayed", "ApproximateNumberOfMessagesVisible", "ApproximateNumberOfMessagesNotVisible"
  65. ],
  66. "AWS/S3": [
  67. "BucketSizeBytes", "NumberOfObjects"
  68. ],
  69. "AWS/SWF": [
  70. "DecisionTaskScheduleToStartTime", "DecisionTaskStartToCloseTime", "DecisionTasksCompleted", "StartedDecisionTasksTimedOutOnClose", "WorkflowStartToCloseTime", "WorkflowsCanceled", "WorkflowsCompleted", "WorkflowsContinuedAsNew", "WorkflowsFailed", "WorkflowsTerminated", "WorkflowsTimedOut"
  71. ],
  72. "AWS/StorageGateway": [
  73. "CacheHitPercent", "CachePercentUsed", "CachePercentDirty", "CloudBytesDownloaded", "CloudDownloadLatency", "CloudBytesUploaded", "UploadBufferFree", "UploadBufferPercentUsed", "UploadBufferUsed", "QueuedWrites", "ReadBytes", "ReadTime", "TotalCacheSize", "WriteBytes", "WriteTime", "WorkingStorageFree", "WorkingStoragePercentUsed", "WorkingStorageUsed", "CacheHitPercent", "CachePercentUsed", "CachePercentDirty", "ReadBytes", "ReadTime", "WriteBytes", "WriteTime", "QueuedWrites"
  74. ],
  75. "AWS/WorkSpaces": [
  76. "Available", "Unhealthy", "ConnectionAttempt", "ConnectionSuccess", "ConnectionFailure", "SessionLaunchTime", "InSessionLatency", "SessionDisconnect"
  77. ],
  78. };
  79. var supportedDimensions = {
  80. "AWS/AutoScaling": [
  81. "AutoScalingGroupName"
  82. ],
  83. "AWS/Billing": [
  84. "ServiceName", "LinkedAccount", "Currency"
  85. ],
  86. "AWS/CloudFront": [
  87. "DistributionId", "Region"
  88. ],
  89. "AWS/CloudSearch": [
  90. ],
  91. "AWS/DynamoDB": [
  92. "TableName", "GlobalSecondaryIndexName", "Operation"
  93. ],
  94. "AWS/ElastiCache": [
  95. "CacheClusterId", "CacheNodeId"
  96. ],
  97. "AWS/EBS": [
  98. "VolumeId"
  99. ],
  100. "AWS/EC2": [
  101. "AutoScalingGroupName", "ImageId", "InstanceId", "InstanceType"
  102. ],
  103. "AWS/ELB": [
  104. "LoadBalancerName", "AvailabilityZone"
  105. ],
  106. "AWS/ElasticMapReduce": [
  107. "ClusterId", "JobId"
  108. ],
  109. "AWS/Kinesis": [
  110. "StreamName"
  111. ],
  112. "AWS/ML": [
  113. "MLModelId", "RequestMode"
  114. ],
  115. "AWS/OpsWorks": [
  116. "StackId", "LayerId", "InstanceId"
  117. ],
  118. "AWS/Redshift": [
  119. "NodeID", "ClusterIdentifier"
  120. ],
  121. "AWS/RDS": [
  122. "DBInstanceIdentifier", "DatabaseClass", "EngineName"
  123. ],
  124. "AWS/Route53": [
  125. "HealthCheckId"
  126. ],
  127. "AWS/SNS": [
  128. "Application", "Platform", "TopicName"
  129. ],
  130. "AWS/SQS": [
  131. "QueueName"
  132. ],
  133. "AWS/S3": [
  134. "BucketName", "StorageType"
  135. ],
  136. "AWS/SWF": [
  137. "Domain", "ActivityTypeName", "ActivityTypeVersion"
  138. ],
  139. "AWS/StorageGateway": [
  140. "GatewayId", "GatewayName", "VolumeId"
  141. ],
  142. "AWS/WorkSpaces": [
  143. "DirectoryId", "WorkspaceId"
  144. ],
  145. };
  146. module.controller('CloudWatchQueryCtrl', function($scope) {
  147. $scope.init = function() {
  148. $scope.target.namespace = $scope.target.namespace || '';
  149. $scope.target.metricName = $scope.target.metricName || '';
  150. $scope.target.dimensions = $scope.target.dimensions || {};
  151. $scope.target.statistics = $scope.target.statistics || {};
  152. $scope.target.period = $scope.target.period || 60;
  153. $scope.target.errors = validateTarget();
  154. };
  155. $scope.refreshMetricData = function() {
  156. $scope.target.errors = validateTarget($scope.target);
  157. // this does not work so good
  158. if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
  159. $scope.oldTarget = angular.copy($scope.target);
  160. $scope.get_data();
  161. }
  162. };
  163. $scope.moveMetricQuery = function(fromIndex, toIndex) {
  164. _.move($scope.panel.targets, fromIndex, toIndex);
  165. };
  166. $scope.duplicate = function() {
  167. var clone = angular.copy($scope.target);
  168. $scope.panel.targets.push(clone);
  169. };
  170. $scope.suggestNamespace = function(query, callback) {
  171. return _.keys(supportedMetrics);
  172. };
  173. $scope.suggestMetrics = function(query, callback) {
  174. return supportedMetrics[$scope.target.namespace] || [];
  175. };
  176. $scope.suggestDimensionKeys = function(query, callback) {
  177. return supportedDimensions[$scope.target.namespace] || [];
  178. };
  179. $scope.suggestDimensionValues = function(query, callback) {
  180. if (!$scope.target.namespace || !$scope.target.metricName) {
  181. return callback([]);
  182. }
  183. var params = {
  184. Namespace: $scope.target.namespace,
  185. MetricName: $scope.target.metricName
  186. };
  187. if (!_.isEmpty($scope.target.dimensions)) {
  188. params.Dimensions = $scope.target.dimensions;
  189. }
  190. $scope.datasource
  191. .performSuggestQuery(params)
  192. .then(function(result) {
  193. var suggestData = _.chain(result.Metrics)
  194. .map(function(metric) {
  195. return metric.Dimensions;
  196. })
  197. .flatten(true)
  198. .filter(function(dimension) {
  199. return dimension.Name === $scope.target.currentDimensionKey;
  200. })
  201. .map(function(metric) {
  202. return metric;
  203. })
  204. .pluck('Value')
  205. .uniq()
  206. .value();
  207. callback(suggestData);
  208. }, function() {
  209. callback([]);
  210. });
  211. };
  212. $scope.addDimension = function() {
  213. if (!$scope.addDimensionMode) {
  214. $scope.addDimensionMode = true;
  215. return;
  216. }
  217. if (!$scope.target.dimensions) {
  218. $scope.target.dimensions = {};
  219. }
  220. $scope.target.dimensions[$scope.target.currentDimensionKey] = $scope.target.currentDimensionValue;
  221. $scope.target.currentDimensionKey = '';
  222. $scope.target.currentDimensionValue = '';
  223. $scope.refreshMetricData();
  224. $scope.addDimensionMode = false;
  225. };
  226. $scope.removeDimension = function(key) {
  227. delete $scope.target.dimensions[key];
  228. $scope.refreshMetricData();
  229. };
  230. $scope.statisticsOptionChanged = function() {
  231. $scope.refreshMetricData();
  232. };
  233. // TODO: validate target
  234. function validateTarget() {
  235. var errs = {};
  236. if ($scope.target.period < 60 || ($scope.target.period % 60) !== 0) {
  237. errs.period = 'Period must be at least 60 seconds and must be a multiple of 60';
  238. }
  239. return errs;
  240. }
  241. });
  242. });