Installing Node-exporter

Installing Node-exporter is very easy, as we can use its Docker image directly, which is available in the Docker.io referencing it on the OpenShift command:

  1. To install Node-exporter, issue the following commands:
 ./oc new-app prom/node-exporter
--> Found Docker image b3e7f67 (7 weeks old) from Docker Hub for "prom/node-exporter"

An image stream tag will be created called node-exporter:latest, which will track this image. This image will be deployed in the deployment config file node-exporter. Port 9100/tcp/ will be load-balanced by the node-exporter service.

  1. Other containers can access this service through the node-exporter host name:
--> Creating resources ...
imagestream.image.openshift.io "node-exporter" created
deploymentconfig.apps.openshift.io "node-exporter" created
service "node-exporter" created
--> Success
  1. You can expose the service by executing the following commands:
'oc expose svc/node-exporter'
  1. Run oc status to view your app. To expose the node-exporter, use the following code:
./oc expose service node-exporter

route.route.openshift.io/node-exporter exposed

Exposing the node-exporter via route is just for testing purposes. What we really need is to have Prometheus grasp the metrics provided by Node-exporter.

To achieve such a configuration, the configuration file of Prometheus needs to be updated.

  1. If you access the Prometheus pod, you will be able to see the current configuration, as follows:
./oc get pods

NAME READY STATUS RESTARTS AGE

node-exporter-1-lgpz2 1/1 Running 0 6m

prometheus-1-qgggp 1/1 Running 0 6h

./oc rsh prometheus-1-qgggp

$ ls -la

total 16

drwxr-xr-x 1 nobody nogroup 4096 Jan 15 20:13 .

drwxr-xr-x 1 root root 4096 Jan 19 14:36 ..

lrwxrwxrwx 1 nobody nogroup 39 Jan 15 20:13 console_libraries -> /usr/share/prometheus/console_libraries

lrwxrwxrwx 1 nobody nogroup 31 Jan 15 20:13 consoles -> /usr/share/prometheus/consoles/

lrwxrwxrwx 1 root root 11 Jan 15 20:13 data -> /prometheus

-rw-r--r-- 1 nobody nogroup 926 Jan 15 20:09 prometheus.yml

$ cat prometheus.yml
# my global config
global:

scrape_interval: 15s
evaluation_interval: 15s

# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:

rule_files:
# - "first_rules.yml"
# - "second_rules.yml"

scrape_configs:
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']

Prometheus's configuration needs the following settings to be loaded:

- job_name: 'node-exporter'
static_configs:
- targets: ['node-exporter:9100']
  1. These new settings can be placed into a ConfigMap and mounted as a volume.
  2. Create a prometheus.yaml file with the following content:
global:
scrape_interval: 15s
evaluation_interval: 15s

alerting:
alertmanagers:
- static_configs:
- targets:

rule_files:

# - "first_rules.yml"
# - "second_rules.yml"

scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node-exporter'
static_configs:
- targets: ['node-exporter:9100']
  1. Save the file and issue the following command:
./oc create configmap prometheus-config-map --from-file=prometheus.yaml
configmap/prometheus-config-map created

Now we need to set the ConfigMap in the Prometheus deployment.

  1. To do that, select the Prometheus deployment from the Web console and edit the YAML configuration. This will add the reference of the ConfigMap and set the updated configuration file. You can look at the code of the YAML file at this URL: https://github.com/PacktPublishing/Hands-On-Cloud-Native-Microservices-with-Jakarta-EE/blob/master/ch10/prometheus-dc.yaml.

These new settings allows Prometheus to load the new configuration file coming from  ConfigMap.

  1. Now a new Prometheus deployment should be triggered automatically, as follows:

The new Prometheus deployment after loading the new configuration file
  1. Going back to the Prometheus application, we should see the node-exporter available on Prometheus, as depicted in the following screenshot:

Now it's time to import everything using Grafana.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset