TLDR – How to view instance console logs using the Oracle OCI Command Line tool
I was working a case last week where a customer asked, “how can I determine if an OCI instance was restarted due to hypervisor issue” Which is a great question. Sadly I was not able to come up with a great answer for the customer. It’s due to a lack of trying. Internally we can see the history of all operations that run against an instance, like, creation, volume attaches, soft restarts, ETC. Externally there is no similar log for an instance. Searching for a solution, I went through all of the OCI CLI (Command Line Interface) and found some other interesting commands I did not know existed.
The stand out commands was the console-history command. One of the troubleshooting tools we have access to internally is a full log of the console. For Linux, is this great you can see everything that would have been displayed on the console screen. For windows, it is not so helpful. To download the console history, you need to know your instance OCID and run the following three commands.
Capturing and viewing the console history
To capture the console history run the following commands
oci compute console-history capture --instance-id ocid1.instance.oc1.eu-frankfurt-1.antheljrsdy6wiqcnqplrk3inniwkcelbdem3k4ot7nztcga5z4mpnrs4tza
From the above command capture the OCID in the ID field and use it in the below command to download a text file containing the console logs
oci compute console-history get-content --instance-console-history-id ocid1.consolehistory.oc1.eu-frankfurt-1.antheljrsdy6wiqctqeaaz2n2l5tuus47nszqgoc43y2iw4e4o4sgwhyqqnq --file bob.txt
You can run cat bob.txt to view the contents of the log file in the command line