Skip to content

Commit 8136fdd

Browse files
authored
Merge pull request #98 from percona/develop
PMM-2203 v0.5.0
2 parents c703533 + 8c13d69 commit 8136fdd

File tree

1,009 files changed

+12295
-179626
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,009 files changed

+12295
-179626
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# editor temp files
2+
*.sw[nop]
3+
4+
# build artifacts
15
mongodb_exporter
26
coverage.txt
37
coverage_temp.txt

.travis.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,40 @@ matrix:
1212
- go: master
1313

1414
env:
15+
- MONGODB_IMAGE=mongo:3.2
1516
- MONGODB_IMAGE=mongo:3.4
1617
- MONGODB_IMAGE=mongo:3.6
18+
- MONGODB_IMAGE=percona/percona-server-mongodb:3.2
1719
- MONGODB_IMAGE=percona/percona-server-mongodb:3.4
18-
- MONGODB_IMAGE=perconalab/percona-server-mongodb:3.6
20+
- MONGODB_IMAGE=percona/percona-server-mongodb:3.6
1921

2022
services:
2123
- docker
2224

2325
before_script:
26+
# Start docker containers.
27+
- docker-compose up -d
28+
# Wait for MongoDB to become available.
29+
- |
30+
until docker-compose exec mongo mongo --quiet --eval 'db.runCommand("ping").ok' > /dev/null; do
31+
>&2 echo "MongoDB is unavailable - sleeping"
32+
sleep 1
33+
done
34+
>&2 echo "MongoDB is up"
35+
# Display logs for debug purposes.
36+
- docker-compose logs
37+
# Display versions.
2438
- docker --version
2539
- docker-compose --version
26-
- docker-compose up -d
40+
- docker-compose exec mongo mongo --version
2741

2842
script:
43+
# ensure that vendor/ is in sync with code and Gopkg.*
44+
- curl https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64 -L -o ~/dep && chmod +x ~/dep
45+
- rm -fr vendor/
46+
- ~/dep ensure -v
47+
- git diff --exit-code
48+
2949
- make format build testall
3050

3151
after_success:
@@ -37,3 +57,4 @@ notifications:
3757
on_failure: always
3858
rooms:
3959
secure: updWrOALfF29z30ogJ4m21WX0oOSYbRX/+abuEqXCC9zZ2QI7EoRR61hrAgNXJXUTffmUIM0vCrToYlybMsdcZHwCXWN8vr2yW3fyypfs/+rUng1qigEy1wVVIFgAC/6NruhmuUMWo1qwe4tUenQmegBiSpYRVRI10Qsnj6TggCNVz0cuoxpmzpVvNH78s1elnU4P1REWhjStuqQvKgG5cWOsvI+9l2Z+t9HdpYE7E7N3Ec73t2Z4wKhlpScbLF+mhnTWV6zgCkLaVdMshFeBEuYWmRr3D2QJWMntl/DrVaRoW76kX9nm2PQ/P4q0BdQslf5WsAiONWPOOWqK6n9RM9SegGSEXnXiqkWtmJQspa3zhjkNZStaD/g5E4yP5QnTbk4WP8ma18yQfMthXeQiQOEWj6zOTzBslu6Iyyc9QzbNijnYy3ZBBBAWGaKjFKmTrMTgl19SbAsvgi41A+zrVL5LeCwAR0/2QUdMegHZSla9WBiURgT/quA8EnA3N+ObNQBpqBETJmSPpJbqrkZI8+7oo4nFxLkwCRVyI4/XInTl5aKsRNYP95kPX3zJuUEe8x39qYhG5QcGV8G8AK0B+jrGoEB2qSN2p+Ye1XE6+Z38KktVzM3GmMOt/v+ts1ZjiaZvK0zlb7vRTMuiBmAjAnB5l5vmNSjkP6+ZL832Og=
60+
email: false

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

3-
## v0.4.0 (2017-01-17)
3+
## v0.5.0 (not released yet)
4+
5+
* Removed tests for EOL'ed MongoDB 3.0 and Percona Server for MongoDB 3.0.
6+
7+
## v0.4.0 (2018-01-17)
48

59
* New flags `-collect.database` and `-collect.collection` can be used to enable collection of database and collection
610
metrics. They are disabled by default.

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ The easiest way to make a local development setup is to use Docker Compose.
77
```
88
docker-compose up
99
make all testall
10-
export MONGODB_URL='mongodb://localhost:27017'
1110
./mongodb_exporter
1211
```
1312

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

1616

1717
## Vendoring

Gopkg.lock

Lines changed: 75 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
1-
# Gopkg.toml example
2-
#
3-
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
4-
# for detailed Gopkg.toml documentation.
5-
#
6-
# required = ["github.com/user/thing/cmd/thing"]
7-
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8-
#
9-
# [[constraint]]
10-
# name = "github.com/user/project"
11-
# version = "1.0.0"
12-
#
13-
# [[constraint]]
14-
# name = "github.com/user/project2"
15-
# branch = "dev"
16-
# source = "github.com/myfork/project2"
17-
#
18-
# [[override]]
19-
# name = "github.com/x/y"
20-
# version = "2.4.0"
1+
[prune]
2+
go-tests = true
3+
non-go = true
4+
unused-packages = true

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ mongodb://CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry@loc
7272

7373
## Note about how this works
7474

75-
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.
75+
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.
7676

7777
## Roadmap
7878

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.0
1+
0.5.0

collector/mongod/server_status.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ import (
2424
)
2525

2626
var (
27+
versionInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{
28+
Namespace: Namespace,
29+
Subsystem: "version",
30+
Name: "info",
31+
Help: "Software version information for mongodb process.",
32+
}, []string{"mongodb"})
2733
instanceUptimeSeconds = prometheus.NewCounter(prometheus.CounterOpts{
2834
Namespace: Namespace,
2935
Subsystem: "instance",
@@ -46,6 +52,7 @@ var (
4652

4753
// ServerStatus keeps the data returned by the serverStatus() method.
4854
type ServerStatus struct {
55+
Version string `bson:"version"`
4956
Uptime float64 `bson:"uptime"`
5057
UptimeEstimate float64 `bson:"uptimeEstimate"`
5158
LocalTime time.Time `bson:"localTime"`
@@ -83,9 +90,11 @@ type ServerStatus struct {
8390

8491
// Export exports the server status to be consumed by prometheus.
8592
func (status *ServerStatus) Export(ch chan<- prometheus.Metric) {
93+
versionInfo.WithLabelValues(status.Version).Set(1)
8694
instanceUptimeSeconds.Set(status.Uptime)
8795
instanceUptimeEstimateSeconds.Set(status.Uptime)
8896
instanceLocalTime.Set(float64(status.LocalTime.Unix()))
97+
versionInfo.Collect(ch)
8998
instanceUptimeSeconds.Collect(ch)
9099
instanceUptimeEstimateSeconds.Collect(ch)
91100
instanceLocalTime.Collect(ch)
@@ -156,6 +165,7 @@ func (status *ServerStatus) Export(ch chan<- prometheus.Metric) {
156165

157166
// Describe describes the server status for prometheus.
158167
func (status *ServerStatus) Describe(ch chan<- *prometheus.Desc) {
168+
versionInfo.Describe(ch)
159169
instanceUptimeSeconds.Describe(ch)
160170
instanceUptimeEstimateSeconds.Describe(ch)
161171
instanceLocalTime.Describe(ch)

collector/mongod/server_status_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ func TestParserServerStatus(t *testing.T) {
3030
serverStatus := &ServerStatus{}
3131
loadServerStatusFromBson(data, serverStatus)
3232

33+
if serverStatus.Version != "2.6.7" {
34+
t.Errorf("Server version incorrect: %s", serverStatus.Version)
35+
}
36+
3337
if serverStatus.Asserts == nil {
3438
t.Error("Asserts group was not loaded")
3539
}

collector/mongodb_collector.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ type MongodbCollectorOpts struct {
4343
CollectCollectionMetrics bool
4444
}
4545

46-
func (in MongodbCollectorOpts) toSessionOps() shared.MongoSessionOpts {
47-
return shared.MongoSessionOpts{
46+
func (in *MongodbCollectorOpts) toSessionOps() *shared.MongoSessionOpts {
47+
return &shared.MongoSessionOpts{
4848
URI: in.URI,
4949
TLSConnection: in.TLSConnection,
5050
TLSCertificateFile: in.TLSCertificateFile,
@@ -57,7 +57,7 @@ func (in MongodbCollectorOpts) toSessionOps() shared.MongoSessionOpts {
5757

5858
// MongodbCollector is in charge of collecting mongodb's metrics.
5959
type MongodbCollector struct {
60-
Opts MongodbCollectorOpts
60+
Opts *MongodbCollectorOpts
6161

6262
scrapesTotal prometheus.Counter
6363
scrapeErrorsTotal prometheus.Counter
@@ -70,7 +70,7 @@ type MongodbCollector struct {
7070
}
7171

7272
// NewMongodbCollector returns a new instance of a MongodbCollector.
73-
func NewMongodbCollector(opts MongodbCollectorOpts) *MongodbCollector {
73+
func NewMongodbCollector(opts *MongodbCollectorOpts) *MongodbCollector {
7474
exporter := &MongodbCollector{
7575
Opts: opts,
7676

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

191191
mongoSess := exporter.getSession()
192192
if mongoSess == nil {
193-
err = fmt.Errorf("Can't create mongo session to %s", exporter.Opts.URI)
193+
err = fmt.Errorf("Can't create mongo session to %s", shared.RedactMongoUri(exporter.Opts.URI))
194194
log.Error(err)
195195
exporter.mongoUp.Set(0)
196196
return

0 commit comments

Comments
 (0)