Loading manifests/monitoring.yaml +69 −96 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ spec: selector: matchLabels: app: monitoring replicas: 1 template: metadata: labels: Loading @@ -13,11 +14,55 @@ spec: spec: terminationGracePeriodSeconds: 5 containers: - name: influxdb image: influxdb:1.8 ports: - containerPort: 8086 env: - name: INFLUXDB_DB value: "monitoring" - name: INFLUXDB_ADMIN_USER value: "teraflow" - name: INFLUXDB_ADMIN_PASSWORD value: "teraflow" - name: INFLUXDB_HTTP_AUTH_ENABLED value: "True" # readinessProbe: # exec: # command: ["curl", "-XGET", "localhost:8086/health"] # livenessProbe: # exec: # command: ["curl", "-XGET", "localhost:8086/health"] resources: requests: cpu: 250m memory: 512Mi limits: cpu: 700m memory: 1024Mi - name: server image: registry.gitlab.com/teraflow-h2020/controller/monitoring:latest imagePullPolicy: Always ports: - containerPort: 8080 - containerPort: 7070 env: - name: PORT value: "7070" readinessProbe: exec: command: ["/bin/grpc_health_probe", "-addr=:7070"] livenessProbe: exec: command: ["/bin/grpc_health_probe", "-addr=:7070"] resources: requests: cpu: 250m memory: 512Mi limits: cpu: 700m memory: 1024Mi # imagePullSecrets: # - name: regcred --- apiVersion: v1 kind: Service Loading @@ -30,99 +75,27 @@ spec: ports: - name: grpc protocol: TCP port: 8080 targetPort: 8080 port: 7070 targetPort: 7070 - name: influxdb protocol: TCP port: 8086 targetPort: 8086 --- # apiVersion: apps/v1 # kind: Deployment # metadata: # name: monitoring # spec: # selector: # matchLabels: # app: monitoring # replicas: 1 # template: # metadata: # labels: # app: monitoring # spec: # terminationGracePeriodSeconds: 5 # containers: # - name: influxdb # image: influxdb:1.8 # ports: # - containerPort: 8086 # resources: # requests: # cpu: 250m # memory: 512Mi # limits: # cpu: 700m # memory: 1024Mi # - name: server # image: registry.gitlab.com/teraflow-h2020/controller/monitoring:latest # imagePullPolicy: Always # ports: # - containerPort: 8080 # env: # - name: PORT # value: "8080" # readinessProbe: # exec: # command: ["/bin/grpc_health_probe", "-addr=:8080"] # livenessProbe: # exec: # command: ["/bin/grpc_health_probe", "-addr=:8080"] # resources: # requests: # cpu: 250m # memory: 512Mi # limits: # cpu: 700m # memory: 1024Mi # imagePullSecrets: # - name: regcred # --- # apiVersion: v1 # kind: Service # metadata: # name: monitoring # spec: # type: ClusterIP # selector: # app: monitoring # ports: # - name: grpc # protocol: TCP # port: 8080 # targetPort: 8080 # - name: influxdb # protocol: TCP # port: 8086 # targetPort: 8086 # --- # apiVersion: v1 # kind: Service # metadata: # name: monitoring-public # spec: # type: NodePort # selector: # app: monitoring # ports: # - name: grpc # protocol: TCP # port: 8080 # targetPort: 8080 # - name: influxdb # protocol: TCP # port: 8086 # targetPort: 8086 No newline at end of file apiVersion: v1 kind: Service metadata: name: monitoring-public spec: type: NodePort selector: app: monitoring ports: - name: grpc protocol: TCP port: 7070 targetPort: 7070 - name: influxdb protocol: TCP port: 8086 targetPort: 8086 No newline at end of file src/monitoring/.gitlab-ci.yml +37 −36 Original line number Diff line number Diff line # build, tag and push the Docker image to the gitlab registry build monitoring: variables: IMAGE_NAME: 'monitoring' # name of the microservice IMAGE_TAG: 'latest' # tag of the container image (production, development, etc) stage: build before_script: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY script: - docker build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile ./src/ - docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" after_script: - docker rmi $(docker images --quiet --filter=dangling=true) rules: - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)' - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"' - changes: - src/$IMAGE_NAME/**/*.{py,in,yml} - src/$IMAGE_NAME/Dockerfile - src/$IMAGE_NAME/tests/*.py - src/$IMAGE_NAME/tests/Dockerfile - manifests/$IMAGE_NAME.yaml - .gitlab-ci.yml # build monitoring: # variables: # IMAGE_NAME: 'monitoring' # name of the microservice # IMAGE_TAG: 'latest' # tag of the container image (production, development, etc) # stage: build # before_script: # - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY # script: # - docker build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile ./src/ # - docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" # - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" # after_script: # - docker rmi $(docker images --quiet --filter=dangling=true) # rules: # - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)' # - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"' # - changes: # - src/$IMAGE_NAME/**/*.{py,in,yml} # - src/$IMAGE_NAME/Dockerfile # - src/$IMAGE_NAME/tests/*.py # - src/$IMAGE_NAME/tests/Dockerfile # - manifests/$IMAGE_NAME.yaml # - .gitlab-ci.yml build influx: stage: build script: - kubectl version - kubectl get all - kubectl delete -f "manifests/monitoring.yaml" # - kubectl delete -f "manifests/influx.yaml" - sleep 60 - kubectl get all - kubectl apply -f "manifests/monitoring.yaml" - sleep 60 - kubectl get all # - kubectl apply -f "manifests/influx.yaml" # - sleep 15 # - kubectl version # - kubectl get all # - curl -XGET "10.106.57.235:8086/health" # - kubectl delete -f "manifests/influx.yaml" # # - kubectl delete -f "manifests/monitoring.yaml" # # - sleep 15 # # - kubectl get all # - kubectl apply -f "manifests/monitoring.yaml" # - sleep 60 # # - kubectl get all # # - kubectl apply -f "manifests/influx.yaml" # # - sleep 15 # # - kubectl get all # - curl -XGET "10.97.74.29:8086/health" # # - kubectl delete -f "manifests/influx.yaml" - cd ./src/monitoring/service - python3 test_influx.py # test if the Docker image can be pulled from the gitlab registry # test monitoring pull: Loading src/monitoring/service/test_influx.py 0 → 100644 +7 −0 Original line number Diff line number Diff line from influx_tools import * from datetime import datetime influx = Influx('10.97.74.29', 8086, 'teraflow', 'teraflow', 'monitoring') influx.write_KPI(datetime.now(),1,1,101,1000) results = influx.client.query('select * from samples;') print(results.raw) No newline at end of file Loading
manifests/monitoring.yaml +69 −96 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ spec: selector: matchLabels: app: monitoring replicas: 1 template: metadata: labels: Loading @@ -13,11 +14,55 @@ spec: spec: terminationGracePeriodSeconds: 5 containers: - name: influxdb image: influxdb:1.8 ports: - containerPort: 8086 env: - name: INFLUXDB_DB value: "monitoring" - name: INFLUXDB_ADMIN_USER value: "teraflow" - name: INFLUXDB_ADMIN_PASSWORD value: "teraflow" - name: INFLUXDB_HTTP_AUTH_ENABLED value: "True" # readinessProbe: # exec: # command: ["curl", "-XGET", "localhost:8086/health"] # livenessProbe: # exec: # command: ["curl", "-XGET", "localhost:8086/health"] resources: requests: cpu: 250m memory: 512Mi limits: cpu: 700m memory: 1024Mi - name: server image: registry.gitlab.com/teraflow-h2020/controller/monitoring:latest imagePullPolicy: Always ports: - containerPort: 8080 - containerPort: 7070 env: - name: PORT value: "7070" readinessProbe: exec: command: ["/bin/grpc_health_probe", "-addr=:7070"] livenessProbe: exec: command: ["/bin/grpc_health_probe", "-addr=:7070"] resources: requests: cpu: 250m memory: 512Mi limits: cpu: 700m memory: 1024Mi # imagePullSecrets: # - name: regcred --- apiVersion: v1 kind: Service Loading @@ -30,99 +75,27 @@ spec: ports: - name: grpc protocol: TCP port: 8080 targetPort: 8080 port: 7070 targetPort: 7070 - name: influxdb protocol: TCP port: 8086 targetPort: 8086 --- # apiVersion: apps/v1 # kind: Deployment # metadata: # name: monitoring # spec: # selector: # matchLabels: # app: monitoring # replicas: 1 # template: # metadata: # labels: # app: monitoring # spec: # terminationGracePeriodSeconds: 5 # containers: # - name: influxdb # image: influxdb:1.8 # ports: # - containerPort: 8086 # resources: # requests: # cpu: 250m # memory: 512Mi # limits: # cpu: 700m # memory: 1024Mi # - name: server # image: registry.gitlab.com/teraflow-h2020/controller/monitoring:latest # imagePullPolicy: Always # ports: # - containerPort: 8080 # env: # - name: PORT # value: "8080" # readinessProbe: # exec: # command: ["/bin/grpc_health_probe", "-addr=:8080"] # livenessProbe: # exec: # command: ["/bin/grpc_health_probe", "-addr=:8080"] # resources: # requests: # cpu: 250m # memory: 512Mi # limits: # cpu: 700m # memory: 1024Mi # imagePullSecrets: # - name: regcred # --- # apiVersion: v1 # kind: Service # metadata: # name: monitoring # spec: # type: ClusterIP # selector: # app: monitoring # ports: # - name: grpc # protocol: TCP # port: 8080 # targetPort: 8080 # - name: influxdb # protocol: TCP # port: 8086 # targetPort: 8086 # --- # apiVersion: v1 # kind: Service # metadata: # name: monitoring-public # spec: # type: NodePort # selector: # app: monitoring # ports: # - name: grpc # protocol: TCP # port: 8080 # targetPort: 8080 # - name: influxdb # protocol: TCP # port: 8086 # targetPort: 8086 No newline at end of file apiVersion: v1 kind: Service metadata: name: monitoring-public spec: type: NodePort selector: app: monitoring ports: - name: grpc protocol: TCP port: 7070 targetPort: 7070 - name: influxdb protocol: TCP port: 8086 targetPort: 8086 No newline at end of file
src/monitoring/.gitlab-ci.yml +37 −36 Original line number Diff line number Diff line # build, tag and push the Docker image to the gitlab registry build monitoring: variables: IMAGE_NAME: 'monitoring' # name of the microservice IMAGE_TAG: 'latest' # tag of the container image (production, development, etc) stage: build before_script: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY script: - docker build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile ./src/ - docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" after_script: - docker rmi $(docker images --quiet --filter=dangling=true) rules: - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)' - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"' - changes: - src/$IMAGE_NAME/**/*.{py,in,yml} - src/$IMAGE_NAME/Dockerfile - src/$IMAGE_NAME/tests/*.py - src/$IMAGE_NAME/tests/Dockerfile - manifests/$IMAGE_NAME.yaml - .gitlab-ci.yml # build monitoring: # variables: # IMAGE_NAME: 'monitoring' # name of the microservice # IMAGE_TAG: 'latest' # tag of the container image (production, development, etc) # stage: build # before_script: # - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY # script: # - docker build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile ./src/ # - docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" # - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" # after_script: # - docker rmi $(docker images --quiet --filter=dangling=true) # rules: # - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)' # - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"' # - changes: # - src/$IMAGE_NAME/**/*.{py,in,yml} # - src/$IMAGE_NAME/Dockerfile # - src/$IMAGE_NAME/tests/*.py # - src/$IMAGE_NAME/tests/Dockerfile # - manifests/$IMAGE_NAME.yaml # - .gitlab-ci.yml build influx: stage: build script: - kubectl version - kubectl get all - kubectl delete -f "manifests/monitoring.yaml" # - kubectl delete -f "manifests/influx.yaml" - sleep 60 - kubectl get all - kubectl apply -f "manifests/monitoring.yaml" - sleep 60 - kubectl get all # - kubectl apply -f "manifests/influx.yaml" # - sleep 15 # - kubectl version # - kubectl get all # - curl -XGET "10.106.57.235:8086/health" # - kubectl delete -f "manifests/influx.yaml" # # - kubectl delete -f "manifests/monitoring.yaml" # # - sleep 15 # # - kubectl get all # - kubectl apply -f "manifests/monitoring.yaml" # - sleep 60 # # - kubectl get all # # - kubectl apply -f "manifests/influx.yaml" # # - sleep 15 # # - kubectl get all # - curl -XGET "10.97.74.29:8086/health" # # - kubectl delete -f "manifests/influx.yaml" - cd ./src/monitoring/service - python3 test_influx.py # test if the Docker image can be pulled from the gitlab registry # test monitoring pull: Loading
src/monitoring/service/test_influx.py 0 → 100644 +7 −0 Original line number Diff line number Diff line from influx_tools import * from datetime import datetime influx = Influx('10.97.74.29', 8086, 'teraflow', 'teraflow', 'monitoring') influx.write_KPI(datetime.now(),1,1,101,1000) results = influx.client.query('select * from samples;') print(results.raw) No newline at end of file