How do I use the Linode APIv4 to gather information about my Linodes?
I would like to know how to write a script to gather information about my Linodes. Most of the API calls look like they are for creating or removing Linodes.
2 Replies
Getting Started
First, you will want to familiarize yourself with using the API. The following Getting Started with the Linode API guide will help get you up to speed on using the API using the curl
command.
What information is available about my Linode?
- label: The Linode's label is for display purposes only. If no label is provided for a Linode, the default will be shown.
- region: This is the location where the Linode was deployed.
- image: The id of the image used to deploy the Linode
- type: the Linode's type which you can use to determine information about your Linode's plan and the default specs for that plan
- id: your Linode's ID
- status: the current state of your Linode
- hypervisor: "kvm" is the only option at the moment.
- created: the creation date of the Linode
- updated: when the Linode was last changed
- ipv4: the Linode's IPv4 address
- ipv6: the Linode's IPv6 addresses
- specs: information about the resources available to the Linode which include disk (storage space), memory, vcpus (the number of vcpus), and transfer (the amount of outbound network transfer)
You can also get information about the alerts you have configured about your Linode as well as details about the backups you have available if you have enabled the Linode Backup Service. Finally you can determine if Lassie, the shutdown watchdog is enabled.
With the LinodeID you can get information about the disks you have allocated your storage to as well as information about your Linode's configuration profile(s). You can use the Linode ID to view statistics about the CPU usage, disk IO, and IPv4 and IPv6 Network traffic over the past 24 hours.
Host Information
Information about a Linode's host is not exposed via the API as of this writing
Further Reading
For details about the API calls used to gather information about your Linode, see: the Linode API documentation
Documentation for the Linode API Library for Python
I hope this helps.
What command gives me this information?
To retrieve information about your Linode via APIv4, you will need to Create an API Token, as outlined in our Getting Started with the Linode API guide.
Then, to run commands that utilize your API Token, set your API token to the variable $TOKEN. This can be done by running the command TOKEN='insert_API_Token_here'
. Confirm that this succeeded by running echo $TOKEN
. A successful command should look like:
echo $TOKEN
{Your_API_Token_Here}
Once you've successfully configured your API Token, run the following command:
curl -H "Authorization: Bearer $TOKEN" \
https://api.linode.com/v4/linode/instances | json_pp
"Authorization: Bearer $TOKEN"
allows you to access account-sensitive information, such as information about your Linodes, through the API.
https://api.linode.com/v4/linode/instances
indicates to the API that you want information about your Linode's instances, and | json_pp
formats the output in a way that is more easy to discern that the default output.
This output provides information about each of your Linodes, including its region, type, Linode ID, and disk image. If you'd like information about a specific Linode, you can specify by adding a Linode ID to the end of the HTTPS link. If you don't know your Linode's ID, this information can be found by running the non-specified https://api.linode.com/v4/linode/instances/
command listed above. A specified command should look like this:
curl -H "Authorization: Bearer $TOKEN" \
https://api.linode.com/v4/linode/instances/{linodeID} | json_pp
If you'd like information on how to access other pieces of information via Linode APIv4, consult the Linode API documentation.