2019-09-18 13:26


  • loops
  • prometheus

i have problem on "reseting" the values for gauges because "life stops" as soon http servervice is started or when i start looping my "runJob" then is server not started..

the way how i am trying to establish this:

i load all the Job-s from YAML array. i generate gauges from that, then i run loop to get some values for them. Then i register them.

And after that i start http service for prometheus.

All works perfect, until next cycle - next cycle is just not starting.

I tryed to move functions inside functions etc..

so thats my main function:

        //gets poll time from yaml (60s)
    timerCh := time.Tick(time.Duration(appConf.PollTimeSec) * time.Second)

    //loop after given time
    for range timerCh {


    //start new muxServer
    server := http.NewServeMux()
    log.Println("DEBUG: Starting server")
    server.Handle(appConf.HostPath, promhttp.Handler())

    http.ListenAndServe(":"+appConf.ListenerPort, server)

and my runJobs function basicly gets Http response codes and ads them to prometheus gauge values. -- everything is OK with that and it works very well on starting, but after i try to start it wheet sleep (as shown in main go) it just gets stuck -

Server is up and values do not change.

So i have (my optinion) two possible ways of fixing it:

  1. My "runJobs" is infinitive loop what runs after every minute

    • thats why is server not started.
    • But when i add there a if statement that on first run(cycle) should server be started, then it still gets stuck when server gets started (next loop cycle just woun't get started)
  2. And the other part, when i start the server first, then it never gets to the part where it starts runJobs()

Prefered outcome should be that:

server is started with first values, and after every minute it runs "runJobs" again.

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享