How to monitoring MySQL Servers?

Monitoring can be defined as observing or checking the quality or process of something over a period of time.Monitoring is a continuous effort to keep things under observation and control.

Operating System Metrics

An operating system is a complex computer program: an interface between applications and hardware.

CPU

The central processing unit (CPU) is the heart of any computer . a CPU is a device that can do a few basic (and not so basic) operations on top of which we build layers and layers of complexity from machine code up to the high-level programming languages running operating systems and ultimately database systems.

Here are a few of the most important metrics of a CPU for a server:

  • CPU frequency(the number of times per second a CPU core can "wake up" to execute a piece of work)
  • Cache memory (The size of the cache defines the amount of memory located directly within the CPU,making it extremely fast)
  • Number of cores (This is the number of execution units within a single CPU package.most CPUs are multicore systems.)

Let's see the vmstat output on an idle system.

[root@DBAMAXWELL ~]# vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0 324712   2104 1234532    0    0    14    29  439  290  1  2 96  0  0
 0  0      0 324820   2104 1234572    0    0     0     0 1915 3578  2  3 96  0  0
 0  0      0 324820   2104 1234572    0    0     0     0 1840 3525  1  2 97  0  0
 0  0      0 324820   2104 1234576    0    0     0     4 1853 3498  1  3 96  0  0
 0  0      0 324820   2104 1234576    0    0     0     0 1863 3569  1  2 97  0  0
 0  0      0 324820   2104 1234576    0    0     0     0 1917 3631  1  3 96  0  0
 1  0      0 324820   2104 1234576    0    0     0    71 1780 3370  1  2 97  0  0
 0  0      0 324820   2104 1234576    0    0     0     0 1890 3598  1  2 97  0  0
 1  0      0 554112   2104 1234376    0    0     0     0 2211 3728  4  8 88  0  0
 1  0      0 457696   2104 1234364    0    0     0     0 2455 3341 42  9 49  0  0
 3  0      0 495120   2104 1234392    0    0     0   621 2682 3214 38 16 47  0  0
 1  0      0 377928   2104 1234524    0    0     0   467 2727 3290 31 24 45  0  0

Here's what the cpu columns indicate:

  • us(user) (Time spent running user programs that load put on a system,this metric shows time spent purely inside the program itself.)
  • sy(system) (Time spent running kernel code. Time spent doing that work will be included in the sy value.)
  • id(idle) (Time spent doing nothing;idle time.On a perfectly idle server ,this metric will be 100)
  • wa(I/O wait) (Time spent waiting for I/O.This is an important metric for MySQL,as reading and writing to various files are a relatively large part of MySQL operation.)
  • ss(steal) (This is a difficult metric to explain without getting deep into the weeds.)

On Linux ,the next-simplest tool to use after vmstat is top

Luckily ,monitoring disk space usage is very easy. On Linux ,it can be done using the simple of df command. without arguments,it will show capacity and usage in 1KB blocks for every filesystem.You can add the -h argument to get human-readable measurements.

[root@DBAMAXWELL ~]# df -h /var/lib/mysql
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        80G   19G   62G  24% /
[root@DBAMAXWELL ~]# 

The metrics presented by the resource monitor are similar to those of iostat.you can use the pidstat tool on Linux .

[root@DBAMAXWELL ~]# iostat
Linux 4.18.0-365.el8.x86_64 (DBAMAXWELL)        03/15/2022      _x86_64_        (2 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.24    0.02    2.33    0.01    0.00   96.40

Device             tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
vda               3.02        27.02        74.89    1253008    3472730

[root@DBAMAXWELL ~]# pidstat -d 5
Linux 4.18.0-365.el8.x86_64 (DBAMAXWELL)        03/15/2022      _x86_64_        (2 CPU)

11:18:36 AM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s iodelay  Command
11:18:41 AM     0      1143      0.00      0.80      0.00       0  AliYunDun
11:18:41 AM    27      7716      0.00      0.80      0.00       0  mysqld

11:18:41 AM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s iodelay  Command

11:18:46 AM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s iodelay  Command
11:18:51 AM     0      6704      0.00      0.00      0.00      17  kworker/u4:0-writeback

11:18:51 AM   UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s iodelay  Command
11:18:56 AM    27      7716      0.00      1.60      0.00       0  mysqld
^C

Average:      UID       PID   kB_rd/s   kB_wr/s kB_ccwr/s iodelay  Command
Average:        0      1143      0.00      0.20      0.00       0  AliYunDun
Average:        0      6704      0.00      0.00      0.00       4  kworker/u4:0-writeback
Average:       27      7716      0.00      0.60      0.00       0  mysqld
[root@DBAMAXWELL ~]# 

Memory

Memory,or RAM, is another important resource for any database.Memory offers vastly superior performance to disk for reading and writing data

[root@DBAMAXWELL ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          3.5Gi       2.0Gi       294Mi       1.0Mi       1.2Gi       1.4Gi
Swap:            0B          0B          0B
[root@DBAMAXWELL ~]# 

Let's further break down the output of this command.The columns are:

  • total (Total amount of memory available on the  machine)
  • used (Amount of memory currently used by applications)
  • free (Actual free memory not used by the OS at all)
  • shared (A special type of memory that needs to be specifically requested and allocated and that multiple processes can access together)
  • buff/cache (Amount of memory the OS is currently using as a cache to improve I/O)
  • available (Amount of memory that applications could use if they needed it, usually the sum of free and buff/cache.)

We'll be touching on the following properties of any network:

  • Bandwidth and its utilization(throughput)
  • Errors--their number and sources

th1: error fetching interface information: Device not found
[root@DBAMAXWELL ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.26.5.177  netmask 255.255.192.0  broadcast 172.26.63.255
        inet6 fe80::216:3eff:fe0f:18f3  prefixlen 64  scopeid 0x20<link>
        ether 00:16:3e:0f:18:f3  txqueuelen 1000  (Ethernet)
        RX packets 46305  bytes 20982961 (20.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 36599  bytes 5540408 (5.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@DBAMAXWELL ~]# sar -n DEV
Linux 4.18.0-365.el8.x86_64 (DBAMAXWELL)        03/15/2022      _x86_64_        (2 CPU)

12:00:03 AM     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil
12:10:03 AM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
12:10:03 AM      eth0      0.56      0.53      0.10      0.07      0.00      0.00      0.00      0.00
12:20:03 AM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
12:20:03 AM      eth0      0.54      0.47      0.09      0.04      0.00      0.00      0.00      0.00
12:30:03 AM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
12:30:03 AM      eth0      0.89      0.84      0.24      0.13      0.00      0.00      0.00      0.00
12:40:03 AM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
12:40:03 AM      eth0      0.53      0.48      0.09      0.04      0.00      0.00      0.00      0.00
12:50:03 AM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
12:50:03 AM      eth0      0.48      0.45      0.09      0.04      0.00      0.00      0.00      0.00

[root@DBAMAXWELL ~]# netstat -s
Ip:
    Forwarding: 2
    26601 total packets received
    5 with invalid addresses
    0 forwarded
    0 incoming packets discarded
    26596 incoming packets delivered
    27155 requests sent out
    89 dropped because of missing route
Icmp:
    3353 ICMP messages received
    1 input ICMP message failed
    ICMP input histogram:
        destination unreachable: 1
        echo requests: 3352
    3354 ICMP messages sent
    0 ICMP messages failed
    ICMP output histogram:
        destination unreachable: 2
        echo replies: 3352
IcmpMsg:
        InType3: 1
        InType8: 3352
        OutType0: 3352
        OutType3: 2
Tcp:
    1313 active connection openings
    33 passive connection openings
    437 failed connection attempts
    5 connection resets received
    2 connections established
    19955 segments received
    20818 segments sent out
    74 segments retransmitted
    0 bad segments received
    1499 resets sent
Udp:
    3248 packets received
    2 packets to unknown port received
    0 packet receive errors
    3725 packets sent
    0 receive buffer errors
    0 send buffer errors
UdpLite:
TcpExt:
    1 invalid SYN cookies received
    437 resets received for embryonic SYN_RECV sockets
    1067 TCP sockets finished time wait in fast timer
    3 packets rejected in established connections because of timestamp
    112 delayed acks sent
    Quick ack mode was activated 15 times
    3784 packet headers predicted
    3107 acknowledgments not containing data payload received
    3773 predicted acknowledgments
    TCPSackRecovery: 2
    9 congestion windows recovered without slow start after partial ack
    TCPLostRetransmit: 19
    TCPSackFailures: 1
    2 fast retransmits
    TCPTimeouts: 30
    TCPLossProbes: 23
    TCPLossProbeRecovery: 4
    TCPSackRecoveryFail: 1
    TCPBacklogCoalesce: 1
    TCPDSACKOldSent: 15
    TCPDSACKRecv: 10
    TCPDSACKOfoRecv: 1
    9 connections reset due to unexpected data
    1 connections reset due to early user close
    TCPDSACKIgnoredNoUndo: 5
    TCPSackShiftFallback: 5
    TCPRcvCoalesce: 310
    TCPOFOQueue: 59
    TCPAutoCorking: 98
    TCPSynRetrans: 45
    TCPOrigDataSent: 12058
    TCPHystartTrainDetect: 1
    TCPHystartTrainCwnd: 20
    TCPDelivered: 13358
IpExt:
    InOctets: 19659854
    OutOctets: 4811068
    InNoECTPkts: 36908
MPTcpExt:
[root@DBAMAXWELL ~]# 
[root@DBAMAXWELL ~]# netstat -e
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode     
tcp        0      0 iZbp1ehco2fi1l7bj:39604 100.100.30.25:http      ESTABLISHED root       26775     
tcp        0      0 iZbp1ehco2fi1l7bj:31158 100.100.45.106:https    TIME_WAIT   root       0         
tcp        0     96 iZbp1ehco2fi1l7bj6h:ssh 120.246.125.125:10067   ESTABLISHED root       70188   
udp        0      0 iZbp1ehco2fi1l7b:bootpc _gateway:bootps         ESTABLISHED root       25145     
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  3      [ ]         DGRAM                    301      /run/systemd/notify
unix  2      [ ]         DGRAM                    303      /run/systemd/cgroups-agent
unix  6      [ ]         DGRAM                    317      /run/systemd/journal/socket
unix  2      [ ]         DGRAM                    44609    /run/user/0/systemd/notify
unix  11     [ ]         DGRAM                    321      /run/systemd/journal/dev-log
unix  2      [ ]         DGRAM                    22264    /run/chrony/chronyd.sock
unix  3      [ ]         STREAM     CONNECTED     19194    
unix  3      [ ]         STREAM     CONNECTED     19167    
unix  3      [ ]         STREAM     CONNECTED     22721    /var/lib/sss/pipes/private/sbus-monitor
unix  3      [ ]         STREAM     CONNECTED     24577    /run/systemd/journal/stdout
unix  3      [ ]         STREAM     CONNECTED     19168    /run/systemd/journal/stdout
unix  3      [ ]         STREAM     CONNECTED     45824    /run/systemd/journal/stdout
unix  2      [ ]         DGRAM                    24800    
unix  3      [ ]         STREAM     CONNECTED     26053    /run/systemd/journal/stdout
unix  3      [ ]         STREAM     CONNECTED     25427    /run/dbus/system_bus_socket
unix  3      [ ]         STREAM     CONNECTED     20479    /run/systemd/journal/stdout
unix  3      [ ]         STREAM     CONNECTED     22520    /var/lib/sss/pipes/private/sbus-dp_implicit_files.838
unix  3      [ ]         STREAM     CONNECTED     26424    
unix  3      [ ]         STREAM     CONNECTED     110417   /run/systemd/journal/stdout
unix  3      [ ]         STREAM     CONNECTED     20477    /run/systemd/journal/stdout
Active Bluetooth connections (w/o servers)
Proto  Destination       Source            State         PSM DCID   SCID      IMTU    OMTU Security
Proto  Destination       Source            State     Channel
[root@DBAMAXWELL ~]# 

MySQL Server Observability

Status Variables

show status is used to get the current status variable values.It has two optional modifiers ,GLOBAL and SESSION,and default to SESSION.


mysql> show status like 'Com_show_status';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| Com_show_status | 2     |
+-----------------+-------+
1 row in set (0.01 sec)

mysql> show status;


mysql> show status like 'Com_show_status';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| Com_show_status | 2     |
+-----------------+-------+
1 row in set (0.01 sec)

mysql> show global status like 'Com_show_status';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| Com_show_status | 3     |
+-----------------+-------+
1 row in set (0.00 sec)

mysql> flush status;
Query OK, 0 rows affected (0.00 sec)

mysql> show status like 'Com_show_status';       
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| Com_show_status | 1     |
+-----------------+-------+
1 row in set (0.00 sec)

mysql> show global status like 'Com_show_status';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| Com_show_status | 5     |
+-----------------+-------+
1 row in set (0.00 sec)

mysql> 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值