Skip to content

Commit

Permalink
prefix Tile38 metrics with tile38_ and correctly parse true and false…
Browse files Browse the repository at this point in the history
… as 1 and 0 (#304)
  • Loading branch information
oliver006 authored Aug 20, 2019
1 parent 863ddc9 commit 09861cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
42 changes: 20 additions & 22 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,23 +220,22 @@ func NewRedisExporter(redisURI string, opts ExporterOptions) (*Exporter, error)

// # Tile38
// based on https://tile38.com/commands/server/
"aof_size": "aof_size_bytes",
"avg_item_size": "avg_item_size_bytes",
"cpus": "cpus_total",
"heap_released": "heap_released_bytes",
"heap_size": "heap_size_bytes",
"http_transport": "http_transport",
"in_memory_size": "in_memory_size_bytes",
"max_heap_size": "max_heap_size_bytes",
"mem_alloc": "mem_alloc_bytes",
"num_collections": "num_collections_total",
"num_hooks": "num_hooks_total",
"num_objects": "num_objects_total",
"num_points": "num_points_total",
"pointer_size": "pointer_size_bytes",
"read_only": "read_only",
"threads": "threads_total",
"version": "version", // since tile38 version 1.14.1
"tile38_aof_size": "tile38_aof_size_bytes",
"tile38_avg_item_size": "tile38_avg_item_size_bytes",
"tile38_cpus": "tile38_cpus_total",
"tile38_heap_released": "tile38_heap_released_bytes",
"tile38_heap_size": "tile38_heap_size_bytes",
"tile38_http_transport": "tile38_http_transport",
"tile38_in_memory_size": "tile38_in_memory_size_bytes",
"tile38_max_heap_size": "tile38_max_heap_size_bytes",
"tile38_mem_alloc": "tile38_mem_alloc_bytes",
"tile38_num_collections": "tile38_num_collections_total",
"tile38_num_hooks": "tile38_num_hooks_total",
"tile38_num_objects": "tile38_num_objects_total",
"tile38_num_points": "tile38_num_points_total",
"tile38_pointer_size": "tile38_pointer_size_bytes",
"tile38_read_only": "tile38_read_only",
"tile38_threads": "tile38_threads_total",
},

metricMapCounters: map[string]string{
Expand Down Expand Up @@ -846,10 +845,9 @@ func (e *Exporter) extractTile38Metrics(ch chan<- prometheus.Metric, c redis.Con
}

for i := 0; i < len(info); i += 2 {
log.Debugf("tile38: %s:%s", info[i], info[i+1])

fieldKey := info[i]
fieldKey := "tile38_" + info[i]
fieldValue := info[i+1]
log.Debugf("tile38 key:%s val:%s", fieldKey, fieldValue)

if !e.includeMetric(fieldKey) {
continue
Expand Down Expand Up @@ -887,10 +885,10 @@ func (e *Exporter) parseAndRegisterConstMetric(ch chan<- prometheus.Metric, fiel

switch fieldValue {

case "ok":
case "ok", "true":
val = 1

case "err", "fail":
case "err", "fail", "false":
val = 0

default:
Expand Down
18 changes: 7 additions & 11 deletions exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,18 @@ func TestTile38(t *testing.T) {
}()

found := false
want := "tile38_threads_total"
for m := range chM {
if strings.Contains(m.Desc().String(), "cpus_total") {
fmt.Println(m.Desc().String())
if strings.Contains(m.Desc().String(), want) {
found = true
break
}
}

if isTile38 && !found {
t.Errorf("cpus_total was *not* found in tile38 metrics but expected")
t.Errorf("%s was *not* found in tile38 metrics but expected", want)
} else if !isTile38 && found {
t.Errorf("cpus_total was *found* in tile38 metrics but *not* expected")
t.Errorf("%s was *found* in tile38 metrics but *not* expected", want)
}
}
}
Expand All @@ -253,7 +254,6 @@ func TestExportClientList(t *testing.T) {
for m := range chM {
if strings.Contains(m.Desc().String(), "connected_clients_details") {
found = true
break
}
}

Expand Down Expand Up @@ -812,7 +812,6 @@ func TestKeySizeList(t *testing.T) {
for m := range chM {
if strings.Contains(m.Desc().String(), "test_key_size") {
found = true
break
}
}

Expand Down Expand Up @@ -908,12 +907,9 @@ func TestCommandStats(t *testing.T) {
func TestIncludeSystemMemoryMetric(t *testing.T) {
for _, inc := range []bool{false, true} {
r := prometheus.NewRegistry()
prometheus.DefaultGatherer = r
prometheus.DefaultRegisterer = r

ts := httptest.NewServer(promhttp.Handler())
ts := httptest.NewServer(promhttp.HandlerFor(r, promhttp.HandlerOpts{}))
e, _ := NewRedisExporter(os.Getenv("TEST_REDIS_URI"), ExporterOptions{Namespace: "test", InclSystemMetrics: inc})
prometheus.Register(e)
r.Register(e)

body := downloadURL(t, ts.URL+"/metrics")
if inc && !strings.Contains(body, "total_system_memory_bytes") {
Expand Down

0 comments on commit 09861cb

Please sign in to comment.