diff --git a/.gitignore b/.gitignore index a841f5fc22565c4769290c30c61fa0f4cb394a97..86434f04bb823a07fcd501b02db55e9f1e2be619 100644 --- a/.gitignore +++ b/.gitignore @@ -53,6 +53,7 @@ coverage.xml .pytest_cache/ .benchmarks/ cover/ +*_report.xml # Translations *.mo @@ -158,4 +159,3 @@ cython_debug/ # TeraFlowSDN-generated files tfs_runtime_env_vars.sh -*_report.xml diff --git a/manifests/monitoringservice.yaml b/manifests/monitoringservice.yaml index e6fa36d1a68e4e0f85776b511631b0b619ec100c..bbd965e792b07d459817eecf61b513a0883a53fc 100644 --- a/manifests/monitoringservice.yaml +++ b/manifests/monitoringservice.yaml @@ -33,6 +33,9 @@ spec: image: influxdb:1.8 ports: - containerPort: 8086 + env: + - name: LOG_LEVEL + value: "DEBUG" envFrom: - secretRef: name: influxdb-secrets @@ -54,6 +57,9 @@ spec: imagePullPolicy: Always ports: - containerPort: 7070 + env: + - name: LOG_LEVEL + value: "DEBUG" envFrom: - secretRef: name: monitoring-secrets diff --git a/manifests/webuiservice.yaml b/manifests/webuiservice.yaml index 52fc75a9868001d50f7380cfe238fa344de27f6e..0ebb811159641904271a2884739b65485abef356 100644 --- a/manifests/webuiservice.yaml +++ b/manifests/webuiservice.yaml @@ -40,7 +40,7 @@ spec: - name: LOG_LEVEL value: "DEBUG" - name: WEBUISERVICE_SERVICE_BASEURL_HTTP - value: "/webui" + value: "/" readinessProbe: httpGet: path: /healthz/ready diff --git a/my_deploy.sh b/my_deploy.sh index 67a2e0558c25d767e14b635e6dd9174433827156..c2921c271d44d372740b7bced1d1e5ce508c5da8 100644 --- a/my_deploy.sh +++ b/my_deploy.sh @@ -1,5 +1,5 @@ # Set the URL of your local Docker registry where the images will be uploaded to. -export TFS_REGISTRY_IMAGE="http://localhost:32000/tfs/" +export TFS_REGISTRY_IMAGE="" # Set the list of components, separated by comas, you want to build images for, and deploy. # Supported components are: @@ -16,7 +16,7 @@ export TFS_IMAGE_TAG="dev" export TFS_K8S_NAMESPACE="tfs" # Set additional manifest files to be applied after the deployment -export TFS_EXTRA_MANIFESTS="manifests/nginx_ingress_http.yaml" +# export TFS_EXTRA_MANIFESTS="manifests/nginx_ingress_http.yaml" # Set the neew Grafana admin password export TFS_GRAFANA_PASSWORD="admin123+" diff --git a/open_dashboard.sh b/open_dashboard.sh index 8291a22c75cd2c2b83bedcab2ac0167c56c966a6..17a9bb4335ce7bf391fcb4d96827253aab19ff6a 100755 --- a/open_dashboard.sh +++ b/open_dashboard.sh @@ -16,10 +16,10 @@ # this script opens the dashboard -K8S_NAMESPACE=${K8S_NAMESPACE:-'tf-dev'} +TFS_K8S_NAMESPACE=${TFS_K8S_NAMESPACE:-'tf-dev'} -GRAFANA_IP=$(kubectl get service/webuiservice -n ${K8S_NAMESPACE} -o jsonpath='{.spec.clusterIP}') -GRAFANA_PORT=$(kubectl get service webuiservice-public --namespace $K8S_NAMESPACE -o 'jsonpath={.spec.ports[?(@.port==3000)].nodePort}') +GRAFANA_IP=$(kubectl get service/webuiservice -n ${TFS_K8S_NAMESPACE} -o jsonpath='{.spec.clusterIP}') +GRAFANA_PORT=3000 #$(kubectl get service webuiservice --namespace $TFS_K8S_NAMESPACE -o 'jsonpath={.spec.ports[?(@.port==3000)].nodePort}') URL=http://${GRAFANA_IP}:${GRAFANA_PORT} echo Opening Dashboard on URL ${URL} diff --git a/open_webui.sh b/open_webui.sh index e4dfdb709ef5008091f3f73357087272dfd7c34e..c58eb2ecee3dd5116dd2e8249bc833b7c9b3b9f2 100755 --- a/open_webui.sh +++ b/open_webui.sh @@ -14,24 +14,79 @@ # this script opens the webui -K8S_NAMESPACE=${K8S_NAMESPACE:-'tf-dev'} +# If not already set, set the neew Grafana admin password +export TFS_K8S_NAMESPACE=${TFS_K8S_NAMESPACE:-'tfs'} -WEBUI_SERVICE_NAME="webuiservice-public" -WEBUI_PROTO=`kubectl get service ${WEBUI_SERVICE_NAME} -n ${K8S_NAMESPACE} -o jsonpath='{.spec.ports[0].name}'` -WEBUI_IP=`kubectl get service ${WEBUI_SERVICE_NAME} -n ${K8S_NAMESPACE} -o jsonpath='{.spec.clusterIP}'` +export TFS_GRAFANA_PASSWORD=${TFS_GRAFANA_PASSWORD:-"admin123+"} + +WEBUI_SERVICE_NAME="webuiservice" +# WEBUI_PROTO=`kubectl get service ${WEBUI_SERVICE_NAME} -n ${TFS_K8S_NAMESPACE} -o jsonpath='{.spec.ports[0].name}'` +WEBUI_IP=`kubectl get service ${WEBUI_SERVICE_NAME} -n ${TFS_K8S_NAMESPACE} -o jsonpath='{.spec.clusterIP}'` # WEBUI_PORT=$(kubectl get service ${WEBUI_SERVICE_NAME} --namespace $K8S_NAMESPACE -o 'jsonpath={.spec.ports[?(@.port==8004)].nodePort}') WEBUI_PORT=8004 # GRAFANA_PORT=$(kubectl get service ${WEBUI_SERVICE_NAME} --namespace $K8S_NAMESPACE -o 'jsonpath={.spec.ports[?(@.port==3000)].nodePort}') GRAFANA_PORT=3000 +echo "Configuring WebUI DataStores and Dashboards..." +sleep 3 +INFLUXDB_HOST="monitoringservice" +INFLUXDB_PORT=$(kubectl --namespace $TFS_K8S_NAMESPACE get service/monitoringservice -o jsonpath='{.spec.ports[?(@.name=="influxdb")].port}') +INFLUXDB_URL="http://${INFLUXDB_HOST}:${INFLUXDB_PORT}" +INFLUXDB_USER=$(kubectl --namespace $TFS_K8S_NAMESPACE get secrets influxdb-secrets -o jsonpath='{.data.INFLUXDB_ADMIN_USER}' | base64 --decode) +INFLUXDB_PASSWORD=$(kubectl --namespace $TFS_K8S_NAMESPACE get secrets influxdb-secrets -o jsonpath='{.data.INFLUXDB_ADMIN_PASSWORD}' | base64 --decode) +INFLUXDB_DATABASE=$(kubectl --namespace $TFS_K8S_NAMESPACE get secrets influxdb-secrets -o jsonpath='{.data.INFLUXDB_DB}' | base64 --decode) +# Exposed through the ingress controller "tfs-ingress" +# GRAFANA_HOSTNAME="127.0.0.1" +# GRAFANA_PORT="80" +# GRAFANA_BASEURL="/grafana" +# Default Grafana credentials +GRAFANA_USERNAME="admin" +GRAFANA_PASSWORD="admin" +# Default Grafana API URL +GRAFANA_URL_DEFAULT=http://${GRAFANA_USERNAME}:${GRAFANA_PASSWORD}@${WEBUI_IP}:${GRAFANA_PORT} #"http://${GRAFANA_USERNAME}:${GRAFANA_PASSWORD}@${GRAFANA_HOSTNAME}:${GRAFANA_PORT}${GRAFANA_BASEURL}" +# Updated Grafana API URL +GRAFANA_URL_UPDATED=http://${GRAFANA_USERNAME}:${TFS_GRAFANA_PASSWORD}@${WEBUI_IP}:${GRAFANA_PORT} #"http://${GRAFANA_USERNAME}:${TFS_GRAFANA_PASSWORD}@${GRAFANA_HOSTNAME}:${GRAFANA_PORT}${GRAFANA_BASEURL}" +echo "Connecting to grafana at URL: ${GRAFANA_URL_DEFAULT}..." +# Configure Grafana Admin Password +# Ref: https://grafana.com/docs/grafana/latest/http_api/user/#change-password +curl -X PUT -H "Content-Type: application/json" -d '{ + "oldPassword": "'${GRAFANA_PASSWORD}'", + "newPassword": "'${TFS_GRAFANA_PASSWORD}'", + "confirmNew" : "'${TFS_GRAFANA_PASSWORD}'" +}' ${GRAFANA_URL_DEFAULT}/api/user/password +echo +# Create InfluxDB DataSource +# Ref: https://grafana.com/docs/grafana/latest/http_api/data_source/ +curl -X POST -H "Content-Type: application/json" -d '{ + "type" : "influxdb", + "name" : "InfluxDB", + "url" : "'"$INFLUXDB_URL"'", + "access" : "proxy", + "basicAuth": false, + "user" : "'"$INFLUXDB_USER"'", + "password" : "'"$INFLUXDB_PASSWORD"'", + "isDefault": true, + "database" : "'"$INFLUXDB_DATABASE"'" +}' ${GRAFANA_URL_UPDATED}/api/datasources +echo +# Create Monitoring Dashboard +# Ref: https://grafana.com/docs/grafana/latest/http_api/dashboard/ +curl -X POST -H "Content-Type: application/json" \ +-d '@src/webui/grafana_dashboard.json' \ +${GRAFANA_URL_UPDATED}/api/dashboards/db +echo +DASHBOARD_URL="${GRAFANA_URL_UPDATED}/api/dashboards/uid/tf-l3-monit" +DASHBOARD_ID=$(curl -s "${DASHBOARD_URL}" | jq '.dashboard.id') +curl -X POST ${GRAFANA_URL_UPDATED}/api/user/stars/dashboard/${DASHBOARD_ID} + # Open WebUI -URL=${WEBUI_PROTO}://${WEBUI_IP}:${WEBUI_PORT} +URL=http://${WEBUI_IP}:${WEBUI_PORT} echo Opening web UI on URL ${URL} # curl -kL ${URL} python3 -m webbrowser ${URL} # Open Dashboard -URL=${WEBUI_PROTO}://${WEBUI_IP}:${GRAFANA_PORT} +URL=http://${WEBUI_IP}:${GRAFANA_PORT} echo Opening Dashboard on URL ${URL} # curl -kL ${URL} python3 -m webbrowser ${URL} diff --git a/src/monitoring/service/MonitoringServiceServicerImpl.py b/src/monitoring/service/MonitoringServiceServicerImpl.py index 00dbf7c8ce84c618581762090ddfca663e304814..ccf0ff83e443f94a866547479e52ee1187b3cbe2 100644 --- a/src/monitoring/service/MonitoringServiceServicerImpl.py +++ b/src/monitoring/service/MonitoringServiceServicerImpl.py @@ -91,8 +91,8 @@ class MonitoringServiceServicerImpl(monitoring_pb2_grpc.MonitoringServiceService monitor_device_request.kpi_descriptor.CopyFrom(kpiDescriptor) monitor_device_request.kpi_id.kpi_id.uuid = request.kpi_id.kpi_id.uuid - monitor_device_request.sampling_duration_s = request.sampling_duration_s - monitor_device_request.sampling_interval_s = request.sampling_interval_s + monitor_device_request.sampling_duration_s = request.monitoring_window_s + monitor_device_request.sampling_interval_s = request.sampling_rate_s device_client = DeviceClient() device_client.MonitorDeviceKpi(monitor_device_request) diff --git a/src/monitoring/service/__main__.py b/src/monitoring/service/__main__.py index e37412fa004704d089a8e00bada8033d8abe53bd..3334a860ccd94d51390ab5f5869d25e2475084ee 100644 --- a/src/monitoring/service/__main__.py +++ b/src/monitoring/service/__main__.py @@ -45,8 +45,8 @@ def start_monitoring(): # Create Monitor Kpi Requests monitor_kpi_request = monitoring_pb2.MonitorKpiRequest() monitor_kpi_request.kpi_id.CopyFrom(kpi_id) - monitor_kpi_request.sampling_duration_s = 86400 - monitor_kpi_request.sampling_interval_s = 30 + monitor_kpi_request.monitoring_window_s = 86400 + monitor_kpi_request.sampling_rate_s = 30 events_collector._monitoring_client.MonitorKpi(monitor_kpi_request) else: # Terminate is set, looping terminates diff --git a/src/monitoring/tests/Messages.py b/src/monitoring/tests/Messages.py index 94fcc78c1a408f21e1b16316237560e329cb78b9..10f41968e7059a6b8feaa451e52ca9639caa780d 100644 --- a/src/monitoring/tests/Messages.py +++ b/src/monitoring/tests/Messages.py @@ -34,11 +34,11 @@ def create_kpi_request(): _create_kpi_request.endpoint_id.endpoint_uuid.uuid = 'END1' # pylint: disable=maybe-no-member return _create_kpi_request -def monitor_kpi_request(kpi_uuid, sampling_duration_s, sampling_interval_s): +def monitor_kpi_request(kpi_uuid, monitoring_window_s, sampling_rate_s): _monitor_kpi_request = monitoring_pb2.MonitorKpiRequest() _monitor_kpi_request.kpi_id.kpi_id.uuid = kpi_uuid # pylint: disable=maybe-no-member - _monitor_kpi_request.sampling_duration_s = sampling_duration_s - _monitor_kpi_request.sampling_interval_s = sampling_interval_s + _monitor_kpi_request.monitoring_window_s = monitoring_window_s + _monitor_kpi_request.sampling_rate_s = sampling_rate_s return _monitor_kpi_request def include_kpi_request():