How do I get a list of labels and values for a GCE instance? - google-compute-engine

How do a get a list of labels & values that have been applied to an instance from within the instance itself?(I am writing a script that will invoke this from within the instance, so even if it means using API, it would be welcome.)
The documentation gives commands like:
gcloud compute instances list --filter="labels.environment:*"
That query returns something like
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
node1 us-central1-a n1-standard-2 true 10.135.224.51 RUNNING
node2 us-central1-a n1-standard-16 10.135.224.52 RUNNING

You can get the details of a GCP instance using this API:
https://cloud.google.com/compute/docs/reference/rest/v1/instances/get
Included in the details is the set of labels associated with the instance.
You can get your own GCP instance resourceId by querying the metadata within your own instance:
https://cloud.google.com/compute/docs/storing-retrieving-metadata

Related

Jmeter Aggregate report with Thread group name using command line

I was trying to integrate apache-jmeter with jenkins pipeline.We are using apache-jmeter version 5.1 and intalled the performance plugin version 3.0 in jenkins.
D:\apache-jmeter-5.1\bin\jmeter.bat -Jjmeter.save.saveservice.output_format=xml -n -t C:\Users\temp\Downloads\tests.jmx -l C:\Users\temp\Downloads\tests.jtl """
Main goal is to get aggregate report for each individual thread group. Have tried 3 different alternatives which are mentioned below:
bat """ D:\apache-jmeter-5.1\bin\FilterResults.bat --output-file C:\Users\temp\Downloads\filteredout.csv --input-file C:\Users\temp\Downloads\tests.jtl --include-labels "Result1,Result2,Result3,Result4" """
Using the above command to get the aggregate report by passing the input as jtl file,the outputfile filteredout.csv is not getting generated.But while using the --exclude-labels the output file is getting generated but it is not the aggregate report, getting report in the form of jtl.
bat """ D:\apache-jmeter-5.1\bin\JMeterPluginsCMD.bat --generate-csv C:\Users\temp\Downloads\aggregatereport.csv --input-jtl C:\Users\temp\Downloads\tests.jtl --plugin-type AggregateReport """
Using the above command to get the aggregate report by passing the input as jtl file, getting aggregate report with 90,95,99 percentile lines but not getting the thread group name.
bat """ java -jar D:\apache-jmeter-5.1\lib\cmdrunner-2.2.jar --tool Reporter --generate-csv C:\Users\temp\Downloads\AggregateReportnew.csv --input-jtl C:\Users\temp\Downloads\tests.jtl --plugin-type AggregateReport"""
Using the above command to get the aggregate report by passing the input as jtl file,getting aggregate report with 90,95,99 percentile lines but not showing report for each individual group.
Using Filter Results Tool version 2.2,Synthesis Report version 2.2,JMeterPluginsCMD Command Line Tool version 2.2 .
Is there any chance that my idea will be possible in realtime? If so please help with this issue
How about adding the Thread Group Name as the prefix/postfix to the Samplers labels using i.e. __threadGroupName() function
This way you will be able to distinguish samplers originating from different thread groups:
If you have a lot of samplers you can append the name of the Thread Group in the runtime using i.e. JSR223 PostProcessor and the following Groovy code:
prev.setSampleLabel(prev.getSampleLabel(true))

Create daily temporary clone of Aurora cluster

I want to create a temporary clone of my Aurora MySQL cluster to run daily ETLs (to make sure it doesn't affect the other services) and then terminate it once the ETLs are done.
import boto3
client = boto3.client('rds')
old_cluster_identifier = 'test-etl'
new_cluster_identifier = 'test-etl-clone'
response = client.restore_db_cluster_to_point_in_time(
DBClusterIdentifier=new_cluster_identifier,
RestoreType='copy-on-write',
SourceDBClusterIdentifier=old_cluster_identifier,
UseLatestRestorableTime=True,
Port=3306,
DBSubnetGroupName='test-etl',
VpcSecurityGroupIds=[
'sg-xxxx',
],
Tags=[],
EnableIAMDatabaseAuthentication=False,
BacktrackWindow=0,
DeletionProtection=False,
CopyTagsToSnapshot=False
)
reader_endpoint = response['DBCluster']['ReaderEndpoint']
response2 = client.create_db_instance(
DBInstanceClass='db.t2.medium',
Engine='aurora',
DBClusterIdentifier=new_cluster_identifier,
DBInstanceIdentifier=new_cluster_identifier + '-instance-1',
)
print(response2)
This code works well for me but then when I want to delete the clone cluster from the console, I just click on the instance name / Actions / Delete and this deletes at the same time both the instance and the cluster.
I tried to find the equivalent in the AWS SDK but if I run the function delete_db_instance() it only deletes the instance and keeps the cluster on with status 'available' so I have to do:
- delete_db_instance('test-etl-clone-instance-1')
- wait until it is deleted
- delete_db_cluster('test-etl-clone')
Is there a way to delete both at the same time directly?
Or can I just have the cloned cluster always available without any instance running and just create/delete a new instance everyday? I'm not sure there are additional costs if I just have the cluster without any instance and if the data will be up-to-date or not when I create a new instance the next day.
Thanks
In the end I found out that I can just delete both the instance and cluster without having to wait in between:
import boto3
client = boto3.client('rds')
new_cluster_identifier = 'test-etl-clone'
client.delete_db_instance(
DBInstanceIdentifier=new_cluster_identifier + '-instance-1',
SkipFinalSnapshot=True,
DeleteAutomatedBackups=True
)
client.delete_db_cluster(
DBClusterIdentifier=new_cluster_identifier,
SkipFinalSnapshot=True,
)
And I tried to reuse the existing cluster but it only contains the data of the original cluster until the moment it was created.
So I will have to create a new cluster + instance each day in the end.

Zabbix 2.2 calculate issue

I need to agregate power data from 8 different PDUs.
So far:
- I've created a template with OIDs to poll by SNMP the desired value and I called it: Amps Total.
- I've created 8 different hosts using the template and it works OK. I can see the Amps Total being graphed for all the devices.
- I've created a fake host to use as "Data Centre" object.
- I've created a new template with 8 items Type "Calculate", Formula:
last("PDU-B1-L:Amps Total")+last("PDU-B1-R:Amps Total")
(PDU-B1-L & PDU-B1-R are my PDU hostnames).
I was expecting to see the agregate data (at least for the 2 PDUs), but nothing is being shown. All the data type is Numeric (Unsigned).
Those hosts are being polled through a Zabbix proxy. I replaced the hostname by proxy:host:key in the formula with no luck. (the host config shows proxy:host as the hostname)
Any clue?
Thanks!
You have to use item keys in the calculated item formula. Given that spaces are not supported in item keys, "Amps Total" most likely is item name.

I created an instance group and all of the 100 created instances have this red exclamination mark saying this instance doesn't exist

I created an instance group and all of the 100 created instances have this red exclamation mark saying this instance doesn’t exist saying it is either terminated or never created what can I do? I tried creating another one but still the same or it created only one.
If you know the name of the instance and its zone you can use https://developers.google.com/apis-explorer/#search/compute.zoneoperations.list/m/compute/v1/compute.zoneOperations.list to find an operation used for creating that instance and see if it contains any errors. To list operations connected to your instance you should enter in filter field: targetLink eq '.*your-instance-name'.

SSIS: Overwite the data source/server in a connection string read from a package configuration value

I have looked at other posts and questions but I couldn't find what I needed.
I am relatively new to SSIS Package creation so bear with me please.
Basically, I need the package to connect to multiple servers based on a list of IPs read from a table. I have a connection string that I am reading from a config table. the connection string is generic in that the datasource is simply 255.255.255.255 and I want to replace the datasource with the IPs read from the table as I loop through during package execution.
I am using IPs since the servers I am connecting to are not on our domain. I have set up the server name as a variable within the connection manager expressions. Thus what I am hoping is that the pkg config is read to obtain the entire connection string. Then as I loop through the IPs, the server name variable will be dynamically substituted into the data source value as it loops thorugh. I hope this makes sense.
So the connstring is: (generic within config table)
Data Source=255.255.255.255,65000;User ID=test;Password=test;Initial Catalog=myDB;Provider=SQLNCLI10.1;Integrated Security=SSPI;Auto Translate=False;Application Name=SSIS-myApp;
Then as I obtain the list of IPs I want it to change to and then obviously connect as:
Data Source=1.1.1.1,1000;User ID=test;Password=test;Initial Catalog=myDB;Provider=SQLNCLI10.1;Integrated Security=SSPI;Auto Translate=False;Application Name=SSIS-myApp;
Then the next IP and connect as:
Data Source=2.2.2.2,1000;User ID=test;Password=test;Initial Catalog=myDB;Provider=SQLNCLI10.1;Integrated Security=SSPI;Auto Translate=False;Application Name=SSIS-myApp;
How can I do this using SSIS?
Create a connection manager connection to a valid database.
Right click on the newly created connection manager connection, select to Properties and copy the value for the connection string
Create a string variable and paste the connection string in your clip board in the value for the newly created variable
Add an Execute SQL Task with a statement similar to this:
SELECT TOP 1
'Data Source=' + [IPAddress] +
';User ID='+[Username] +
...
FROM dbo.IPTable
Pass the result set to the string variable you previously created
Right click on your connection manager connection and click the ellipsis next to Expressions
In the dialog that pops out, under Property, select ConnectionString and click the ellipsis next to the blank value for Expression.
In the Expression Builder, add the variable name to the variable you created. Ex: #[User::CreatedVariableName]
And you're finished. This a basic concept and you can tweak from there..