Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
kgvarun authored Sep 17, 2024
2 parents 2d7b0e5 + 82e458c commit d1e57a9
Show file tree
Hide file tree
Showing 56 changed files with 16,206 additions and 7 deletions.
122 changes: 122 additions & 0 deletions flows/scripts/sanitize-dashboards.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Copyright (c) 2024, Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl.

# script to read a json file from path, replace value of key "compartmentId" with "${compartment_ocid}"
# if present, remove createdBy, timeCreated, freeformTags, definedTags,
# replace all values matching "ocid1*" with the value's md5 hash

import json
import hashlib
import argparse
import logging
import os

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)

# Read json file from path
def read_json(path):
try:
with open(path, 'r') as f:
return json.load(f)
except Exception as e:
logger.error("Error reading file: {}".format(e))
exit(1)

# Write json file to path

def write_json(path, data):
try:
if os.path.exists(path):
if os.access(path, os.W_OK):
with open(path, 'w') as f:
json.dump(data, f, indent=2)
else:
logger.error("File {} is not writable".format(path))
exit(1)
else:
if os.access(os.path.dirname(path), os.W_OK):
with open(path, 'w') as f:
json.dump(data, f, indent=2)
else:
logger.error("Path {} is not writable".format(os.path.dirname(path)))
exit(1)
except Exception as e:
logger.error("Error writing file: {}".format(e))
exit(1)

# Replace value of key "compartmentId" with "${compartment_ocid}"

def replace_compartment_id(data):
if 'dashboards' in data:
for dashboard in data['dashboards']:
if 'compartmentId' in dashboard:
dashboard['compartmentId'] = "${compartment_ocid}"
else:
logger.info("compartmentId not found")
return data

# Remove createdBy, timeCreated, freeformTags, definedTags

def remove_keys(data):
if "createdBy" in data:
del data["createdBy"]
if "timeCreated" in data:
del data["timeCreated"]
if "freeformTags" in data:
del data["freeformTags"]
if "definedTags" in data:
del data["definedTags"]
return data

# Replace all values matching "ocid1*" with the value's md5 hash

def replace_ocid(data):
for key in data:
if isinstance(data[key], str):
if data[key].startswith("ocid1"):
data[key] = hashlib.md5(data[key].encode()).hexdigest()
elif isinstance(data[key], dict):
replace_ocid(data[key])
elif isinstance(data[key], list):
for item in data[key]:
if isinstance(item, dict):
replace_ocid(item)
return data


def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--path", help="path to json file")
args = parser.parse_args()
if args.path:
if os.path.exists(args.path):
return args.path
else:
logger.error("File {} does not exist".format(args.path))
exit(1)
else:
logger.error("Path not specified")
exit(1)

# main function

def main():
path = parse_args()
data = read_json(path)
data = replace_compartment_id(data)
data = remove_keys(data)
data = replace_ocid(data)
write_json(path, data)

if __name__ == "__main__":
main()

def Usage():
print("Usage: python3 sanitize.py --path <path_to_json_file>")
exit(1)
19 changes: 12 additions & 7 deletions knowlege-content/grafana-on-oci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ Gather the following information before deployment:
![General config](Images/RM-GenConfig.jpg)

- Instance Configuration:
- Enter a Hostname of your choice (Only use [allowable](https://docs.oracle.com/en-us/iaas/Content/Network/Concepts/dns.htm) characters)
- Select a suitable Linux Image (Oracle-Linux-8.9-2024.05.29-0 is recommended and tested)
- Select a Linux Instance Shape (Choose from list, to suite your monitoring requirements). Minimum requirements; memory:512MB, CPU:1.
- Hostname
- Linux Image (Oracle-Linux-8.9-2024.05.29-0 recommended and tested)
- Linux Instance Shape (Choose from list, to suite your monitoring requirements). Minimum requirements; memory:512MB, CPU:1.
- Number of OCPUs (for flexible shapes)
- Memory in GBs (for flexible shapes)
- Assign Public IP (default: true)
Expand Down Expand Up @@ -84,6 +84,7 @@ Gather the following information before deployment:

### Configuring OCI Monitoring Data Source to add Instance Principle


Next step is to add the OCI datasource and configure the Instance Principle.

1. Navigate to the Menu on the left > Connections > Data Sources
Expand All @@ -97,22 +98,26 @@ Next step is to add the OCI datasource and configure the Instance Principle.
6. Click on Save & test and verify Success
![Success](Images/GF-ConnectionSuccess.jpg)


Once the Success box has appeared this confirms the oci-metrics-datasource and Instance Principle have been configured.



### Adding Custom Dashboards

Now you can import some example Observability and Management dashboards in Grafana to visualise your OCI metrics.
After deployment, you can import custom dashboards in Grafana to visualise your OCI metrics.
All dashboards are located in the Dashboards directory (<https://github.com/Mesh44/Grafana-Install/tree/main/Dashboards>)

1. Click on one of dashboard json files within the github to see the json code (for example Stack-Monitoring-Dashboard.json)
2. Copy the content.
1. Click on one of dashboard json files (for example Stack_Monitoring.json)
2. Copy the content the content.
![copyjson](Images/GH-dashboardjson.jpg)
3. On the Grafana install click on the Menu and find Dashboards and then New > Import
3. On the Grafana install click on Dashboards and New > Import
![Import](Images/GF-Import.jpg)
4. Past the copied content (from step 2) to the section under "Import via dashboard JSON model" and click Load
![LoadImport](Images/GF-LoadImport.jpg)
Ensure to choose oci-metrics-datasource as the Default data source.


At this point you have now imported an example Dashboard, follow the instructions in the Dashboard to view your metrics.

## Troubleshooting
Expand Down
Loading

0 comments on commit d1e57a9

Please sign in to comment.