Skip to content

Commit

Permalink
Merge pull request #98 from percona/develop
Browse files Browse the repository at this point in the history
PMM-2203 v0.5.0
  • Loading branch information
rnovikovP authored May 24, 2018
2 parents c703533 + 8c13d69 commit 8136fdd
Show file tree
Hide file tree
Showing 1,009 changed files with 12,295 additions and 179,626 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# editor temp files
*.sw[nop]

# build artifacts
mongodb_exporter
coverage.txt
coverage_temp.txt
25 changes: 23 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,40 @@ matrix:
- go: master

env:
- MONGODB_IMAGE=mongo:3.2
- MONGODB_IMAGE=mongo:3.4
- MONGODB_IMAGE=mongo:3.6
- MONGODB_IMAGE=percona/percona-server-mongodb:3.2
- MONGODB_IMAGE=percona/percona-server-mongodb:3.4
- MONGODB_IMAGE=perconalab/percona-server-mongodb:3.6
- MONGODB_IMAGE=percona/percona-server-mongodb:3.6

services:
- docker

before_script:
# Start docker containers.
- docker-compose up -d
# Wait for MongoDB to become available.
- |
until docker-compose exec mongo mongo --quiet --eval 'db.runCommand("ping").ok' > /dev/null; do
>&2 echo "MongoDB is unavailable - sleeping"
sleep 1
done
>&2 echo "MongoDB is up"
# Display logs for debug purposes.
- docker-compose logs
# Display versions.
- docker --version
- docker-compose --version
- docker-compose up -d
- docker-compose exec mongo mongo --version

script:
# ensure that vendor/ is in sync with code and Gopkg.*
- curl https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 -L -o ~/dep && chmod +x ~/dep
- rm -fr vendor/
- ~/dep ensure -v
- git diff --exit-code

- make format build testall

after_success:
Expand All @@ -37,3 +57,4 @@ notifications:
on_failure: always
rooms:
secure: updWrOALfF29z30ogJ4m21WX0oOSYbRX/+abuEqXCC9zZ2QI7EoRR61hrAgNXJXUTffmUIM0vCrToYlybMsdcZHwCXWN8vr2yW3fyypfs/+rUng1qigEy1wVVIFgAC/6NruhmuUMWo1qwe4tUenQmegBiSpYRVRI10Qsnj6TggCNVz0cuoxpmzpVvNH78s1elnU4P1REWhjStuqQvKgG5cWOsvI+9l2Z+t9HdpYE7E7N3Ec73t2Z4wKhlpScbLF+mhnTWV6zgCkLaVdMshFeBEuYWmRr3D2QJWMntl/DrVaRoW76kX9nm2PQ/P4q0BdQslf5WsAiONWPOOWqK6n9RM9SegGSEXnXiqkWtmJQspa3zhjkNZStaD/g5E4yP5QnTbk4WP8ma18yQfMthXeQiQOEWj6zOTzBslu6Iyyc9QzbNijnYy3ZBBBAWGaKjFKmTrMTgl19SbAsvgi41A+zrVL5LeCwAR0/2QUdMegHZSla9WBiURgT/quA8EnA3N+ObNQBpqBETJmSPpJbqrkZI8+7oo4nFxLkwCRVyI4/XInTl5aKsRNYP95kPX3zJuUEe8x39qYhG5QcGV8G8AK0B+jrGoEB2qSN2p+Ye1XE6+Z38KktVzM3GmMOt/v+ts1ZjiaZvK0zlb7vRTMuiBmAjAnB5l5vmNSjkP6+ZL832Og=
email: false
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## v0.4.0 (2017-01-17)
## v0.5.0 (not released yet)

* Removed tests for EOL'ed MongoDB 3.0 and Percona Server for MongoDB 3.0.

## v0.4.0 (2018-01-17)

* New flags `-collect.database` and `-collect.collection` can be used to enable collection of database and collection
metrics. They are disabled by default.
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ The easiest way to make a local development setup is to use Docker Compose.
```
docker-compose up
make all testall
export MONGODB_URL='mongodb://localhost:27017'
./mongodb_exporter
```

`testall` make target will run integration tests.
`testall` make target will run integration tests against MongoDB instance specified in
`TEST_MONGODB_URL` environment variable (defaults to `mongodb://localhost:27017`).


## Vendoring
Expand Down
92 changes: 75 additions & 17 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 4 additions & 20 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
[prune]
go-tests = true
non-go = true
unused-packages = true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ mongodb://CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry@loc

## Note about how this works

Point the process to any mongo port and it will detect if it is a mongos, replicaset member, or stand alone mongod and return the appropriate metrics for that type of node. This was done to preent the need to an exporter per type of process.
Point the process to any mongo port and it will detect if it is a mongos, replicaset member, or stand alone mongod and return the appropriate metrics for that type of node. This was done to prevent the need to an exporter per type of process.

## Roadmap

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.0
0.5.0
10 changes: 10 additions & 0 deletions collector/mongod/server_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ import (
)

var (
versionInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Subsystem: "version",
Name: "info",
Help: "Software version information for mongodb process.",
}, []string{"mongodb"})
instanceUptimeSeconds = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: Namespace,
Subsystem: "instance",
Expand All @@ -46,6 +52,7 @@ var (

// ServerStatus keeps the data returned by the serverStatus() method.
type ServerStatus struct {
Version string `bson:"version"`
Uptime float64 `bson:"uptime"`
UptimeEstimate float64 `bson:"uptimeEstimate"`
LocalTime time.Time `bson:"localTime"`
Expand Down Expand Up @@ -83,9 +90,11 @@ type ServerStatus struct {

// Export exports the server status to be consumed by prometheus.
func (status *ServerStatus) Export(ch chan<- prometheus.Metric) {
versionInfo.WithLabelValues(status.Version).Set(1)
instanceUptimeSeconds.Set(status.Uptime)
instanceUptimeEstimateSeconds.Set(status.Uptime)
instanceLocalTime.Set(float64(status.LocalTime.Unix()))
versionInfo.Collect(ch)
instanceUptimeSeconds.Collect(ch)
instanceUptimeEstimateSeconds.Collect(ch)
instanceLocalTime.Collect(ch)
Expand Down Expand Up @@ -156,6 +165,7 @@ func (status *ServerStatus) Export(ch chan<- prometheus.Metric) {

// Describe describes the server status for prometheus.
func (status *ServerStatus) Describe(ch chan<- *prometheus.Desc) {
versionInfo.Describe(ch)
instanceUptimeSeconds.Describe(ch)
instanceUptimeEstimateSeconds.Describe(ch)
instanceLocalTime.Describe(ch)
Expand Down
4 changes: 4 additions & 0 deletions collector/mongod/server_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func TestParserServerStatus(t *testing.T) {
serverStatus := &ServerStatus{}
loadServerStatusFromBson(data, serverStatus)

if serverStatus.Version != "2.6.7" {
t.Errorf("Server version incorrect: %s", serverStatus.Version)
}

if serverStatus.Asserts == nil {
t.Error("Asserts group was not loaded")
}
Expand Down
10 changes: 5 additions & 5 deletions collector/mongodb_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ type MongodbCollectorOpts struct {
CollectCollectionMetrics bool
}

func (in MongodbCollectorOpts) toSessionOps() shared.MongoSessionOpts {
return shared.MongoSessionOpts{
func (in *MongodbCollectorOpts) toSessionOps() *shared.MongoSessionOpts {
return &shared.MongoSessionOpts{
URI: in.URI,
TLSConnection: in.TLSConnection,
TLSCertificateFile: in.TLSCertificateFile,
Expand All @@ -57,7 +57,7 @@ func (in MongodbCollectorOpts) toSessionOps() shared.MongoSessionOpts {

// MongodbCollector is in charge of collecting mongodb's metrics.
type MongodbCollector struct {
Opts MongodbCollectorOpts
Opts *MongodbCollectorOpts

scrapesTotal prometheus.Counter
scrapeErrorsTotal prometheus.Counter
Expand All @@ -70,7 +70,7 @@ type MongodbCollector struct {
}

// NewMongodbCollector returns a new instance of a MongodbCollector.
func NewMongodbCollector(opts MongodbCollectorOpts) *MongodbCollector {
func NewMongodbCollector(opts *MongodbCollectorOpts) *MongodbCollector {
exporter := &MongodbCollector{
Opts: opts,

Expand Down Expand Up @@ -190,7 +190,7 @@ func (exporter *MongodbCollector) scrape(ch chan<- prometheus.Metric) {

mongoSess := exporter.getSession()
if mongoSess == nil {
err = fmt.Errorf("Can't create mongo session to %s", exporter.Opts.URI)
err = fmt.Errorf("Can't create mongo session to %s", shared.RedactMongoUri(exporter.Opts.URI))
log.Error(err)
exporter.mongoUp.Set(0)
return
Expand Down
Loading

0 comments on commit 8136fdd

Please sign in to comment.