Deploy Grafana & Prometheus metrcs tracking system for your Go program

Deploy Grafana & Prometheus metrcs tracking system for your Go program - 1

Step 1: integrate prometheus

for let prometheus get metrics from go program, we need prometheus/client_golang to collect some informations

import (
    "github.com/prometheus/client_golang/prometheus/promhttp"
    "net/http"
)

func main() {
    // ...
    http.Handle("/metrics", promhttp.Handler())
    http.ListenAndServe(":9200", nil)
}

Step 2: Set up Prometheus Server

  1. configuration for Prometheus Server
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
scrape_configs:
  - job_name: 'yourprogramname'
    metrics_path: "/metrics"
    static_configs:
      - targets: ['[yourhostaddress]:9200']
  1. Start up Prometheus docker container(otherwise you can deploy on your host side, just make sure configurations are all good, up to you)
> docker run \
-p 9090:9090 \
-v [your prometheus config file location]:/etc/prometheus/prometheus.yml \
-d prom/prometheus

Step 3: Set up Grafana

  1. start up Grafana docker container
> docker run -d --name=grafana -p 3000:3000 grafana/grafana
  1. access your grafana web ui, localhost:3000
  2. Configuration -> Add data source -> prometheus -> set url to http://localhost:9090 -> set access to browser -> save & test
  3. Dashboard -> import -> id: 240 -> set prometheus to the data source you just set

Enjoy!

7 thoughts on “Deploy Grafana & Prometheus metrcs tracking system for your Go program”

  1. 专制是腐败的土壤。没有政党竞争、没有真正的选举、没有三权分立与制衡、没有独立的司法、没有独立的媒体、没有独立的民间社会,这必然导致全局性、制度性腐败。就是说,只能我反腐败,不能你、民间或者是其他的别人做。大家都是一条线上的蚂蚱——中南海这座政治大庙已经没有谁干净了。如果真的宪政民主了,不但没机会腐败,已经腐败的还要受审判和清算,人财两空、身败名裂。反腐败往往是跟权力斗争有关。老百姓不应该对中共反腐报有任何希望,跟老百姓无关。抛弃其党退出其组织,才是走向宪政民主的前提。

Leave a Reply

Your email address will not be published. Required fields are marked *