-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated fetch entities to fetch workloads and added script to overrid…
…e and reset workload golden signals (#33) * feat: add support for fetching workloads Added --workload flag to fetch workload entities * feat: Added script to override and reset workload golden signals Golden signals can be specified in a json file saved under ./goldensignals directory
- Loading branch information
1 parent
3cbf8c5
commit 8710e2a
Showing
10 changed files
with
373 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"domain": "INFRA", | ||
"type": "HOST", | ||
"metrics": [ | ||
{ | ||
"eventId": "entityGuid", | ||
"facet": "entityName", | ||
"from": "SystemSample", | ||
"name": "cpuUsage", | ||
"select": "average(cpuPercent)", | ||
"title": "CPU usage (%)", | ||
"where": "operatingSystem = 'linux'" | ||
}, | ||
{ | ||
"eventId": "entityGuid", | ||
"facet": "entityName", | ||
"from": "SystemSample", | ||
"select": "average(memoryUsedPercent)", | ||
"name": "memoryUsage", | ||
"title": "Memory usage (%)", | ||
"where": "operatingSystem = 'linux'" | ||
}, | ||
{ | ||
"eventId": "entityGuid", | ||
"facet": "entityName", | ||
"from": "SystemSample", | ||
"select": "average(loadAverageFiveMinute)", | ||
"name": "loadAverageFiveMinute", | ||
"title": "Load Average 5 Minutes", | ||
"where": "operatingSystem = 'linux'" | ||
}, | ||
{ | ||
"eventId": "entityGuid", | ||
"facet": "entityName", | ||
"from": "StorageSample", | ||
"select": "average(diskUsedPercent)", | ||
"name": "rootDiskUsedPercentage", | ||
"title": "Root Disk Used (%)", | ||
"where": "operatingSystem = 'linux' AND mountPoint = '/'" | ||
}, | ||
{ | ||
"eventId": "entityGuid", | ||
"facet": "entityName", | ||
"from": "SystemSample", | ||
"select": "average(swapUsedBytes/swapTotalBytes*100)", | ||
"name": "swapUsedPercentage", | ||
"title": "Swap Used (%)", | ||
"where": "operatingSystem = 'linux'" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"domain": "INFRA", | ||
"type": "HOST", | ||
"metrics": [ | ||
{ | ||
"eventId": "entityGuid", | ||
"facet": "entityName", | ||
"from": "SystemSample", | ||
"name": "cpuUsage", | ||
"select": "average(cpuPercent)", | ||
"title": "CPU usage (%)", | ||
"where": "operatingSystem = 'windows'" | ||
}, | ||
{ | ||
"eventId": "entityGuid", | ||
"facet": "entityName", | ||
"from": "SystemSample", | ||
"select": "average(memoryUsedPercent)", | ||
"name": "memoryUsage", | ||
"title": "Memory usage (%)", | ||
"where": "operatingSystem = 'windows'" | ||
}, | ||
{ | ||
"eventId": "entityGuid", | ||
"facet": "entityName", | ||
"from": "SystemSample", | ||
"select": "average(loadAverageFiveMinute)", | ||
"name": "loadAverageFiveMinute", | ||
"title": "Load Average 5 Minutes", | ||
"where": "operatingSystem = 'windows'" | ||
}, | ||
{ | ||
"eventId": "entityGuid", | ||
"facet": "entityName", | ||
"from": "StorageSample", | ||
"select": "average(diskUsedPercent)", | ||
"name": "rootDiskUsedPercentage", | ||
"title": "C: Drive Used (%)", | ||
"where": "operatingSystem = 'windows' AND mountPoint= 'C:'" | ||
}, | ||
{ | ||
"eventId": "entityGuid", | ||
"facet": "entityName", | ||
"from": "SystemSample", | ||
"select": "average(swapUsedBytes/swapTotalBytes*100)", | ||
"name": "swapUsedPercentage", | ||
"title": "Swap Used (%)", | ||
"where": "operatingSystem = 'windows'" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import os | ||
import json | ||
import library.migrationlogger as logger | ||
import library.clients.gql as nerdgraph | ||
from library.clients.endpoints import Endpoints | ||
|
||
logger = logger.get_logger(os.path.basename(__file__)) | ||
|
||
|
||
class GoldenSignals: | ||
|
||
def __init__(self, region=Endpoints.REGION_US): | ||
self.region = region | ||
pass | ||
|
||
def reset(self, user_api_key, workload_guid, domain, type): | ||
payload = GoldenSignals._reset_golden_signals_payload(workload_guid, domain, type) | ||
logger.debug(json.dumps(payload)) | ||
return nerdgraph.GraphQl.post(user_api_key, payload, self.region) | ||
|
||
|
||
def override(self, user_api_key, workload_guid, domain, type, metrics): | ||
payload = GoldenSignals._override_golden_signals_payload(workload_guid, domain, type, metrics) | ||
logger.debug(json.dumps(payload)) | ||
return nerdgraph.GraphQl.post(user_api_key, payload, self.region) | ||
|
||
@staticmethod | ||
def _reset_golden_signals_payload(workload_guid, domain, type): | ||
mutation_query = '''mutation($context: EntityGoldenContextInput!, $domainType: DomainTypeInput!) { | ||
entityGoldenMetricsReset(context: $context, domainType: $domainType) { | ||
errors {message type} | ||
} | ||
}''' | ||
return {'query': mutation_query, 'variables': {'context': {'guid': workload_guid}, | ||
'domainType': {'domain': domain, 'type': type} | ||
} | ||
} | ||
|
||
@staticmethod | ||
def _override_golden_signals_payload(workload_guid, domain, type, metrics): | ||
|
||
mutation_query = '''mutation($context: EntityGoldenContextInput!, $domainType: DomainTypeInput!, | ||
$metrics: [EntityGoldenMetricInput!]!) { | ||
entityGoldenMetricsOverride(context: $context, domainType: $domainType, metrics: $metrics) { | ||
errors { message type } | ||
metrics { metrics { name query title } } | ||
} | ||
} | ||
''' | ||
return {'query': mutation_query, 'variables': {'context': {'guid': workload_guid}, | ||
'domainType': {'domain': domain, 'type': type}, | ||
'metrics': metrics | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
import requests | ||
import json | ||
import library.migrationlogger as logger | ||
from library.clients.endpoints import Endpoints | ||
|
||
|
||
logger = logger.get_logger(os.path.basename(__file__)) | ||
|
||
|
||
class GraphQl: | ||
|
||
def __init__(self): | ||
pass | ||
|
||
@staticmethod | ||
def post(per_api_key, payload, region=Endpoints.REGION_US): | ||
result = {} | ||
response = requests.post(Endpoints.of(region).GRAPHQL_URL, headers=GraphQl.headers(per_api_key), | ||
data=json.dumps(payload)) | ||
result['status'] = response.status_code | ||
if response.text: | ||
response_json = response.json() | ||
if 'errors' in response_json: | ||
logger.error('Error : ' + response.text) | ||
result['error'] = response_json['errors'] | ||
else: | ||
logger.debug('Success : ' + response.text) | ||
result['response'] = response_json | ||
return result | ||
|
||
@staticmethod | ||
def headers(api_key): | ||
return {'api-key': api_key, 'Content-Type': 'application/json'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.