Skip to content

Commit

Permalink
Testing build with prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
PatMis16 committed Apr 22, 2021
1 parent 000a4a4 commit 2b221e7
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 65 deletions.
98 changes: 49 additions & 49 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ jobs:
run: go get gopkg.in/yaml.v2
- name: Install github.com/patrickmn/go-cache
run: go get github.com/patrickmn/go-cache
#- name: Install github.com/prometheus/client_golang/prometheus
# run: go get github.com/prometheus/client_golang/prometheus
#- name: Install github.com/prometheus/client_golang/prometheus/promauto
# run: go get github.com/prometheus/client_golang/prometheus/promauto
#- name: Install github.com/prometheus/client_golang/prometheus/promhttp
# run: go get github.com/prometheus/client_golang/prometheus/promhttp
- name: Install github.com/prometheus/client_golang/prometheus
run: go get github.com/prometheus/client_golang/prometheus
- name: Install github.com/prometheus/client_golang/prometheus/promauto
run: go get github.com/prometheus/client_golang/prometheus/promauto
- name: Install github.com/prometheus/client_golang/prometheus/promhttp
run: go get github.com/prometheus/client_golang/prometheus/promhttp
- name: compile and release
uses: ngs/go-release.action@v1.0.2
uses: ngs/go-release.action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: "386"
Expand All @@ -43,14 +43,14 @@ jobs:
run: go get gopkg.in/yaml.v2
- name: Install github.com/patrickmn/go-cache
run: go get github.com/patrickmn/go-cache
#- name: Install github.com/prometheus/client_golang/prometheus
# run: go get github.com/prometheus/client_golang/prometheus
#- name: Install github.com/prometheus/client_golang/prometheus/promauto
# run: go get github.com/prometheus/client_golang/prometheus/promauto
#- name: Install github.com/prometheus/client_golang/prometheus/promhttp
# run: go get github.com/prometheus/client_golang/prometheus/promhttp
- name: Install github.com/prometheus/client_golang/prometheus
run: go get github.com/prometheus/client_golang/prometheus
- name: Install github.com/prometheus/client_golang/prometheus/promauto
run: go get github.com/prometheus/client_golang/prometheus/promauto
- name: Install github.com/prometheus/client_golang/prometheus/promhttp
run: go get github.com/prometheus/client_golang/prometheus/promhttp
- name: compile and release
uses: ngs/go-release.action@v1.0.2
uses: ngs/go-release.action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: amd64
Expand All @@ -67,14 +67,14 @@ jobs:
run: go get gopkg.in/yaml.v2
- name: Install github.com/patrickmn/go-cache
run: go get github.com/patrickmn/go-cache
#- name: Install github.com/prometheus/client_golang/prometheus
# run: go get github.com/prometheus/client_golang/prometheus
#- name: Install github.com/prometheus/client_golang/prometheus/promauto
# run: go get github.com/prometheus/client_golang/prometheus/promauto
#- name: Install github.com/prometheus/client_golang/prometheus/promhttp
# run: go get github.com/prometheus/client_golang/prometheus/promhttp
- name: Install github.com/prometheus/client_golang/prometheus
run: go get github.com/prometheus/client_golang/prometheus
- name: Install github.com/prometheus/client_golang/prometheus/promauto
run: go get github.com/prometheus/client_golang/prometheus/promauto
- name: Install github.com/prometheus/client_golang/prometheus/promhttp
run: go get github.com/prometheus/client_golang/prometheus/promhttp
- name: compile and release
uses: ngs/go-release.action@v1.0.2
uses: ngs/go-release.action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: "arm"
Expand All @@ -91,14 +91,14 @@ jobs:
run: go get gopkg.in/yaml.v2
- name: Install github.com/patrickmn/go-cache
run: go get github.com/patrickmn/go-cache
#- name: Install github.com/prometheus/client_golang/prometheus
# run: go get github.com/prometheus/client_golang/prometheus
#- name: Install github.com/prometheus/client_golang/prometheus/promauto
# run: go get github.com/prometheus/client_golang/prometheus/promauto
#- name: Install github.com/prometheus/client_golang/prometheus/promhttp
# run: go get github.com/prometheus/client_golang/prometheus/promhttp
- name: Install github.com/prometheus/client_golang/prometheus
run: go get github.com/prometheus/client_golang/prometheus
- name: Install github.com/prometheus/client_golang/prometheus/promauto
run: go get github.com/prometheus/client_golang/prometheus/promauto
- name: Install github.com/prometheus/client_golang/prometheus/promhttp
run: go get github.com/prometheus/client_golang/prometheus/promhttp
- name: compile and release
uses: ngs/go-release.action@v1.0.2
uses: ngs/go-release.action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: arm64
Expand All @@ -115,14 +115,14 @@ jobs:
run: go get gopkg.in/yaml.v2
- name: Install github.com/patrickmn/go-cache
run: go get github.com/patrickmn/go-cache
#- name: Install github.com/prometheus/client_golang/prometheus
# run: go get github.com/prometheus/client_golang/prometheus
#- name: Install github.com/prometheus/client_golang/prometheus/promauto
# run: go get github.com/prometheus/client_golang/prometheus/promauto
#- name: Install github.com/prometheus/client_golang/prometheus/promhttp
# run: go get github.com/prometheus/client_golang/prometheus/promhttp
- name: Install github.com/prometheus/client_golang/prometheus
run: go get github.com/prometheus/client_golang/prometheus
- name: Install github.com/prometheus/client_golang/prometheus/promauto
run: go get github.com/prometheus/client_golang/prometheus/promauto
- name: Install github.com/prometheus/client_golang/prometheus/promhttp
run: go get github.com/prometheus/client_golang/prometheus/promhttp
- name: compile and release
uses: ngs/go-release.action@v1.0.2
uses: ngs/go-release.action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: amd64
Expand All @@ -139,14 +139,14 @@ jobs:
run: go get gopkg.in/yaml.v2
- name: Install github.com/patrickmn/go-cache
run: go get github.com/patrickmn/go-cache
#- name: Install github.com/prometheus/client_golang/prometheus
# run: go get github.com/prometheus/client_golang/prometheus
#- name: Install github.com/prometheus/client_golang/prometheus/promauto
# run: go get github.com/prometheus/client_golang/prometheus/promauto
#- name: Install github.com/prometheus/client_golang/prometheus/promhttp
# run: go get github.com/prometheus/client_golang/prometheus/promhttp
- name: Install github.com/prometheus/client_golang/prometheus
run: go get github.com/prometheus/client_golang/prometheus
- name: Install github.com/prometheus/client_golang/prometheus/promauto
run: go get github.com/prometheus/client_golang/prometheus/promauto
- name: Install github.com/prometheus/client_golang/prometheus/promhttp
run: go get github.com/prometheus/client_golang/prometheus/promhttp
- name: compile and release
uses: ngs/go-release.action@v1.0.2
uses: ngs/go-release.action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: "386"
Expand All @@ -163,14 +163,14 @@ jobs:
run: go get gopkg.in/yaml.v2
- name: Install github.com/patrickmn/go-cache
run: go get github.com/patrickmn/go-cache
#- name: Install github.com/prometheus/client_golang/prometheus
# run: go get github.com/prometheus/client_golang/prometheus
#- name: Install github.com/prometheus/client_golang/prometheus/promauto
# run: go get github.com/prometheus/client_golang/prometheus/promauto
#- name: Install github.com/prometheus/client_golang/prometheus/promhttp
# run: go get github.com/prometheus/client_golang/prometheus/promhttp
- name: Install github.com/prometheus/client_golang/prometheus
run: go get github.com/prometheus/client_golang/prometheus
- name: Install github.com/prometheus/client_golang/prometheus/promauto
run: go get github.com/prometheus/client_golang/prometheus/promauto
- name: Install github.com/prometheus/client_golang/prometheus/promhttp
run: go get github.com/prometheus/client_golang/prometheus/promhttp
- name: compile and release
uses: ngs/go-release.action@v1.0.2
uses: ngs/go-release.action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GOARCH: amd64
Expand Down
33 changes: 17 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ import (
"encoding/json"
"flag"
"fmt"
"github.com/patrickmn/go-cache"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
"math/rand"
"net/http"
"os"
"strings"
"time"

//"github.com/prometheus/client_golang/prometheus"
//"github.com/prometheus/client_golang/prometheus/promauto"
"gopkg.in/yaml.v2"
)

type Config struct {
Expand Down Expand Up @@ -227,7 +228,7 @@ func (config Config) Run() {
fmt.Fprintf(w, "Event(s) created")
} else {
WarningLogger.Println("Failed to send event(s) to TrueSight.")
//promAlertsCache.Add(RandomString(10), events, cache.DefaultExpiration)
promAlertsCache.Add(RandomString(10), events, cache.DefaultExpiration)
http.Error(w, "Something went wrong on the server!", http.StatusInternalServerError)
}
}
Expand Down Expand Up @@ -333,7 +334,7 @@ func SendEventToTS(token string, tsimServer string, tsimPort string, tsCell stri
return eventSendState
}

/*func Heartbeat() {
func Heartbeat() {
// Heartbeat for self-monitoring
InfoLogger.Println("starting heartbeat...")
value := 0
Expand All @@ -347,7 +348,7 @@ func SendEventToTS(token string, tsimServer string, tsimPort string, tsCell stri
InfoLogger.Println("Heartbeat value in loop: ", value)
time.Sleep(1 * time.Minute)
}
}*/
}

func InitLogging(logName string) {
file, err := os.OpenFile(logName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
Expand All @@ -368,11 +369,11 @@ var (
)

// Initiate Prometheus Alerts Cache
//var promAlertsCache = cache.New(60*time.Minute, 90*time.Minute)
//var promalToTSOMHeartbeat = promauto.NewGauge(prometheus.GaugeOpts{
// Name: "prometheus_alerts_to_tsom_heartbeat",
// Help: "Prometheus Alerts to TrueSight",
//})
var promAlertsCache = cache.New(60*time.Minute, 90*time.Minute)
var promalToTSOMHeartbeat = promauto.NewGauge(prometheus.GaugeOpts{
Name: "prometheus_alerts_to_tsom_heartbeat",
Help: "Prometheus Alerts to TrueSight",
})

func main() {
// Initialize logging
Expand All @@ -394,10 +395,10 @@ func main() {
// Initialize prometheus metering
InfoLogger.Println("starting heartbeat")

//fmt.Println("starting heartbeat")
//go Heartbeat()
//http.Handle("/metrics", promhttp.Handler())
//http.ListenAndServe(":"+cfg.Server.PromMetricPort, nil)
fmt.Println("starting heartbeat")
go Heartbeat()
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":"+cfg.Server.PromMetricPort, nil)
time.Sleep(1 * time.Second)

}

0 comments on commit 2b221e7

Please sign in to comment.