I hope this post was useful, even if it’s not really a runnable example per se and needed some previous knowledge, but having built something similar to this recently, I thought it’d be a good idea to share it. The used libraries, elastic and the prometheus client both have good APIs and fantastic documentation - I had absolutely no issues. With seamless cross-compilation and Go’s simplicity, it’s just a delight to create small tools such as this to streamline and improve your monitoring and operations toolchain. It’s no wonder Go has so many fans among the Ops-crowd. Here is a link to the Full Code Conclusion We also label the entries with the environment, the actual status code and the type of the status code, which enables us to query for 5xx errors from a specific server for example. Inc() for every log, increasing the counter. Here, we categorize the status_code in the HTTP statusCode categories (5xx, 4xx…) and call. This example isn’t necessarily there to copy and run with your own data, as that will require a bit of setup and knowledge of ES and prometheus, but rather to see how one could go about doing something like this using Go.įirst off, we define the data structure for our structured log as described above: type GatewayLog struct if the 99th percentile of response-time is above a certain threshold) Our goal is to make these data-points available to prometheus, so we can analyze the data and/or create alerts based on it. The idea behind the example is that we have an index some_logging_index with structured logging data on Elasticsearch, including the server environment the log is coming from, the processing_time of requests as well as their status_code. In the following example code, we will take a look at how to interact with an Elasticsearch cluster using elastic, as well as how to expose metrics for prometheus using the official prometheus go client. ![]() To monitor Elasticsearch with Prometheus, we have to export the monitoring data in the Prometheus. In this post, I assume the reader to have at least basic knowledge of Elasticsearch as well as Prometheus in regards to what they are and what these tools are used for, as I won’t go into any detail on these topics. Overview of Elasticsearch Monitoring using Prometheus. This can be useful if, for example, you collect logs of a web application using the ELK stack, in which case the logs will be saved in Elasticsearch.Ī sample use-case would be to analyze the collected logs in regards to returned response codes or response time of single requests. This post describes how to create a small Go HTTP server, which is able to expose data from Elasticsearch on a Prometheus /metrics endpoint. Elasticsearch to Prometheus Exporter in Go
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |