From d909df0e38a3cabf41d86ecdc1dbbb05a53458fd Mon Sep 17 00:00:00 2001
From: Markus Klose <Markus.Klose@Student.Reutlingen-university.de>
Date: Sun, 27 Nov 2022 17:17:40 +0100
Subject: [PATCH] Node-exporter first steps

---
 docker-compose.yaml       | 33 +++++++++++++++++++++++++++++++++
 index.js                  | 18 +++++++++---------
 prometheus/prometheus.yml | 16 ++++++++++++++--
 3 files changed, 56 insertions(+), 11 deletions(-)

diff --git a/docker-compose.yaml b/docker-compose.yaml
index 0692ec6..90026e4 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -1,6 +1,32 @@
 version: '3'
 
+networks:
+  monitor:
+    driver: bridge
+
 services:
+  node-exporter:
+    image: prom/node-exporter:latest
+    container_name: node-exporter
+    ports:
+      - 9100:9100
+    restart: unless-stopped
+    volumes:
+      - /proc:/host/proc:ro
+      - /sys:/host/sys:ro
+      - /:/rootfs:ro
+    command:
+      - '--path.procfs=/host/proc'
+      - '--path.rootfs=/rootfs'
+      - '--path.sysfs=/host/sys'
+      - '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'
+    expose:
+      - 9100
+    deploy:
+      mode: global
+    networks:
+      - monitor
+
   prometheus:
     image: prom/prometheus:latest
     container_name: prometheus
@@ -14,6 +40,8 @@ services:
     restart: unless-stopped
     command:
       - "--config.file=/etc/prometheus/prometheus.yml"
+    networks:
+      - monitor
 
   grafana:
     image: grafana/grafana:latest
@@ -32,6 +60,9 @@ services:
       - 27017:27017
     volumes:
       - mongodb:/data/db
+    networks:
+      - monitor
+    
 
   node:
     restart: always
@@ -46,6 +77,8 @@ services:
       - mongodb
     environment:
       WAIT_HOSTS: mongodb:27017
+    networks:
+      - monitor
       
 volumes:
  mongodb:
diff --git a/index.js b/index.js
index 2b1e81d..057e8f4 100644
--- a/index.js
+++ b/index.js
@@ -76,22 +76,22 @@ const messageGroup = new client.Counter({
   name: 'node_message_counter_Group',
   help: 'Counts the amount of times group message is used'
 });
-
+    
 const clientActiveUsers = new client.Gauge({
   name: 'node_active_users',
   help: 'Active Users'
-});
+    });
 
 const successfullLogIns = new client.Counter({
   name: 'node_successful_logins',
   help: 'Successfull LogIns total'
-});
+  });
 global.SUCCESSFULLLOG = successfullLogIns;
 
 const notSuccessfullLogIns = new client.Counter({
   name: 'node_not_successful_logins',
   help: 'Not successfull LogIns total'
-});
+    });
 global.NOTSUCCESSFULLLOG = notSuccessfullLogIns;
 
 const audioFileCounter = new client.Counter({
@@ -178,8 +178,8 @@ io.on('connection', (socket) => {
 
 
 /**
- * Summary:
- * Function to add a user to map of users, who are currently online.
+* Summary:
+* Function to add a user to map of users, who are currently online.
 *
 * Description:
 * Function will take the username from response and append it together with the socketID to map activeUsers.
@@ -314,7 +314,7 @@ io.on('connection', (socket) => {
           sender : sender,
           receiver: receiver,
           dateTime: dateTime
-          })
+        })
       return 0;
         }
       }
@@ -341,7 +341,7 @@ io.on('connection', (socket) => {
 * @listens  socket.on() 'groupMessage' event
 */
   socket.on('groupMessage', (response) => {
-
+    
     messageCounterIn.inc(1);
     messageGroup.inc(1);
     
@@ -422,7 +422,7 @@ io.on("connection", (socket) => {
     io.emit('video', file);
   });
 });
-          
+
 /**
 * Summary:
 * Function for sending audio files
diff --git a/prometheus/prometheus.yml b/prometheus/prometheus.yml
index 4a0cd22..ce397e1 100644
--- a/prometheus/prometheus.yml
+++ b/prometheus/prometheus.yml
@@ -14,5 +14,17 @@ scrape_configs:
     scrape_interval: 5s
     # scheme: https
     static_configs:
-      - targets: ['192.168.0.230:5000']
-  
\ No newline at end of file
+      - targets: ['192.168.178.45:5000']
+
+  - job_name: 'node-exporter'
+    honor_labels: true
+    scrape_interval: 5s
+    # scheme: https
+    static_configs:
+      - targets: ['node-exporter:9100']
+
+#remote_write:
+#- url: "localhost:3000"
+#  basic_auth:
+#    username: "admin"
+#    password: "admin" 
\ No newline at end of file
-- 
GitLab