Skip to content

Commit

Permalink
applied go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinbudny committed May 4, 2018
1 parent fdbf089 commit 743c2bc
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 62 deletions.
37 changes: 18 additions & 19 deletions collector.go
Expand Up @@ -39,22 +39,22 @@ type exporter struct {

func newExporter() *exporter {
return &exporter{
up: createGauge("up", "Whether the RavenDB scrape was successful"),
workingSet: createGauge("working_set_bytes", "Process working set"),
cpuTime: createCounter("cpu_time_seconds", "CPU time"),
isLeader: createGauge("is_leader", "If 1, then node is the cluster leader, otherwise 0"),
requestCount: createCounter("request_count", "Server-wide request count"),
documentPutCount: createCounter("document_put_count", "Server-wide document puts count"),
documentPutBytes: createCounter("document_put_bytes", "Server-wide document put bytes"),
mapIndexIndexedCount: createCounter("mapindex_indexed_count", "Server-wide map index indexed count"),
mapReduceIndexMappedCount: createCounter("mapreduceindex_mapped_count", "Server-wide map-reduce index mapped count"),
mapReduceIndexReducedCount: createCounter("mapreduceindex_reduced_count", "Server-wide map-reduce index reduced count"),

databaseDocumentCount: createDatabaseGaugeVec("database_document_count", "Count of documents in a database"),
databaseIndexCount: createDatabaseGaugeVec("database_index_count", "Count of indexes in a database"),
databaseStaleIndexCount: createDatabaseGaugeVec("database_stale_index_cont", "Count of stale indexes in a database"),
databaseSize: createDatabaseGaugeVec("database_size_bytes", "Database size in bytes"),
up: createGauge("up", "Whether the RavenDB scrape was successful"),
workingSet: createGauge("working_set_bytes", "Process working set"),
cpuTime: createCounter("cpu_time_seconds", "CPU time"),
isLeader: createGauge("is_leader", "If 1, then node is the cluster leader, otherwise 0"),
requestCount: createCounter("request_count", "Server-wide request count"),
documentPutCount: createCounter("document_put_count", "Server-wide document puts count"),
documentPutBytes: createCounter("document_put_bytes", "Server-wide document put bytes"),
mapIndexIndexedCount: createCounter("mapindex_indexed_count", "Server-wide map index indexed count"),
mapReduceIndexMappedCount: createCounter("mapreduceindex_mapped_count", "Server-wide map-reduce index mapped count"),
mapReduceIndexReducedCount: createCounter("mapreduceindex_reduced_count", "Server-wide map-reduce index reduced count"),

databaseDocumentCount: createDatabaseGaugeVec("database_document_count", "Count of documents in a database"),
databaseIndexCount: createDatabaseGaugeVec("database_index_count", "Count of indexes in a database"),
databaseStaleIndexCount: createDatabaseGaugeVec("database_stale_index_cont", "Count of stale indexes in a database"),
databaseSize: createDatabaseGaugeVec("database_size_bytes", "Database size in bytes"),

databaseRequestCount: createDatabaseCounterVec("database_request_count", "Database request count"),
databaseDocumentPutCount: createDatabaseCounterVec("database_document_put_count", "Database document puts count"),
databaseDocumentPutBytes: createDatabaseCounterVec("database_document_put_bytes", "Database document put bytes"),
Expand Down Expand Up @@ -130,7 +130,7 @@ func (e *exporter) Collect(ch chan<- prometheus.Metric) {
collectPerDatabaseCounter(stats, e.databaseMapIndexIndexedCount, getDatabaseMapIndexIndexedCount, ch)
collectPerDatabaseCounter(stats, e.databaseMapReduceIndexMappedCount, getDatabaseMapReduceIndexMappedCount, ch)
collectPerDatabaseCounter(stats, e.databaseMapReduceIndexReducedCount, getDatabaseMapReduceIndexReducedCount, ch)

}
}

Expand Down Expand Up @@ -217,7 +217,7 @@ func getDatabaseStaleIndexCount(dbStats *dbStats) float64 {
count++
}
}, "Indexes")

return float64(count)
}

Expand Down Expand Up @@ -256,7 +256,6 @@ func getDatabaseMapReduceIndexReducedCount(dbStats *dbStats) float64 {
return value
}


func createGauge(name string, help string) prometheus.Gauge {
return prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Expand Down
12 changes: 6 additions & 6 deletions collector_test.go
Expand Up @@ -3,12 +3,12 @@ package main
import "testing"

func TestParseTimeSpan(t *testing.T) {

testCases := make(map[string]float64)
testCases["55.11:22:33.0444000"] = 55 * 24 * 60 * 60 + 11 * 60 * 60 + 22 * 60 + 33 + 0.0444000
testCases["55.11:22:33"] = 55 * 24 * 60 * 60 + 11 * 60 * 60 + 22 * 60 + 33
testCases["11:22:33"] = 11 * 60 * 60 + 22 * 60 + 33
testCases["55.11:22:33.0444000"] = 55*24*60*60 + 11*60*60 + 22*60 + 33 + 0.0444000
testCases["55.11:22:33"] = 55*24*60*60 + 11*60*60 + 22*60 + 33
testCases["11:22:33"] = 11*60*60 + 22*60 + 33

for testCase, expected := range testCases {
t.Run(testCase, func(t *testing.T) {
actual := timeSpanToSeconds(testCase)
Expand All @@ -17,4 +17,4 @@ func TestParseTimeSpan(t *testing.T) {
}
})
}
}
}
71 changes: 34 additions & 37 deletions ravendb_client.go
@@ -1,33 +1,33 @@
package main

import (
"fmt"
"crypto/tls"
"crypto/x509"
"fmt"
jp "github.com/buger/jsonparser"
"io/ioutil"
"net/http"
jp "github.com/buger/jsonparser"
)

var (
client http.Client
)

type stats struct {
cpu []byte
memory []byte
metrics []byte
cpu []byte
memory []byte
metrics []byte
nodeInfo []byte
dbStats []*dbStats
dbStats []*dbStats
}

type dbStats struct {
database string
database string
collectionStats []byte
metrics []byte
indexes []byte
databaseStats []byte
storage []byte
metrics []byte
indexes []byte
databaseStats []byte
storage []byte
}

func initializeClient() {
Expand Down Expand Up @@ -60,16 +60,15 @@ func initializeClient() {

}


func getStats() (*stats, error) {

databases, err := getDatabaseNames()
if err != nil {
return nil, err
}

paths := preparePaths(databases)

results := getAllPaths(paths, 16)

return organizeGetResults(results, databases)
Expand Down Expand Up @@ -141,11 +140,11 @@ func getAllPaths(paths []string, maxParallelism int) map[string]getResult {

func getWorker(paths <-chan string, results chan<- getResult) <-chan bool {
done := make(chan bool)

go func() {
for path := range paths {
result, err := get(path)
results <- getResult { path, result, err }
results <- getResult{path, result, err}
}
done <- true
}()
Expand All @@ -154,17 +153,16 @@ func getWorker(paths <-chan string, results chan<- getResult) <-chan bool {
}

type getResult struct {
path string
path string
result []byte
err error
err error
}


func get(path string) ([]byte, error) {
url := ravenDbURL + path

log.WithField("url", url).Debug("GET request to RavenDB")

response, err := client.Get(url)
if err != nil {
return nil, err
Expand All @@ -180,33 +178,32 @@ func get(path string) ([]byte, error) {
}

func organizeGetResults(results map[string]getResult, databases []string) (*stats, error) {

for _, result := range results {
if result.err != nil {
return nil, result.err
}
}
stats := stats {
cpu: results["/admin/debug/cpu/stats"].result,
memory: results["/admin/debug/memory/stats"].result,
metrics: results["/admin/metrics"].result,

stats := stats{
cpu: results["/admin/debug/cpu/stats"].result,
memory: results["/admin/debug/memory/stats"].result,
metrics: results["/admin/metrics"].result,
nodeInfo: results["/cluster/node-info"].result,
}

for _, database := range databases {
dbs := &dbStats {
database: database,
dbs := &dbStats{
database: database,
collectionStats: results[fmt.Sprintf("/databases/%s/collections/stats", database)].result,
indexes: results[fmt.Sprintf("/databases/%s/indexes", database)].result,
metrics: results[fmt.Sprintf("/databases/%s/metrics", database)].result,
databaseStats: results[fmt.Sprintf("/databases/%s/stats", database)].result,
storage: results[fmt.Sprintf("/databases/%s//debug/storage/report", database)].result,
indexes: results[fmt.Sprintf("/databases/%s/indexes", database)].result,
metrics: results[fmt.Sprintf("/databases/%s/metrics", database)].result,
databaseStats: results[fmt.Sprintf("/databases/%s/stats", database)].result,
storage: results[fmt.Sprintf("/databases/%s//debug/storage/report", database)].result,
}

stats.dbStats = append(stats.dbStats, dbs)
}

return &stats, nil
}

0 comments on commit 743c2bc

Please sign in to comment.