title: Custom metric is not exposed in prometheus
body: <p>I'm writing a Go application and I need to log some custom metrics using Prometheus. I have a local instance of Prometheus and this is my prometheus.yml file:</p>
  <pre><code>scrape_configs:
  - job_name: myapp
    scrape_interval: 10s
    static_configs:
    - targets:
      - localhost:2112
  </code></pre>
  <p>And this is my Go code:</p>
  <pre><code>package main
  
  import (
      &quot;github.com/prometheus/client_golang/prometheus&quot;
      &quot;github.com/prometheus/client_golang/prometheus/promauto&quot;
      &quot;github.com/prometheus/client_golang/prometheus/promhttp&quot;
  
      &quot;net/http&quot;
      &quot;time&quot;
  )
  
  func recordMetrics() {
      go func() {
          for {
              opsProcessed.Inc()
              time.Sleep(2 * time.Second)
  
          }
      }()
  }
  
  var (
      opsProcessed = promauto.NewCounter(prometheus.CounterOpts{
          Name: &quot;myapp_processed_ops_total&quot;,
          Help: &quot;The total number of processed events&quot;,
      })
  )
  
  func main() {
      recordMetrics()
  
      http.Handle(&quot;/metrics&quot;, promhttp.Handler())
      http.ListenAndServe(&quot;:2112&quot;, nil)
  }
  </code></pre>
  <p>As you see, I have defined a custom metric called opsProcessed which its name is myapp_processed_ops_total. I can see myapp_processed_ops_total at http://localhost:2112/metrics. However, I can not see this metric at my Prometheus instance.
  <a href="https://i.stack.imgur.com/0MIiq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0MIiq.png" alt="enter image description here" /></a></p>
  <p>What is the problem?
  I think my server is scraped since I can see other metrics like scrape_duration_seconds in Prometheus:</p>
  <p><a href="https://i.stack.imgur.com/d3Vkh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/d3Vkh.png" alt="enter image description here" /></a></p>
  <p>Maybe The problem is from my docker-compose file for prometheus. This is the target page in prometheus UI:</p>
  <p><a href="https://i.stack.imgur.com/pxkld.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pxkld.png" alt="enter image description here" /></a></p>
  <p>And this is my docker-compose file:</p>
  <pre><code>version: '2.1'
  
  networks:
    monitor-net:
      driver: bridge
  
  volumes:
      prometheus_data: {}
      grafana_data: {}
  
  services:
  
    prometheus:
      image: prom/prometheus:v2.15.2
      container_name: prometheus1
      volumes:
        - ./prometheus:/etc/prometheus
        - prometheus_data:/prometheus
      command:
        - '--config.file=/etc/prometheus/prometheus.yml'
        - '--storage.tsdb.path=/prometheus'
        - '--web.console.libraries=/etc/prometheus/console_libraries'
        - '--web.console.templates=/etc/prometheus/consoles'
        - '--storage.tsdb.retention.time=200h'
        - '--web.enable-lifecycle'
      restart: unless-stopped
      expose:
        - 9090
      ports:
        - &quot;9090:9090&quot;
      networks:
        - monitor-net
      labels:
        org.label-schema.group: &quot;monitoring&quot;
  
    grafana:
      image: grafana/grafana:6.5.3
      container_name: grafana1
      volumes:
        - grafana_data:/var/lib/grafana
        - ./grafana/provisioning:/etc/grafana/provisioning
      environment:
        - GF_SECURITY_ADMIN_USER=${ADMIN_USER:-admin}
        - GF_SECURITY_ADMIN_PASSWORD=${ADMIN_PASSWORD:-admin}
        - GF_USERS_ALLOW_SIGN_UP=false
      restart: unless-stopped
      ports:
        - &quot;3000:3000&quot;
      networks:
        - monitor-net
      labels:
        org.label-schema.group: &quot;monitoring&quot;
  </code></pre>