Compare commits

..

12 commits

Author SHA1 Message Date
118b28157a Удаление старого скрипта 2025-01-25 06:54:32 +07:00
74de141ab4 Добавление импортера в композ 2025-01-25 06:54:21 +07:00
c0886cb4ec Создание импортера и добавление скрипта для ожидания доступности контейнера 2025-01-25 06:53:44 +07:00
a0d69ac4fd Указание адреса до графаны статикой и сокращение пути до даша апача 2025-01-25 06:52:53 +07:00
dc823fc26a Проброс скриптов и панелей в контейнер 2025-01-25 05:50:11 +07:00
266a141aca Добавление скрипта загрузки даша апача по АПИ 2025-01-25 05:31:41 +07:00
dd2db7b1e2 Удаление старого dash'а 2025-01-25 05:31:08 +07:00
11a63aafc2 Смена пути до даша апача 2025-01-25 05:25:11 +07:00
fd27953f40 Добавление Dashboard для работы с Apache 2025-01-25 05:18:27 +07:00
107569459b Лаунчер для передергивания контейнеров 2025-01-25 02:56:27 +07:00
563ebc3fbd Добавление панели с метриками 2025-01-25 02:56:06 +07:00
0b65c6583a Не будет поддерживаться директива в новых версиях 2025-01-25 02:31:48 +07:00
9 changed files with 824 additions and 45 deletions

7
launcher.sh Normal file
View file

@ -0,0 +1,7 @@
#!/bin/bash
docker stop stransit-test-grafana
docker rm stransit-test-grafana
docker volume rm stransit-test_grafana_data
docker-compose -f manufacturer/container/services/docker-compose.yml up -d

View file

@ -1,9 +0,0 @@
apiVersion: 1
providers:
- name: 'apache-dashboard'
type: file
disableDeletion: false
updateIntervalSeconds: 10
allowUiUpdates: true
options:
path: /var/lib/grafana/dashboard

View file

@ -0,0 +1,16 @@
providers:
- name: 'default'
orgId: 1
folder: ''
type: file
disableDeletion: false
editable: true
options:
path: /var/lib/grafana/dashboards/default
dashboards:
default:
spring-boot-stat:
gnetId: 3894
revision: 2
datasource: Prometheus

View file

@ -0,0 +1,724 @@
{
"dashboard": {
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"description": "Apache Prometheus Dashboard",
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"gnetId": 3894,
"hideControls": false,
"id": null,
"links": [],
"refresh": "1m",
"rows": [
{
"collapse": false,
"height": 102,
"panels": [
{
"cacheTimeout": null,
"colorBackground": false,
"colorValue": false,
"colors": [
"rgba(245, 54, 54, 0.9)",
"rgba(237, 129, 40, 0.89)",
"rgba(50, 172, 45, 0.97)"
],
"datasource": "Prometheus",
"decimals": 1,
"format": "s",
"gauge": {
"maxValue": 100,
"minValue": 0,
"show": false,
"thresholdLabels": false,
"thresholdMarkers": true
},
"id": 8,
"interval": null,
"links": [],
"mappingType": 1,
"mappingTypes": [
{
"name": "value to text",
"value": 1
},
{
"name": "range to text",
"value": 2
}
],
"maxDataPoints": 100,
"nullPointMode": "connected",
"nullText": null,
"postfix": "s",
"postfixFontSize": "50%",
"prefix": "",
"prefixFontSize": "50%",
"rangeMaps": [
{
"from": "null",
"text": "N/A",
"to": "null"
}
],
"span": 2,
"sparkline": {
"fillColor": "rgba(31, 118, 189, 0.18)",
"full": false,
"lineColor": "rgb(31, 120, 193)",
"show": false
},
"tableColumn": "",
"targets": [
{
"expr": "apache_uptime_seconds_total{instance=~\"$host:$port\"}",
"format": "time_series",
"intervalFactor": 1,
"refId": "A",
"step": 240
}
],
"thresholds": "",
"title": "Uptime",
"type": "singlestat",
"valueFontSize": "50%",
"valueMaps": [
{
"op": "=",
"text": "N/A",
"value": "null"
}
],
"valueName": "avg"
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "Prometheus",
"decimals": 0,
"fill": 7,
"id": 5,
"legend": {
"alignAsTable": true,
"avg": true,
"current": true,
"max": true,
"min": true,
"rightSide": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 3,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [
{
"alias": "Apache Down",
"color": "#BF1B00"
},
{
"alias": "Apache Down",
"transform": "negative-Y"
}
],
"spaceLength": 10,
"span": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "count(apache_up{instance=~\"$host:$port\"} == 1)",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "Apache Up",
"refId": "A",
"step": 240
},
{
"expr": "scalar(count(apache_up{instance=~\"$host:$port\"} == 0))",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "Apache Down",
"refId": "B",
"step": 240
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Apache Up / Down",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": "1",
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": false
}
]
}
],
"repeat": null,
"repeatIteration": null,
"repeatRowId": null,
"showTitle": false,
"title": "Basic Apache status",
"titleSize": "h6"
},
{
"collapse": false,
"height": "365",
"panels": [
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "Prometheus",
"decimals": 2,
"fill": 1,
"id": 3,
"legend": {
"alignAsTable": true,
"avg": true,
"current": true,
"max": true,
"min": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"span": 6,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "rate(apache_sent_kilobytes_total{instance=~\"$host:$port\"}[5m])",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "Kilobytes Sent",
"refId": "A",
"step": 240
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Current total kbytes sent",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "deckbytes",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": false
}
]
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "Prometheus",
"decimals": 2,
"fill": 1,
"id": 1,
"legend": {
"alignAsTable": true,
"avg": true,
"current": true,
"max": true,
"min": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"span": 6,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "rate(apache_accesses_total{instance=~\"$host:$port\"}[5m])",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "Accesses",
"refId": "A",
"step": 240
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Current total apache accesses",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": false
}
]
}
],
"repeat": null,
"repeatIteration": null,
"repeatRowId": null,
"showTitle": false,
"title": "Traffic Load",
"titleSize": "h6"
},
{
"collapse": false,
"height": "365",
"panels": [
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "Prometheus",
"decimals": 2,
"fill": 1,
"id": 2,
"legend": {
"alignAsTable": true,
"avg": true,
"current": true,
"max": true,
"min": true,
"rightSide": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"span": 12,
"stack": true,
"steppedLine": false,
"targets": [
{
"expr": "apache_scoreboard{instance=~\"$host:$port\"}",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "{{ state }}",
"refId": "A",
"step": 240
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Apache scoreboard statuses",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": false
}
]
}
],
"repeat": null,
"repeatIteration": null,
"repeatRowId": null,
"showTitle": false,
"title": "Scoreboard",
"titleSize": "h6"
},
{
"collapse": false,
"height": "365",
"panels": [
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "Prometheus",
"decimals": 2,
"fill": 1,
"id": 7,
"legend": {
"alignAsTable": true,
"avg": true,
"current": true,
"max": true,
"min": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"span": 6,
"stack": true,
"steppedLine": false,
"targets": [
{
"expr": "apache_workers{instance=~\"$host:$port\"}\n",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "{{ state }}",
"refId": "A",
"step": 240
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Apache worker statuses",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": false
}
]
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "Prometheus",
"decimals": 2,
"fill": 1,
"id": 4,
"legend": {
"alignAsTable": true,
"avg": true,
"current": true,
"max": true,
"min": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"span": 6,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "apache_cpuload{instance=~\"$host:$port\"}",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "Load",
"refId": "A",
"step": 240
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Apache CPU load",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": "0",
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": false
}
]
}
],
"repeat": null,
"repeatIteration": null,
"repeatRowId": null,
"showTitle": false,
"title": "Processing Load",
"titleSize": "h6"
}
],
"schemaVersion": 14,
"style": "dark",
"tags": [],
"templating": {
"list": [
{
"allValue": null,
"current": {},
"datasource": "Prometheus",
"hide": 0,
"includeAll": false,
"label": "host",
"multi": false,
"name": "host",
"options": [],
"query": "label_values(apache_up, instance)",
"refresh": 2,
"regex": "/([^:]+):.*/",
"sort": 1,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
},
{
"allValue": null,
"current": {},
"datasource": "Prometheus",
"hide": 2,
"includeAll": false,
"label": null,
"multi": false,
"name": "port",
"options": [],
"query": "label_values(apache_up, instance)",
"refresh": 1,
"regex": "/[^:]+:(.*)/",
"sort": 0,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
}
]
},
"time": {
"from": "now-24h",
"to": "now"
},
"timepicker": {
"refresh_intervals": [
"5s",
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"time_options": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
]
},
"timezone": "",
"title": "Apache",
"version": 13,
"description": "Apache Prometheus Dashboard"
},
"overwrite": true
}

View file

@ -1,32 +0,0 @@
#!/bin/bash
GF_SECURITY_ADMIN_PASSWORD=admin
GRAFANA_URL=localhost
DASHBOARD_FILE="dashboard.json"
DATA_SOURCE_UID="10.10.1.3:9090"
GRAFANA_URL=http://admin:${GF_SECURITY_ADMIN_PASSWORD}@${GRAFANA_URL}:3000
if [[ ! -f "$DASHBOARD_FILE" ]]; then
echo "Ошибка: Файл с дашбордом '${DASHBOARD_FILE}' не найден."
exit 1
fi
DASHBOARD_JSON=$(<"$DASHBOARD_FILE")
DASHBOARD_JSON=$(echo "$DASHBOARD_JSON" | sed "s/\${DS_LOCALHOST}/$DATA_SOURCE_UID/g")
IMPORT_JSON=$(jq -n --argjson dashboard "$DASHBOARD_JSON" \
'{dashboard: $dashboard, overwrite: true}')
echo "Измененный JSON дашборда:"
echo "$IMPORT_JSON"
response=$(curl -X POST "${GRAFANA_URL}/api/dashboards/import" \
-H "Content-Type: application/json" \
-d "${IMPORT_JSON}")
echo "Ответ от Grafana: ${response}"

View file

@ -0,0 +1,32 @@
#!/bin/bash
# Устанавливаю переменные
GF_URL=10.10.1.4:3000
GF_LOGIN=admin
GF_PASSWORD=${GF_SECURITY_ADMIN_PASSWORD}
GF_DASHBOARD_URL=/scripts/apache.json
# Проверяю, что файл существует
if [[ ! -f "$GF_DASHBOARD_URL" ]]; then
echo "Файл $GF_DASHBOARD_URL не найден!"
exit 1
fi
# Загружаю JSON в переменную
GF_DASHBOARD_JSON=$(<"$GF_DASHBOARD_URL")
# Создаю запрос на создание дашборда
response=$(curl -u "$GF_LOGIN:$GF_PASSWORD" \
-X POST \
-H "Content-Type: application/json" \
-d "$GF_DASHBOARD_JSON" \
"$GF_URL/api/dashboards/db")
# Вывожу ответ от API графы
if [[ $? -eq 0 ]]; then
echo "Ответ API: $response"
else
echo "Произошла ошибка при создании дашборда."
echo "Ответ API: $response"
fi

View file

@ -0,0 +1,8 @@
FROM alpine:3.21
# Устанавливаю BASH и CURL для работы с API графаны
RUN apk add --no-cache bash curl
COPY manufacturer/container/importer/scripts/wait_for_it.sh /usr/local/bin/wait-for-it
RUN chmod +x /usr/local/bin/wait-for-it

View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -e
host="$1"
shift
port="$1"
shift
cmd="$@"
until nc -z "$host" "$port"; do
>&2 echo "Графана $host:$port недоступна - ждем..."
sleep 1
done
>&2 echo "Графана $host:$port доступна - импортирую даш."
exec $cmd

View file

@ -23,8 +23,8 @@ services:
ipv4_address: 10.10.2.3
volumes:
- wordpress_data:/var/www/html
extends:
service: stransit-test-db
depends_on:
- stransit-test-db
stransit-test-apache:
build:
@ -88,8 +88,24 @@ services:
volumes:
- grafana_data:/var/lib/grafana
- ../../configs/grafana/provisioning:/etc/grafana/provisioning
# - ../grafana/import_dashboard.sh:/docker-entrypoint-init.d/import_dashboard.sh
# entrypoint: [ "/bin/sh", "-c", "chmod +x /docker-entrypoint-init.d/import_dashboard.sh && /docker-entrypoint-init.d/import_dashboard.sh" ]
stransit-test-grafana-importer:
build:
context: ../../../.
dockerfile: manufacturer/container/importer/Dockerfile
image: stransit-test-grafana-importer:v1
container_name: stransit-test-grafana-importer
networks:
stransit-test-metrics:
volumes:
- ../grafana/scripts/import_apache_dashboard.sh:/scripts/import_apache_dashboard.sh
- ../../configs/grafana/provisioning/dashboards/default/apache.json:/scripts/apache.json
depends_on:
- stransit-test-grafana
env_file:
- .env
command:
[ "/bin/bash", "-c", "wait-for-it stransit-test-grafana:3000 -- bash /scripts/import_apache_dashboard.sh" ]
volumes:
db_data: