-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathingest-gitlab-stats.sh
executable file
·45 lines (37 loc) · 1.23 KB
/
ingest-gitlab-stats.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
#!/usr/bin/env bash
#
# Script for cron job
#
# Crontab schedule line example:
## at 15 min of 2am, 4am, 6am, 8am..., everyday
# 15 0-23/2 * * * $HOME/bin/ingest-gitlab-stats.sh ~/Developer/gitlab-pipeline-stats 1d 2>&1
## at 45 min of 10, 14 and 16 hour of Monday
# 45 10,14,16 * * 1 $HOME/bin/ingest-gitlab-stats.sh ~/Developer/gitlab-pipeline-stats 3d 2>&1
#
export PATH="/usr/local/bin:$PATH"
DOCKER_COMPOSE="/usr/local/bin/docker-compose --no-ansi"
set -e
cd "${1:-.}"
# Save initial ES running status
set +e
${DOCKER_COMPOSE} ps elasticsearch | grep elasticsearch | grep ' Up '
es_status=$?
set -e
# Ingest Gitlab pipelines status
delta=${2:-6h}
shift
shift
${DOCKER_COMPOSE} run --rm ingest --dump-config --no-pipelines --no-merge-requests --check-missing-intervals 30d $*
${DOCKER_COMPOSE} run --rm ingest --dump-config $delta $*
# Stop ES if it was not running and Kibana is not running now
set +e
${DOCKER_COMPOSE} ps kibana | grep kibana | grep ' Up '
kibana_status=$?
set -e
if [ $es_status == 0 ] || [ $kibana_status == 0 ]
then
echo "ES was running before or Kibana is running now, leaving ES running"
else
echo "ES was not running before and Kibana is not running now, stopping ES..."
${DOCKER_COMPOSE} stop
fi