Ubuntu-based MRTG configuration for monitoring multiple server system resources

Source: Internet
Author: User
Tags snmp mrtg

The article is to refer to other people's blog integration, changes come!!


The result of the experiment is to monitor the CPU, memory, traffic and nginx of two virtual machines, referred to as server side and client side. (For the sake of convenience, only two, the actual operation is completed, you will find that the increase in quantity is very simple)


Install Package server-side MRTG SNMP Sysstat Curl Nginx

Client Side SNMP Sysstat Curl

Server-side configuration

Edit Server-side/etc/snmp/snmpd.conf (You can replace the original configuration directly, remember to back up the original file)

Com2sec notconfiguser localhost public

Group Notconfiggroup v1 Notconfiguser

Group Notconfiggroup v2c Notconfiguser

View SystemView included. 1.3.6.1.2.1.1

View SystemView included. 1.3.6.1.2.1.25.1.1

Access Notconfiggroup "" Any noauth exact none none

View all included. 1 80

Syslocation Unknown (edit/etc/snmp/snmpd.conf)

Syscontact Root


Shell script holds directory/HOME/MRTG (path optional, same as behind)

Mrtg.ram

#!/bin/bash

# Run this script to check the MEM usage.

Swapmem= '/usr/bin/free |grep Swap |awk ' {print $} '

Usedmem= '/usr/bin/free |grep Mem |awk ' {print $} '

Uptime= '/usr/bin/uptime | awk ' {print $ ' "$4" "$ $"

Echo $usedmem

Echo $swapmem

Echo $UPtime

Hostname


Mtrg.cpu

#!/bin/bash

Cpuusr= '/usr/bin/sar-u 1 3 | grep Average | awk ' {print $} '

Cpusys= '/usr/bin/sar-u 1 3 | grep Average | awk ' {print $} '

Uptime= '/usr/bin/uptime | awk ' {print $ ' "$4" "$ $"

Echo $CPUUSR

Echo $cpusys

Echo $UPtime

Hostname


Nginx_status

Curl Http://localhost/nginx_status | grep Active | awk ' {print $} ' >/home/mrtg/ngx.active

Curl Http://localhost/nginx_status | grep Waiting | awk ' {print $6} ' >/home/mrtg/ngx.waiting


Mrtg.ngx

#!/usr/bin/perl-w

'/home/mrtg/nginx_status ';

$hostname = ' hostname ';

$hostname =~s/\s+$//;

$nginx _active_conn= ' tail/home/mrtg/ngx.active ';

$nginx _waiting_conn= ' tail/home/mrtg/ngx.waiting ';

$nginx _active_conn=~s/\n$//;

$nginx _waiting_conn=~s/\n$//;

$nginx _active_conn=~s/^\s+|\s+$//;

$nginx _waiting_conn=~s/^\s+|\s+$//;

$gettime = ' Uptime|awk ' {print \$1 "" \$3 "" \$4} ";

$gettime =~s/\,|\n$//g;

Print ("$nginx _active_conn\n");

Print ("$nginx _waiting_conn\n");

Print ("$gettime \ n");

Print ("$hostname \ n");


Add the module in Nginx (nginx configuration directory,/sites-enabled/default, included in the server, otherwise it will be an error)

Location ~ ^/nginx_status {

Stub_status on;

Access_log off;

}

Re-start Nginx


Build configuration file

Cfgmaker [email protected]--output/root/mrtg.cfg


Modify Configuration

Workdir:/HOME/MRTG/MRTG (working directory)

and add content to it

TARGET[CPU]: '/home/mrtg/mrtg.cpu '

MAXBYTES[CPU]: 100

OPTIONS[CPU]: Gauge, nopercent, growright

YLEGEND[CPU]: CPU loading (%)

SHORTLEGEND[CPU]:%

LEGENDO[CPU]: CPU us;

LEGENDI[CPU]: CPU sy;

TITLE[CPU]: CPU Loading

PAGETOP[CPU]:


Target[ram]: '/home/mrtg/mrtg.ram '

#Unscaled [RAM]: Dwym

Maxbytes[ram]: 1642472 #这里的数值为服务器内存的最大值 can be viewed with the free command.

Title[ram]:memory

Shortlegend[ram]: &

Kmg[ram]:kb,mb

kilo[ram]:1024

Ylegend[ram]: Memory Usage:

Legend1[ram]: Swap Memory:

Legend2[ram]: Used Memory:

Legendi[ram]: Swap Memory:

Legendo[ram]: Used Memory:

Options[ram]: growright,gauge,nopercent

Pagetop[ram]:


Target[nginx_conn]: '/home/mrtg/mrtg.ngx '

Options[nginx_conn]: Gauge,nopercent,growright

Directory[nginx_conn]: Nginx_conn

Maxbytes[nginx_conn]: 8000

Ylegend[nginx_conn]: Nginx_conn

Shortlegend[nginx_conn]:

Legendi[nginx_conn]: Active connections:

Legendo[nginx_conn]: Waiting:

Title[nginx_conn]: Nginx

Pagetop[nginx_conn]:





Then configure the client side

Edit/etc/snmp/snmpd.conf

Comment out the agentaddress udp:127.0.0.1:161

Remove the #agentaddress udp:161,udp6:[::1]:161 annotation

This enables remote monitoring of SNMP.

However, the server is still unable to monitor the CPU, memory, traffic data, so the following modifications need to be made:

Find the content below

View systemonly included. 1.3.6.1.2.1.1

View systemonly included. 1.3.6.1.2.1.25.1

Add a line below

View systemonly included. 1 80

This allows all devices to be monitored.

After all the modifications are complete, restart the SNMP

Service SNMPD Restart

A local test of whether SNMP monitors various indicators: run the following command

Snmpwalk-v 2c-c public localhost

If there is a lot of content output, it means success.


The client's configuration file is then generated on the server side

Set up the client directory/HOME/MRTG1 (executed on server side)

Copy the files in the/HOME/MRTG to/HOME/MRTG1

Cfgmaker [email protected]--output/root/mrtg1.cfg (192.168.51.236 for client side IP)

The addition of the top add content to the configuration file, but will be an error, prompted to have the same name, modify it, for example:

target[cpu]: '/home/mrtg/mrtg.cpu ' → target[cpu1]: '/home/mrtg1/ Mrtg.cpu '

Create a client-side directory/HOME/MRTG1

Copy the files in the/HOME/MRTG to/HOME/MRTG1


Merging the configuration files

Cat mrtg.cfg mtrg1.cfg > Mrtg.cfg

and move to/etc


Create sub-folders in MRTG MRTG1, respectively MRTG

Build MRTG Home

Indexmaker/etc/mrtg.cfg >/home/mrtg/mrtg/index.html


Draw a chart

Env Lang=c Mrtg/etc/mrtg.cfg


Configure cron schedule to perform tasks, collect/etc/crontab once per minute


*/1 * * * * env LANG=C/USR/BIN/MRTG/ETC/MRTG.CFG

Restart Cron Service


adding modules to Nginx

Location ~ ^/MRTG {

ROOT/HOME/MRTG;

}

Re-start Nginx


Visit HTTP://SERVERIP/MRTG


Ubuntu-based MRTG configuration for monitoring multiple server system resources

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.