{"id":38253,"date":"2019-10-31T22:22:35","date_gmt":"2019-10-31T19:22:35","guid":{"rendered":"https:\/\/prohoster.info\/blog\/monitoring-postgres-vnutri-openshift\/"},"modified":"2019-10-31T22:22:35","modified_gmt":"2019-10-31T19:22:35","slug":"monitoring-postgres-vnutri-openshift","status":"publish","type":"post","link":"https:\/\/prohoster.info\/pl\/blog\/administrirovanie\/monitoring-postgres-vnutri-openshift","title":{"rendered":"Monitoring postgres w Openshift","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<p>Dzie\u0144 dobry, mieszka\u0144cy Habra!<\/p>\n<p>Dzi\u015b chcia\u0142bym opowiedzie\u0107, jak bardzo chcieli\u015bmy monitorowa\u0107 Postgresa oraz kilka innych element\u00f3w w klastrze OpenShift i jak to zrealizowali\u015bmy.<\/p>\n<p>Na wej\u015bciu mieli\u015bmy:<\/p>\n<ul>\n<li>Openshift<\/li>\n<li>Helm<\/li>\n<li>Prometheus<\/li>\n<\/ul>\n<p>\n<noindex><a rel=\"nofollow\" name=\"habracut\"><\/a><\/noindex><br \/>\nPraca z aplikacj\u0105 Java by\u0142a do\u015b\u0107 prosta i przejrzysta, a je\u015bli dok\u0142adniej, to:<\/p>\n<p>1) Dodanie do build.gradle <\/p>\n<pre><code class=\"plaintext\"> implementation \"io.micrometer:micrometer-registry-prometheus\"<\/code><\/pre>\n<p>\n2) Uruchomienie Prometheus z konfiguracj\u0105 <\/p>\n<pre><code class=\"xml\"> - job_name: 'job-name'\n    metrics_path: '\\\/actuator\\\/prometheus'\n    scrape_interval: 5s\n    kubernetes_sd_configs:\n    - role: pod\n      namespaces:\n        names: \n          - 'name'<\/code><\/pre>\n<p>\n3) Dodanie wy\u015bwietlania w Grafanie <\/p>\n<p>Zanim jednak wr\u00f3cili\u015bmy do monitorowania baz, kt\u00f3re znajduj\u0105 si\u0119 w naszej przestrzeni nazw (tak, to \u017ale, nikt tak nie robi, ale zdarza si\u0119 r\u00f3\u017cnie).<\/p>\n<h3>Jak to dzia\u0142a? <\/h3>\n<p>\nOpr\u00f3cz podu z Postgres i samego Prometheus potrzebujemy jeszcze jednego elementu \u2014 exportera.<\/p>\n<p>Exporter w og\u00f3lnym uj\u0119ciu to agent, kt\u00f3ry zbiera metryki z aplikacji lub nawet <a class=\"wpil_keyword_link\" href=\"https:\/\/prohoster.info\/pl\/server\/dts-los-angeles\/\"   title=\"serwera\" data-wpil-keyword-link=\"linked\"  data-wpil-monitor-id=\"3521\">serwera<\/a>. Dla Postgres, exporter jest napisany w Go, dzia\u0142a na zasadzie uruchamiania wewn\u0119trznie skrypt\u00f3w SQL w bazie, a nast\u0119pnie uzyskane wyniki s\u0105 odbierane przez Prometheus. Pozwala to r\u00f3wnie\u017c na rozszerzenie zbieranych metryk, dodaj\u0105c w\u0142asne.<\/p>\n<p>Deployujemy go w ten spos\u00f3b (przyk\u0142ad deployment.yaml, niczego nie zobowi\u0105zuj\u0105cy):<\/p>\n<pre><code class=\"xml\">\n---\napiVersion: extensions\\\/v1beta1\nkind: Deployment\nmetadata:\n  name: postgres-exporter\n  labels:\n    app: {{ .Values.name }}\n    monitoring: prometheus\nspec:\n  serviceName: {{ .Values.name }}\n  replicas: 1\n  revisionHistoryLimit: 5\n  template:\n    metadata:\n      labels:\n        app: postgres-exporter\n        monitoring: prometheus\n    spec:\n      containers:\n      - env:\n        - name: DATA_SOURCE_URI\n          value: postgresdb:5432\\\/pstgr?sslmode=disable\n        - name: DATA_SOURCE_USER\n          value: postgres\n        - name: DATA_SOURCE_PASS\n          value: postgres\n        resources:\n          limits:\n            cpu: 100m\n            memory: 50Mi\n          requests:\n            cpu: 100m\n            memory: 50Mi\n        livenessProbe:\n          tcpSocket:\n            port: metrics\n          initialDelaySeconds: 30\n          periodSeconds: 30\n        readinessProbe:\n          tcpSocket:\n            port: metrics\n          initialDelaySeconds: 10\n          periodSeconds: 30\n        image: exporter\n        name: postgres-exporter\n        ports:\n        - containerPort: 9187\n          name: metrics<\/code><\/pre>\n<p>\nPotrzebny by\u0142 r\u00f3wnie\u017c serwis oraz image stream<\/p>\n<p>Po wdro\u017ceniu bardzo chcemy, aby wszystkie elementy si\u0119 widzia\u0142y.<\/p>\n<p>Dodajemy do konfiguracji Prometeusza nast\u0119puj\u0105cy fragment:<\/p>\n<pre><code class=\"xml\">  - job_name: 'postgres_exporter'\n    metrics_path: '\\\/metrics'\n    scrape_interval: 5s\n    dns_sd_configs:\n    - names:\n      - 'postgres-exporter'\n      type: 'A'\n      port: 9187<\/code><\/pre>\n<p>\nI w\u0142a\u015bnie w tym momencie wszystko zacz\u0119\u0142o dzia\u0142a\u0107, wystarczy doda\u0107 to wszystko do Grafany i cieszy\u0107 si\u0119 wynikami.<\/p>\n<p>Opr\u00f3cz mo\u017cliwo\u015bci dodawania w\u0142asnych zapyta\u0144, w prometheus mo\u017cna zmienia\u0107 ustawienia, aby zbiera\u0107 bardziej ukierunkowane metryki.<\/p>\n<p>W podobny spos\u00f3b zrobiono dla:<\/p>\n<ul>\n<li>Kafka<\/li>\n<li>Elasticsearch<\/li>\n<li>Mongo<\/li>\n<\/ul>\n<p>\nP.S. Wszystkie dane dotycz\u0105ce nazw, port\u00f3w i innych informacji zosta\u0142y wymy\u015blone i nie maj\u0105 \u017cadnej warto\u015bci. <\/p>\n<p>Przydatne linki:<br \/>\n<noindex><a rel=\"nofollow\" href=\"https:\/\/prometheus.io\/docs\/instrumenting\/exporters\/\">Lista r\u00f3\u017cnych eksporter\u00f3w<\/a><\/noindex><br \/>\n<br \/>\u0179r\u00f3d\u0142o: <a content=\"nofollow\" rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/post\/467915\/\">habr.com<\/a><\/p>","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"excerpt":{"rendered":"<p>\u0414\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a \u0436\u0438\u0442\u0435\u043b\u0438 \u0425\u0430\u0431\u0440\u0430! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c, \u043a\u0430\u043a \u043d\u0430\u043c \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0442\u044c postgres \u0438 \u0435\u0449\u0435 \u043f\u0430\u0440\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 OpenShift \u0438 \u043a\u0430\u043a \u043c\u044b \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043b\u0438. \u041d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0438\u043c\u0435\u043b\u0438: Openshift Helm Prometheus \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 java \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0432\u0441\u0435 \u0431\u044b\u043b\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e, \u0430 \u0435\u0441\u043b\u0438 \u0431\u044b\u0442\u044c \u0442\u043e\u0447\u043d\u0435\u0435, \u0442\u043e: 1) \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 build.gradle implementation &#171;io.micrometer:micrometer-registry-prometheus&#187; [&hellip;]<\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[688],"tags":[],"class_list":["post-38253","post","type-post","status-publish","format-standard","hentry","category-administrirovanie"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.1.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"\u0414\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a \u0436\u0438\u0442\u0435\u043b\u0438 \u0425\u0430\u0431\u0440\u0430! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c, \u043a\u0430\u043a \u043d\u0430\u043c \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0442\u044c postgres \u0438 \u0435\u0449\u0435 \u043f\u0430\u0440\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 OpenShift \u0438 \u043a\u0430\u043a \u043c\u044b \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043b\u0438. \u041d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0438\u043c\u0435\u043b\u0438: .\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Yuri Gagarin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/prohoster.info\/pl\/blog\/administrirovanie\/monitoring-postgres-vnutri-openshift\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.1.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"pl_PL\" \/>\n\t\t<meta property=\"og:site_name\" content=\"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"\ud83e\udd47\u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 postgres \u0432\u043d\u0443\u0442\u0440\u0438 Openshift | ProHoster\" \/>\n\t\t<meta property=\"og:description\" content=\"\u0414\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a \u0436\u0438\u0442\u0435\u043b\u0438 \u0425\u0430\u0431\u0440\u0430! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c, \u043a\u0430\u043a \u043d\u0430\u043c \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0442\u044c postgres \u0438 \u0435\u0449\u0435 \u043f\u0430\u0440\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 OpenShift \u0438 \u043a\u0430\u043a \u043c\u044b \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043b\u0438. \u041d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0438\u043c\u0435\u043b\u0438: .\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/prohoster.info\/pl\/blog\/administrirovanie\/monitoring-postgres-vnutri-openshift\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"350\" \/>\n\t\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2019-10-31T19:22:35+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2019-10-31T19:22:35+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"\ud83e\udd47Monitorowanie postgres wewn\u0105trz Openshift | ProHoster","description":"Dzie\u0144 dobry mieszka\u0144cy Habr! Dzi\u015b chc\u0119 opowiedzie\u0107, jak bardzo chcieli\u015bmy monitorowa\u0107 postgres i jeszcze kilka encji wewn\u0105trz klastra OpenShift oraz jak to zrobili\u015bmy. Na wej\u015bciu mieli\u015bmy:","canonical_url":"https:\/\/prohoster.info\/pl\/blog\/administrirovanie\/monitoring-postgres-vnutri-openshift","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"pl_PL","og:site_name":"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b","og:type":"article","og:title":"\ud83e\udd47\u041c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 postgres \u0432\u043d\u0443\u0442\u0440\u0438 Openshift | ProHoster","og:description":"\u0414\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a \u0436\u0438\u0442\u0435\u043b\u0438 \u0425\u0430\u0431\u0440\u0430! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0445\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0432\u0430\u043c, \u043a\u0430\u043a \u043d\u0430\u043c \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u0442\u044c postgres \u0438 \u0435\u0449\u0435 \u043f\u0430\u0440\u0443 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 OpenShift \u0438 \u043a\u0430\u043a \u043c\u044b \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043b\u0438. \u041d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0438\u043c\u0435\u043b\u0438: .","og:url":"https:\/\/prohoster.info\/pl\/blog\/administrirovanie\/monitoring-postgres-vnutri-openshift","og:image":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:secure_url":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:width":350,"og:image:height":350,"article:published_time":"2019-10-31T19:22:35+00:00","article:modified_time":"2019-10-31T19:22:35+00:00","article:publisher":"https:\/\/www.facebook.com\/prohoster","article:author":"https:\/\/www.facebook.com\/prohoster"},"aioseo_meta_data":{"post_id":"38253","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"seo_analyzer_scan_date":"2026-02-22 15:56:24","breadcrumb_settings":null,"limit_modified_date":false,"reviewed_by":null,"ai":null,"created":"2021-03-01 01:12:23","updated":"2026-02-22 15:56:24","focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"gt_translate_keys":[{"key":"link","format":"url"}],"_links":{"self":[{"href":"https:\/\/prohoster.info\/pl\/wp-json\/wp\/v2\/posts\/38253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/pl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/pl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/pl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/pl\/wp-json\/wp\/v2\/comments?post=38253"}],"version-history":[{"count":1,"href":"https:\/\/prohoster.info\/pl\/wp-json\/wp\/v2\/posts\/38253\/revisions"}],"predecessor-version":[{"id":162047,"href":"https:\/\/prohoster.info\/pl\/wp-json\/wp\/v2\/posts\/38253\/revisions\/162047"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/pl\/wp-json\/wp\/v2\/media?parent=38253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/pl\/wp-json\/wp\/v2\/categories?post=38253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/pl\/wp-json\/wp\/v2\/tags?post=38253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}