Prometheus


Prometheus Install

Docker Install

cat <<EOF > prometheus.yml
global:
  scrape_interval:     10s
  evaluation_interval: 10s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

EOF

This tells the Prometheus server to scrape itself on port 9090.

Now let’s create a Dockerfile that adds this on top of the prom/prometheus image:

cat <<EOF > Dockerfile
FROM prom/prometheus

# Add in the configuration file from the local directory.
ADD prometheus.yml /etc/prometheus/prometheus.yml
EOF

Next we can build and run it:

docker build -t prometheus_simple .
docker run -p 9090:9090 prometheus_simple

Control - C to stop this

Disabling SELinux

    Configure SELINUX=disabled in the /etc/selinux/config file:

    # This file controls the state of SELinux on the system.
    # SELINUX= can take one of these three values:
    #       enforcing - SELinux security policy is enforced.
    #       permissive - SELinux prints warnings instead of enforcing.
    #       disabled - No SELinux policy is loaded.
    SELINUX=disabled
    # SELINUXTYPE= can take one of these two values:
    #       targeted - Targeted processes are protected,
    #       mls - Multi Level Security protection.
    SELINUXTYPE=targeted

    Reboot your system. After reboot, confirm that the getenforce command returns Disabled:

    ~]~ getenforce
    Disabled

Manual Install

mkdir Downloads

cd Downloads

Download

curl -LO "https://github.com/prometheus/prometheus/releases/download/v2.2.1/prometheus-2.2.1.linux-amd64.tar.gz"

goto Root directory

mkdir Prometheus

cd Prometheus

tar -xvzf ~/Downloads/prometheus-2.2.1.linux-amd64.tar.gz

./prometheus --version

sudo vi /etc/systemd/system/node_exporter.service

This file should contain the path of the node_exporter executable, and also specify which user should run the executable. Accordingly, add the following code:

/etc/init/node_exporter.conf
[Unit]
Description=Node Exporter

[Service]
User=prometheus
ExecStart=/home/prometheus/Prometheus/node_exporter/node_exporter

[Install]
WantedBy=default.target

Reload systemd so that it reads the configuration file you just created.

sudo systemctl daemon-reload

At this point, Node Exporter is available as a service which can be managed using the systemctl command. Enable it so that it starts automatically at boot time.

sudo systemctl enable node_exporter.service
You can now either reboot your server, or use the following command to start the service manually:

sudo systemctl start node_exporter.service

Starting Prometheus Server

Enter the directory where you installed the Prometheus server:

cd ~/Prometheus/prometheus-0.16.0.linux-amd64
Before you start Prometheus, you must first create a configuration file for it called prometheus.yml.

vi ~/Prometheus/prometheus-0.16.0.linux-amd64/prometheus.yml
Copy the following code into the file.

~/Prometheus/prometheus-0.16.0.linux-amd64/prometheus.yml
scrape_configs:
  - job_name: "node"
    scrape_interval: "15s"
    target_groups:
    - targets: ['localhost:9100']

This creates a scrape_configs section and defines a job called node. It includes the URL of your Node Exporter’s web interface in its array of targets. The scrape_interval is set to 15 seconds so that Prometheus scrapes the metrics once every fifteen seconds.

You could name your job anything you want, but calling it “node” allows you to use the default console templates of Node Exporter.

Save the file and exit.

Start the Prometheus server as a background process.

nohup ./prometheus > prometheus.log 2>&1 &

Note that you redirected the output of the Prometheus server to a file called prometheus.log. You can view the last few lines of the file using the tail command:

tail ~/Prometheus/prometheus-0.16.0.linux-amd64/prometheus.log

Once the server is ready, you will see the following messages in the file: Use a browser to visit Prometheus’s homepage available at http://your_server_ip:9090. You’ll see the following homepage.


These writings represent my own personal views alone.
Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.