cloudscale 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/cloudscale +5 -0
- data/lib/cloudscale/monitor/agent/agent.rb +8 -2
- data/lib/cloudscale/monitor/reporter/influxdb_reporter.rb +29 -5
- data/lib/cloudscale/plugins/mongo/preops/mongodb_preop.rb +12 -4
- data/lib/cloudscale/plugins/mysql/data/mysql_chart.json +506 -0
- data/lib/cloudscale/plugins/mysql/data/mysql_menu.json +35 -0
- data/lib/cloudscale/plugins/mysql/mysql_counters.rb +90 -0
- data/lib/cloudscale/plugins/mysql/mysql_general_status.rb +119 -0
- data/lib/cloudscale/plugins/mysql/mysql_innodb.rb +113 -0
- data/lib/cloudscale/plugins/mysql/mysql_querycache.rb +59 -0
- data/lib/cloudscale/plugins/mysql/preops/mysql_preop.rb +95 -0
- data/lib/cloudscale/plugins/postgres/preops/postgres_preop.rb +12 -4
- data/lib/cloudscale/plugins/redis/data/redis_chart.json +110 -0
- data/lib/cloudscale/plugins/redis/data/redis_menu.json +17 -0
- data/lib/cloudscale/plugins/redis/preops/redis_preop.rb +117 -0
- data/lib/cloudscale/plugins/redis/redis_server_status.rb +227 -0
- data/lib/cloudscale/rest/rest_client.rb +14 -8
- data/lib/cloudscale/rest/rest_client_helper.rb +23 -16
- data/lib/cloudscale/schedule.rb +1 -0
- data/lib/cloudscale/store/agent/agent.store +1 -1
- data/lib/cloudscale/store/agent/agent_instance.store +11 -0
- data/lib/cloudscale/store/agent/influxdb.store +1 -1
- data/lib/cloudscale/version.rb +1 -1
- data/lib/store/plugin/host +1 -0
- data/lib/store/plugin/mongo-connect-timeout +1 -0
- data/lib/store/plugin/mongo-db +1 -0
- data/lib/store/plugin/mongo-host +1 -0
- data/lib/store/plugin/mongo-op-timeout +1 -0
- data/lib/store/plugin/mongo-password +1 -0
- data/lib/store/plugin/mongo-port +2 -0
- data/lib/store/plugin/mongo-ssl +2 -0
- data/lib/store/plugin/mongo-username +1 -0
- data/lib/store/plugin/mysql-db +0 -0
- data/lib/store/plugin/mysql-host +0 -0
- data/lib/store/plugin/mysql-password +0 -0
- data/lib/store/plugin/mysql-port +1 -0
- data/lib/store/plugin/mysql-username +0 -0
- data/lib/store/plugin/port +1 -0
- data/lib/store/plugin/postgres-db +0 -0
- data/lib/store/plugin/postgres-host +0 -0
- data/lib/store/plugin/postgres-password +0 -0
- data/lib/store/plugin/postgres-port +1 -0
- data/lib/store/plugin/postgres-username +0 -0
- data/lib/store/plugin/redis-db +0 -0
- data/lib/store/plugin/redis-host +0 -0
- data/lib/store/plugin/redis-password +0 -0
- data/lib/store/plugin/redis-port +1 -0
- data/lib/store/plugin/redis-reconnect-attempts +1 -0
- data/lib/store/plugin/redis-timeout +1 -0
- data/lib/store/plugin/redis-username +0 -0
- data/lib/store/plugin/token +1 -0
- metadata +45 -11
- data/bin/autospec +0 -16
- data/bin/bundler +0 -16
- data/bin/htmldiff +0 -16
- data/bin/ldiff +0 -16
- data/bin/monitor +0 -16
- data/bin/rake +0 -16
- data/bin/restclient +0 -16
- data/bin/rspec +0 -16
@@ -0,0 +1,35 @@
|
|
1
|
+
{
|
2
|
+
"mysql":{
|
3
|
+
"menuId" : "mysql",
|
4
|
+
"label" : "MySQL",
|
5
|
+
"description": "MySQL information",
|
6
|
+
"order" : 1,
|
7
|
+
"agentInstanceId" : null,
|
8
|
+
"subItems" : [
|
9
|
+
{
|
10
|
+
"menuId" : "mysql.general",
|
11
|
+
"label" : "General Stats",
|
12
|
+
"description" : "All relevant information regarding the MySQL Endpoint",
|
13
|
+
"order" : 1
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"menuId" : "mysql.counter",
|
17
|
+
"label" : "Counter Stats",
|
18
|
+
"description" : "All relevant information regarding the MySQL Endpoint",
|
19
|
+
"order" : 1
|
20
|
+
},
|
21
|
+
{
|
22
|
+
"menuId" : "mysql.innodb",
|
23
|
+
"label" : "InnoDB Stats",
|
24
|
+
"description" : "All relevant information regarding the MySQL Endpoint",
|
25
|
+
"order" : 1
|
26
|
+
},
|
27
|
+
{
|
28
|
+
"menuId" : "mysql.querycache",
|
29
|
+
"label" : "Querycache Stats",
|
30
|
+
"description" : "All relevant information regarding the MySQL Endpoint",
|
31
|
+
"order" : 1
|
32
|
+
}
|
33
|
+
]
|
34
|
+
}
|
35
|
+
}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#require "#{File.dirname(__FILE__)}/../preops/plugin_postgres_preop"
|
2
|
+
require "#{File.dirname(__FILE__)}/../plugin"
|
3
|
+
|
4
|
+
##
|
5
|
+
#
|
6
|
+
# @author Johannes Hiemer.
|
7
|
+
#
|
8
|
+
##
|
9
|
+
module Cloudscale
|
10
|
+
module Plugins
|
11
|
+
class MySqlCounter < Plugins::Plugin
|
12
|
+
attr_reader :connection
|
13
|
+
|
14
|
+
def is_enabled
|
15
|
+
Preops::MysqlPreop.instance.is_enabled
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
super
|
20
|
+
if is_enabled
|
21
|
+
@connection = Preops::MysqlPreop.instance.connection
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def collect(agentInstanceId)
|
26
|
+
registry = Monitor::Registry.instance
|
27
|
+
metrics = Metrics::Agent.new
|
28
|
+
log.info("Calling Collect on MySqlCounter")
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def report_database_stats(registry, metrics)
|
33
|
+
results = mysql.query('SHOW GLOBAL STATUS')
|
34
|
+
|
35
|
+
registry.metrics["mysql.handler.general.write"] = metrics.gauge :handlerWrite do
|
36
|
+
{ :value => results['handlerWrite'] }
|
37
|
+
end
|
38
|
+
|
39
|
+
registry.metrics["mysql.handler.general.update"] = metrics.gauge :handlerUpdate do
|
40
|
+
{ :value => results['handlerUpdate'] }
|
41
|
+
end
|
42
|
+
|
43
|
+
registry.metrics["mysql.handler.general.delete"] = metrics.gauge :handlerDelete do
|
44
|
+
{ :value => results['handlerDelete'] }
|
45
|
+
end
|
46
|
+
|
47
|
+
registry.metrics["mysql.handler.read.paging.first"] = metrics.gauge :handlerRead_first do
|
48
|
+
{ :value => results['handlerRead_first'] }
|
49
|
+
end
|
50
|
+
|
51
|
+
registry.metrics["mysql.handler.read.paging.key"] = metrics.gauge :handlerRead_key do
|
52
|
+
{ :value => results['handlerRead_key'] }
|
53
|
+
end
|
54
|
+
|
55
|
+
registry.metrics["mysql.handler.read.paging.next"] = metrics.gauge :handlerRead_next do
|
56
|
+
{ :value => results['handlerRead_next'] }
|
57
|
+
end
|
58
|
+
|
59
|
+
registry.metrics["mysql.handler.read.paging.prev"] = metrics.gauge :handlerRead_prev do
|
60
|
+
{ :value => results['handlerRead_prev'] }
|
61
|
+
end
|
62
|
+
|
63
|
+
registry.metrics["mysql.handler.read.paging.rnd"] = metrics.gauge :handlerRead_rnd do
|
64
|
+
{ :value => results['handlerRead_rnd'] }
|
65
|
+
end
|
66
|
+
|
67
|
+
registry.metrics["mysql.handler.read.paging.rnd.next"] = metrics.gauge :handlerRead_rnd_next do
|
68
|
+
{ :value => results['handlerRead_rnd_next'] }
|
69
|
+
end
|
70
|
+
|
71
|
+
registry.metrics["mysql.handler.read.transaction.commit"] = metrics.gauge :handlerCommit do
|
72
|
+
{ :value => results['handlerCommit'] }
|
73
|
+
end
|
74
|
+
|
75
|
+
registry.metrics["mysql.handler.read.transaction.rollback"] = metrics.gauge :handlerRollback do
|
76
|
+
{ :value => results['handlerRollback'] }
|
77
|
+
end
|
78
|
+
|
79
|
+
registry.metrics["mysql.handler.read.transaction.savepoint"] = metrics.gauge :handlerSavepoint do
|
80
|
+
{ :value => results['handlerSavepoint'] }
|
81
|
+
end
|
82
|
+
|
83
|
+
registry.metrics["mysql.handler.read.transaction.savepoint.rollback"] = metrics.gauge :handlerSavepointRollback do
|
84
|
+
{ :value => results['handlerSavepointRollback'] }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
#require "#{File.dirname(__FILE__)}/../preops/plugin_postgres_preop"
|
2
|
+
require "#{File.dirname(__FILE__)}/../plugin"
|
3
|
+
|
4
|
+
##
|
5
|
+
#
|
6
|
+
# @author Johannes Hiemer.
|
7
|
+
#
|
8
|
+
##
|
9
|
+
module Cloudscale
|
10
|
+
module Plugins
|
11
|
+
class MySqlGeneralStatus < Plugins::Plugin
|
12
|
+
attr_reader :connection
|
13
|
+
|
14
|
+
def is_enabled
|
15
|
+
Preops::MysqlPreop.instance.is_enabled
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
super
|
20
|
+
if is_enabled
|
21
|
+
@connection = Preops::MysqlPreop.instance.connection
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def collect(agentInstanceId)
|
26
|
+
registry = Monitor::Registry.instance
|
27
|
+
metrics = Metrics::Agent.new
|
28
|
+
log.info("Calling Collect on MysqlGeneralStatus")
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def report_database_stats(registry, metrics)
|
33
|
+
results = mysql.query('SHOW GLOBAL STATUS')
|
34
|
+
|
35
|
+
registry.metrics["mysql.general.network.bytes.rx"] = metrics.gauge :bytes_received do
|
36
|
+
{ :value => results['rxBytes'] }
|
37
|
+
end
|
38
|
+
|
39
|
+
registry.metrics["mysql.general.network.bytes.tx"] = metrics.gauge :bytes_send do
|
40
|
+
{ :value => results['txBytes'] }
|
41
|
+
end
|
42
|
+
|
43
|
+
registry.metrics["mysql.general.key.read.requests"] = metrics.gauge :keyRead_requests do
|
44
|
+
{ :value => results['keyRead_requests'] }
|
45
|
+
end
|
46
|
+
|
47
|
+
registry.metrics["mysql.general.key.read.count"] = metrics.gauge :keyReads do
|
48
|
+
{ :value => results['keyReads'] }
|
49
|
+
end
|
50
|
+
|
51
|
+
registry.metrics["mysql.general.key.write.requests"] = metrics.gauge :keyWrite_requests do
|
52
|
+
{ :value => results['keyWrite_requests'] }
|
53
|
+
end
|
54
|
+
|
55
|
+
registry.metrics["mysql.general.key.write.count"] = metrics.gauge :keyWrites do
|
56
|
+
{ :value => results['keyWrites'] }
|
57
|
+
end
|
58
|
+
|
59
|
+
registry.metrics["mysql.general.binlog.cache.use"] = metrics.gauge :binlogCacheUse do
|
60
|
+
{ :value => results['binlogCacheUse'] }
|
61
|
+
end
|
62
|
+
|
63
|
+
registry.metrics["mysql.general.binlog.disk.use"] = metrics.gauge :binlogCacheDiskUse do
|
64
|
+
{ :value => results['binlogCacheDiskUse'] }
|
65
|
+
end
|
66
|
+
|
67
|
+
registry.metrics["mysql.general.connections.max"] = metrics.gauge :maxUsedConnections do
|
68
|
+
{ :value => results['maxUsedConnections'] }
|
69
|
+
end
|
70
|
+
|
71
|
+
registry.metrics["mysql.general.aborted.clients"] = metrics.gauge :abortedClients do
|
72
|
+
{ :value => results['abortedClients'] }
|
73
|
+
end
|
74
|
+
|
75
|
+
registry.metrics["mysql.general.aborted.connects"] = metrics.gauge :abortedConnects do
|
76
|
+
{ :value => results['abortedConnects'] }
|
77
|
+
end
|
78
|
+
|
79
|
+
registry.metrics["mysql.general.threads.connected"] = metrics.gauge :threadsConnected do
|
80
|
+
{ :value => results['threadsConnected'] }
|
81
|
+
end
|
82
|
+
|
83
|
+
registry.metrics["mysql.general.open.files"] = metrics.gauge :openFiles do
|
84
|
+
{ :value => results['openFiles'] }
|
85
|
+
end
|
86
|
+
|
87
|
+
registry.metrics["mysql.general.open.tables"] = metrics.gauge :openTables do
|
88
|
+
{ :value => results['openTables'] }
|
89
|
+
end
|
90
|
+
|
91
|
+
registry.metrics["mysql.general.open.opened.tables"] = metrics.gauge :openedTables do
|
92
|
+
{ :value => results['openedTables'] }
|
93
|
+
end
|
94
|
+
|
95
|
+
registry.metrics["mysql.general.select.full.join"] = metrics.gauge :fullJoins do
|
96
|
+
{ :value => results['fullJoins'] }
|
97
|
+
end
|
98
|
+
|
99
|
+
registry.metrics["mysql.general.select.full.range.join"] = metrics.gauge :fullRangeJoins do
|
100
|
+
{ :value => results['fullRangeJoins'] }
|
101
|
+
end
|
102
|
+
|
103
|
+
registry.metrics["mysql.general.select.range"] = metrics.gauge :selectRange do
|
104
|
+
{ :value => results['selectRange'] }
|
105
|
+
end
|
106
|
+
|
107
|
+
registry.metrics["mysql.general.select.range.check"] = metrics.gauge :selectRange_check do
|
108
|
+
{ :value => results['selectRange_check'] }
|
109
|
+
end
|
110
|
+
|
111
|
+
registry.metrics["mysql.general.select.scan"] = metrics.gauge :selectScan do
|
112
|
+
{ :value => results['selectScan'] }
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
#require "#{File.dirname(__FILE__)}/../preops/plugin_postgres_preop"
|
2
|
+
require "#{File.dirname(__FILE__)}/../plugin"
|
3
|
+
|
4
|
+
##
|
5
|
+
#
|
6
|
+
# @author Johannes Hiemer.
|
7
|
+
#
|
8
|
+
##
|
9
|
+
module Cloudscale
|
10
|
+
module Plugins
|
11
|
+
class MySqlInnoDb < Plugins::Plugin
|
12
|
+
attr_reader :connection
|
13
|
+
|
14
|
+
def is_enabled
|
15
|
+
Preops::MysqlPreop.instance.is_enabled
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
super
|
20
|
+
if is_enabled
|
21
|
+
@connection = Preops::MysqlPreop.instance.connection
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def collect(agentInstanceId)
|
26
|
+
registry = Monitor::Registry.instance
|
27
|
+
metrics = Metrics::Agent.new
|
28
|
+
log.info("Calling Collect on MySqlInnoDb")
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def report_database_stats(registry, metrics)
|
33
|
+
results = mysql.query('SHOW GLOBAL STATUS')
|
34
|
+
|
35
|
+
registry.metrics["mysql.innodb.buffer.page.total"] = metrics.gauge :bufferTotal_pages do
|
36
|
+
{ :value => results['bufferTotal_pages'] }
|
37
|
+
end
|
38
|
+
|
39
|
+
registry.metrics["mysql.innodb.buffer.page.free"] = metrics.gauge :bufferFree_pages do
|
40
|
+
{ :value => results['bufferFree_pages'] }
|
41
|
+
end
|
42
|
+
|
43
|
+
registry.metrics["mysql.innodb.buffer.page.dirty"] = metrics.gauge :bufferDirty_pages do
|
44
|
+
{ :value => results['bufferDirty_pages'] }
|
45
|
+
end
|
46
|
+
|
47
|
+
registry.metrics["mysql.innodb.buffer.page.data"] = metrics.gauge :bufferUsed_pages do
|
48
|
+
{ :value => results['bufferUsed_pages'] }
|
49
|
+
end
|
50
|
+
|
51
|
+
registry.metrics["mysql.innodb.page.size"] = metrics.gauge :pageSize do
|
52
|
+
{ :value => results['pageSize'] }
|
53
|
+
end
|
54
|
+
|
55
|
+
registry.metrics["mysql.innodb.page.created"] = metrics.gauge :pagesCreated do
|
56
|
+
{ :value => results['pagesCreated'] }
|
57
|
+
end
|
58
|
+
|
59
|
+
registry.metrics["mysql.innodb.page.read"] = metrics.gauge :pagesRead do
|
60
|
+
{ :value => results['pagesRead'] }
|
61
|
+
end
|
62
|
+
|
63
|
+
registry.metrics["mysql.innodb.page.written"] = metrics.gauge :pagesWritten do
|
64
|
+
{ :value => results['pagesWritten'] }
|
65
|
+
end
|
66
|
+
|
67
|
+
registry.metrics["mysql.innodb.row.lock.current.waits"] = metrics.gauge :currentLockWaits do
|
68
|
+
{ :value => results['currentLockWaits'] }
|
69
|
+
end
|
70
|
+
|
71
|
+
registry.metrics["mysql.innodb.row.lock.waits"] = metrics.gauge :lockWaitTimes do
|
72
|
+
{ :value => results['lockWaitTimes'] }
|
73
|
+
end
|
74
|
+
|
75
|
+
registry.metrics["mysql.innodb.row.lock.time"] = metrics.gauge :rowLockTime do
|
76
|
+
{ :value => results['rowLockTime'] }
|
77
|
+
end
|
78
|
+
|
79
|
+
registry.metrics["mysql.innodb.data.reads"] = metrics.gauge :fileReads do
|
80
|
+
{ :value => results['fileReads'] }
|
81
|
+
end
|
82
|
+
|
83
|
+
registry.metrics["mysql.innodb.data.writes"] = metrics.gauge :fileWrites do
|
84
|
+
{ :value => results['fileWrites'] }
|
85
|
+
end
|
86
|
+
|
87
|
+
registry.metrics["mysql.innodb.data.fsync"] = metrics.gauge :fileFsyncs do
|
88
|
+
{ :value => results['fileFsyncs'] }
|
89
|
+
end
|
90
|
+
|
91
|
+
registry.metrics["mysql.innodb.log.writes"] = metrics.gauge :logWrites do
|
92
|
+
{ :value => results['logWrites'] }
|
93
|
+
end
|
94
|
+
|
95
|
+
registry.metrics["mysql.innodb.rows.updated"] = metrics.gauge :rowsUpdated do
|
96
|
+
{ :value => results['rowsUpdated'] }
|
97
|
+
end
|
98
|
+
|
99
|
+
registry.metrics["mysql.innodb.rows.read"] = metrics.gauge :rowsRead do
|
100
|
+
{ :value => results['rowsRead'] }
|
101
|
+
end
|
102
|
+
|
103
|
+
registry.metrics["mysql.innodb.rows.deleted"] = metrics.gauge :rowsDeleted do
|
104
|
+
{ :value => results['rowsDeleted'] }
|
105
|
+
end
|
106
|
+
|
107
|
+
registry.metrics["mysql.innodb.rows.inserted"] = metrics.gauge :rowsInserted do
|
108
|
+
{ :value => results['rowsInserted'] }
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#require "#{File.dirname(__FILE__)}/../preops/plugin_postgres_preop"
|
2
|
+
require "#{File.dirname(__FILE__)}/../plugin"
|
3
|
+
|
4
|
+
##
|
5
|
+
#
|
6
|
+
# @author Johannes Hiemer.
|
7
|
+
#
|
8
|
+
##
|
9
|
+
module Cloudscale
|
10
|
+
module Plugins
|
11
|
+
class MySqlQueryCache < Plugins::Plugin
|
12
|
+
attr_reader :connection
|
13
|
+
|
14
|
+
def is_enabled
|
15
|
+
Preops::MysqlPreop.instance.is_enabled
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
super
|
20
|
+
if is_enabled
|
21
|
+
@connection = Preops::MysqlPreop.instance.connection
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def collect(agentInstanceId)
|
26
|
+
registry = Monitor::Registry.instance
|
27
|
+
metrics = Metrics::Agent.new
|
28
|
+
log.info("Calling Collect on MysqlQueryCache")
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def report_database_stats(registry, metrics)
|
33
|
+
results = mysql.query('SHOW GLOBAL STATUS')
|
34
|
+
|
35
|
+
registry.metrics["mysql.qcache.queries.cache"] = metrics.gauge :queriesInCache do
|
36
|
+
{ :value => results['queriesInCache'] }
|
37
|
+
end
|
38
|
+
|
39
|
+
registry.metrics["mysql.qcache.cache.hits"] = metrics.gauge :cacheHits do
|
40
|
+
{ :value => results['cacheHits'] }
|
41
|
+
end
|
42
|
+
|
43
|
+
registry.metrics["mysql.qcache.inserts"] = metrics.gauge :inserts do
|
44
|
+
{ :value => results['inserts'] }
|
45
|
+
end
|
46
|
+
|
47
|
+
registry.metrics["mysql.qcache.notcached"] = metrics.gauge :notCached do
|
48
|
+
{ :value => results['notCached'] }
|
49
|
+
end
|
50
|
+
|
51
|
+
registry.metrics["mysql.qcache.lowmem.prunes"] = metrics.gauge :lowMemPrunes do
|
52
|
+
{ :value => results['lowMemPrunes'] }
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require "logger"
|
2
|
+
begin
|
3
|
+
require "mysql2"
|
4
|
+
rescue LoadError
|
5
|
+
puts "WARNING: Load error mysql2 needs to be installed via bundler"
|
6
|
+
end
|
7
|
+
require "singleton"
|
8
|
+
require "#{File.dirname(__FILE__)}/../../preops/plugin_preop"
|
9
|
+
|
10
|
+
##
|
11
|
+
#
|
12
|
+
# @author Johannes Hiemer.
|
13
|
+
#
|
14
|
+
##
|
15
|
+
module Cloudscale
|
16
|
+
module Preops
|
17
|
+
class MysqlPreop < Preops::PluginPreop
|
18
|
+
include Singleton
|
19
|
+
|
20
|
+
attr_accessor :options, :connection
|
21
|
+
|
22
|
+
def is_enabled
|
23
|
+
enabled = false
|
24
|
+
|
25
|
+
if defined? Mysql2
|
26
|
+
enabled = true
|
27
|
+
end
|
28
|
+
|
29
|
+
enabled
|
30
|
+
end
|
31
|
+
|
32
|
+
def register
|
33
|
+
if is_enabled
|
34
|
+
init_charts("#{File.dirname(__FILE__)}/../data/mysql_chart.json")
|
35
|
+
init_menus("#{File.dirname(__FILE__)}/../data/mysql_menu.json")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def initialize
|
40
|
+
self.init
|
41
|
+
@options = {
|
42
|
+
:"mysql-host" => {
|
43
|
+
:argument => "--mysql-host",
|
44
|
+
:description => "Host for your MySQL Instance (e.g. host.instance.com)",
|
45
|
+
:required => true,
|
46
|
+
:value => nil
|
47
|
+
},
|
48
|
+
:"mysql-port" => {
|
49
|
+
:argument => "--mysql-port",
|
50
|
+
:description => "Port for your MySQL Instance (Standard 5432)",
|
51
|
+
:required => false,
|
52
|
+
:value => 3306
|
53
|
+
},
|
54
|
+
:"mysql-db" => {
|
55
|
+
:argument => "--mysql-db",
|
56
|
+
:description => "Database of your MySQL instance",
|
57
|
+
:required => true,
|
58
|
+
:value => nil
|
59
|
+
},
|
60
|
+
:"mysql-username" => {
|
61
|
+
:argument => "--mysql-username",
|
62
|
+
:description => "Username for your MySQL instance",
|
63
|
+
:required => false,
|
64
|
+
:value => nil
|
65
|
+
},
|
66
|
+
:"mysql-password" => {
|
67
|
+
:argument => "--mysql-password",
|
68
|
+
:description => "Password for your MySQL instance",
|
69
|
+
:required => false,
|
70
|
+
:value => nil
|
71
|
+
}
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
def connection
|
76
|
+
if @connection == nil
|
77
|
+
if defined? Mysql2
|
78
|
+
begin
|
79
|
+
@connection = Mysql2::Client.new(
|
80
|
+
host: options[:'mysql-host'][:value],
|
81
|
+
port: options[:'mysql-port'][:value],
|
82
|
+
username: options[:'mysql-user'][:value],
|
83
|
+
password: options[:'mysql-password'][:value],
|
84
|
+
)
|
85
|
+
rescue PGError => e
|
86
|
+
puts e.message
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
@connection
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|