Skip to content

Commit

Permalink
fix issue #17 & tag is_slave bug
Browse files Browse the repository at this point in the history
  • Loading branch information
martianzhang committed Aug 8, 2018
1 parent a0f2594 commit 3668cd8
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -13,5 +13,7 @@ innodb_mymon.*
process_mymon.*
fixtures/innodb_mymon.*
fixtures/process_mymon.*
*push_metric.txt
coverage.*
version.go
release/.*
34 changes: 29 additions & 5 deletions Makefile
Expand Up @@ -21,10 +21,12 @@ fmt:
# Run all test cases
.PHONY: test
test:
go test ./...
go test `go list ./... | grep -Ev '/fixtures|/vendor/'`

.PHONY: cover
cover:
go test -coverpkg=./... -coverprofile=coverage.data ./... | column -t
go test `go list ./... | grep -Ev '/fixtures|/vendor/'` \
-coverpkg=./... -coverprofile=coverage.data ./... | column -t
go tool cover -html=coverage.data -o coverage.html
go tool cover -func=coverage.data -o coverage.txt
@tail -n 1 coverage.txt | awk '{sub(/%/, "", $$NF); \
Expand Down Expand Up @@ -52,19 +54,39 @@ clean:
$(info rm -f ${BINARY})
@if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi
@rm -f coverage.* innodb_mymon.* ./fixtures/innodb_mymon.* ./fixtures/process_mymon.* ./fixtures/*.log
@for GOOS in darwin linux windows; do \
for GOARCH in 386 amd64; do \
rm -f ./release/${BINARY}.$${GOOS}-$${GOARCH} ;\
done ;\
done
@find . -name "innodb_*" -delete
@find . -name "process_*" -delete
@find . -name "*.log" -delete
@find . -name "push_metric.txt" -delete
@docker stop mymon-master 2>/dev/null || true
@docker stop mymon-slave 2>/dev/null || true
@kill -9 `lsof -ti tcp:1988` 2>/dev/null || true

.PHONY: lint
lint:
gometalinter.v1 --config metalinter.json ./...

.PHONY: docker
docker:
.PHONY: release
release:
@echo "\033[92mCross platform building for release ...\033[0m"
@for GOOS in darwin linux windows; do \
for GOARCH in 386 amd64; do \
GOOS=$${GOOS} GOARCH=$${GOARCH} go build -v -o ./release/${BINARY}.$${GOOS}-$${GOARCH} 2>/dev/null ; \
done ; \
done

.PHONY: test_env
test_env:
@echo "\033[92mBuild mysql test enviorment\033[0m"
@docker stop mymon-master 2>/dev/null || true
@docker stop mymon-slave 2>/dev/null || true
@kill -9 `lsof -ti tcp:1988` 2>/dev/null || true

@docker run --name mymon-master --rm -d \
-e MYSQL_ROOT_PASSWORD=1tIsB1g3rt \
-e MYSQL_DATABASE=mysql \
Expand All @@ -91,7 +113,9 @@ docker:
printf '.' ; sleep 1 ; done ; echo '.'
@echo "mysql slave environment is ready!"

@echo "begin to set falcon push environment: "
go run fixtures/push_mock.go &

.PHONY: daily
daily: fmt docker test cover lint clean
daily: fmt test_env test cover lint clean
@echo "\033[93mdaily build successed! \033[m"
9 changes: 7 additions & 2 deletions main.go
Expand Up @@ -106,7 +106,6 @@ func fetchData(conf *common.Config, db mysql.Conn) (err error) {
if err != nil {
return
}
Tag = GetTag(conf)

// SHOW XXX Metric
var data []*MetaData
Expand All @@ -117,6 +116,8 @@ func fetchData(conf *common.Config, db mysql.Conn) (err error) {
return
}

Tag = GetTag(conf)

globalStatus, err := ShowGlobalStatus(conf, db)
if err != nil {
return
Expand Down Expand Up @@ -145,7 +146,11 @@ func fetchData(conf *common.Config, db mysql.Conn) (err error) {

// Send Data to falcon-agent
msg, err := SendData(conf, data)
Log.Info("Send response %s:%d - %s", conf.DataBase.Host, conf.DataBase.Port, string(msg))
if err != nil {
Log.Error("Send response %s:%d - %s", conf.DataBase.Host, conf.DataBase.Port, string(msg))
} else {
Log.Info("Send response %s:%d - %s", conf.DataBase.Host, conf.DataBase.Port, string(msg))
}

err = ShowProcesslist(conf, db)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion metalinter.json
Expand Up @@ -19,7 +19,7 @@
],
"Exclude": [
".*permissions.*",
"shadows declaration at show.go:98"
"shadows declaration at .*show.go:98"
],
"Deadline": "2m"
}
49 changes: 25 additions & 24 deletions metric.go
Expand Up @@ -25,30 +25,31 @@ import (

//DataType all variables should be monitor
var DataType = map[string]string{
"Innodb_buffer_pool_reads": DeltaPs,
"Innodb_buffer_pool_read_requests": DeltaPs,
"Innodb_compress_time": DeltaPs,
"Innodb_data_fsyncs": DeltaPs,
"Innodb_data_read": DeltaPs,
"Innodb_data_reads": DeltaPs,
"Innodb_data_writes": DeltaPs,
"Innodb_data_written": DeltaPs,
"Innodb_last_checkpoint_at": DeltaPs,
"Innodb_log_flushed_up_to": DeltaPs,
"Innodb_log_sequence_number": DeltaPs,
"Innodb_mutex_os_waits": DeltaPs,
"Innodb_mutex_spin_rounds": DeltaPs,
"Innodb_mutex_spin_waits": DeltaPs,
"Innodb_pages_flushed_up_to": DeltaPs,
"Innodb_rows_deleted": DeltaPs,
"Innodb_rows_inserted": DeltaPs,
"Innodb_rows_locked": DeltaPs,
"Innodb_rows_modified": DeltaPs,
"Innodb_rows_read": DeltaPs,
"Innodb_rows_updated": DeltaPs,
"Innodb_row_lock_time": DeltaPs,
"Innodb_row_lock_waits": DeltaPs,
"Innodb_uncompress_time": DeltaPs,
"Innodb_buffer_pool_reads": DeltaPs,
"Innodb_buffer_pool_read_requests": DeltaPs,
"Innodb_buffer_pool_write_requests": DeltaPs,
"Innodb_compress_time": DeltaPs,
"Innodb_data_fsyncs": DeltaPs,
"Innodb_data_read": DeltaPs,
"Innodb_data_reads": DeltaPs,
"Innodb_data_writes": DeltaPs,
"Innodb_data_written": DeltaPs,
"Innodb_last_checkpoint_at": DeltaPs,
"Innodb_log_flushed_up_to": DeltaPs,
"Innodb_log_sequence_number": DeltaPs,
"Innodb_mutex_os_waits": DeltaPs,
"Innodb_mutex_spin_rounds": DeltaPs,
"Innodb_mutex_spin_waits": DeltaPs,
"Innodb_pages_flushed_up_to": DeltaPs,
"Innodb_rows_deleted": DeltaPs,
"Innodb_rows_inserted": DeltaPs,
"Innodb_rows_locked": DeltaPs,
"Innodb_rows_modified": DeltaPs,
"Innodb_rows_read": DeltaPs,
"Innodb_rows_updated": DeltaPs,
"Innodb_row_lock_time": DeltaPs,
"Innodb_row_lock_waits": DeltaPs,
"Innodb_uncompress_time": DeltaPs,

"Binlog_event_count": DeltaPs,
"Binlog_number": DeltaPs,
Expand Down
2 changes: 1 addition & 1 deletion senddata.go
Expand Up @@ -37,7 +37,7 @@ func SendData(conf *common.Config, data []*MetaData) ([]byte, error) {
}
Log.Info("Send to %s, size: %d", conf.Base.FalconClient, len(data))
for _, m := range data {
Log.Info("%s", m)
Log.Info("%v", m)
}

res, err := http.Post(conf.Base.FalconClient, "Content-Type: application/json", bytes.NewBuffer(js))
Expand Down

0 comments on commit 3668cd8

Please sign in to comment.