javascript
带有Prometheus的Spring Boot和测微表第6部分:保护指标
以前,我們使用Prometheus成功啟動了Spring Boot應用程序。 Spring應用程序中的一個端點正在公開我們的指標數據,以便Prometheus能夠檢索它們。
想到的主要問題是如何保護此信息。
Spring已經為我們提供了強大的安全框架
因此,將其輕松用于我們的應用程序。 目標是對執行器/普羅米修斯端點使用基本身份驗證,并配置普羅米修斯以便使用基本身份驗證訪問該信息。
因此,第一步是在我們的應用程序上啟用安全性。 第一步是添加安全罐。
< dependency > < groupId >org.springframework.boot</ groupId > < artifactId >spring-boot-starter-security</ artifactId > </ dependency > 通過為默認用戶生成密碼,Spring Boot應用程序將自行獲得保護。
但是,我們確實希望控制用戶名和密碼,因此我們將使用一些環境變量。
通過使用默認用戶的憑據運行應用程序,我們可以通過最少的配置保護Prometheus端點。
SPRING_SECURITY_USER_NAME= test -user SPRING_SECURITY_USER_PASSWORD= test -password mvn spring-boot:run -user SPRING_SECURITY_USER_PASSWORD= -password mvn spring-boot:run因此,既然我們的應用程序具有安全設置,就該更新我們的prometheus配置了。
scrape_configs: - job_name: 'prometheus-spring' scrape_interval: 1m metrics_path: '/actuator/prometheus' static_configs: - targets: [ 'my.local.machine:8080' ] basic_auth: username: "test-user" password: "test-password"因此,讓我們再次如前所述運行普羅米修斯。
在此更改后對應用程序求和,Prometheus將以安全的方式為我們的應用程序收集指標數據。
翻譯自: https://www.javacodegeeks.com/2020/05/spring-boot-and-micrometer-with-prometheus-part-6-securing-metrics.html
總結
以上是生活随笔為你收集整理的带有Prometheus的Spring Boot和测微表第6部分:保护指标的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 安卓缩写英文(安卓缩写)
- 下一篇: 使用AWS Elastic Beanst