A few notes about devops and automation

Getting started with Prometheus

· by Jacqueline · Read in about 2 min · (324 Words)
devops

Prometheus delivers real-time monitoring, alerting and time-series database capabilities including powerful queries and visualizations. Written in Go, Prometheus is one of the fastest-growing projects on GitHub according to the CNCF project and is also mentioned in the Kubernetes docs.

So what does Prometheus do? Well, it collects metrics from configured targets at given intervals, evaluates rule expressions, displays the results, and can trigger alerts if some condition is observed to be true.

Well then, how to get started with it? Getting started with Prometheus shouldn’t be that hard. You can get up and running quickly. And although you get some beautiful graphs in a second, you may not know what you are doing. So here is a blog that takes some steps back and takes the from scratch approach.

I would recommend this book by the way.

Installing Prometheus

Grab the latest version from here

tar -xzf prometheus-2.6.0.linux-amd64.tar.gz
sudo cp prometheus-2.6.0.linux-amd64/prometheus /usr/local/bin/
sudo cp prometheus-2.6.0.linux-amd64/promtool /usr/local/bin/

You can now go ahead and see if the installation went well:

prometheus --version

This should return the current version.

Now go ahead and copy the promotheus.yml file from the extracted folder to /etc/prometheus and start the server:

sudo mkdir /etc/prometheus
sudo cp prometheus.yml /etc/prometheus/
prometheus --config.file "/etc/prometheus.yml"

If you browse to localhost:9090 you will see the Prometheus dashboard and you can execute some of the queries in the dropdown list. What it basically does right now is monitoring itself.

Monitoring a node

Download and install the node exporter here: https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz

tar -xzf node_exp*
sudo cp node_exporter-*/node_exporter /usr/local/bin

Configure the Textfile collector

sudo mkdir -p /var/lib/node_exporter/textfile_collector
echo 'metadata{role="docker_server",datacenter="RDAM"} 1' | sudo tee \
 /var/lib/node_exporter/textfile_collector/metadata.prom

Then we can launch node_exporter:

node_exporter --collector.textfile.directory /var/lib/node_exporter/textfile_collector \
--collector.systemd --collector.systemd.unit-whitelist="(docker|ssh|rsyslog).service"

Then scrape it. Our new prometheus.yml file will look like so:

scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]
  - job_name: "node"
    static_configs:
      - targets: ["192.168.2.66:9100"]

This is a first post on Prometheus. Next time I will write about running Prometheus in Kubernetes.

Comments