-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor status with prometheus (#340)
* refactor status with prometheus
- Loading branch information
1 parent
7b48b8c
commit d4e8812
Showing
10 changed files
with
77 additions
and
94 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
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,9 +1,13 @@ | ||
module github.com/siddontang/go-mysql-elasticsearch | ||
|
||
go 1.12 | ||
|
||
require ( | ||
github.com/BurntSushi/toml v0.3.1 | ||
github.com/juju/errors v0.0.0-20190207033735-e65537c515d7 | ||
github.com/pingcap/check v0.0.0-20190102082844-67f458068fc8 | ||
github.com/prometheus/client_golang v0.9.3 | ||
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726 | ||
github.com/siddontang/go-log v0.0.0-20180807004314-8d05993dda07 | ||
github.com/siddontang/go-mysql v0.0.0-20190303113352-670f74e8daf5 | ||
github.com/siddontang/go-log v0.0.0-20190221022429-1e957dd83bed | ||
github.com/siddontang/go-mysql v0.0.0-20190524062908-de6c3a84bcbe | ||
) |
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,54 @@ | ||
package river | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
) | ||
|
||
var ( | ||
esInsertNum = promauto.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "mysql2es_inserted_num", | ||
Help: "The number of docs inserted to elasticsearch", | ||
}, []string{"index"}, | ||
) | ||
esUpdateNum = promauto.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "mysql2es_updated_num", | ||
Help: "The number of docs updated to elasticsearch", | ||
}, []string{"index"}, | ||
) | ||
esDeleteNum = promauto.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "mysql2es_deleted_num", | ||
Help: "The number of docs deleted from elasticsearch", | ||
}, []string{"index"}, | ||
) | ||
canalSyncState = promauto.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "mysql2es_canal_state", | ||
Help: "The canal slave running state: 0=stopped, 1=ok", | ||
}, | ||
) | ||
canalDelay = promauto.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "mysql2es_canal_delay", | ||
Help: "The canal slave lag", | ||
}, | ||
) | ||
) | ||
|
||
func (r *River) collectMetrics() { | ||
for range time.Tick(10 * time.Second) { | ||
canalDelay.Set(float64(r.canal.GetDelay())) | ||
} | ||
} | ||
|
||
func InitStatus(addr string, path string) { | ||
http.Handle(path, promhttp.Handler()) | ||
http.ListenAndServe(addr, nil) | ||
} |
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
This file was deleted.
Oops, something went wrong.
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