Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d96f8d8a9 | |||
| c065174d68 | |||
| 44780c8f41 | |||
| b3eefd65a2 | |||
| 232a151b85 | |||
| f5961a8843 |
23
.env.dist
23
.env.dist
@ -11,7 +11,7 @@ PRX_NGINX_CONF_DIR=<path_to_your_gtw_conf_dir>
|
||||
#------------------------------------------------
|
||||
# minio
|
||||
# path where minio data will be stored (ex: /home/docker/minio)
|
||||
MINIO_DATA_ROOT_DIR=<path_to_your_minio_data_dir>
|
||||
MINIO_DATA_DIR=<path_to_your_minio_data_dir>
|
||||
# path where mino client will be stored (ex: /home/docker/minio-cli)
|
||||
MINIO_CONF_CLI_DIR=<path_to_your_minio_conf_dir>
|
||||
# user
|
||||
@ -25,9 +25,9 @@ MINIO_REDIRECT_URL=<server_fqdn>/minio/ui/
|
||||
# admin user
|
||||
GF_ADMIN_USER=admin
|
||||
# admin user password
|
||||
GF_ADMIN_PASSWORD=admin
|
||||
GF_ADMIN_PASS=admin
|
||||
# path where grafana data will be stored (ex: /home/docker/grafana)
|
||||
GF_VOLUME_DIR=<path_to_your_gf_data_dir>
|
||||
GF_DATA_DIR=<path_to_your_gf_data_dir>
|
||||
# url redirect (ex: https://docker1.gmolab.net/grafana/)
|
||||
GF_ROOT_URL=<server_fqdn>/grafana/
|
||||
#------------------------------------------------
|
||||
@ -36,3 +36,20 @@ GF_ROOT_URL=<server_fqdn>/grafana/
|
||||
PROM_CONF_DIR=<path_to_your_prom_conf_dir>
|
||||
# data dir (ex: /home/docker/prometheus-data)
|
||||
PROM_DATA_DIR=<path_to_your_prom_data_dir>
|
||||
#------------------------------------------------
|
||||
# loki
|
||||
# conf dir prometheus.yml
|
||||
LOKI_CONF_DIR=<path_to_your_loki_conf_dir>
|
||||
# data dir (ex: /home/docker/loki-data)
|
||||
LOKI_DATA_DIR=<path_to_your_loki_data_dir>
|
||||
# data dir (ex: /home/docker/loki-gen-log)
|
||||
LOKI_GEN_LOG_DIR=<path_to_your_loki_data_dir>
|
||||
#------------------------------------------------
|
||||
# promtail
|
||||
# conf dir promatal.yaml (ex: /home/docker/promtail)
|
||||
PROMTAIL_CONF_DIR=<path_to_your_promtail_conf_dir>
|
||||
#------------------------------------------------
|
||||
# flog
|
||||
# flog docker image
|
||||
#FLOG_DOCKER_IMG=mingrammer/flog # (amd64)
|
||||
#FLOG_DOCKER_IMG=gmouchet/flog # (arm64)
|
||||
1180
FROM-AI.md
Normal file
1180
FROM-AI.md
Normal file
File diff suppressed because it is too large
Load Diff
33
LICENSE
Normal file
33
LICENSE
Normal file
@ -0,0 +1,33 @@
|
||||
Non-Commercial Use License – [manage.sh]
|
||||
|
||||
Copyright (c) [2025] [Gilles Mouchet]
|
||||
|
||||
This script is provided free of charge with its source code. You are permitted to:
|
||||
|
||||
Use the script for personal, educational, or non-commercial professional purposes.
|
||||
Study, modify, and share the script freely, provided this license is included.
|
||||
|
||||
You are strictly prohibited from:
|
||||
|
||||
- Selling this script or any modified version.
|
||||
- Using it in commercial services or products.
|
||||
- Distributing it in exchange for financial compensation, directly or indirectly.
|
||||
|
||||
This script is provided "as is", without any warranty of any kind.
|
||||
-----------------------------------------------------------------------------------------
|
||||
Licence d’utilisation non commerciale – [manage.sh]
|
||||
|
||||
Copyright (c) [2025] [Gilles Mouchet]
|
||||
|
||||
Ce script est fourni gratuitement avec son code source. Toute personne est autorisée à :
|
||||
|
||||
Utiliser le script à des fins personnelles, éducatives ou professionnelles non commerciales.
|
||||
Étudier, modifier et partager le script gratuitement, à condition de conserver cette licence.
|
||||
|
||||
Il est strictement interdit de :
|
||||
|
||||
- Vendre ce script ou une version modifiée.
|
||||
- L’utiliser dans des services ou produits commerciaux.
|
||||
- Le distribuer en échange d’une contrepartie financière, directe ou indirecte.
|
||||
|
||||
Ce script est fourni "tel quel", sans garantie d’aucune sorte.
|
||||
117
README.md
117
README.md
@ -12,9 +12,14 @@ This dokcer run stack grafana, loki, promtail, minio
|
||||
| <COMPOSE_PROJECT_NAME>-minio-cli-1 | - | client minio |
|
||||
| <COMPOSE_PROJECT_NAME>-prometheus-1 | `http://<server_fqdn>:9090` | prometheus |
|
||||
| <COMPOSE_PROJECT_NAME>-node-exporter-1 | - | node metrics for prometheus |
|
||||
| <COMPOSE_PROJECT_NAME>-promtail-1 | - | promtail |
|
||||
| <COMPOSE_PROJECT_NAME>-loki-1 | - | loki |
|
||||
| <COMPOSE_PROJECT_NAME>-log-generator-1 | - | fake log generator |
|
||||
## Requirements
|
||||
### Certificats
|
||||
Create a folder named `/home/docker/certs` and copy your certificates into it.
|
||||
Create a folder named `/home/docker/certs` and copy your certificates into it.
|
||||
IMPORTANT: Certificates must be named `tls.crt` and `tls.key`
|
||||
|
||||
```bash
|
||||
sudo mkdir -p /home/docker/certs
|
||||
```
|
||||
@ -24,47 +29,33 @@ All variables are described in the `.env.dist` file
|
||||
|
||||
Copy the `.env.dist` file to `.env` and update it with values appropriate for your setup.
|
||||
|
||||
### Proxy (nginx)
|
||||
Create the folder where the ngnix config will be stored and copy the `config/nginx.conf` into it
|
||||
```bash
|
||||
sudo mkdir -p /home/docker/nginx
|
||||
sudo cp ./config/default.conf /home/docker/nginx/.
|
||||
```
|
||||
|
||||
### Minio
|
||||
Create the folder where the minio data will be stored
|
||||
```bash
|
||||
sudo mkdir -p /home/docker/minio
|
||||
```
|
||||
|
||||
### Minio client
|
||||
Create the folder where the minio client comfig will be stored
|
||||
```bash
|
||||
sudo mkdir -p /home/docker/minio-cli
|
||||
```
|
||||
|
||||
### Grafana
|
||||
Create the folder where the grafana data will be stored
|
||||
```bash
|
||||
sudo mkdir -p /home/docker/grafana
|
||||
```
|
||||
|
||||
### Prometheus
|
||||
Create the folder where the grafana data will be stored
|
||||
```bash
|
||||
sudo mkdir -p /home/docker/prometheus
|
||||
```
|
||||
Create the folder where the prometheus data will be stored
|
||||
```bash
|
||||
sudo mkdir -p /home/docker/prometheus-data
|
||||
```
|
||||
|
||||
## Run
|
||||
|
||||
Create folder for persistents volumes and copy config files
|
||||
To be executed each time the configuration files are modified
|
||||
```bash
|
||||
docker compose up -d
|
||||
./manage.sh config
|
||||
```
|
||||
|
||||
Create container
|
||||
```bash
|
||||
./manage.sh create
|
||||
```
|
||||
|
||||
Start the stack
|
||||
```bash
|
||||
./manage.sh start
|
||||
```
|
||||
|
||||
For more information about `manage.sh` script execute `./manage.sh --help`
|
||||
|
||||
## Config
|
||||
### Prometheus
|
||||
#### grafana source
|
||||
`http://prometheus:9090`
|
||||
#### grafana dashboard
|
||||
3662 - Prometheus 2.0 Overview
|
||||
|
||||
### Minio client
|
||||
Create an alias
|
||||
```bash
|
||||
@ -76,9 +67,8 @@ Create prometheus metrics job
|
||||
docker exec -it <COMPOSE_PROJECT_NAME>-minio-cli-1 /bin/sh -c "mc admin prometheus generate myminio"
|
||||
```
|
||||
|
||||
Copy the output into prometheus.yml
|
||||
Copy the output into `<PROM_CONF_DIR>/prometheus.yml
|
||||
```yaml
|
||||
scrape_configs:
|
||||
- job_name: minio-job
|
||||
bearer_token: eyJhbGciOiJIUzUxMiIs..InR5cCI6IkpXVCJ9
|
||||
metrics_path: /minio/v2/metrics/cluster
|
||||
@ -91,20 +81,33 @@ Restart prometheus
|
||||
```bash
|
||||
docker compose restart prometheus
|
||||
```
|
||||
|
||||
Add dashboard ***13502 - MinIO Dashboard*** to grafana
|
||||
|
||||
### Prometheus
|
||||
#### grafana source
|
||||
`http://prometheus:9090`
|
||||
|
||||
#### grafana dashboard
|
||||
3662 - Prometheus 2.0 Overview
|
||||
13502 - MinIO Dashboard
|
||||
|
||||
### Loki
|
||||
Create bulk loki
|
||||
```bash
|
||||
docker exec -it <COMPOSE_PROJECT_NAME>-minio-cli-1 /bin/sh -c "mc mb myminio/loki"
|
||||
```
|
||||
#### grafana source
|
||||
`http://loki:3100`
|
||||
#### grafana dashboard
|
||||
13639 - Logs / App
|
||||
|
||||
### Node exporter
|
||||
#### grafana dashboard
|
||||
1860 - Node Exporter Full
|
||||
|
||||
## Fake log generator
|
||||
Use for testing only
|
||||
```bash
|
||||
docker compose up log-generator -d
|
||||
```
|
||||
On grafana select - Explore - Loki (to the right of Outline) - Label filters job=generated-logs
|
||||
```bash
|
||||
docker compose stop log-generator
|
||||
```
|
||||
|
||||
## Access
|
||||
|
||||
**dns-tools**
|
||||
@ -144,7 +147,7 @@ docker exec -it <COMPOSE_PROJECT_NAME>-proxy-1 /bin/sh -c "curl http://prometheu
|
||||
TOKEN=$(echo "Authorization: Bearer $(grep "bearer_token" config/prometheus.yml | cut -d':' -f2 |cut -d' ' -f2)")
|
||||
```
|
||||
```bash
|
||||
docker exec -it gmo-loki-proxy-1 /bin/bash -c "curl -H \"Accept: application/json\" -H \"${TOKEN}\" http://minio:9000/minio/v2/metrics/cluster"
|
||||
docker exec -it <COMPOSE_PROJECT_NAME>-proxy-1 /bin/bash -c "curl -H \"Accept: application/json\" -H \"${TOKEN}\" http://minio:9000/minio/v2/metrics/cluster"
|
||||
```
|
||||
|
||||
## Sources
|
||||
@ -158,16 +161,32 @@ docker exec -it gmo-loki-proxy-1 /bin/bash -c "curl -H \"Accept: application/jso
|
||||
|
||||
### Prometheus
|
||||
* https://mxulises.medium.com/simple-prometheus-setup-on-docker-compose-f702d5f98579
|
||||
|
||||
### Loki/promtail
|
||||
* https://blog.stephane-robert.info/docs/observer/logs/loki/
|
||||
* https://grafana.com/docs/loki/latest/setup/install/docker/
|
||||
* https://medium.com/@netopschic/implementing-the-log-monitoring-stack-using-promtail-loki-and-grafana-using-docker-compose-bcb07d1a51aa
|
||||
|
||||
## Changelog
|
||||
### [1.2.0] - 2025-06-14
|
||||
#### Added
|
||||
- promtail container
|
||||
- loki container
|
||||
- log generator container
|
||||
#### Created
|
||||
- script manage.sh
|
||||
#### Fixed
|
||||
- certificates names
|
||||
|
||||
### [1.1.0] - 2025-06-09
|
||||
#### Added
|
||||
- prometheus container
|
||||
- node exporter container
|
||||
- grafana dashboard
|
||||
- 1860 - Node Exporter Full
|
||||
- 3662 - Prometheus 2.0 Overview
|
||||
- 19268 - Prometheus All Metrics
|
||||
- 13502 - MinIO Dashboard
|
||||
- 13639 Logs / APP
|
||||
|
||||
### [1.0.0] - 2025-06-08
|
||||
#### Added
|
||||
|
||||
127
config/loki/local-config.yaml.tmpl
Normal file
127
config/loki/local-config.yaml.tmpl
Normal file
@ -0,0 +1,127 @@
|
||||
auth_enabled: false
|
||||
|
||||
server:
|
||||
http_listen_port: 3100
|
||||
grpc_listen_port: 9095
|
||||
log_level: info
|
||||
|
||||
common:
|
||||
ring:
|
||||
instance_addr: 127.0.0.1
|
||||
kvstore:
|
||||
store: inmemory
|
||||
path_prefix: /loki
|
||||
compactor_address: http://loki:3100
|
||||
replication_factor: 1
|
||||
|
||||
memberlist:
|
||||
join_members: ["loki"]
|
||||
dead_node_reclaim_time: 30s
|
||||
gossip_to_dead_nodes_time: 15s
|
||||
left_ingesters_timeout: 30s
|
||||
bind_addr: ['0.0.0.0']
|
||||
bind_port: 7946
|
||||
gossip_interval: 2s
|
||||
|
||||
ingester:
|
||||
lifecycler:
|
||||
ring:
|
||||
kvstore:
|
||||
store: memberlist
|
||||
replication_factor: 1
|
||||
chunk_idle_period: 5m
|
||||
chunk_retain_period: 30s
|
||||
#max_transfer_retries: 0
|
||||
|
||||
schema_config:
|
||||
configs:
|
||||
- from: 2022-01-01
|
||||
store: boltdb-shipper
|
||||
object_store: s3
|
||||
schema: v13
|
||||
index:
|
||||
prefix: index_
|
||||
period: 24h
|
||||
|
||||
- from: 2023-07-11
|
||||
store: tsdb
|
||||
object_store: s3
|
||||
schema: v13
|
||||
index:
|
||||
prefix: index_
|
||||
period: 24h
|
||||
|
||||
storage_config:
|
||||
boltdb_shipper:
|
||||
active_index_directory: /loki/index
|
||||
cache_location: /loki/index_cache
|
||||
#shared_store: s3
|
||||
|
||||
aws:
|
||||
bucketnames: loki
|
||||
endpoint: http://minio:9000
|
||||
access_key_id: ${MINIO_BUCKET_USER}
|
||||
secret_access_key: ${MINIO_BUCKET_PASS}
|
||||
insecure: true
|
||||
s3forcepathstyle: true
|
||||
|
||||
#compactor:
|
||||
# working_directory: /loki/compactor
|
||||
# #shared_store: s3
|
||||
|
||||
#limits_config:
|
||||
# reject_old_samples: true
|
||||
# reject_old_samples_max_age: 168h
|
||||
|
||||
limits_config:
|
||||
max_cache_freshness_per_query: '10m'
|
||||
reject_old_samples: true
|
||||
reject_old_samples_max_age: 30m
|
||||
ingestion_rate_mb: 10
|
||||
ingestion_burst_size_mb: 20
|
||||
# parallelize queries in 15min intervals
|
||||
split_queries_by_interval: 15m
|
||||
volume_enabled: true
|
||||
|
||||
|
||||
|
||||
#chunk_store_config:
|
||||
# max_look_back_period: 0s
|
||||
|
||||
table_manager:
|
||||
retention_deletes_enabled: true
|
||||
retention_period: 336h # 14 jours
|
||||
|
||||
|
||||
ruler:
|
||||
storage:
|
||||
type: local
|
||||
local:
|
||||
directory: /loki/rules
|
||||
rule_path: /loki/rules-temp
|
||||
alertmanager_url: http://localhost:9093
|
||||
ring:
|
||||
kvstore:
|
||||
store: memberlist
|
||||
enable_api: true
|
||||
|
||||
query_range:
|
||||
# make queries more cache-able by aligning them with their step intervals
|
||||
align_queries_with_step: true
|
||||
max_retries: 5
|
||||
parallelise_shardable_queries: true
|
||||
cache_results: true
|
||||
|
||||
frontend:
|
||||
log_queries_longer_than: 5s
|
||||
compress_responses: true
|
||||
max_outstanding_per_tenant: 2048
|
||||
|
||||
query_scheduler:
|
||||
max_outstanding_requests_per_tenant: 1024
|
||||
|
||||
querier:
|
||||
query_ingesters_within: 2h
|
||||
|
||||
compactor:
|
||||
working_directory: /tmp/compactor
|
||||
33
config/minio/policy.json.tmpl
Normal file
33
config/minio/policy.json.tmpl
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Action": [
|
||||
"s3:PutBucketPolicy",
|
||||
"s3:GetBucketPolicy",
|
||||
"s3:DeleteBucketPolicy",
|
||||
"s3:ListAllMyBuckets",
|
||||
"s3:ListBucket"
|
||||
],
|
||||
"Effect": "Allow",
|
||||
"Resource": [
|
||||
"arn:aws:s3:::${MINIO_BUCKET_NAME}"
|
||||
],
|
||||
"Sid": ""
|
||||
},
|
||||
{
|
||||
"Action": [
|
||||
"s3:AbortMultipartUpload",
|
||||
"s3:DeleteObject",
|
||||
"s3:GetObject",
|
||||
"s3:ListMultipartUploadParts",
|
||||
"s3:PutObject"
|
||||
],
|
||||
"Effect": "Allow",
|
||||
"Resource": [
|
||||
"arn:aws:s3:::${MINIO_BUCKET_NAME}/*"
|
||||
],
|
||||
"Sid": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,3 +1,8 @@
|
||||
map $http_upgrade $connection_upgrade {
|
||||
default upgrade;
|
||||
'' close;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 8080 default_server;
|
||||
server_name _;
|
||||
@ -8,8 +13,8 @@ server {
|
||||
listen 8443 ssl;
|
||||
#listen [::]:8443;
|
||||
server_name _;
|
||||
ssl_certificate /etc/nginx/certs/gmolab.net.crt;
|
||||
ssl_certificate_key /etc/nginx/certs/gmolab.net.key;
|
||||
ssl_certificate /etc/nginx/certs/tls.crt;
|
||||
ssl_certificate_key /etc/nginx/certs/tls.key;
|
||||
# allow special characters in headers
|
||||
ignore_invalid_headers off;
|
||||
# allow any size file to be uploaded.
|
||||
@ -26,11 +31,23 @@ server {
|
||||
}
|
||||
|
||||
#------- GRAFANA -------
|
||||
location /grafana/ {
|
||||
proxy_pass http://grafana:3000/;
|
||||
location /grafana {
|
||||
proxy_set_header Host $host;
|
||||
proxy_pass http://grafana:3000/;
|
||||
rewrite ^/grafana/(.*) /$1 break;
|
||||
}
|
||||
|
||||
# Proxy Grafana Live WebSocket connections.
|
||||
location /grafana/api/live/ {
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
proxy_set_header Host $host;
|
||||
proxy_pass http://grafana:3000;
|
||||
rewrite ^/grafana/(.*) /$1 break;
|
||||
}
|
||||
|
||||
|
||||
#------- MINIO UI -------
|
||||
location /minio/ui/ {
|
||||
rewrite ^/minio/ui/(.*) /$1 break;
|
||||
@ -1,6 +1,6 @@
|
||||
global:
|
||||
scrape_interval: 10s
|
||||
|
||||
|
||||
scrape_configs:
|
||||
- job_name: prometheus
|
||||
static_configs:
|
||||
@ -11,8 +11,9 @@ scrape_configs:
|
||||
- targets:
|
||||
- node-exporter:9100
|
||||
- job_name: minio-job
|
||||
bearer_token: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJwcm9tZXRoZXVzIiwic3ViIjoiYWRtaW4iLCJleHAiOjQ5MDI5NzQ1Mzh9.BuzZdu0W1TBfolWIMUPYhuRHuAFfrHuLw0CYMCK3NhqWzmx9u_P6uu3rJl4R71JlUhTDU31U3q4-mh9Ev7aOjQ
|
||||
bearer_token: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJwcm9tZXRoZXVzIiwic3ViIjoibWluaW8iLCJleHAiOjQ5MDM3NjQ0NTR9.NxAYmMmAy0w0sv0zfP9MvgllPCxokn305qy8cY1Zj6v0peaNnqFYuyqXWcXo-UjAua9ZK-7Gbfa5gCSme1an6g
|
||||
metrics_path: /minio/v2/metrics/cluster
|
||||
scheme: http
|
||||
static_configs:
|
||||
- targets: ['minio:9000']
|
||||
- targets: ['minio:9000']
|
||||
|
||||
34
config/promtail/config.yml
Normal file
34
config/promtail/config.yml
Normal file
@ -0,0 +1,34 @@
|
||||
server:
|
||||
http_listen_port: 9080
|
||||
grpc_listen_port: 0
|
||||
|
||||
positions:
|
||||
filename: /tmp/positions.yaml
|
||||
|
||||
clients:
|
||||
- url: http://loki:3100/loki/api/v1/push
|
||||
|
||||
scrape_configs:
|
||||
- job_name: system
|
||||
static_configs:
|
||||
- targets:
|
||||
- localhost
|
||||
labels:
|
||||
job: varlogs
|
||||
__path__: /var/log/*log
|
||||
|
||||
- job_name: generated-logs
|
||||
static_configs:
|
||||
- targets:
|
||||
- localhost
|
||||
labels:
|
||||
job: generated-logs
|
||||
__path__: /tmp/generated-logs.txt
|
||||
pipeline_stages:
|
||||
- json:
|
||||
expressions:
|
||||
http_method: 'method'
|
||||
http_status: "status"
|
||||
- labels:
|
||||
http_method:
|
||||
http_status:
|
||||
@ -11,24 +11,26 @@ services:
|
||||
/bin/sh -c "
|
||||
chown 472:root /var/lib/grafana;
|
||||
chown 101:root /etc/nginx/conf.d/default.conf;
|
||||
chown 10001:10001 /loki -R;
|
||||
chown nobody:nobody /prometheus -R;
|
||||
exit 0;
|
||||
"
|
||||
volumes:
|
||||
- '${GF_VOLUME_DIR}:/var/lib/grafana'
|
||||
- '${GF_DATA_DIR}:/var/lib/grafana'
|
||||
- '${PRX_NGINX_CONF_DIR}/default.conf:/etc/nginx/conf.d/default.conf'
|
||||
- '${PROM_DATA_DIR}:/prometheus'
|
||||
- '${LOKI_DATA_DIR}:/loki'
|
||||
networks:
|
||||
- loki
|
||||
|
||||
#------- container with tools dns (nslookup, tcptraceroute, etc). Use just for debug
|
||||
# dns-tools:
|
||||
# image: jonlabelle/network-tools
|
||||
# command: tail -f /dev/null
|
||||
# stdin_open: true
|
||||
# tty: true
|
||||
# networks:
|
||||
# - loki
|
||||
dns-tools:
|
||||
image: jonlabelle/network-tools
|
||||
command: tail -f /dev/null
|
||||
stdin_open: true
|
||||
tty: true
|
||||
networks:
|
||||
- loki
|
||||
|
||||
#-------proxy (nginx)
|
||||
proxy:
|
||||
@ -62,27 +64,27 @@ services:
|
||||
- loki
|
||||
|
||||
#------- minio client
|
||||
# minio-cli:
|
||||
# image: minio/mc
|
||||
# # insure that the server container is running before building the client
|
||||
# depends_on:
|
||||
# - minio
|
||||
# entrypoint: >
|
||||
# /bin/sh -c "tail -f /dev/null"
|
||||
# #/usr/bin/mc admin info play;
|
||||
# #/usr/bin/mc alias set myminio http://minio:9000 ${MINIO_ACCESS_KEY} ${MINIO_SECRET_KEY};
|
||||
# #/usr/bin/mc admin prometheus generate myminio
|
||||
# ##/usr/bin/mc mb myminio/test-bucket;
|
||||
# ##/usr/bin/mc mb myminio/loki-1;
|
||||
# ##echo 'my content' > myfile.txt;
|
||||
# ##/usr/bin/mc cp myfile.txt myminio/test-bucket;
|
||||
# #exit 0;
|
||||
# #"
|
||||
# volumes:
|
||||
# - ${MINIO_CONF_CLI_DIR}/.mc:/root/.mc
|
||||
# restart: unless-stopped
|
||||
# networks:
|
||||
# - loki
|
||||
minio-cli:
|
||||
image: minio/mc
|
||||
# insure that the server container is running before building the client
|
||||
depends_on:
|
||||
- minio
|
||||
entrypoint: >
|
||||
/bin/sh -c "tail -f /dev/null"
|
||||
#/usr/bin/mc admin info play;
|
||||
#/usr/bin/mc alias set myminio http://minio:9000 ${MINIO_ACCESS_KEY} ${MINIO_SECRET_KEY};
|
||||
#/usr/bin/mc admin prometheus generate myminio
|
||||
##/usr/bin/mc mb myminio/test-bucket;
|
||||
##/usr/bin/mc mb myminio/loki-1;
|
||||
##echo 'my content' > myfile.txt;
|
||||
##/usr/bin/mc cp myfile.txt myminio/test-bucket;
|
||||
#exit 0;
|
||||
#"
|
||||
volumes:
|
||||
- ${MINIO_CONF_CLI_DIR}/.mc:/root/.mc
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- loki
|
||||
|
||||
#------- grafana
|
||||
grafana:
|
||||
@ -90,7 +92,7 @@ services:
|
||||
ports:
|
||||
- "3000:3000"
|
||||
volumes:
|
||||
- '${GF_VOLUME_DIR}:/var/lib/grafana'
|
||||
- '${GF_DATA_DIR}:/var/lib/grafana'
|
||||
environment:
|
||||
- GF_SECURITY_ADMIN_USER=${GF_ADMIN_USER}
|
||||
- GF_SECURITY_ADMIN_PASSWORD=${GF_ADMIN_PASS}
|
||||
@ -121,7 +123,69 @@ services:
|
||||
- 9100:9100
|
||||
restart: unless-stopped
|
||||
|
||||
#------- loki
|
||||
loki:
|
||||
image: grafana/loki:latest
|
||||
ports:
|
||||
- 3100:3100
|
||||
volumes:
|
||||
- ${LOKI_CONF_DIR}/local-config.yaml:/etc/loki/local-config.yaml
|
||||
- ${LOKI_DATA_DIR}:/loki
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- loki
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '0.50'
|
||||
memory: 256M
|
||||
reservations:
|
||||
cpus: '0.25'
|
||||
memory: 128M
|
||||
|
||||
#------- promtail
|
||||
promtail:
|
||||
image: grafana/promtail:latest
|
||||
volumes:
|
||||
- ${PROMTAIL_CONF_DIR}/config.yml:/etc/promtail/config.yml
|
||||
- ${LOKI_GEN_LOG_DIR}:/tmp
|
||||
- /var/log/:/var/log/
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- loki
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '0.50'
|
||||
memory: 256M
|
||||
reservations:
|
||||
cpus: '0.25'
|
||||
memory: 128M
|
||||
|
||||
#------- flog generated log
|
||||
log-generator:
|
||||
image: ${FLOG_DOCKER_IMG}
|
||||
command:
|
||||
- --loop
|
||||
- --format=json
|
||||
- --number=5 # number of log lines to generate per second (delay=1000ms)
|
||||
- --delay=1000ms # delay between log lines
|
||||
#- --output=/var/log/generated-logs.txt
|
||||
- --output=/tmp/generated-logs.txt
|
||||
- --overwrite
|
||||
- --type=log
|
||||
#- --bytes=50000
|
||||
volumes:
|
||||
- ${LOKI_GEN_LOG_DIR}:/tmp/
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '0.50'
|
||||
memory: 256M
|
||||
reservations:
|
||||
cpus: '0.25'
|
||||
memory: 128M
|
||||
#volumes:
|
||||
# grafana-storage:
|
||||
# prometheus:
|
||||
# loki:
|
||||
# loki-data:
|
||||
191
manage-old.sh
Executable file
191
manage-old.sh
Executable file
@ -0,0 +1,191 @@
|
||||
#!/bin/bash
|
||||
############################################################
|
||||
# Decription: Script to manage stack docker
|
||||
#
|
||||
# Author: Gilles Mouchet (gilles.mouchet@gmail.com)
|
||||
# Creation Date: 12-06-2025
|
||||
# Version: 1.0
|
||||
# Usage: ./manage.sh
|
||||
# Changelog:
|
||||
# V1.0 - dd-Mmm-2025 - GMo
|
||||
# Added
|
||||
# - Creation of script from scratch
|
||||
#
|
||||
############################################################
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
# Doesn't change anything from here
|
||||
#-----------------------------------------------------------------
|
||||
version="1.0-rc1"
|
||||
|
||||
prog_name="./$(/bin/basename $0)"
|
||||
|
||||
containers_to_start=(init minio minio-cli grafana loki promtail prometheus node-exporter proxy)
|
||||
containers_all=("${containers_to_start[@]}" log-generator dns-tools)
|
||||
|
||||
# Couleurs
|
||||
VERT="\e[32m"
|
||||
ROUGE="\e[31m"
|
||||
NORMAL="\e[0m"
|
||||
#-----------------------------------------------------------------
|
||||
# Functions
|
||||
#-----------------------------------------------------------------
|
||||
# display help
|
||||
function print_usage {
|
||||
/bin/cat << EOF
|
||||
|
||||
Usage: $prog_name [options]
|
||||
|
||||
Options:
|
||||
config Create folder for persit. vol. and copy conf files
|
||||
param Display all vars defined in .env file
|
||||
list Display container (servie) list define in docker compose file
|
||||
create Create container
|
||||
start Start stack '${COMPOSE_PROJECT_NAME}'
|
||||
stop Stop stack '${COMPOSE_PROJECT_NAME}'
|
||||
down Stop stack '${COMPOSE_PROJECT_NAME}' and delete containers
|
||||
restart Restart stack '${COMPOSE_PROJECT_NAME}'
|
||||
version,-v,--version Display script version
|
||||
help,-h,--help Display this help
|
||||
|
||||
Examples:
|
||||
To start stack '${COMPOSE_PROJECT_NAME}'
|
||||
$prog_name start
|
||||
To stop stack '${COMPOSE_PROJECT_NAME}'
|
||||
$prog_name stop
|
||||
To start a specific container and his depend
|
||||
docker compose up <container_name> -d
|
||||
Ex:
|
||||
docker compose up minio-cli -d
|
||||
To create a new stack
|
||||
$prog_name config
|
||||
$prog_name create
|
||||
$prog_name start
|
||||
EOF
|
||||
}
|
||||
# create all containers
|
||||
function create_container {
|
||||
|
||||
for cont_item in "${containers_all[@]}"; do
|
||||
# check if container exist. If not create it
|
||||
if [ $(docker ps -a | grep ${COMPOSE_PROJECT_NAME}-$cont_item | wc -l) -eq 0 ]; then
|
||||
echo -n "Create container $cont_item: "
|
||||
if docker compose create $cont_item > /dev/null 2>&1; then
|
||||
echo -e "${VERT}SUCCESS${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR${NORMAL}"
|
||||
fi
|
||||
else
|
||||
echo "Container $cont_item already exist"
|
||||
fi
|
||||
done
|
||||
}
|
||||
# start container
|
||||
function start_container {
|
||||
for cont_item in "${containers_to_start[@]}"; do
|
||||
echo -n "Start container $cont_item: "
|
||||
if docker compose up -d $cont_item > /dev/null 2>&1; then
|
||||
echo -e "${VERT}SUCCESS${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR${NORMAL}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
# MAIN
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
# read .env if exist
|
||||
if [ ! -f .env ]; then
|
||||
echo "file '.env' doesn't exist!"
|
||||
echo "See README.md"
|
||||
exit
|
||||
fi
|
||||
. .env
|
||||
|
||||
#if [ ! -z "$1" ]; then
|
||||
#print_usage
|
||||
# exit 0
|
||||
#fi
|
||||
|
||||
case "$1" in
|
||||
config)
|
||||
echo "Create folder for persistent volume"
|
||||
sudo mkdir -p ${PRX_CERTS_DIR}
|
||||
sudo mkdir -p ${PRX_NGINX_CONF_DIR}
|
||||
sudo mkdir -p ${MINIO_DATA_ROOT_DIR}
|
||||
sudo mkdir -p ${MINIO_CONF_CLI_DIR}
|
||||
sudo mkdir -p ${GF_DATA_DIR}
|
||||
sudo mkdir -p ${PROM_CONF_DIR}
|
||||
sudo mkdir -p ${PROM_DATA_DIR}
|
||||
sudo mkdir -p ${LOKI_CONF_DIR}
|
||||
sudo mkdir -p ${LOKI_DATA_DIR}
|
||||
sudo mkdir -p ${LOKI_GEN_LOG_DIR}
|
||||
sudo mkdir -p ${PROMTAIL_CONF_DIR}
|
||||
echo "Copy configs files"
|
||||
sudo cp ./config/nginx/default.conf ${PRX_NGINX_CONF_DIR}/.
|
||||
sudo cp ./config/prometheus/prometheus.yml ${PROM_CONF_DIR}/.
|
||||
sudo cp ./config/loki/local-config.yaml ${LOKI_CONF_DIR}/.
|
||||
sudo cp ./config/promtail/config.yml ${PROMTAIL_CONF_DIR}/.
|
||||
;;
|
||||
param)
|
||||
cat << EOF
|
||||
COMPOSE_PROJECT_NAME = ${COMPOSE_PROJECT_NAME}
|
||||
PRX_CERTS_DIR = ${PRX_CERTS_DIR}
|
||||
PRX_NGINX_CONF_DIR = ${PRX_NGINX_CONF_DIR}
|
||||
MINIO_DATA_ROOT_DIR = ${MINIO_DATA_ROOT_DIR}
|
||||
MINIO_CONF_CLI_DIR = ${MINIO_CONF_CLI_DIR}
|
||||
MINIO_ACCESS_KEY = ${MINIO_ACCESS_KEY}
|
||||
MINIO_SECRET_KEY = ${MINIO_SECRET_KEY}
|
||||
MINIO_REDIRECT_URL = ${MINIO_REDIRECT_URL}
|
||||
GF_ADMIN_USER = ${GF_ADMIN_USER}
|
||||
GF_ADMIN_PASS = ${GF_ADMIN_PASS}
|
||||
GF_DATA_DIR = ${GF_DATA_DIR}
|
||||
GF_ROOT_URL = ${GF_ROOT_URL}
|
||||
PROM_CONF_DIR = ${PROM_CONF_DIR}
|
||||
PROM_DATA_DIR = ${PROM_DATA_DIR}
|
||||
LOKI_CONF_DIR = ${LOKI_CONF_DIR}
|
||||
LOKI_DATA_DIR = ${LOKI_DATA_DIR}
|
||||
LOKI_GEN_LOG_DIR = ${LOKI_GEN_LOG_DIR}
|
||||
PROMTAIL_CONF_DIR = ${PROMTAIL_CONF_DIR}
|
||||
EOF
|
||||
;;
|
||||
create)
|
||||
create_container
|
||||
;;
|
||||
start)
|
||||
create_container
|
||||
start_container
|
||||
;;
|
||||
stop)
|
||||
docker compose stop
|
||||
;;
|
||||
down)
|
||||
docker compose down
|
||||
;;
|
||||
list)
|
||||
echo "-------------------------------------"
|
||||
echo " Container list"
|
||||
echo "-------------------------------------"
|
||||
docker compose config --services | sort
|
||||
#for cont_item in "${containers_all[@]}"; do
|
||||
# echo "- $cont_item"
|
||||
#done
|
||||
;;
|
||||
-h|--help|help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
-v|--version|version)
|
||||
cat << EOF
|
||||
$(basename "$0") v$version (c) 1990 - $(date +%Y) by Gilles Mouchet
|
||||
Non-Commercial Use License – See LICENSE for details
|
||||
EOF
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
573
manage.sh
Executable file
573
manage.sh
Executable file
@ -0,0 +1,573 @@
|
||||
#!/bin/bash
|
||||
############################################################
|
||||
# Decription: Script to manage stack docker
|
||||
#
|
||||
# Author: Gilles Mouchet (gilles.mouchet@gmail.com)
|
||||
# Creation Date: 12-06-2025
|
||||
# Version: 1.0
|
||||
# Usage: ./manage.sh
|
||||
# Changelog:
|
||||
# V1.0 - dd-Mmm-2025 - GMo
|
||||
# Added
|
||||
# - Creation of script from scratch
|
||||
#
|
||||
############################################################
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
# Doesn't change anything from here
|
||||
#-----------------------------------------------------------------
|
||||
version="1.0-rc1"
|
||||
|
||||
prog_name="./$(/bin/basename $0)"
|
||||
|
||||
containers_to_start=(init minio minio-cli grafana loki promtail prometheus node-exporter proxy)
|
||||
containers_all=("${containers_to_start[@]}" log-generator dns-tools)
|
||||
|
||||
# Couleurs
|
||||
VERT="\e[32m"
|
||||
ROUGE="\e[31m"
|
||||
NORMAL="\e[0m"
|
||||
#-----------------------------------------------------------------
|
||||
# Functions
|
||||
#-----------------------------------------------------------------
|
||||
# display help
|
||||
function print_usage {
|
||||
/bin/cat << EOF
|
||||
|
||||
Usage: $prog_name [options]
|
||||
|
||||
Options:
|
||||
config Create folder for persit. vol. and copy conf files
|
||||
param Display all vars defined in .env file
|
||||
list Display container (servie) list define in docker compose file
|
||||
create Create container
|
||||
start-stack Start stack '${COMPOSE_PROJECT_NAME}'
|
||||
stop Stop stack '${COMPOSE_PROJECT_NAME}'
|
||||
down Stop stack '${COMPOSE_PROJECT_NAME}' and delete containers
|
||||
restart Restart stack '${COMPOSE_PROJECT_NAME}'
|
||||
version,-v,--version Display script version
|
||||
help,-h,--help Display this help
|
||||
|
||||
Examples:
|
||||
To start stack '${COMPOSE_PROJECT_NAME}'
|
||||
$prog_name start
|
||||
To stop stack '${COMPOSE_PROJECT_NAME}'
|
||||
$prog_name stop
|
||||
To start a specific container and his depend
|
||||
docker compose up <container_name> -d
|
||||
Ex:
|
||||
docker compose up minio-cli -d
|
||||
To create a new stack
|
||||
$prog_name config
|
||||
$prog_name create
|
||||
$prog_name start
|
||||
EOF
|
||||
}
|
||||
#-----------------------------------------------------------------
|
||||
# create folders for persistent volume and config file
|
||||
function create_folder {
|
||||
for folder_item in "${folder_to_create[@]}"; do
|
||||
echo -n "Create folder '${folder_item}': "
|
||||
sudo mkdir -p ${folder_item}
|
||||
rc=$?
|
||||
if [ $rc -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESS${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR${NORMAL}"
|
||||
exit $rc
|
||||
fi
|
||||
done
|
||||
}
|
||||
#-----------------------------------------------------------------
|
||||
# remove folders for persistent volume and config file
|
||||
function remove_folder {
|
||||
for folder_item in "${folder_to_create[@]}"; do
|
||||
# we doesn't delete the certs folder.
|
||||
# this folder is maybe shared with other container
|
||||
if [ "${folder_item}" != "${PRX_CERTS_DIR}" ]; then
|
||||
echo -n "Remove folder '${folder_item}': "
|
||||
sudo rm -rf ${folder_item}
|
||||
rc=$?
|
||||
if [ $rc -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESS${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR${NORMAL}"
|
||||
exit $rc
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
#-----------------------------------------------------------------
|
||||
# copy config file
|
||||
function copy_conf_file {
|
||||
echo -n "Copy loki config file into '${LOKI_CONF_DIR}/': "
|
||||
envsubst < ./config/loki/local-config.yaml.tmpl | \
|
||||
sudo tee ${LOKI_CONF_DIR}/local-config.yaml > /dev/null
|
||||
rc=$?
|
||||
if [ $rc -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESS${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc)${NORMAL}"
|
||||
exit $rc
|
||||
fi
|
||||
|
||||
echo -n "Copy proxy (nginx) config file into '${PRX_NGINX_CONF_DIR}/': "
|
||||
sudo cp ./config/nginx/default.conf ${PRX_NGINX_CONF_DIR}/. > /dev/null 2>&1
|
||||
rc=$?
|
||||
if [ $rc -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESS${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc)${NORMAL}"
|
||||
exit $rc
|
||||
fi
|
||||
|
||||
echo -n "Copy the Prometheus configuration file into '${PROM_CONF_DIR}/': "
|
||||
sudo cp ./config/prometheus/prometheus.yml ${PROM_CONF_DIR}/. > /dev/null 2>&1
|
||||
rc=$?
|
||||
if [ $rc -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESS${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc)${NORMAL}"
|
||||
exit $rc
|
||||
fi
|
||||
|
||||
echo -n "Copy promtail config file into '${PROMTAIL_CONF_DIR}/': "
|
||||
sudo cp ./config/promtail/config.yml ${PROMTAIL_CONF_DIR}/. > /dev/null 2>&1
|
||||
rc=$?
|
||||
if [ $rc -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESS${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc)${NORMAL}"
|
||||
exit $rc
|
||||
fi
|
||||
|
||||
}
|
||||
#-----------------------------------------------------------------
|
||||
# create all containers
|
||||
function create_container {
|
||||
for cont_item in "${containers_all[@]}"; do
|
||||
# check if container exist. If not create it
|
||||
if [ $(docker ps -a | grep ${COMPOSE_PROJECT_NAME}-$cont_item | wc -l) -eq 0 ]; then
|
||||
echo -n "Create container $cont_item: "
|
||||
if docker compose create $cont_item > /dev/null 2>&1; then
|
||||
echo -e "${VERT}SUCCESS${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR${NORMAL}"
|
||||
fi
|
||||
# else
|
||||
# echo "Container $cont_item already exist"
|
||||
fi
|
||||
done
|
||||
}
|
||||
#-----------------------------------------------------------------
|
||||
# start container
|
||||
function start_container {
|
||||
for cont_item in "${containers_to_start[@]}"; do
|
||||
echo -n "Start container $cont_item: "
|
||||
if docker compose up -d $cont_item > /dev/null 2>&1; then
|
||||
echo -e "${VERT}SUCCESS${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR${NORMAL}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
#-----------------------------------------------------------------
|
||||
# create grafana ds
|
||||
# $1 = ds name
|
||||
# $2 = url
|
||||
function add_gf_data_source {
|
||||
curl -k -X POST "${GF_ROOT_URL}/api/datasources" \
|
||||
-u "${GF_ADMIN_USER}:${GF_ADMIN_PASS}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"name": "'"${1^}"'",
|
||||
"type": "'"$1"'",
|
||||
"access": "proxy",
|
||||
"url": "'"$2"'",
|
||||
"basicAuth": false,
|
||||
"isDefault": false,
|
||||
"jsonData": {
|
||||
"maxLines": 1000
|
||||
}
|
||||
}' > /dev/null 2>&1
|
||||
}
|
||||
#-----------------------------------------------------------------
|
||||
# import grafana dashboard
|
||||
# $1 = dashboard ID
|
||||
# $2 = source
|
||||
# $3 = dashboard title. Needed for check if already impoerted
|
||||
function import_gf_dashboard {
|
||||
db_file=/tmp/dashboard-$1.json
|
||||
wr_file=/tmp/wrapped-dashboard.json
|
||||
|
||||
#download json
|
||||
curl -s -k -o "$db_file" "https://grafana.com/api/dashboards/$1/revisions/latest/download"
|
||||
if [ ! -s "$db_file" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# stage 2 - clean up and add datadource
|
||||
sed -i 's/"id":[ ]*[0-9]\+/"id": null/g' "$db_file"
|
||||
sed -i 's/"uid":[ ]*"[^"]*"/"uid": null/g' "$db_file"
|
||||
sed -i 's/"datasource": ".*"/"datasource": "'"${2^}"'"/g' "$db_file"
|
||||
|
||||
# stage 3 - creating the final JSON file expected by the Grafana API
|
||||
echo '{' > "$wr_file"
|
||||
echo '"dashboard":' >> "$wr_file"
|
||||
cat "$db_file" >> "$wr_file"
|
||||
echo ',' >> "$wr_file"
|
||||
echo '"overwrite": true' >> "$wr_file"
|
||||
echo '}' >> "$wr_file"
|
||||
|
||||
# stage 4 - import dashboard into grafana
|
||||
curl -s -k -X POST "$GF_ROOT_URL/api/dashboards/db" \
|
||||
-u "$GF_ADMIN_USER:$GF_ADMIN_PASS" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data-binary "@$wr_file" > /dev/null 2>&1
|
||||
|
||||
#rm -f $db_file $wr_file
|
||||
}
|
||||
#-----------------------------------------------------------------
|
||||
# MAIN
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
# read .env if exist
|
||||
if [ ! -f .env ]; then
|
||||
echo "file '.env' doesn't exist!"
|
||||
echo "See README.md"
|
||||
exit
|
||||
fi
|
||||
set -a
|
||||
source .env
|
||||
set +a
|
||||
|
||||
# create array folder to create
|
||||
folder_to_create=(${PRX_CERTS_DIR}
|
||||
${PRX_NGINX_CONF_DIR}
|
||||
${MINIO_DATA_ROOT_DIR}
|
||||
${MINIO_CONF_CLI_DIR}
|
||||
${GF_DATA_DIR}
|
||||
${PROM_CONF_DIR}
|
||||
${PROM_DATA_DIR}
|
||||
${LOKI_CONF_DIR}
|
||||
${LOKI_DATA_DIR}
|
||||
${LOKI_GEN_LOG_DIR}
|
||||
${PROMTAIL_CONF_DIR})
|
||||
|
||||
case "$1" in
|
||||
param)
|
||||
cat << EOF
|
||||
COMPOSE_PROJECT_NAME = ${COMPOSE_PROJECT_NAME}
|
||||
PRX_CERTS_DIR = ${PRX_CERTS_DIR}
|
||||
PRX_NGINX_CONF_DIR = ${PRX_NGINX_CONF_DIR}
|
||||
MINIO_DATA_ROOT_DIR = ${MINIO_DATA_ROOT_DIR}
|
||||
MINIO_CONF_CLI_DIR = ${MINIO_CONF_CLI_DIR}
|
||||
MINIO_ACCESS_KEY = ${MINIO_ACCESS_KEY}
|
||||
MINIO_SECRET_KEY = ${MINIO_SECRET_KEY}
|
||||
MINIO_BUCKET_NAME = ${MINIO_BUCKET_NAME}
|
||||
MINIO_BUCKET_USER = ${MINIO_BUCKET_USER}
|
||||
MINIO_BUCKET_PASS = ${MINIO_BUCKET_PASS}
|
||||
MINIO_BUCKET_POL_NAME = ${MINIO_BUCKET_POL_NAME}
|
||||
MINIO_REDIRECT_URL = ${MINIO_REDIRECT_URL}
|
||||
MINIO_ALIAS = ${MINIO_ALIAS}
|
||||
GF_ADMIN_USER = ${GF_ADMIN_USER}
|
||||
GF_ADMIN_PASS = ${GF_ADMIN_PASS}
|
||||
GF_DATA_DIR = ${GF_DATA_DIR}
|
||||
GF_ROOT_URL = ${GF_ROOT_URL}
|
||||
PROM_CONF_DIR = ${PROM_CONF_DIR}
|
||||
PROM_DATA_DIR = ${PROM_DATA_DIR}
|
||||
LOKI_CONF_DIR = ${LOKI_CONF_DIR}
|
||||
LOKI_DATA_DIR = ${LOKI_DATA_DIR}
|
||||
LOKI_GEN_LOG_DIR = ${LOKI_GEN_LOG_DIR}
|
||||
PROMTAIL_CONF_DIR = ${PROMTAIL_CONF_DIR}
|
||||
EOF
|
||||
;;
|
||||
start-stack)
|
||||
echo -e "---- Create Folders ----"
|
||||
create_folder
|
||||
echo -e "\n---- Copy config file ----"
|
||||
copy_conf_file
|
||||
echo -e "\n---- Config minio ----"
|
||||
#-----
|
||||
echo -n "Start minio container: "
|
||||
if docker compose up -d minio > /dev/null 2>&1; then
|
||||
echo -e "${VERT}SUCCESS${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR${NORMAL}"
|
||||
fi
|
||||
#----
|
||||
echo -n "Wait until minio container is started: "
|
||||
while ! curl -s "http://$HOSTNAME:9000/minio/health/live" >/dev/null; do
|
||||
sleep 1
|
||||
done
|
||||
echo -e "${VERT}STARTED${NORMAL}"
|
||||
#-----
|
||||
echo -n "Start minio-cli container: "
|
||||
docker compose up -d minio-cli > /dev/null 2>&1
|
||||
rc=$?
|
||||
if [ $rc -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESS${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc)${NORMAL}"
|
||||
exit $rc
|
||||
fi
|
||||
#-----
|
||||
echo -n "Create minios alias: "
|
||||
docker exec ${COMPOSE_PROJECT_NAME}-minio-cli-1 mc alias set ${MINIO_ALIAS} http://minio:9000 \
|
||||
${MINIO_ACCESS_KEY} ${MINIO_SECRET_KEY} > /dev/null 2>&1
|
||||
rc=$?
|
||||
if [ $rc -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESS${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc)${NORMAL}"
|
||||
exit $rc
|
||||
fi
|
||||
#-----
|
||||
echo -n "Copy mino policy config file into ${MINIO_CONF_CLI_DIR}/: "
|
||||
envsubst < ./config/minio/policy.json.tmpl |
|
||||
sudo tee ${MINIO_CONF_CLI_DIR}/.mc/policy.json > /dev/null
|
||||
rc=$?
|
||||
if [ $rc -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESS${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc)${NORMAL}"
|
||||
exit $rc
|
||||
fi
|
||||
#-----
|
||||
echo -n "Create user for bucket ${MINIO_BUCKET_NAME}: "
|
||||
docker exec ${COMPOSE_PROJECT_NAME}-minio-cli-1 mc admin user add \
|
||||
${MINIO_ALIAS} ${MINIO_BUCKET_USER} ${MINIO_BUCKET_PASS} >/dev/null 2>&1
|
||||
rc=$?
|
||||
if [ $rc -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESS${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc)${NORMAL}"
|
||||
exit $rc
|
||||
fi
|
||||
#-----
|
||||
echo -n "Create policy for access to bucket ${MINIO_BUCKET_NAME}: "
|
||||
docker exec ${COMPOSE_PROJECT_NAME}-minio-cli-1 mc admin policy create \
|
||||
${MINIO_ALIAS} ${MINIO_BUCKET_POL_NAME} /root/.mc/policy.json >/dev/null 2>&1
|
||||
rc=$?
|
||||
if [ $rc -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESS${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc)${NORMAL}"
|
||||
exit $rc
|
||||
fi
|
||||
#-----
|
||||
echo -n "Attach policy to user ${MINIO_BUCKET_USER}: "
|
||||
docker exec ${COMPOSE_PROJECT_NAME}-minio-cli-1 mc admin policy attach \
|
||||
${MINIO_ALIAS} ${MINIO_BUCKET_POL_NAME} --user=${MINIO_BUCKET_USER} >/dev/null 2>&1
|
||||
rc=$?
|
||||
if [ $rc -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESS${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc)${NORMAL}"
|
||||
exit $rc
|
||||
fi
|
||||
#-----
|
||||
echo -n "Create bucket if not exist: "
|
||||
docker exec ${COMPOSE_PROJECT_NAME}-minio-cli-1 mc ls "${MINIO_ALIAS}/$MINIO_BUCKET_NAME" >/dev/null 2>&1
|
||||
rc=$?
|
||||
if [ $rc -ne 0 ]; then
|
||||
docker exec -it ${COMPOSE_PROJECT_NAME}-minio-cli-1 /bin/sh -c \
|
||||
"mc mb ${MINIO_ALIAS}/${MINIO_BUCKET_NAME}" >/dev/null 2>&1
|
||||
rc1=$?
|
||||
if [ $rc1 -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESSFULLY CREATED${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc1)${NORMAL}"
|
||||
exit $rc1
|
||||
fi
|
||||
else
|
||||
echo -e "${VERT}ALREADY EXISTING${NORMAL}"
|
||||
fi
|
||||
# ----
|
||||
echo -n "Set token minio metrics: "
|
||||
token=$(docker exec vdg-loki-minio-cli-1 mc admin prometheus generate myminio|grep bearer_token| sed 's/^[ \t]*//')
|
||||
#token=$(docker exec -it vdg-loki-minio-cli-1 /bin/sh -c "mc admin prometheus generate myminio" | grep bearer_token)
|
||||
rc1=$?
|
||||
if [ $rc1 -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESSFULLY CREATED${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc1)${NORMAL}"
|
||||
exit $rc1
|
||||
fi
|
||||
# ----
|
||||
echo -n "Set token in prometheus config: "
|
||||
sudo sed -i "s|bearer_token:\(.*\)|$token|" ${PROM_CONF_DIR}/prometheus.yml
|
||||
rc1=$?
|
||||
if [ $rc1 -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESS${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc1)${NORMAL}"
|
||||
exit $rc1
|
||||
fi
|
||||
# ----
|
||||
echo -e "\n---- Create container ----"
|
||||
create_container
|
||||
echo -e "\n---- Start container ----"
|
||||
start_container
|
||||
echo -e "\n---- Create Grafana DS ----"
|
||||
# ----
|
||||
# wait until grafan is up
|
||||
echo -n "Wait until grafana is starting: "
|
||||
timeout=60 # Max time to wait in seconds
|
||||
interval=2 # Wait time between checks
|
||||
elapsed=0
|
||||
while true; do
|
||||
status_code=$(curl -k -s -o /dev/null -w "%{http_code}" \
|
||||
-u "$GF_ADMIN_USER:$GF_ADMIN_PASS" \
|
||||
"$GF_ROOT_URL/api/health")
|
||||
|
||||
if [ "$status_code" -eq 200 ]; then
|
||||
echo -e "${VERT}STARTED${NORMAL}"
|
||||
break
|
||||
fi
|
||||
|
||||
if [ "$elapsed" -ge "$timeout" ]; then
|
||||
echo -e "${ROUGE}ERROR ($status_code)${NORMAL}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep "$interval"
|
||||
elapsed=$((elapsed + interval))
|
||||
done
|
||||
# ----
|
||||
echo -n "Create Loki DS: "
|
||||
add_gf_data_source loki http://loki:3100
|
||||
rc1=$?
|
||||
if [ $rc1 -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESSFULLY CREATED${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc1)${NORMAL}"
|
||||
exit $rc1
|
||||
fi
|
||||
# ----
|
||||
echo -n "Create Prometheus DS: "
|
||||
add_gf_data_source prometheus http://prometheus:9090 ""
|
||||
rc1=$?
|
||||
if [ $rc1 -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESSFULLY CREATED${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc1)${NORMAL}"
|
||||
exit $rc1
|
||||
fi
|
||||
echo -e "\n---- Install Grafana dashboard ----"
|
||||
# ----
|
||||
db_name="Node Exporter Full"
|
||||
echo -n "Import '$db_name' dashboard: "
|
||||
# check if already imported
|
||||
response=$(curl -k -s -u "$GF_ADMIN_USER:$GF_ADMIN_PASS" "$GF_ROOT_URL/api/search?query=")
|
||||
if echo "$response" | grep -iq "\"title\":\"$db_name\""; then
|
||||
echo -e "${VERT}ALREADY IMPORTED${NORMAL}"
|
||||
else
|
||||
import_gf_dashboard 1860 prometheus
|
||||
rc1=$?
|
||||
if [ $rc1 -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESSFULLY IMPORTED${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc1)${NORMAL}"
|
||||
exit $rc1
|
||||
fi
|
||||
fi
|
||||
# ----
|
||||
db_name="Logs / App"
|
||||
echo -n "Import '$db_name' dashboard: "
|
||||
# check if already imported
|
||||
response=$(curl -k -s -u "$GF_ADMIN_USER:$GF_ADMIN_PASS" "$GF_ROOT_URL/api/search?query=")
|
||||
if echo "$response" | grep -iq "\"title\":\"$db_name\""; then
|
||||
echo -e "${VERT}ALREADY IMPORTED${NORMAL}"
|
||||
else
|
||||
import_gf_dashboard 13639 loki
|
||||
rc1=$?
|
||||
if [ $rc1 -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESSFULLY IMPORTED${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc1)${NORMAL}"
|
||||
exit $rc1
|
||||
fi
|
||||
fi
|
||||
# ----
|
||||
#db_name="Prometheus 2.0 Overview"
|
||||
db_name="Prometheus All Metrics"
|
||||
echo -n "Import '$db_name' dashboard: "
|
||||
# check if already imported
|
||||
response=$(curl -k -s -u "$GF_ADMIN_USER:$GF_ADMIN_PASS" "$GF_ROOT_URL/api/search?query=")
|
||||
if echo "$response" | grep -iq "\"title\":\"$db_name\""; then
|
||||
echo -e "${VERT}ALREADY IMPORTED${NORMAL}"
|
||||
else
|
||||
#import_gf_dashboard 3662 prometheus
|
||||
import_gf_dashboard 19268 prometheus
|
||||
rc1=$?
|
||||
if [ $rc1 -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESSFULLY IMPORTED${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc1)${NORMAL}"
|
||||
exit $rc1
|
||||
fi
|
||||
fi
|
||||
# ----
|
||||
db_name="MinIO Dashboard"
|
||||
echo -n "Import '$db_name' dashboard: "
|
||||
# check if already imported
|
||||
response=$(curl -k -s -u "$GF_ADMIN_USER:$GF_ADMIN_PASS" "$GF_ROOT_URL/api/search?query=")
|
||||
if echo "$response" | grep -iq "\"title\":\"$db_name\""; then
|
||||
echo -e "${VERT}ALREADY IMPORTED${NORMAL}"
|
||||
else
|
||||
import_gf_dashboard 13502 prometheus
|
||||
rc1=$?
|
||||
if [ $rc1 -eq 0 ]; then
|
||||
echo -e "${VERT}SUCCESSFULLY IMPORTED${NORMAL}"
|
||||
else
|
||||
echo -e "${ROUGE}ERROR ($rc1)${NORMAL}"
|
||||
exit $rc1
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
stop-stack)
|
||||
docker compose stop
|
||||
;;
|
||||
down-down)
|
||||
docker compose down
|
||||
;;
|
||||
del-stack)
|
||||
# confirm installation
|
||||
while true; do
|
||||
read -p "Are you sure you want to permanently delete the stack '${COMPOSE_PROJECT_NAME}'? [y/n] ? " yn
|
||||
case $yn in
|
||||
[Yy]* ) break;;
|
||||
* ) exit; #echo "Please answer yes or no.";;
|
||||
esac
|
||||
done
|
||||
echo -e "\n---- Stop and remove all container ----"
|
||||
docker compose down
|
||||
echo -e "\n---- Delete all folder ----"
|
||||
remove_folder
|
||||
;;
|
||||
list)
|
||||
echo "-------------------------------------"
|
||||
echo " Container list"
|
||||
echo "-------------------------------------"
|
||||
docker compose config --services | sort
|
||||
#for cont_item in "${containers_all[@]}"; do
|
||||
# echo "- $cont_item"
|
||||
#done
|
||||
;;
|
||||
-h|--help|help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
-v|--version|version)
|
||||
cat << EOF
|
||||
$(basename "$0") v$version (c) 1990 - $(date +%Y) by Gilles Mouchet
|
||||
Non-Commercial Use License – See LICENSE for details
|
||||
EOF
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
65
preprare.sh
Executable file
65
preprare.sh
Executable file
@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
|
||||
containers=(minio grafana proxy)
|
||||
containers_no_start=(dns-tools minio-cli)
|
||||
|
||||
if [ ! -f .env ]; then
|
||||
echo "file '.env' doesn't exist!"
|
||||
echo "See README.md"
|
||||
exit
|
||||
fi
|
||||
|
||||
. .env
|
||||
#set create dir
|
||||
#DIR=$(grep PRX_CERTS_DIR .env | cut -d'=' -f2)
|
||||
cat << EOF
|
||||
COMPOSE_PROJECT_NAME = ${COMPOSE_PROJECT_NAME}
|
||||
PRX_CERTS_DIR = ${PRX_CERTS_DIR}
|
||||
PRX_NGINX_CONF_DIR = ${PRX_NGINX_CONF_DIR}
|
||||
MINIO_DATA_ROOT_DIR = ${MINIO_DATA_ROOT_DIR}
|
||||
MINIO_CONF_CLI_DIR = ${MINIO_CONF_CLI_DIR}
|
||||
MINIO_ACCESS_KEY = ${MINIO_ACCESS_KEY}
|
||||
MINIO_SECRET_KEY = ${MINIO_SECRET_KEY}
|
||||
MINIO_REDIRECT_URL = ${MINIO_REDIRECT_URL}
|
||||
GF_ADMIN_USER = ${GF_ADMIN_USER}
|
||||
GF_ADMIN_PASS = ${GF_ADMIN_PASS}
|
||||
GF_DATA_DIR = ${GF_DATA_DIR}
|
||||
GF_ROOT_URL = ${GF_ROOT_URL}
|
||||
PROM_CONF_DIR = ${PROM_CONF_DIR}
|
||||
PROM_DATA_DIR = ${PROM_DATA_DIR}
|
||||
LOKI_CONF_DIR = ${LOKI_CONF_DIR}
|
||||
LOKI_DATA_DIR = ${LOKI_DATA_DIR}
|
||||
LOKI_GEN_LOG_DIR = ${LOKI_GEN_LOG_DIR}
|
||||
PROMTAIL_CONF_DIR = ${PROMTAIL_CONF_DIR}
|
||||
EOF
|
||||
echo "create folders"
|
||||
sudo mkdir -p ${PRX_CERTS_DIR}
|
||||
sudo mkdir -p ${PRX_NGINX_CONF_DIR}
|
||||
sudo mkdir -p ${MINIO_DATA_ROOT_DIR}
|
||||
sudo mkdir -p ${MINIO_CONF_CLI_DIR}
|
||||
sudo mkdir -p ${GF_DATA_DIR}
|
||||
sudo mkdir -p ${PROM_CONF_DIR}
|
||||
sudo mkdir -p ${PROM_DATA_DIR}
|
||||
sudo mkdir -p ${LOKI_CONF_DIR}
|
||||
sudo mkdir -p ${LOKI_DATA_DIR}
|
||||
sudo mkdir -p ${LOKI_GEN_LOG_DIR}
|
||||
sudo mkdir -p ${PROMTAIL_CONF_DIR}
|
||||
echo "down"
|
||||
docker compose down
|
||||
echo "copy config file"
|
||||
sudo cp ./config/default.conf ${PRX_NGINX_CONF_DIR}/.
|
||||
sudo cp ./config/prometheus.yml ${PROM_CONF_DIR}/.
|
||||
sudo cp ./config/local-config.yaml ${LOKI_CONF_DIR}/.
|
||||
sudo cp ./config/config.yml ${PROMTAIL_CONF_DIR}/.
|
||||
#docker compose up -d --remove-orphans
|
||||
echo "create container"
|
||||
docker compose create
|
||||
|
||||
for cont_item in "${containers[@]}"; do
|
||||
echo "Start container $cont_item"
|
||||
docker compose up -d $cont_item --remove-orphans
|
||||
done
|
||||
|
||||
|
||||
#docker compose stop minio-client
|
||||
#docker compose stop log-generator
|
||||
11
start.sh
Executable file
11
start.sh
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
docker compose down
|
||||
sudo cp ./config/default.conf /home/docker/nginx/.
|
||||
sudo cp ./config/prometheus.yml /home/docker/prometheus/.
|
||||
sudo cp ./config/local-config.yaml /home/docker/loki/.
|
||||
sudo cp ./config/config.yml /home/docker/promtail/.
|
||||
docker compose up -d --remove-orphans
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user