{"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\/en\/blog\/administrirovanie\/monitoring-postgres-vnutri-openshift","title":{"rendered":"Monitoring postgres inside Openshift","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<p>Good day, residents of Habr!<\/p>\n<p>Today, I want to share how we really wanted to monitor Postgres and a couple of entities within the OpenShift cluster, and how we did it.<\/p>\n<p>We started with:<\/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 \/>\nWorking with the Java application was quite simple and straightforward, to be more precise:<\/p>\n<p>1) Adding to build.gradle <\/p>\n<pre><code class=\"plaintext\"> implementation \"io.micrometer:micrometer-registry-prometheus\"<\/code><\/pre>\n<p>\n2) Starting Prometheus with the configuration <\/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) Adding a display in Grafana <\/p>\n<p>Everything was quite straightforward until the moment we wanted to monitor the databases that are nearby in the namespace (yes, it's bad, nobody does that, but it happens).<\/p>\n<h3>How does it work? <\/h3>\n<p>\nBesides the Pod with Postgres and Prometheus, we also need another entity \u2014 the exporter.<\/p>\n<p>An exporter, in abstract terms, is an agent that collects metrics from an application or even <a class=\"wpil_keyword_link\" href=\"https:\/\/prohoster.info\/en\/server\/dts-los-angeles\/\"   title=\"server\" data-wpil-keyword-link=\"linked\"  data-wpil-monitor-id=\"3521\">server<\/a>. The Postgres exporter is written in Go and works by executing SQL scripts on the database and then retrieving the results for Prometheus. This also allows you to extend the metrics collected by adding your own.<\/p>\n<p>We deploy it like this (an example of deployment.yaml, not binding):<\/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>\nWe also needed a service and image stream for it.<\/p>\n<p>After deployment, we really want everyone to see each other.<\/p>\n<p>We add this piece to the Prometheus config:<\/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>\nAnd that's when everything started working; we just need to add all this goodness to Grafana and enjoy the results.<\/p>\n<p>In addition to being able to add your own queries, you can also change the settings in Prometheus to collect the necessary metrics more targetedly.<\/p>\n<p>The same approach was taken for:<\/p>\n<ul>\n<li>Kafka<\/li>\n<li>Elasticsearch<\/li>\n<li>Mongo<\/li>\n<\/ul>\n<p>\nP.S. All data regarding names, ports, and the like are arbitrary and do not carry any actual information. <\/p>\n<p>Useful links:<br \/>\n<noindex><a rel=\"nofollow\" href=\"https:\/\/prometheus.io\/docs\/instrumenting\/exporters\/\">A list of various exporters<\/a><\/noindex><br \/>\n<br \/>Source: <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.2 - 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\/en\/blog\/administrirovanie\/monitoring-postgres-vnutri-openshift\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.2\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\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\/en\/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\udd47Monitoring PostgreSQL within OpenShift | ProHoster","description":"Good day, Habr residents! Today I want to share how we really wanted to monitor PostgreSQL and a couple of other entities within the OpenShift cluster, and how we accomplished that. At the outset, we had:","canonical_url":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/monitoring-postgres-vnutri-openshift","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","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\/en\/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\/en\/wp-json\/wp\/v2\/posts\/38253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/comments?post=38253"}],"version-history":[{"count":1,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts\/38253\/revisions"}],"predecessor-version":[{"id":162047,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts\/38253\/revisions\/162047"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/media?parent=38253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/categories?post=38253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/tags?post=38253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}