Skip to content

Working with Prometheus

Ali Kareem Raja edited this page Jun 16, 2019 · 1 revision

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

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.

Configuration

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 be basic_auth but bearer_token and bearer_token_file are also options
      • username: mit
      • password: colab
    • static_configs:
    • targets:
      • 127.0.0.1:18082

Download Prometheus Docker image

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 Query API

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"}

Security concerns

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.