Fetching info from JVM MBeans - java

I was trying to fetch the below details for my monitoring application using JVM MBeans
thread-states.blocked
thread-states.waiting
gc.ConcurrentMarkSweep.runs
gc.ParNew.runs
thread_count
daemon_thread_count
memory.heap_usage
memory.non_heap_usage
I am able to fetch most of them except
thread-states.blocked
thread-states.waiting
gc.ConcurrentMarkSweep.runs
gc.ParNew.runs
Does anybody know what MBean and attribute can be used to collect these values?
PS: i have googled this before posting it here

thread-states.blocked
thread-states.waiting
you can use getAllThreadIds() and get each Thread's information getThreadInfo() and filter based on the state
gc.ConcurrentMarkSweep.runs
gc.ParNew.runs
get getGarbageCollectorMXBeans() filter them for CMS and ParNew and getCollectionCount()

Related

Elastic apm - Disable transaction/span programatically for specific endpoint

I am using elastic-apm with spring application to monitor API requests and track all SQL's executed for given endpoint. The problem is give the amount of traffic elastic search is collecting huge magnitude of data and I would like to enable capturing span only for specific endpoints.
I tried using public api of elastic-apm https://www.elastic.co/guide/en/apm/agent/java/current/public-api.html
I can customize a transaction and span but I couldn't find a way to enable/disable to specific endpoints.
I have tried this but no luck -
ElasticApm.currentSpan().startSpan();
ElasticApm.currentSpan().end();
Looks like it can be done using drop_event processor in api-server.yml.
processors:
- drop_event:
when:
equals:
transaction.custom.transactions_sampled: false
and in code set custom context:
Transaction elasticTransaction = ElasticApm.currentTransaction();
elasticTransaction.addCustomContext("transactions.sampled", false);

How to get instanceid from cloud_run?

The logs from cloud run spit out some good json with resource.labels.revision_name = my_name-00046-kip.
The json path labels.instanceId is more like this though
00bf4bf02d71261c0c1f55a601331b336a5d90d365cca1b28330dcf3e456fb7c07d5b72f1d3c9a971e391b5edc3512aea8559d172b24e639
per this document I was able to get revision_name
https://cloud.google.com/run/docs/reference/container-contract#env-vars
but I can't get the instance id and metrics must be reported per instance or two instances reporting in the same minute will be rejected. how do I get instance id (preferably through DockerFile and if not through api call). If cloud run boots up 10 instances under one revision name, I have to make sure to uniquely report metrics to Generic Task resource where I plan on filling in job_id with the instance id.
thanks,
Dean
Please try using the metadata server to get the instance ID using the url:
http://metadata.google.internal/computeMetadata/v1/instance/id
Note that "Metadata-Flavor: Google" header is also required.
If you're using Java (as indicated by the tags), the easiest way to get the instance ID from the "internal metadata server" programmatically is probably to include the dependency com.google.cloud:google-cloud-core:1.93.5 (or newer) through Gradle/Maven and then call the following method:
import com.google.cloud.MetadataConfig;
String instanceId = MetadataConfig.getInstanceId();
The entries in the logging in Stackdriver is as follows
labels: {
instanceId: "00bf4bf02d4b374e91dda64bc4c4241a218302c4bcc73a01ecf85e582127e8c8076fcbe18b3cc934f5ed33e5dc1348c58cfd40cbecc0c9ae2a0b6d2356"
}
labels: {
configuration_name: "cloudrunservice"
location: "us-central1"
project_id: "xxxx-xxxx-000"
revision_name: "cloudrunservice-00002-leq"
service_name: "cloudrunservice"
}
type: "cloud_run_revision"
As you mentioned, each one has the instance Id, Revision name, and Service name. In this way, you do not have to worry about rejected entries in the logging by the same instance / time.
I could no see something related with the instances ID in the UI, managing Revisions. Handling this JSON from logging you could get the InsanceID.

How to user KafkaAdminClient to set Quota limits?

I find alterConfigs in KafkaAdminClient,So I want to set Quota limits via KafkaAdminClient, Can it even possible? and How to set the config Map?
Thanks.
Currently, quota-related broker configs can only be updated using Zookeeper(namely by ConfigCommand). Users cannot set these values by AdminClient. KIP-248 will migrate all of the functions to the new AdminClient. See it for more details.

In java, how can I get an Amazon EC2 Instance to see its own tags?

So I have a java program running within an Amazon EC2 instance. Is there a way to programatically get its own tags? I have tried instantiating a new AmazonEC2Client to us the describeTags() function but it only gives me null. Any help would be appreciated thank you.
Edit: To make things clearer, the instances are going to be unmanned worker machines spun up to solely do some computations
This should help you get started...
String instanceId = EC2MetadataUtils.getInstanceId();
AmazonEC2 client = AmazonEC2ClientBuilder.standard()
.withCredentials(new DefaultAWSCredentialsProviderChain())
.build();
DescribeTagsRequest req = new DescribeTagsRequest()
.withFilters(new Filter("resource-id", Collections.singletonList(instanceId)));
DescribeTagsResult describeTagsResult = client.describeTags(req);
List<TagDescription> tags = describeTagsResult.getTags()
You should be able to get the current instance id by sending a request to: http://169.254.169.254/latest/meta-data/instance-id. This only works within ec2. With this you can access quite a bit of information about the instance. However, tags do not appear to be included.
You should be able to take the instance id along with the correct authentication to get the instance tags. If you are going to run this on an instance, you may want to provide an IAM user with limited access instead of a user which has access to everything in case the instance is compromised.
While using user-data may be the simplest solution, the OP was asking specifically about the tagging, and unfortunately amazon hasn't made this as easy as it could be. However, It can be done. You want to use a combination of 2 amazon services.
First you need to retrieve the Instance ID. This can be achieved by hitting the URL from within your instance:
http://169.254.169.254/latest/meta-data/instance-id
Once you have the resource ID, you'll want to use Amazon's EC2 API to access the tags. Since you said you're using Java, I would suggest the Using the AWS SDK amazon makes available. Within this SDK you'll find a method called describeTags (documentation). You can use a Resource ID as one of the filters to get the specific tags to your instance. Supported filters are
tag key
resource-id
resource-type
I suggest doing this retrieval at boot using something like cloud-init and caching the tags on your server for use later if necessary.

How do I maintain session state with a Google Earth client?

I'm playing with dynamic updates to Google Earth KML files.
The updates are of the form
<kml...>
<NetworkLinkControl>
<Update>
<targetHref="...">
<Change>
<Placemark targetId="...">
...stuff to update...
</Placemark>
</Change>
</Update>
</NetworkLinkControl>
</kml>
And it all works greatm from my Java Servlet - except that GE doesn't seem to support HTTP Sessions, and I need to provide only the updates that have occurred since the last request from a given client.
Am I doing something wrong? Does GE support sessions and I'm too stupid to work out how? If I need to provide client-specific updates without sessions, how can I do that? (I know I could use the source IP address as a coarse measure but that feels kinda nasty...)
Thanks!
Old question, but you need to encode the session ID as part of the URLs. GE does not maintain cookies.
It seems that I can use the kml/NetworkLinkControl/cookie element to give the client a parameter to send back to me. Trying to use this to get the client to tell me when it last requested an update and use this instead of sessions...

Categories

Resources