OCI(Oracle Cloud Infrastructure) has observability services like Stack Monitoring, Logging Analytics ,OpsInsights etc.. to help monitor your system .
You can enable automatically to monitor all new hosts in a compartment for stack monitoring .If you are starting a project and looking for full monitoring for your hosts I would suggest this method . In case this was not done and you want to enable stack monitoring for existing hosts you need to enable management agent on those hosts first before discovery.
Similarly Opsinsights provide auto host promotion feature as well. The above scenario applies to this as well if you have not done enabled auto host promotion.
For all the observability services management agent should be running to enable monitoring of the host.Below python script can be used to enable management agent as part of the oracle cloud agent in OCI Oracle Linux instances.
The signer is configured to run in Cloud shell please change it in the script if you are running locally.Also update the compartment id in the script before running.
NOTE: Since the API used is compute update API please test it in dev environment to make sure its giving the expected results .
import oci
# To run in cloudshell
delegation_token = open('/etc/oci/delegation_token', 'r').read()
signer = oci.auth.signers.InstancePrincipalsDelegationTokenSigner(
delegation_token=delegation_token
)
#list instances
core_client = oci.core.ComputeClient(config={},signer=signer)
compartment_id = "<replace with compartment OCID>"
#list running instances in a compartment
list_instances_response = core_client.list_instances(
compartment_id=compartment_id,
lifecycle_state="RUNNING")
list_response = list_instances_response.data
for instance in list_response:
get_image_response = core_client.get_image(image_id=instance.image_id)
image_response = get_image_response.data
if image_response.operating_system == "Oracle Linux":
plugin_list = instance.agent_config.plugins_config
for plugin in plugin_list:
if plugin.name == "Management Agent" and plugin.desired_state == "DISABLED":
plugin.desired_state = "ENABLED"
print(f"Updating plugin for instance {instance.display_name}")
update_instance_response = core_client.update_instance(
instance_id=instance.id,
update_instance_details=oci.core.models.UpdateInstanceDetails(
agent_config=oci.core.models.UpdateInstanceAgentConfigDetails(
is_monitoring_disabled=instance.agent_config.is_monitoring_disabled,
is_management_disabled=instance.agent_config.is_management_disabled,
are_all_plugins_disabled=instance.agent_config.are_all_plugins_disabled,
plugins_config=plugin_list)))
This example is for Management Agent Plugin but you can modify the script to enable other plugins as part of Oracle Cloud agent as well to do bulk update.