Im trying to identify a way to list all running instances with grafana. Have any of you been able to do this?
Essentially I want a grafana dashboard to display:
Instance-ID >> Region >> Status(up or down) >> Current running time
Do any of you know a way to achieve this?
I don't know if you can do that in grafana, but you can see just the information you want (except for the running time) in the prometheus alert module.
You can find it if you go to prometheus:9090 -> Status -> Targets
It should look something like this
Tom
For anyone that comes to this thread, I have resolved my predicament by using the aws cli.
Essentially I broke it down into two pieces, first get the list of regions, then second get all the instance information i required:
echo Grabbing instances in all regions, please wait..
for region in $(aws ec2 describe-regions --output text | cut -f3);
do
> $region.txt;
$quote="'";
aws ec2 describe-instances --region $region --query 'Reservations[].Instances[].[Tags[?Key==`Name`]| [0].Value,State.Name,InstanceType,PublicIpAddress,Placement.AvailabilityZone,LaunchTime]' --filters Name=instance-state-name,Values=running --output json >> /home/ubuntu/$region.txt; done
Related
I have created two instances with the package information t2.micro.
When I checked with service-quotes, there were 02 instances. How can I use AWS CLI (or API) to get value at Usage?
Hope you can help me.
You can get the total value of instances in region using something like this:
aws ec2 describe-instances --query "Reservations[].Instances[].InstanceId" --output text | wc -w
Refer this, Maybe you can get some insights
Was unable to find any K8s API which can query all volumeIDs related to specific AWS account region wide. My primary intention is to clean all stale volumes. For doing this, I'm collecting volume information from AWS which are in Available state using below shell script.
for regions in $(aws ec2 describe-regions --output text|awk {'print $4'})
do
for volumes in $(aws ec2 describe-volumes --region $regions --output text| grep available | awk '{print $9}' | grep vol| tr '\n' ' ')
do
echo "$regions" "$volumes"
done
done
But that alone isn't sufficient as sometimes I keep some of my environments down and that time pods are not running which in turn marks the volumes as Available but they will be in use/attached to pods once the environment comes up. Hence, I need to get both the lists (from AWS and K8s) and diff them. Finally, I get the volumes which are actually not associated to any of my environments. Any help is greatly appreciated.
N.B: It is known the below k8s API can fetch volumes taking namespaces as input which I'm not looking for.
GET /api/v1/namespaces/{namespace}/persistentvolumeclaims
Two answers: first you can kubectl get pvc —all-namespaces. Second, the PVs themselves are not in namespaces so kubectl get pv.
I'm trying to get into the reporting of AWS instances within my environments, and I am trying to create a script using AWS cli to generate a report of the status of EC2 instances. I'm still a beginner, so I'm learning how all this works. I was wondering if it was possible to do with a line similar to this:
AWS EC2 describe-instances --region $REGION --query 'Reservations[].Instances[?LaunchTime>=`2015-03-01`][].{id: InstanceId, type: InstanceType, launched: LaunchTime}'
I am using the Cygwin Terminal to perform this query, and any with this would be awesome thanks!
If it's possible I am also trying to see if I could get the CPU usage at that time of the report. I am still trying to understand how all this works since I am new to the AWS API.
Firstly, you will need to install the aws-sdk. Checkout the following answer for doing this in cygwin.
Then you can configure your account using aws configure and following the prompts.
After that you should be able to run aws ec2 describe-instances.
Thanks for everyone's input! I was able to figure it out here. I'm starting to understand how the population output all comes together, but right now I'm trying to put this information into at TSV file. To get the status and launch time of the instances I used the following:
aws ec2 describe-instances --region $REGION --query "Reservations[].Instances[].[InstanceId, LaunchTime, State.Name] --output text >> Instances_In_AWS.tsv
Thank you guys for your help!
I am very new to AWS. I've got a Windows instance running and have my aws command line configured. I've read through the AWS docs but can't seem to find exactly what I'm looking for.
How do I view my current instances from the command line?
If by view your current instances, you mean list all running instances from the command line, you can call the describe-instances command:
aws ec2 describe-instances
This will list all of your current instances.
See describe-instances
As noted in the answer by Rodrigo M, you should use describe-instances to view your EC2 instances. In general, the help command is the best way to explore the CLI. Start with aws ec2 help and try the various options. You can get more details on subcommands with aws ec2 describe-instances help as well.
The output is a bit verbose and by default in JSON. This can be a bit overwhelming and hard to read without additional processing. I'd recommend getting familiar with the --query aws CLI parameter if you intend to use the CLI interactively.
In particular, I use this for a quick overview of my EC2 instances:
aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId, Tags[?Key==`Name`] | [0].Value, State.Name, PublicDnsName]' --output table
To check one particular attribute on an instance:
aws ec2 describe-instances --query Reservations[0].Instances[0].InstanceType --output text --instance-ids <my-instance-id>
The CLI is very powerful once you get comfortable with learning the commands and managing the output. It's also helpful for learning the porgramming APIs as well, since aws CLI commands generally map one-to-one with an API call.
I am working on creating a monitor dashboard for monitoring status of ec2 instances.
I am searching for a method to get information (especially instances ID) of newly spawned instances using auto scaling.
Can anyone point me in the right direction. Thanks
If you know your instance type then you can use describe-instances command to get details about instances and use query command to get the details what you need (in your case Instance-id)
aws ec2 describe-instances --filters "Name=instance-type,Values=t1.micro" --query 'Reservations[*].{InstanceId:Instances[0].InstanceId}'
## Enter your instance type in the 'Values' field of '--filters' command
I was able to get instance id by using combination of following commands
aws elb describe-load-balancers --load-balancer-name "LoadBalanceID" --region "region" --output text | grep INSTANCES
Using the AWS CLI you can get a list of scaling activities for an auto scaling group.
aws autoscaling describe-scaling-activities --auto-scaling-group-name my-group-name
See AWS CLI
This is the newer Python CLI, so you would need to install that if you have not already done so. It will return a JSON block with all of the scale up and down activities in the group, including the reason an the date and time.