I was wondering if it is possible to collect all metric from Prometheus with Java client?
For example Go metrics, host metrics etc.
If yes, can these metrics be queried like on HTTP api?
Could you please clarify: "instrumenting" usually means exposing metrics from your application's code to a Prometheus endpoint. The question reads that you either want to read metrics from an application, or from a Prometheus instance that has already scraped the metrics.
For this answer I assume that you're running a Prometheus instance that has already scraped the metrics.
If you want to read the most current values that Prometheus has scraped from your applications, you can use Prometheus' federation endpoint via HTTP: you can read all metrics with their current readings in one go, or apply a query. I'm not aware of a Java library to parse the format, but you find the definition here. You could use the same approach to query your applications directly.
If you want to receive a JSON that might be easier to parse, you can use Prometheus's HTTP API.
If you want to receive updates on values as soon as Prometheus queries them, you can hook up to the remote write API. There is already existing integrations, but at first glance there is no Java integration. You could use Kafka as an intermediary. Also, this might be more than you've asked for in this questions.
Related
We have one Redis for our company and multiple teams are using it. We are getting a surge of requests and nobody seems to know which application is causing it. We have only one password that goes around the whole company and our Redis is secured under a VPN so we know it's not coming from the outside.
Is there a way to know whose using Redis? Maybe we can pass in some headers with the connection from every app to identify who makes the most requests, etc.
We use Spring Data Redis for our communication.
This question is too broad since different strategies can be used here:
Use Redis MONITOR command. This is basically a built-in debugging tool that monitors all the commands executed by Redis
Use some kind of intermediate proxy. Instead of routing all the commands directly to redis - route everything to proxy that will do some processing like measuring the amounts of commands by the calling host or maybe types of commands depending what you want.
This is still only a configuration related solution so you won't need any changes at the level of applications
Since you have spring boot, you can use Micrometer / metering integration. This way you could create a counter / gauge that will get updated upon each request to Redis. If you also stream the metering data to tools like Prometheus, you'll be able to create a dashboard, say in grafana to see the whole picture. Micrometer can integrate also with other products, Prometheus/Grafana was only an example, you can chose any other solution (maybe in your organization you already have something like that).
We are trying to get live configuration data from our kubernetes cluster. Therefore we would like to read the configmaps from each of our services.
Is there a way to exctract this data with a spring microservice which runs alongside the rest of the services?
Or are there other (better?) ways / tools to get this information?
Using Kubernetes APIs you can get the configmaps you need. I am not familiar with the Java client, but here it is:
https://github.com/kubernetes-client/java
You can retrieve a list of configmaps and their contents using these APIs. Your application will need a cluster role and a cluster role binding to allow it reading from configmap resources if you're using RBAC.
To extract information you can just query the Kubernetes API, likely in your case using the Java Kubernetes client. Likely the biggest issue you will face will be ensuring you have read access for the namespace(s) that the ConfigMaps are in.
The bigger question about a 'better way' is trying to understand why you want to read all of the ConfigMaps for your applications. The goal you are trying to accomplish will guide the solution.
I would like to gather and store data on the availability of the service or node. The day after I could summarize the figures, like { day-1: service = 98.5%; day-2 = 99%}.
I could get the data by calling a simple rest (ping) service (e.g. via Actuator or what). Then I would need to write a custom scheduled application calling the Actuator/ping services.
Is there a simple solution for collecting/storing the availability data? Via Spring Batch?
UPDATE 31-05: I read about Spring Boot Admin. Is this the right solution? See also this introduction.
The data could be extracted and formatted in a CSV, JasperReporting, etc.
I hope that I can help you. I think that what you need is a way of monitoring your applications in a persistent way. You can build your own solution creating a Ping resource and scheduling a client to collect availability information from time to time. But, to no re-invent the wheel, a really suggest you use some professional tool.
I recommend that you use a Dashboard tool like Grafana to create these reports, and I suggest you try Prometheus to capture monitoring pieces of information.
I have listed some links below.
Actuator and Prometheus
monitoring-spring-boot-applications-with-prometheus
Prometheus dashboard in Grafana
I am working on an application that accepts incoming HTTP requests and contains the user's zip code. I would like to track each of the zip codes received using a metric such that it can be reported to Prometheus and graphed inside Grafana. It would not make sense to have a counter for every single zip code but I worry that a Gauge would not be appropriate and Grafana would miss some of the data between Prometheus scrapes. Any suggestions for how I could possibly accomplish this task? We do have logging but we need this information displayed in Grafana.
This is more a use case for logging than metrics given the cardinality.
This is a use case for a label, however Dropwizard doesn't support those. Thus if you're going to do this with Prometheus I'd suggest using the Java client with a Counter with a label for the zip code.
I am using com.sparkjava library for writing API.I want to monitor the metrics of these API like the average ,min and max time taken to give the response, throughput for the API's and count of request sent for the API etc.,
I was looking for a suitable library which provides all these data.I want these metrics data to be registered in the JVM using the JMX technology.I know of codahale.metrics library for registering ,apart from that are there any other better libraries?I don't want to write the MBean objects and register in the MBeanRegisrty unless there is no other alternative.I am looking for a library which gives the above metrics data once i run the application.
Have you tried newrelic? It's very easy to set up and gives you a lot of data out of the box :)