From f8ffba962c744eae71f0574773894419424e0c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pelayo=20Rojas=20=C3=8D=C3=B1igo?= Date: Tue, 16 Apr 2024 20:54:22 +0200 Subject: [PATCH] Add grafana and prometheus --- .env | 4 ++ Dockerfile | 4 +- docker-compose.yml | 43 ++++++++++++-- pom.xml | 8 +++ prometheus.yml | 14 +++++ .../resources/application-prod.properties | 3 +- src/main/resources/application.properties | 6 +- testCert.crt | 55 ++++++++++++++++++ testCert.p12 | Bin 0 -> 5129 bytes 9 files changed, 127 insertions(+), 10 deletions(-) create mode 100644 .env create mode 100644 prometheus.yml create mode 100644 testCert.crt create mode 100644 testCert.p12 diff --git a/.env b/.env new file mode 100644 index 00000000..a78d130b --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +MYSQL_HOST=db +KEYSTORE_PATH=./testCert.p12 +KEYSTORE_PASSWORD=123456 +WIQ_IMAGE=pelayori/wiq_es04b \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 752ecea9..0edd0077 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # Build stage with Maven and JDK 17 FROM maven:3.8.4-openjdk-17-slim as build -WORKDIR /app +WORKDIR ./app COPY pom.xml . COPY src src/ # Use Maven directly instead of the Maven Wrapper @@ -8,6 +8,6 @@ RUN mvn clean package -DskipTests # Run stage with JDK 17 FROM openjdk:17-slim -COPY --from=build /app/target/*.jar app.jar +COPY --from=build ./app/target/*.jar app.jar ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=prod","-jar","/app.jar"] EXPOSE 443 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index a61915cf..a3593872 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,13 +18,13 @@ services: restart: always wiq_es04b: - image: ghcr.io/arquisoft/wiq_es04b:latest + image: ${WIQ_IMAGE:-"ghcr.io/arquisoft/wiq_es04b:latest"} environment: MYSQL_HOST: ${MYSQL_HOST} - MYSQL_PORT: ${MYSQL_PORT} - MYSQL_DATABASE: ${MYSQL_DATABASE} - MYSQL_USER: ${MYSQL_USER} - MYSQL_PASSWORD: ${MYSQL_PASSWORD} + MYSQL_DATABASE: ${MYSQL_DATABASE:-wiq_es04b} + MYSQL_USER: ${MYSQL_USER:-wiq_es04b} + MYSQL_PASSWORD: ${MYSQL_PASSWORD:-wiq_es04b} + MYSQL_PORT: ${MYSQL_PORT:-3306} KEYSTORE_PATH: ${KEYSTORE_PATH} KEYSTORE_PASSWORD: ${KEYSTORE_PASSWORD} ports: @@ -38,9 +38,40 @@ services: volumes: - ${KEYSTORE_PATH}:/certs/keystore.p12 + prometheus: + image: prom/prometheus:latest + volumes: + - prometheus_data:/prometheus + - ./prometheus.yml:/etc/prometheus/prometheus.yml + ports: + - "9090:9090" + networks: + - mynetwork + depends_on: + - wiq_es04b + restart: always + + grafana: + image: grafana/grafana:latest + volumes: + - grafana_data:/var/lib/grafana + environment: + GF_AUTH_DISABLE_LOGIN_FORM: true + GF_AUTH_ANONYMOUS_ENABLED: true + GF_AUTH_ANONYMOUS_ORG_ROLE: Admin + ports: + - "3000:3000" + networks: + - mynetwork + depends_on: + - prometheus + restart: always + volumes: db_data: + prometheus_data: + grafana_data: networks: mynetwork: - driver: bridge + driver: bridge \ No newline at end of file diff --git a/pom.xml b/pom.xml index 7961a9d5..52e13e70 100644 --- a/pom.xml +++ b/pom.xml @@ -114,6 +114,14 @@ springdoc-openapi-starter-webmvc-ui 2.5.0 + + org.springframework.boot + spring-boot-starter-actuator + + + io.micrometer + micrometer-registry-prometheus + diff --git a/prometheus.yml b/prometheus.yml new file mode 100644 index 00000000..127bc94a --- /dev/null +++ b/prometheus.yml @@ -0,0 +1,14 @@ +global: + scrape_interval: 2s + scrape_timeout: 1s + +scrape_configs: + - job_name: 'spring-application' + scrape_interval: 2s + scrape_timeout: 1s + metrics_path: '/actuator/prometheus' + scheme: https + tls_config: + insecure_skip_verify: true + static_configs: + - targets: [ 'wiq_es04b:443' ] \ No newline at end of file diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 6e483e24..d7689afa 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -11,4 +11,5 @@ spring.jpa.hibernate.ddl-auto=update server.ssl.key-store=/certs/keystore.p12 server.ssl.key-store-password=${KEYSTORE_PASSWORD} server.ssl.keyStoreType=PKCS12 -server.ssl.keyAlias=keystore \ No newline at end of file +server.ssl.keyAlias=keystore +server.ssl.enabled-protocols=TLSv1.2 \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b2dc761a..660a6bfa 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,5 @@ # Port 3000 for testing, local deployment -server.port=3000 +server.port=3100 server.address=0.0.0.0 # HSQL db @@ -13,3 +13,7 @@ springdoc.api-docs.path=/api-docs springdoc.swagger-ui.path=/api springdoc.swagger-ui.operationsSorter=method springdoc.packagesToScan=com.uniovi.controllers.api + +management.endpoint.metrics.enabled=true +management.endpoints.web.exposure.include=prometheus +management.endpoints.jmx.exposure.include=* diff --git a/testCert.crt b/testCert.crt new file mode 100644 index 00000000..d366bf5c --- /dev/null +++ b/testCert.crt @@ -0,0 +1,55 @@ +Bag Attributes + friendlyName: youralias + localKeyID: 54 69 6D 65 20 31 37 31 33 32 38 34 33 38 34 39 32 35 +subject=C = d, ST = d, L = d, O = d, OU = d, CN = d + +issuer=C = d, ST = d, L = d, O = d, OU = d, CN = d + +-----BEGIN CERTIFICATE----- +MIIDMzCCAhugAwIBAgIINBF3UUhqeiAwDQYJKoZIhvcNAQELBQAwSDEKMAgGA1UE +BhMBZDEKMAgGA1UECBMBZDEKMAgGA1UEBxMBZDEKMAgGA1UEChMBZDEKMAgGA1UE +CxMBZDEKMAgGA1UEAxMBZDAeFw0yNDA0MTYxNjE5NDRaFw0zNDA0MTQxNjE5NDRa +MEgxCjAIBgNVBAYTAWQxCjAIBgNVBAgTAWQxCjAIBgNVBAcTAWQxCjAIBgNVBAoT +AWQxCjAIBgNVBAsTAWQxCjAIBgNVBAMTAWQwggEiMA0GCSqGSIb3DQEBAQUAA4IB +DwAwggEKAoIBAQC5E0IFN+5p/sv0qGs9MnvVVjusbWV+BIW4wWmt8c3Rbd73cuSG +BS6iHErbZh7t8uv7wY0hO06lqsphRRjBzD5ouS4MS4dsLpMkgjMcll8PY17nA/iy +HiIb/Cp18srzqGQIXBow6gXaMcTU8irN+TEtmlT/DvwtVpVqy6eCqmmhPxXsyyw1 +8DxlWRTV2o7pPXg0YC6r6YEHLbprBbwa1YAqiaSciKTWgQuR1w7abkQz8slaM4kH +MLdad1ra0F96YaHDuDQBRD0Pe13xk4yvE4il3JiOoA1EEa7xC5CYdg2lb/kR1RME +3t7L7Aiv+ThxiIeK3Agj11Oj9lOn5NL93CW/AgMBAAGjITAfMB0GA1UdDgQWBBSv ++MwjgZhyyuU+LUZvM14sw4JmCjANBgkqhkiG9w0BAQsFAAOCAQEAp455G+Awasa0 +ZbN2tTyFaT5rhFfyZ5BNTPBnmVVOP6XCa2Ot3tc+wWu4eMp5bmPDziHYfyeApI8r +zPbSiPgt8SKDCBwI4UCysdKgjxPfWSPxlWV/SXAU3wyijlm/hyQpZzcDakW0Wrj6 +ihvC+zoOC0DOkU2AfWTHgz6M/zB+OCY8jPX57niPTTp4LUlA/VNUu2O6QWn/4M2y +mzkKtpmKyfS8niQOq+4K3UlVXHb4pu+hSdeizXYz1a81mB8AbLDwcuEsfMNJ9BeY +iYeTlkeBbY7Zw9yTNnZsrjyCtTedCO8POvEbC6nbZAyLb1MD6DsBrF/8D5Wf37ZK +/bF0j5s1jA== +-----END CERTIFICATE----- +Bag Attributes + friendlyName: keystore + localKeyID: 54 69 6D 65 20 31 37 31 33 32 38 35 39 38 39 39 34 30 +subject=C = Unknown, ST = Unknown, L = Unknown, O = Unknown, OU = Unknown, CN = Unknown + +issuer=C = Unknown, ST = Unknown, L = Unknown, O = Un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Q5DZyQn +XI8R7VDhcKRoCMBvqCWm2ynU1viPUEfNV/064S8TFuhYD4wXcqhSzgogsO0iKLIE +nGWRbkEeN+fuaiwUDszemLNXfpp5ojwbWW5+I6i2QUWqVbJbk0fDItgGGX5pzTqj +8cnJoqNaeBTzKTTW9/0mr5kkPqXtQCQum/3vnUo9wQ== +-----END CERTIFICATE----- diff --git a/testCert.p12 b/testCert.p12 new file mode 100644 index 0000000000000000000000000000000000000000..a6f4004585c34e934b82b51fda1269dcd99083fc GIT binary patch literal 5129 zcmbW5WmFV^md9rp7#O;wLy(pj29Sm!MjE691nH0lfgz+EI;5mU8c7-H6eWcLq(cPh zZegTheP{Q)_x8)~p8ay~x&IsA?(f`lp(tuR93TjaqC$fqe37b=XCy#;U_Oc}9~VWH z^HbCK*+W*L>cJ6^b+pp93G}l zZS2YeJBO(TR%^ty$tRt*7vT*jbct1n#do>@ z+9uvPJZXE?Q7E%YUcjd`f}fs-@6$1tmRZI#U@GAxJsOi z3hvAcnSZiU$N^)NMY4Wz?aHDTyJYk{7nKoJqOBqcG4R#E6*IMf<`W zmmXa^8r9a>*}Wu8+U41F%^M1eo!Di}o!}=K ziE>`(Xo%PH`0fej{R5G=L8 z+wR02{clD-6seWIs$_HRBYO=$L_;@yvrVfR14an7aeomLeiX_2t<)zH#QAN2FlnJt zpy~7GOzWNKQ$djKBHm3MwTdzR+)QzvZPGx0$FdFTA)-kW$jgt0_XbvC;9i6nM}+ToC@r z!#+MR=%)<-jXa9>^Dq|~fR*EKA*=NSKA%zETxeS-yA7at>2&brcO~SMfl@wpWG{P| zr)h>d({9gsg0FT7Ollb)T_IqlTe8L7lFBpZg~JWhM|~{*;4MdilwtD?uBnzcrqTF3 z0fkxV;&buESvVxzxwR5%UUzBq)0``Ew)4V&m_6D561Jn z?Ugf-aD=f^y_vzD>d-66mD}&E2ie?$3W7%IX>3bp0&^_ds&5Dh$rU`?P-gSz;vmmE zp$isOx}}fD95uY~msJjd3++Ceq7DPkrY+0OloA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