Exposing docker-composed service to Prometheus
When playing around, I use docker-compose to join the pieces together. Here’s how you can configure Prometheus to scrape metrics from a composed (and possibly scaled) service:
scrape_configs:
  - job_name: 'prometheus'              # scrape self
    static_configs:
      - targets: ['127.0.0.1:9090']
  - job_name: 'some-composed-services'  # this will end up in the 'job' tag
    metrics_path: '/prometheus'         # path to the actual endpoint
    scrape_interval: 5s
    dns_sd_configs:
      - names:
          - app                         # app is the service name as given in the compose file
        type: 'A'                       # yup, that's an A record - hop onto composed container, dig <service-name> and see it
        port: 8081                      # the port on which the metrics endpoint is exposed
    relabel_configs:                    # this relabel config will add an 'application' tag with value of the domain name
      - source_labels: ['__meta_dns_name']
        target_label: application
Handy when figuring what to expose and how to visualize. Later helps when doing all kinds of experiments with the monitored service.
A full example with a Go service and a Grafana instance to visualize the metrics can be found here.
make compose to spawn it, Prometheus on localhost:9090, Grafana on localhost:3000