-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_docker_compose.sh
executable file
·160 lines (132 loc) · 3.4 KB
/
generate_docker_compose.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
# Determine the operating system
OS="$(uname)"
# Define the Docker Compose file content
if [[ "$OS" == "Darwin" ]]; then
# macOS configuration
cat <<EOF > docker-compose.yml
services:
prometheus:
image: prom/prometheus:latest
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- 9090:9090
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
redis-exporter:
image: oliver006/redis_exporter:latest
command:
- '--redis.addr=host.docker.internal:6379'
ports:
- 9121:9121
extra_hosts:
- "host.docker.internal:host-gateway"
grafana:
image: grafana/grafana:latest
ports:
- 3000:3000
environment:
- GF_AUTH_DISABLE_LOGIN_FORM=true
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
- GF_DASHBOARDS_JSON_ENABLED=true
volumes:
- ./grafana-datasources.yml:/etc/grafana/provisioning/datasources/datasources.yml
- ./dashboards:/var/lib/grafana/dashboards
- ./provisioning:/etc/grafana/provisioning
volumes:
prometheus_data:
EOF
cat <<EOF > prometheus.yml
global:
scrape_interval: 5s
scrape_timeout: 500ms
scrape_configs:
- job_name: 'falkor_benchmark'
static_configs:
- targets: [ 'host.docker.internal:8080' ]
- job_name: 'redis'
static_configs:
- targets: [ 'redis-exporter:9121' ]
EOF
cat <<EOF > grafana-datasources.yml
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
EOF
elif [[ "$OS" == "Linux" ]]; then
# Linux configuration
HOST_IP=$(hostname -I | awk '{print $1}') # Get the host IP address
cat <<EOF > docker-compose.yml
version: '3.8'
services:
prometheus:
image: prom/prometheus:latest
ports:
- 9090:9090
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
redis-exporter:
image: oliver006/redis_exporter:latest
command:
- '--redis.addr=${HOST_IP}:6379' # Use host IP for Linux
ports:
- 9121:9121
grafana:
image: grafana/grafana:latest
ports:
- 3000:3000
environment:
- GF_AUTH_DISABLE_LOGIN_FORM=true
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
- GF_DASHBOARDS_JSON_ENABLED=true
volumes:
- ./grafana-datasources.yml:/etc/grafana/provisioning/datasources/datasources.yml
- ./dashboards:/var/lib/grafana/dashboards
- ./provisioning:/etc/grafana/provisioning
node-exporter:
image: prom/node-exporter:latest
ports:
- 9100:9100
volumes:
prometheus_data:
EOF
cat <<EOF > prometheus.yml
global:
scrape_interval: 5s
scrape_timeout: 500ms
scrape_configs:
- job_name: 'falkor_benchmark'
static_configs:
- targets: [ '${HOST_IP}:8080' ] # Use host IP for Linux
- job_name: 'redis'
static_configs:
- targets: [ 'redis-exporter:9121' ]
- job_name: 'node-exporter'
static_configs:
- targets: [ 'node-exporter:9100' ]
EOF
cat <<EOF > grafana-datasources.yml
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
EOF
else
echo "Unsupported OS"
exit 1
fi
echo "Docker Compose files generated successfully."