# grafana

#### Задание:

7\. Настройте мониторинг с помощью NodeExporter, Prometheus и Grafana.

* 1\. Создайте в домашней директории пользователя altlinux файл monitoring.yml для Docker Compose
  * 1\. Используйте контейнеры NodeExporter, Prometheus и Grafana для сбора, обработки и отображения метрик.
  * 2\. Настройте Dashboard в Grafana, в котором будет отображаться загрузка CPU, объём свободной оперативной памяти и места на диске.&#x20;
  * 3\. Интерфейс Grafana должен быть доступен по внешнему адресу на порту 3000.

#### Выполнение:

* В домашней директории пользователя **altlinux** создаём файл **monitoring.yml**:

```
vim ~/monitoring.yml
```

* * содержимое:

```
version: "3.9"
services:
  grafana:
    container_name: Grafana
    image: grafana/grafana
    ports:
      - "3000:3000"
    volumes:
      - grafana-data:/var/lib/grafana
      - grafana-configs:/etc/grafana

  prometheus:
    container_name: Prometheus
    image: prom/prometheus
    ports:
      - "9090:9090"
    volumes:
      - prom-data:/prometheus
      - prom-configs:/etc/prometheus

  node-exporter:
    container_name: NodeExporter
    image: prom/node-exporter
    ports:
      - "9100:9100"
    volumes:
      - /proc:/host/proc:ro
      - /sys:/host/sys:ro
      - /:/rootfs:ro
    command:
      - '--path.procfs=/host/proc'
      - '--path.sysfs=/host/sys'
      - '--collector.filesystem.mount-points-exclude'
      - '^/(sys|proc|dev|host|etc|rootfs/var/lib/docker/containers|rootfs/var/lib/docker/overlay2|rootfs/run/docker/netns|rootfs/var/lib/docker/aufs)($$|/)'
volumes:
  grafana-data:
  grafana-configs:
  prom-data:
  prom-configs:
```

Данный файл представляет описание трёх контейнеров:  **grafana, prometheus** и **node-exporter:**

* * **grafana** - это то, что мы будем видеть в браузере, это визуализатор метрик;
  * **prometheus** - это  своего рода база данных  в которой хранятся метрики;
  * **node-exporter** - это контейнер, который будет собирать метрики и отдавать на порту 9100

Схема работы получается следующая: **prometheus** забирает метрики с **node-exporter,** а **grafana** забирает метрики с **prometheus**

* Выполняем сборку и запуск **стека контейнеров** описанных в файле **monitoring.yml**:

```
docker-compose -f monitoring.yml up -d
```

* Проверяем:
*

```
<figure><img src="/files/jyaxojDpR9IpZwulsYDC" alt=""><figcaption></figcaption></figure>
```

<img src="https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image.png" alt="" height="154" width="915">

* Переходим в браузер **http\://<внешний IP адрес ControlVM>:3000**

  * для доступа в веб-интерфейс **Grafana** - стандартный логин и пароль "**admin**":
  *

  ```
  <figure><img src="/files/YLjEE7Eq81cOu9LzzIdh" alt=""><figcaption></figcaption></figure>
  ```

<img src="https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%281%29.png" alt="" height="611" width="928">

* Задаём новый пароль:
*

```
<figure><img src="/files/VviyKY2xsehQenmZ2Quk" alt=""><figcaption></figcaption></figure>
```

<img src="https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%282%29.png" alt="" height="641" width="926">

* Добавляем в **Grafana - Prometheus:**

  * на главном меню нажимаем **Add your first data source**
  *

  ```
  <figure><img src="/files/dwaHUv0UrO3K3FErj5Jw" alt=""><figcaption></figcaption></figure>
  ```

![](https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%283%29.png)

* выбираем **Prometheus**:
*

```
<figure><img src="/files/9GzuGBDcsarfJCYpc7Ct" alt=""><figcaption></figcaption></figure>
```

<img src="https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%284%29.png" alt="" height="636" width="925">

* вводим адрес контейнера с **Prometheus**:
*

```
<figure><img src="/files/LejyuH9P8JzMBjOHAWHM" alt=""><figcaption></figcaption></figure>
```

<img src="https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%285%29.png" alt="" height="506" width="926">

* Затем внизу на этой де странице нажимаем **Save and Test**:
*

```
<figure><img src="/files/qCjwB1duQR9JoZb4rwOC" alt=""><figcaption></figcaption></figure>
```

![](https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%286%29.png)

* * результат теста:
  *

  ```
  <figure><img src="/files/yUUVbGrkbsyH14ucNqEJ" alt=""><figcaption></figcaption></figure>
  ```

![](https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%287%29.png)

* Далее необходимо экспортировать **grafana dashboard:**
  * [grafana dashboard node\_exporter](https://grafana.com/grafana/dashboards/12486-node-exporter-full/)

    * переходим на сайт и нажимаем **Download JSON**
    *

    ```
    <figure><img src="/files/6CpAGql4mNGQaPi2kSen" alt=""><figcaption></figcaption></figure>
    ```

<img src="https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%288%29.png" alt="" height="661" width="1010">

![](https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%289%29.png)

<figure><img src="/files/XuCmyGgwGCOf31Fxg4OP" alt=""><figcaption></figcaption></figure>

* Открываем скаченный файл и копируем его содержимое, затем переходим в наш веб-интерфейс **grafana**:

  * нажимаем **Create your first dashboard**:
  *

  ```
  <figure><img src="/files/f6yiUFkFBnlQmaRopsnH" alt=""><figcaption></figcaption></figure>
  ```

<img src="https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%2810%29.png" alt="" height="424" width="1031">

* Нажимаем **Import dashboard**:
*

```
<figure><img src="/files/arwQ65s4KnwrVvkeLNTw" alt=""><figcaption></figcaption></figure>
```

<img src="https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%2811%29.png" alt="" height="557" width="1034">

* Вставляем скопированное содержимое из скаченного файла и нажимаем **Load**:
*

```
<figure><img src="/files/7BfgULnlKjpS2ZyDRB7Y" alt=""><figcaption></figcaption></figure>
```

<img src="https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%2812%29.png" alt="" height="771" width="1036">

* Затем выбираем наш **Prometheus** и нажимаем **Import**:
*

```
<figure><img src="/files/asSbpDZzuvTCvM54e4Qd" alt=""><figcaption></figcaption></figure>
```

<img src="https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%2813%29.png" alt="" height="669" width="1035">

* Результат:
*

```
<figure><img src="/files/BSPA5nOktOtqhAFTJKMh" alt=""><figcaption></figcaption></figure>
```

<img src="https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%2814%29.png" alt="" height="426" width="1033">

*На данном этапе пока ещё результатов нет, так как необходимо добавить **node-exporter** в **prometheus.yml** расположенный в volumes docker*

* Открываем на редактирование файл по пути **/var/lib/docker/volumes/altlinux\_prom-configs/\_data/prometheus.yml:**

```
sudo vim /var/lib/docker/volumes/altlinux_prom-configs/_data/prometheus.yml
```

* * добавляем в конец информацию о нашем контейнере с node-exporter:
  *

  ```
  <figure><img src="/files/bnszlbPjl22pooXWtSJj" alt=""><figcaption></figcaption></figure>
  ```

![](https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%2821%29.png)

* Далее переходим в веб-интерфейс **prometheus** по **http\://<внешний IP адрес ControlVM>:9090**

  * перейти в раздел **Status** -> **Targets**
  *

  ```
  <figure><img src="/files/fNSjvvSbo1YivfyVnXQK" alt=""><figcaption></figcaption></figure>
  ```

<img src="https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%2816%29.png" alt="" height="411" width="927">

* Должен появиться новый Targets который мы добавили в файле **prometheus.yml**
*

```
<figure><img src="/files/VH0Wzj9b5M2hcXvLu3Rf" alt=""><figcaption></figcaption></figure>
```

<img src="https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%2817%29.png" alt="" height="395" width="962">

* Чтобы он появился необходимо перезапустить контейнеры:

```
docker-compose -f monitoring.yml restart
```

* * результат:
  *

  ```
  <figure><img src="/files/bfy7zvEfx2BjSvoSyYx6" alt=""><figcaption></figcaption></figure>
  ```

![](https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%2818%29.png)

* Возвращаемся в веб-интерфейс **prometheus**:
*

```
<figure><img src="/files/Ac2SrE9mCRWkB3pzEAfG" alt=""><figcaption></figcaption></figure>
```

<img src="https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%2820%29.png" alt="" height="391" width="959">

* Переходим в веб-интерфейс **Grafana**:

  * наблюдаем необходимую по заданию информация - CPU, объём свободной оперативной памяти и места на диске:&#x20;
  *

  ```
  <figure><img src="/files/jcq9MzncSuu0OJhaDVI5" alt=""><figcaption></figcaption></figure>
  ```

<img src="https://sysahelper.ru/pluginfile.php/310/mod_page/content/2/image%20%2822%29.png" alt="" height="399" width="962">


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://seraphim.gitbook.io/volodyazetkin2024gitbook/controlvm/grafana.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
