This file is indexed.

/usr/lib/mysql-workbench/modules/wb_admin_monitor.py is in mysql-workbench 6.2.3+dfsg-7.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; version 2 of the
# License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301  USA

from mforms import newBarGraphWidget, newLineDiagramWidget
import mforms

import wba_monitor_be

class WbAdminMonitor(mforms.Box):
    mon_be      = None
    ctrl_be          = None
    server_info      = None
    cpu_usage        = None
    memory           = None
    heartbeat        = None
    connection_usage = None
    traffic          = None
    hitrate          = None
    key_efficiency   = None
    ib_usage         = None
    innodb_reads     = None
    innodb_writes    = None

    widgets = None

    def __init__(self, server_profile, ctrl_be):
        mforms.Box.__init__(self, False)

        self.widgets = {}

        self.server_profile = server_profile
        self.set_managed()
        self.set_release_on_add()

        self.suspend_layout()

        self.ctrl_be = ctrl_be

        def bigLabel(text="---\n"):
            l = mforms.newLabel(text)
            l.set_style(mforms.VeryBigStyle)
            return l

        # Status icon
        self.box1 = mforms.newBox(True)
        self.box1.set_spacing(28)

        health_text = mforms.newBox(True)
        health_text.set_spacing(20)

        self.status_icon = mforms.newServerStatusWidget()
        self.status_icon.set_description("Server Status")
        self.status_icon.set_size(86, -1)
        self.box1.add(self.status_icon, False, True)

        self.status_label = bigLabel("Unknown\n")
        self.status_label.set_size(86, -1)
        health_text.add(self.status_label, False, True)

        # System.
        system_box = mforms.newBox(True)
        system_box.set_spacing(28)
        self.cpu_usage = newBarGraphWidget()
        if self.server_profile.target_is_windows:
            self.cpu_usage.set_description("CPU")
        else:
            self.cpu_usage.set_description("Load")
        self.cpu_usage.set_right_align(True)
        self.cpu_usage.set_size(31, -1);
        system_box.add(self.cpu_usage, False, True)

        label = bigLabel()
        label.set_size(47, -1)
        label.set_text_align(mforms.TopRight)
        health_text.add(label, False, True)
        if self.server_profile.target_is_windows:
            self.cpu_widget = (self.cpu_usage, label, lambda x: str(int(x*100)) + "%\n", None)
        else:
            self.cpu_usage.enable_auto_scale(True)
            self.cpu_widget = (self.cpu_usage, label, lambda x: str(x)+"\n", None)

        sql = {}
        self.connection_usage= newLineDiagramWidget()
        self.connection_usage.set_description("Connections")
        self.connection_usage.enable_auto_scale(True)
        self.connection_usage.set_thresholds([0.0], [10.0, 50.0, 100.0, 500.0, 1000.0])
        system_box.add(self.connection_usage, True, True)
        label = bigLabel()
        health_text.add(label, True, True)
        self.widgets['get_connections'] = (self.connection_usage, label, lambda x: "%s\n"%str(int(x)), None)
        sql['get_connections'] = {'query' : ("Threads_connected",), 'min' : 0, 'max' : 10, 'calc' : None}
        self.box1.add(system_box, True, True)

        self.add(self.box1, False, True)
        self.add(health_text, False, True)

        # Server health.
        health = mforms.newBox(True)
        health.set_spacing(28)
        health_text = mforms.newBox(True)
        health_text.set_homogeneous(True)
        health_text.set_spacing(24) # 4px less as for the widgets (the labels have a bit leading space).

        self.traffic = newLineDiagramWidget()
        self.traffic.set_description("Traffic")
        self.traffic.enable_auto_scale(True)
        self.traffic.set_thresholds([0.0], [100000.0, 1000000.0, 10000000.0, 100000000.0])
        health.add(self.traffic, True, True)
        label = bigLabel()
        health_text.add(label, True, True)
        self.widgets['get_traffic'] = (self.traffic, label, lambda x: "%s\n"%self.format_value(x), None)
        self.last_traffic = 0
        sql['get_traffic'] = {'query' : ("Bytes_sent",), 'min' : 0, 'max' : 100, 'calc' : self.calc_traffic}

        self.key_efficiency= newLineDiagramWidget()
        self.key_efficiency.set_description("Key Efficiency")
        health.add(self.key_efficiency, True, True)
        label = bigLabel()
        health_text.add(label, True, True)
        self.widgets['get_key_efficiency'] = (self.key_efficiency, label, lambda x: ("%.1f%%\n" % x), None)
        sql['get_key_efficiency'] = {'query' : ("Key_reads","Key_read_requests"), 'min' : 0, 'max' : 100, 'calc' : self.calc_key_efficiency}

        self.add(health, False, True)
        self.add(health_text, False, True)

        # Query
        health= mforms.newBox(True)
        health.set_spacing(28)
        health_text = mforms.newBox(True)
        health_text.set_homogeneous(True)
        health_text.set_spacing(24)

        self.qps= newLineDiagramWidget()
        self.qps.set_description("Selects per Second")
        self.qps.enable_auto_scale(True)
        self.qps.set_thresholds([0.0], [50.0, 100.0, 200.0, 500.0, 1000.0, 5000.0, 10000.0])
        health.add(self.qps, True, True)
        label = bigLabel()
        health_text.add(label, True, True)
        self.widgets['get_qps'] = (self.qps, label, lambda x: ("%.0f\n" % x), None)
        self.last_qcount = 0
        sql['get_qps'] = {'query' : ("Com_select",), 'min' : 0, 'max' : 100, 'calc' : self.calc_qps}

#        self.hitrate= newLineDiagramWidget()
#        self.hitrate.set_description("Query Cache Hitrate")
#        health.add(self.hitrate, True, True)
#        label = bigLabel()
#        health_text.add(label, True, True)
#        self.widgets['get_hitrate'] = (self.hitrate, label, lambda x: ("%.1f%%\n" % x), None)
#        sql['get_hitrate'] = {'query' : ("Qcache_hits", "Qcache_inserts", "Qcache_not_cached"), 'min' : 0, 'max' : 100, 'calc' : self.calc_hitrate}
#
#        self.add(health, False, True)
#        self.add(health_text, False, True)
#
#        # Cache/buffer
#        health = mforms.newBox(True)
#        health.set_spacing(28)
#        health_text = mforms.newBox(True)
#        health_text.set_homogeneous(True)
#        health_text.set_spacing(24)
#
#        self.qcache_usage = newLineDiagramWidget()
#        self.qcache_usage.set_description("Query Cache Usage")
#        health.add(self.qcache_usage, True, True)
#        label = bigLabel()
#        health_text.add(label, True, True)
#        self.widgets['get_qcache_usage'] = (self.qcache_usage, label, lambda x: ("%.1f%%\n" % x), None)
#        sql['get_qcache_usage'] = {'query' : ("Qcache_free_blocks", "Qcache_total_blocks"), 'min' : 0, 'max' : 100, 'calc' : self.calc_qcache_usage}

        self.ib_usage = newLineDiagramWidget()
        self.ib_usage.set_description("InnoDB Buffer Usage")
        health.add(self.ib_usage, True, True)
        label = bigLabel()
        health_text.add(label, True, True)
        self.widgets['get_ib_usage'] = (self.ib_usage, label, lambda x: ("%.1f%%\n" % x), None)
        sql['get_ib_usage'] = {'query' : ("Innodb_buffer_pool_pages_free", "Innodb_buffer_pool_pages_total"), 'min' : 0, 'max' : 100, 'calc' : self.calc_ib_usage}
        
        self.add(health, False, True)
        self.add(health_text, False, True)

        # InnoDB Reads/Writes per second:
        health= mforms.newBox(True)
        health.set_spacing(28)
        health_text = mforms.newBox(True)
        health_text.set_homogeneous(True)
        health_text.set_spacing(24)

        self.innodb_reads = newLineDiagramWidget()
        self.innodb_reads.set_description('InnoDB Reads per Second')
        self.innodb_reads.enable_auto_scale(True)
        self.innodb_reads.set_thresholds([0.0], [50.0, 100.0, 200.0, 500.0, 1000.0, 5000.0, 10000.0])
        health.add(self.innodb_reads, True, True)
        label = bigLabel()
        health_text.add(label, True, True)
        self.widgets['get_innodb_reads'] = (self.innodb_reads, label, lambda x: ('%.0f\n' % x), None)
        self.last_ircount = 0
        sql['get_innodb_reads'] = {'query' : ('Innodb_data_reads',), 'min' : 0, 'max' : 100, 'calc' : self.calc_innodb_reads_per_second}

        self.innodb_writes = newLineDiagramWidget()
        self.innodb_writes.set_description('InnoDB Writes per Second')
        self.innodb_writes.enable_auto_scale(True)
        self.innodb_writes.set_thresholds([0.0], [50.0, 100.0, 200.0, 500.0, 1000.0, 5000.0, 10000.0])
        health.add(self.innodb_writes, True, True)
        label = bigLabel()
        health_text.add(label, True, True)
        self.widgets['get_innodb_writes'] = (self.innodb_writes, label, lambda x: ('%.0f\n' % x), None)
        self.last_iwcount = 0
        sql['get_innodb_writes'] = {'query' : ('Innodb_data_writes',), 'min' : 0, 'max' : 100, 'calc' : self.calc_innodb_writes_per_second}
        
        self.add(health, False, True)
        self.add(health_text, False, True)

        self.resume_layout()

        self.mon_be = wba_monitor_be.WBAdminMonitorBE(3, server_profile, ctrl_be, self.widgets, self.cpu_widget, sql)

    def calc_traffic(self, x):
        tx = int(x[0])
        if self.last_traffic == 0:
            self.last_traffic = tx
            return 0
        ret = tx - self.last_traffic
        self.last_traffic = tx
        return ret

    def calc_key_efficiency(self, (key_reads, key_read_requests)):
        key_read_requests = float(key_read_requests)
        if key_read_requests == 0.0:
            return 0
        return 100 - (float(key_reads) / key_read_requests * 100)

#    def calc_hitrate(self, (hits, inserts, not_cached)):
#        hits = float(hits)
#        inserts = int(inserts)
#        not_cached = int(not_cached)
#        t = hits + inserts + not_cached
#        if t == 0:
#            return 0
#        return (hits/t)*100

    def calc_qps(self, counts):
        c = sum([int(c) for c in counts])
        if self.last_qcount == 0:
            self.last_qcount = c
            return 0
        ret = c - self.last_qcount
        self.last_qcount = c
        return ret

#    def calc_qcache_usage(self, (free_blocks, total_blocks)):
#        free_blocks, total_blocks = float(free_blocks), float(total_blocks)
#        if -0.00001 <= total_blocks <= 0.00001:
#            return 0
#        return 100 * (total_blocks - free_blocks) / total_blocks

    def calc_ib_usage(self, (free_pages, total_pages)):
        free_pages, total_pages = float(free_pages), float(total_pages)
        if -0.00001 <= total_pages <= 0.00001:
            return 0
        return 100 * (total_pages - free_pages) / total_pages

    def calc_innodb_reads_per_second(self, (count,)):
        if self.last_ircount == 0:
            self.last_ircount = count
            return 0
        ret = count - self.last_ircount
        self.last_ircount = count
        return ret

    def calc_innodb_writes_per_second(self, (count,)):
        if self.last_iwcount == 0:
            self.last_iwcount = count
            return 0
        ret = count - self.last_iwcount
        self.last_iwcount = count
        return ret

    def refresh_status(self, status):
        if status == "running" or status == "started":
            self.mon_be.note_server_running()
            self.status_icon.set_server_status(1)
            self.status_label.set_text("Running\n")
        elif status == "stopped":
            self.status_icon.set_server_status(0)
            self.status_label.set_text("Stopped\n")

    def format_value(self, value):
        if value < 1024:
            return str(value) + " B/s"
        else:
            if value < 1024 * 1024:
                return "%.2f KB/s" % (value / 1024)
            else:
                return "%.2f MB/s" % (value / 1024 / 1024)


    def stop(self):
        self.mon_be.stop()