forked from ClickHouse/clickhouse_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ClickHouse#18 from AlekSi/promu-and-travis
Use Docker Compose in Travis CI
- Loading branch information
Showing
11 changed files
with
71 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea/ | ||
.build/ | ||
clickhouse_exporter | ||
.idea | ||
.build | ||
coverage.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ build: | |
prefix: . | ||
binaries: | ||
- name: clickhouse_exporter | ||
path: . | ||
path: . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
all: build test | ||
|
||
init: | ||
go get -u github.com/prometheus/promu | ||
go get -u github.com/AlekSi/gocoverutil | ||
|
||
build: | ||
go install -v | ||
promu build | ||
|
||
test: | ||
go test -v -race | ||
gocoverutil -coverprofile=coverage.txt test -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.1 | ||
0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
const ( | ||
clickhouseMetrics = `Query 1 | ||
Merge 0 | ||
ReplicatedFetch 0 | ||
ReplicatedSend 0 | ||
ReplicatedChecks 0 | ||
BackgroundPoolTask 0 | ||
DiskSpaceReservedForMerge 0 | ||
DistributedSend 0 | ||
QueryPreempted 0 | ||
TCPConnection 0 | ||
HTTPConnection 1 | ||
InterserverConnection 0 | ||
OpenFileForRead 0 | ||
OpenFileForWrite 0 | ||
Read 1 | ||
Write 0 | ||
SendExternalTables 0 | ||
QueryThread 0 | ||
ReadonlyReplica 0 | ||
MemoryTracking 8704 | ||
` | ||
metricCount = 20 | ||
) | ||
func TestScrape(t *testing.T) { | ||
url, err := url.Parse("http://127.0.0.1:8123/") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
exporter := NewExporter(*url) | ||
|
||
func TestClickhouseStatus(t *testing.T) { | ||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Write([]byte(clickhouseMetrics)) | ||
t.Run("Describe", func(t *testing.T) { | ||
ch := make(chan *prometheus.Desc) | ||
go func() { | ||
exporter.Describe(ch) | ||
close(ch) | ||
}() | ||
|
||
for range ch { | ||
} | ||
}) | ||
server := httptest.NewServer(handler) | ||
|
||
url, _ := url.Parse(server.URL) | ||
e := NewExporter(*url) | ||
ch := make(chan prometheus.Metric) | ||
t.Run("Collect", func(t *testing.T) { | ||
ch := make(chan prometheus.Metric) | ||
var err error | ||
go func() { | ||
err = exporter.collect(ch) | ||
close(ch) | ||
}() | ||
|
||
go func() { | ||
defer close(ch) | ||
e.Collect(ch) | ||
}() | ||
// because asks 3 tables | ||
for i := 1; i <= 3*metricCount; i++ { | ||
m := <-ch | ||
if m == nil { | ||
t.Error("expected metric but got nil") | ||
for range ch { | ||
} | ||
} | ||
if <-ch != nil { | ||
t.Error("expected closed channel") | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,9 @@ | ||
--- | ||
version: '3' | ||
services: | ||
prometheus: | ||
image: prom/prometheus:v2.0.0-beta.2 | ||
ports: | ||
- 127.0.0.1:9090:9090 | ||
network_mode: host | ||
volumes: | ||
- ./docker/prometheus:/etc/prometheus | ||
|
||
clickhouse: | ||
image: yandex/clickhouse-server | ||
ports: | ||
- 127.0.0.1:8123:8123 | ||
- 127.0.0.1:9000:9000 | ||
- 127.0.0.1:9009:9009 | ||
network_mode: host | ||
# volumes: | ||
# - ./config.xml:/etc/clickhouse-server/config.xml | ||
# - ./users.xml:/etc/clickhouse-server/users.xml | ||
|
||
clickhouse_exporter: | ||
image: f1yegor/clickhouse-exporter | ||
ports: | ||
- 127.0.0.1:9116:9116 | ||
network_mode: host | ||
command: -scrape_uri=http://127.0.0.1:8123/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters