-
Notifications
You must be signed in to change notification settings - Fork 10
Working with Prometheus
As a microservice architecture, an instance of the XCoLab can profit greatly from collecting insights about the usage of the system. If your XCoLab instance is slowing down and you would like to analyze how how frequently each service endpoint is called and with what parameters, then this guide would come in handy for you.
Prometheus is an open source monitoring and alerting system that directly scrapes metrics from agents running on the target hosts and stores the collected samples centrally on its server.
Repository contains a prometheus.yml file at root. This file contains the configuration necessary for Prometheus to be able to scrape the services and view of the system. We will give you a run down of the most important configurations here.
-
scrape_configs
: A scrape_config section specifies a set of targets and parameters describing how to scrape them. In the general case, one scrape configuration specifies a single job.-
job_name
: Provide a name for each job. For example, user microservice can be called "user" -
scrape_interval
: How frequently to scrape the provided endpoint -
scrape_timeout
: How long until a scrape request times out -
metrics_path
: Which endpoint to scrape, for XCoLab it would be /actuator/prometheus -
scheme
: Configures the protocol scheme used for requests (http, https) -
basic_auth
: Authentication information used to authenticate to the API server. For CoLab it would bebasic_auth
butbearer_token
andbearer_token_file
are also options-
username
: mit -
password
: colab
-
-
static_configs
: -
targets
:- 127.0.0.1:18082
-
Run this command in terminal to download and setup a Prometheus docker container. This container will be able to scrape the XCoLab. Make sure to modify the path to .yml file in the command.
docker run --name spring_boot_prometheus --network="host" -p 9090:9090 -v /home/alikareemraja/MIT/XCoLab/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
Prometheus provides a functional query language called PromQL (Prometheus Query Language) that lets the user select and aggregate time series data in real time. The result of an expression can either be shown as a graph, viewed as tabular data in Prometheus's expression browser. Following are some of the examples to query Prometheus:
sum(contest_service_total{endpoint=~"/contests/.*/activePhase"})
activity_service_total{Arguments="activitiesAfter : 2019-05-28 11:14:55 | ",endpoint="/activityEntries",function="activityEntries",instance="127.0.0.1:18084",job="activity",method="GET"}
Although basic auth is implemented for the XCoLab view, the username password is very weak and fixed in code. It is something that could be a security problem going forward.