Prometheus is a monitoring tool which was created to monitor highly dynamic container environments like Kubernetes, Docker swarm etc. It can also be used to monitor bare server where applications are directly deployed.
Prometheus working.
Prometheus collects and stores its metrics as time series data, i.e. metrics information is stored with the timestamp at which it was recorded, alongside optional key-value pairs called labels.
Prometheus pulls metric data, stores metrics data in a time series database which is stored in local, it then accepts queries called PromQL.
Architecture diagram
Components of monitoring with prometheus
1. Target: A machine, application server, microservice, containers, log services etc. We will monitor our own machine in the example. 2. Prometheus server 3. Exporter: Each target will have an exporter which exposes an end point like localhost:3030/metrics The end point is/metrics
Prometheus pulls the metrics from this URL. For our example since we are monitoring our machine we will use node exporter. For windows we have windows exporter.
As you have noticed we already have a job called prometheus which is monitoring the prometheus server itself at localhost:9090 .
rule_files: this will be another yaml file which has rules either recording i.e. precompute frequently needed or computationally expensive expressions and save their result as a new set of time series or alerting rules.
Run prometheus using the following command
./prometheus --config.file=prometheus.yml
By default prometheus uses port 9090 . Which means we have to check the end point http://localhost:9090/metrics  for metrics. Open up http://localhost:9090/ in your browser to open the prometheus dashboard.
Open it and check how the metrics appears.
Execute few queries and check for data.
promhttp_metric_handler_requests_total
You may not get same as above as it has more targets.
Step 2: Install the Exporter – node_exporter/windows_exporter
Restart the prometheus service with new config. Run the query to monitor the average amount of CPU time spent in system mode, per second, over the last minute (in seconds) rate(node_cpu_seconds_total{mode=”system”}[1m])
Windows Exporter dashboard: 2. You can copy the JSON or better just copy the dashboard ID, paste it and click on Load. 3. Select Prometheus as data source and click on Import. You should be redirected to the newly created dashboard.https://grafana.com/grafana/dashboards/14694
1. Click on the plus icon and click on Import option.
2. You can copy the JSON or better just copy the dashboard ID, paste it and click on Load
3. Select Prometheus as data source and click on.You should be redirected to the newly created dashboard.
All dashboard and panel configs are available as json. To learn how any panel is created or which metric and formula is used to calculate a visualization. Follow the steps.
1. Click on the down arrow on a panel. 2. Click on edit. Alternatively, you can click on a panel and press For this example the node(Host) and job(value of job from metric) variables are used as filters. The are values of the metric node_cpu_seconds_total
Check other dashboards/panels and checkout the values used and create your own dashboard to monitor your system.
Here we have only done monitoring. A proper monitoring solution should also have alerting system. As mentioned prometheus allows alerting and so does Grafana.
Learn how to setup alerts from the following links
This Post Has 0 Comments