Monitor custom kubernetes pod metrics using Prometheus












2















I am using Prometheus to monitor my Kubernetes cluster. I have set up Prometheus in a separate namespace. I have multiple namespaces and multiple pods are running. Each pod container exposes a custom metrics at this end point, :80/data/metrics . I am getting the Pods CPU, memory metrics etc, but how to configure Prometheus to pull data from :80/data/metrics in each available pod ? I have used this tutorial to set up Prometheus, Link










share|improve this question



























    2















    I am using Prometheus to monitor my Kubernetes cluster. I have set up Prometheus in a separate namespace. I have multiple namespaces and multiple pods are running. Each pod container exposes a custom metrics at this end point, :80/data/metrics . I am getting the Pods CPU, memory metrics etc, but how to configure Prometheus to pull data from :80/data/metrics in each available pod ? I have used this tutorial to set up Prometheus, Link










    share|improve this question

























      2












      2








      2








      I am using Prometheus to monitor my Kubernetes cluster. I have set up Prometheus in a separate namespace. I have multiple namespaces and multiple pods are running. Each pod container exposes a custom metrics at this end point, :80/data/metrics . I am getting the Pods CPU, memory metrics etc, but how to configure Prometheus to pull data from :80/data/metrics in each available pod ? I have used this tutorial to set up Prometheus, Link










      share|improve this question














      I am using Prometheus to monitor my Kubernetes cluster. I have set up Prometheus in a separate namespace. I have multiple namespaces and multiple pods are running. Each pod container exposes a custom metrics at this end point, :80/data/metrics . I am getting the Pods CPU, memory metrics etc, but how to configure Prometheus to pull data from :80/data/metrics in each available pod ? I have used this tutorial to set up Prometheus, Link







      kubernetes containers prometheus prometheus-node-exporter






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 18 '18 at 20:36









      Dinesh AhujaDinesh Ahuja

      13618




      13618
























          2 Answers
          2






          active

          oldest

          votes


















          1














          You have to add this three annotation to your pods:



          prometheus.io/scrape: 'true'
          prometheus.io/path: '/data/metrics'
          prometheus.io/port: '80'


          How it will work?



          Look at the kubernetes-pods job of config-map.yaml you are using to configure prometheus,



          - job_name: 'kubernetes-pods'

          kubernetes_sd_configs:
          - role: pod

          relabel_configs:
          - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
          action: keep
          regex: true
          - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
          action: replace
          target_label: __metrics_path__
          regex: (.+)
          - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
          action: replace
          regex: ([^:]+)(?::d+)?;(d+)
          replacement: $1:$2
          target_label: __address__
          - action: labelmap
          regex: __meta_kubernetes_pod_label_(.+)
          - source_labels: [__meta_kubernetes_namespace]
          action: replace
          target_label: kubernetes_namespace
          - source_labels: [__meta_kubernetes_pod_name]
          action: replace
          target_label: kubernetes_pod_name


          Check this three relabel configuration



          - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
          action: keep
          regex: true
          - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
          action: replace
          target_label: __metrics_path__
          regex: (.+)
          - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
          action: replace
          regex: ([^:]+)(?::d+)?;(d+)
          replacement: $1:$2
          target_label: __address__


          Here, __metrics_path__ and port and whether to scrap metrics from this pod are being read from pod annotations.



          For, more details on how to configure Prometheus see here.






          share|improve this answer

































            0














            The link provided in the question refers to this ConfigMap for the prometheus configuration. It that ConfigMap is used then prometheus is already configured to scrape pods.



            For that configuration (see relabel_configs) to have prometheus scrape the custom metrics exposed by pods at :80/data/metrics, add these annotations to the pods deployment configurations:



            metadata:
            annotations:
            prometheus.io/scrape: 'true'
            prometheus.io/path: '/data/metrics'
            prometheus.io/port: '80'


            See the configuration options for Kubernetes discovery in the prometheus docs (scroll down) for settings related to scraping over https and more.



            Edit:
            I saw Emruz Hossain's answer only after I posted mine. His answer currently lacks the prometheus.io/scrape: 'true' annotation and specified = instead of : as annotations' name/value separator which is invalid in yaml or json.






            share|improve this answer


























            • Thank you @apisim for pointing out limitation of my answer. I have updated it.

              – Emruz Hossain
              Nov 19 '18 at 10:59











            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365191%2fmonitor-custom-kubernetes-pod-metrics-using-prometheus%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            You have to add this three annotation to your pods:



            prometheus.io/scrape: 'true'
            prometheus.io/path: '/data/metrics'
            prometheus.io/port: '80'


            How it will work?



            Look at the kubernetes-pods job of config-map.yaml you are using to configure prometheus,



            - job_name: 'kubernetes-pods'

            kubernetes_sd_configs:
            - role: pod

            relabel_configs:
            - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
            action: keep
            regex: true
            - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
            action: replace
            target_label: __metrics_path__
            regex: (.+)
            - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
            action: replace
            regex: ([^:]+)(?::d+)?;(d+)
            replacement: $1:$2
            target_label: __address__
            - action: labelmap
            regex: __meta_kubernetes_pod_label_(.+)
            - source_labels: [__meta_kubernetes_namespace]
            action: replace
            target_label: kubernetes_namespace
            - source_labels: [__meta_kubernetes_pod_name]
            action: replace
            target_label: kubernetes_pod_name


            Check this three relabel configuration



            - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
            action: keep
            regex: true
            - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
            action: replace
            target_label: __metrics_path__
            regex: (.+)
            - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
            action: replace
            regex: ([^:]+)(?::d+)?;(d+)
            replacement: $1:$2
            target_label: __address__


            Here, __metrics_path__ and port and whether to scrap metrics from this pod are being read from pod annotations.



            For, more details on how to configure Prometheus see here.






            share|improve this answer






























              1














              You have to add this three annotation to your pods:



              prometheus.io/scrape: 'true'
              prometheus.io/path: '/data/metrics'
              prometheus.io/port: '80'


              How it will work?



              Look at the kubernetes-pods job of config-map.yaml you are using to configure prometheus,



              - job_name: 'kubernetes-pods'

              kubernetes_sd_configs:
              - role: pod

              relabel_configs:
              - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
              action: keep
              regex: true
              - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
              action: replace
              target_label: __metrics_path__
              regex: (.+)
              - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
              action: replace
              regex: ([^:]+)(?::d+)?;(d+)
              replacement: $1:$2
              target_label: __address__
              - action: labelmap
              regex: __meta_kubernetes_pod_label_(.+)
              - source_labels: [__meta_kubernetes_namespace]
              action: replace
              target_label: kubernetes_namespace
              - source_labels: [__meta_kubernetes_pod_name]
              action: replace
              target_label: kubernetes_pod_name


              Check this three relabel configuration



              - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
              action: keep
              regex: true
              - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
              action: replace
              target_label: __metrics_path__
              regex: (.+)
              - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
              action: replace
              regex: ([^:]+)(?::d+)?;(d+)
              replacement: $1:$2
              target_label: __address__


              Here, __metrics_path__ and port and whether to scrap metrics from this pod are being read from pod annotations.



              For, more details on how to configure Prometheus see here.






              share|improve this answer




























                1












                1








                1







                You have to add this three annotation to your pods:



                prometheus.io/scrape: 'true'
                prometheus.io/path: '/data/metrics'
                prometheus.io/port: '80'


                How it will work?



                Look at the kubernetes-pods job of config-map.yaml you are using to configure prometheus,



                - job_name: 'kubernetes-pods'

                kubernetes_sd_configs:
                - role: pod

                relabel_configs:
                - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
                action: keep
                regex: true
                - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
                action: replace
                target_label: __metrics_path__
                regex: (.+)
                - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
                action: replace
                regex: ([^:]+)(?::d+)?;(d+)
                replacement: $1:$2
                target_label: __address__
                - action: labelmap
                regex: __meta_kubernetes_pod_label_(.+)
                - source_labels: [__meta_kubernetes_namespace]
                action: replace
                target_label: kubernetes_namespace
                - source_labels: [__meta_kubernetes_pod_name]
                action: replace
                target_label: kubernetes_pod_name


                Check this three relabel configuration



                - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
                action: keep
                regex: true
                - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
                action: replace
                target_label: __metrics_path__
                regex: (.+)
                - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
                action: replace
                regex: ([^:]+)(?::d+)?;(d+)
                replacement: $1:$2
                target_label: __address__


                Here, __metrics_path__ and port and whether to scrap metrics from this pod are being read from pod annotations.



                For, more details on how to configure Prometheus see here.






                share|improve this answer















                You have to add this three annotation to your pods:



                prometheus.io/scrape: 'true'
                prometheus.io/path: '/data/metrics'
                prometheus.io/port: '80'


                How it will work?



                Look at the kubernetes-pods job of config-map.yaml you are using to configure prometheus,



                - job_name: 'kubernetes-pods'

                kubernetes_sd_configs:
                - role: pod

                relabel_configs:
                - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
                action: keep
                regex: true
                - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
                action: replace
                target_label: __metrics_path__
                regex: (.+)
                - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
                action: replace
                regex: ([^:]+)(?::d+)?;(d+)
                replacement: $1:$2
                target_label: __address__
                - action: labelmap
                regex: __meta_kubernetes_pod_label_(.+)
                - source_labels: [__meta_kubernetes_namespace]
                action: replace
                target_label: kubernetes_namespace
                - source_labels: [__meta_kubernetes_pod_name]
                action: replace
                target_label: kubernetes_pod_name


                Check this three relabel configuration



                - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
                action: keep
                regex: true
                - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
                action: replace
                target_label: __metrics_path__
                regex: (.+)
                - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
                action: replace
                regex: ([^:]+)(?::d+)?;(d+)
                replacement: $1:$2
                target_label: __address__


                Here, __metrics_path__ and port and whether to scrap metrics from this pod are being read from pod annotations.



                For, more details on how to configure Prometheus see here.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 19 '18 at 11:09

























                answered Nov 19 '18 at 3:42









                Emruz HossainEmruz Hossain

                1,094310




                1,094310

























                    0














                    The link provided in the question refers to this ConfigMap for the prometheus configuration. It that ConfigMap is used then prometheus is already configured to scrape pods.



                    For that configuration (see relabel_configs) to have prometheus scrape the custom metrics exposed by pods at :80/data/metrics, add these annotations to the pods deployment configurations:



                    metadata:
                    annotations:
                    prometheus.io/scrape: 'true'
                    prometheus.io/path: '/data/metrics'
                    prometheus.io/port: '80'


                    See the configuration options for Kubernetes discovery in the prometheus docs (scroll down) for settings related to scraping over https and more.



                    Edit:
                    I saw Emruz Hossain's answer only after I posted mine. His answer currently lacks the prometheus.io/scrape: 'true' annotation and specified = instead of : as annotations' name/value separator which is invalid in yaml or json.






                    share|improve this answer


























                    • Thank you @apisim for pointing out limitation of my answer. I have updated it.

                      – Emruz Hossain
                      Nov 19 '18 at 10:59
















                    0














                    The link provided in the question refers to this ConfigMap for the prometheus configuration. It that ConfigMap is used then prometheus is already configured to scrape pods.



                    For that configuration (see relabel_configs) to have prometheus scrape the custom metrics exposed by pods at :80/data/metrics, add these annotations to the pods deployment configurations:



                    metadata:
                    annotations:
                    prometheus.io/scrape: 'true'
                    prometheus.io/path: '/data/metrics'
                    prometheus.io/port: '80'


                    See the configuration options for Kubernetes discovery in the prometheus docs (scroll down) for settings related to scraping over https and more.



                    Edit:
                    I saw Emruz Hossain's answer only after I posted mine. His answer currently lacks the prometheus.io/scrape: 'true' annotation and specified = instead of : as annotations' name/value separator which is invalid in yaml or json.






                    share|improve this answer


























                    • Thank you @apisim for pointing out limitation of my answer. I have updated it.

                      – Emruz Hossain
                      Nov 19 '18 at 10:59














                    0












                    0








                    0







                    The link provided in the question refers to this ConfigMap for the prometheus configuration. It that ConfigMap is used then prometheus is already configured to scrape pods.



                    For that configuration (see relabel_configs) to have prometheus scrape the custom metrics exposed by pods at :80/data/metrics, add these annotations to the pods deployment configurations:



                    metadata:
                    annotations:
                    prometheus.io/scrape: 'true'
                    prometheus.io/path: '/data/metrics'
                    prometheus.io/port: '80'


                    See the configuration options for Kubernetes discovery in the prometheus docs (scroll down) for settings related to scraping over https and more.



                    Edit:
                    I saw Emruz Hossain's answer only after I posted mine. His answer currently lacks the prometheus.io/scrape: 'true' annotation and specified = instead of : as annotations' name/value separator which is invalid in yaml or json.






                    share|improve this answer















                    The link provided in the question refers to this ConfigMap for the prometheus configuration. It that ConfigMap is used then prometheus is already configured to scrape pods.



                    For that configuration (see relabel_configs) to have prometheus scrape the custom metrics exposed by pods at :80/data/metrics, add these annotations to the pods deployment configurations:



                    metadata:
                    annotations:
                    prometheus.io/scrape: 'true'
                    prometheus.io/path: '/data/metrics'
                    prometheus.io/port: '80'


                    See the configuration options for Kubernetes discovery in the prometheus docs (scroll down) for settings related to scraping over https and more.



                    Edit:
                    I saw Emruz Hossain's answer only after I posted mine. His answer currently lacks the prometheus.io/scrape: 'true' annotation and specified = instead of : as annotations' name/value separator which is invalid in yaml or json.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 19 '18 at 4:31

























                    answered Nov 19 '18 at 4:22









                    apisimapisim

                    4826




                    4826













                    • Thank you @apisim for pointing out limitation of my answer. I have updated it.

                      – Emruz Hossain
                      Nov 19 '18 at 10:59



















                    • Thank you @apisim for pointing out limitation of my answer. I have updated it.

                      – Emruz Hossain
                      Nov 19 '18 at 10:59

















                    Thank you @apisim for pointing out limitation of my answer. I have updated it.

                    – Emruz Hossain
                    Nov 19 '18 at 10:59





                    Thank you @apisim for pointing out limitation of my answer. I have updated it.

                    – Emruz Hossain
                    Nov 19 '18 at 10:59


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365191%2fmonitor-custom-kubernetes-pod-metrics-using-prometheus%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to pass form data using jquery Ajax to insert data in database?

                    National Museum of Racing and Hall of Fame

                    Guess what letter conforming each word