CloudNativeJS / appmetrics-prometheus

Module for providing a /metrics endpoint using data from appmetrics for use with Prometheus
Other
63 stars 16 forks source link

Making endpoint configurable #2

Open abhay40711cs opened 7 years ago

abhay40711cs commented 7 years ago

Currently, the endpoints are by default /metrices , if possible can we change the endpoint configurable in order to have the flexibility to use existing default metrics (wrappers for prom-client)

tobespc commented 7 years ago

@abhay40711cs yes, we can look at adding this

james-wallis commented 7 years ago

@abhay40711cs Hi, I have been looking into adding the configurable endpoint feature into Prometheus.

IMO we should add an option to change the endpoint which by default is /metrics. In this way you would be able to change the endpoint by using the following code when you require appmetrics-prometheus:

var options = {
    endpoint: '/yourMetricEndpoint'
};
require('appmetrics-prometheus').attach(options);

If you do decide to add a custom endpoint you will need to tell Prometheus to scrape the new endpoint instead of /metrics. This can be achieved by adding metrics_path: '/yourMetricEndpoint' to the prometheus.yml file.

Using our example on the readme, the prometheus.yml file would look like:

global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.
  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    monitor: 'codelab-monitor'

# A scrape configuration:
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'YOUR JOB NAME'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    # Override the metrics path to scrape 
    metrics_path: '/yourMetricEndpoint'

    static_configs:
      - targets: ['IPADDRESS:PORT', 'IPADDRESS:PORT']