root / plugins / mongodb / mongo_btree @ 4387edfa
Historique | Voir | Annoter | Télécharger (1,38 ko)
| 1 | 4387edfa | Lars Kruse | #!/usr/bin/env python3 |
|---|---|---|---|
| 2 | 276169a6 | Alban | """ |
| 3 | =head1 NAME |
||
| 4 | c6f88968 | Lars Kruse | |
| 5 | mongo_btree - MongoDB btree Plugin |
||
| 6 | a200e01f | Eliot Horowitz | |
| 7 | 276169a6 | Alban | =head1 APPLICABLE SYSTEMS |
| 8 | |||
| 9 | c6f88968 | Lars Kruse | Works until MongoDB 2.7. The "indexCounters" field was removed in 2.8 version. |
| 10 | 276169a6 | Alban | |
| 11 | =head1 CONFIGURATION |
||
| 12 | |||
| 13 | [mongo_btree] |
||
| 14 | env.MONGO_DB_URI mongodb://user:password@host:port/dbname |
||
| 15 | |||
| 16 | =head1 AUTHOR |
||
| 17 | |||
| 18 | c6f88968 | Lars Kruse | Original script there : https://github.com/comerford/mongo-munin |
| 19 | |||
| 20 | Doc added by Alban Espie-Guillon <alban.espie@alterway.fr> |
||
| 21 | |||
| 22 | =cut |
||
| 23 | 276169a6 | Alban | """ |
| 24 | a200e01f | Eliot Horowitz | |
| 25 | 4387edfa | Lars Kruse | import json |
| 26 | import urllib.request |
||
| 27 | a200e01f | Eliot Horowitz | import sys |
| 28 | |||
| 29 | |||
| 30 | def getServerStatus(): |
||
| 31 | 4387edfa | Lars Kruse | raw = urllib.request.urlopen("http://127.0.0.1:28017/_status").read()
|
| 32 | return json.loads(raw)["serverStatus"] |
||
| 33 | |||
| 34 | a200e01f | Eliot Horowitz | |
| 35 | def get(): |
||
| 36 | 271a38f0 | Dimitri Savineau | status = getServerStatus() |
| 37 | if status["version"] >= "2.4.0": |
||
| 38 | return getServerStatus()["indexCounters"] |
||
| 39 | else: |
||
| 40 | return getServerStatus()["indexCounters"]["btree"] |
||
| 41 | a200e01f | Eliot Horowitz | |
| 42 | |||
| 43 | 4387edfa | Lars Kruse | def doData(): |
| 44 | for k, v in get().items(): |
||
| 45 | print(str(k) + ".value " + str(int(v))) |
||
| 46 | a200e01f | Eliot Horowitz | |
| 47 | |||
| 48 | 4387edfa | Lars Kruse | def doConfig(): |
| 49 | print("graph_title MongoDB btree stats")
|
||
| 50 | print("graph_args --base 1000 -l 0")
|
||
| 51 | print("graph_vlabel mb ${graph_period}")
|
||
| 52 | print("graph_category db")
|
||
| 53 | a200e01f | Eliot Horowitz | for k in get(): |
| 54 | 4387edfa | Lars Kruse | print(k + ".label " + k) |
| 55 | print(k + ".min 0") |
||
| 56 | print(k + ".type COUNTER") |
||
| 57 | print(k + ".max 500000") |
||
| 58 | print(k + ".draw LINE1") |
||
| 59 | a200e01f | Eliot Horowitz | |
| 60 | |||
| 61 | if __name__ == "__main__": |
||
| 62 | if len(sys.argv) > 1 and sys.argv[1] == "config": |
||
| 63 | doConfig() |
||
| 64 | else: |
||
| 65 | doData() |
