forked from kubernauts/jmeter-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
initialize_cluster.sh
executable file
·53 lines (32 loc) · 1.79 KB
/
initialize_cluster.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
#!/usr/bin/env bash
## Create jmeter database automatically in Influxdb
namespace="$1"
[ -n "$namespace" ] || read -p 'Enter the Jmeter Namespace: ' namespace
kubectl get namespace | grep $namespace >> /dev/null
if [ $? != 0 ];
then
echo "Namespace does not exist in the kubernetes cluster"
echo ""
echo "Below is the list of namespaces in the kubernetes cluster"
kubectl get namespaces
echo ""
echo "Please check and try again"
exit
fi
echo "Creating Influxdb jmeter Database"
##Wait until Influxdb Deployment is up and running
##influxdb_status=`kubectl get po -n $tenant | grep influxdb-jmeter | awk '{print $2}' | grep Running
influxdb_pod=`kubectl -n $namespace get po | grep influxdb | awk '{print $1}'`
kubectl -n $namespace exec -ti $influxdb_pod -- influx -execute 'CREATE DATABASE jmeter'
## Create the influxdb datasource in Grafana
echo "Creating the Influxdb data source"
grafana_pod=`kubectl -n $namespace get po | grep grafana | awk '{print $1}'`
## Make load test script in Jmeter master pod executable
#Get Master pod details
master_pod=`kubectl -n $namespace get po | grep master | awk '{print $1}'`
# Workaround for the read only attribute of config map
kubectl -n $namespace exec -ti $master_pod -- cp -rf /load_test /jmeter/load_test
kubectl -n $namespace exec -ti $master_pod -- chmod 755 /jmeter/load_test
#Get the name of the influxDB svc
influxdb_svc=`kubectl -n $namespace get svc | grep influxdb | awk '{print $1}'`
kubectl -n $namespace exec -ti $grafana_pod -- curl 'http://admin:[email protected]:3000/api/datasources' -X POST -H 'Content-Type: application/json;charset=UTF-8' --data-binary '{"name":"jmeterdb","type":"influxdb","url":"http://'$influxdb_svc':8086","access":"proxy","isDefault":true,"database":"jmeter","user":"admin","password":"admin"}'