Skip to content

Instantly share code, notes, and snippets.

@sxiii
Last active October 24, 2021 00:08
Show Gist options
  • Save sxiii/97f9324973eb6450a643eb852418401c to your computer and use it in GitHub Desktop.
Save sxiii/97f9324973eb6450a643eb852418401c to your computer and use it in GitHub Desktop.
Install MRTG into Arch

Let's say you want to install MRTG to Archlinux...

  1. First things first, you need Apache, PHP, PHP-GD, GD library on itself. sudo pacman -S gd autoconf apache php-gd perl
  2. Install development version of GD: pikaur -S gd-git (instead of pikaur you can use yay or any other AUR helper)
  3. Then enable mod_fcgi in Apache: https://wiki.archlinux.org/title/Apache_HTTP_Server/mod_fcgid

I will not include this in the manual as this is covered by ArchWiki and a lot of articles

  1. After that, you can either follow steps here: https://wiki.archlinux.org/title/Multi_Router_Traffic_Grapher or here:
  2. Add mrtg user: sudo useradd -d /srv/http/mrtg mrtg
  3. Create directories with proper permissions: sudo mkdir /srv/http/mrtg/ && sudo chown mrtg:mrtg /srv/http/mrtg
  4. Edit httpd apache conf: sudo nano /etc/httpd/conf/httpd.conf
  5. Paste the following in the end:
Alias /mrtg /srv/http/mrtg/html/
<Directory "/srv/http/mrtg/html/">
   AllowOverride None
   Options None
   DirectoryIndex index.html
   Order allow,deny
   Allow from all
</Directory>
  1. Restart Apache: apachectl restart
  2. Create HTTP dir: sudo mkdir /srv/http/mrtg/html
  3. Write SNMP config: sudo cfgmaker --output=/srv/http/mrtg/mrtg.cfg --ifref=name --ifref=descr --global "WorkDir: /srv/http/mrtg" public@localhost
  4. Edit MRTG config file: sudo nano /srv/http/mrtg/mrtg.cfg
  5. Insert the following:
# Created by 
# /usr/bin/cfgmaker --output=/srv/http/mrtg/mrtg.cfg --ifref=name --ifref=descr --global "WorkDir: /srv/http/mrtg" public@localhost


### Global Config Options

### Global configuration  ###

LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt
EnableIPv6: no
HtmlDir: /srv/http/mrtg/html
ImageDir: /srv/http/mrtg/html
LogDir: /srv/http/mrtg
ThreshDir: /srv/http/mrtg
RunAsDaemon: Yes
Interval: 5
Refresh: 600

#  for UNIX
# WorkDir: /home/http/mrtg

#  or for NT
# WorkDir: c:\mrtgdata

### Global Defaults

#  to get bits instead of bytes and graphs growing to the right
# Options[_]: growright, bits

EnableIPv6: no
WorkDir: /srv/http/mrtg

######################################################################
# System: 
# Description: 
# Contact: 
# Location: 
######################################################################


Target[localhost.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:[email protected] + ssCpuRawSystem.0&ssCpuRawSystem.0:[email protected] + ssCpuRawNice.0&ssCpuRawNice.0:[email protected]
RouterUptime[localhost.cpu]: [email protected]
MaxBytes[localhost.cpu]: 100
Title[localhost.cpu]: <H1>CPU Load</H1>
PageTop[localhost.cpu]: <h1>Active CPU Load %</h1>
Unscaled[localhost.cpu]: ymwd
ShortLegend[localhost.cpu]: %
YLegend[localhost.cpu]: CPU Utilization
Legend1[localhost.cpu]: Active CPU in % (Load)
Legend2[localhost.cpu]:
Legend3[localhost.cpu]:
Legend4[localhost.cpu]:
LegendI[localhost.cpu]:  Active
LegendO[localhost.cpu]:
Options[localhost.cpu]: growright,nopercent
# get memory Usage
Target[localhost.memtotal]: ( .1.3.6.1.4.1.2021.4.5.0&.1.3.6.1.4.1.2021.4.5.0:public@localhost ) - ( .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.6.0:public@localhost )
PageTop[localhost.memtotal]: <h1> Memory Usage </h1>
Options[localhost.memtotal]: nopercent,growright,gauge
Title[localhost.memtotal]: Memory Usage
MaxBytes[localhost.memtotal]: 100000000
kMG[localhost.memtotal]: k,M,G,T,P,X
YLegend[localhost.memtotal]: bytes
ShortLegend[localhost.memtotal]: bytes
LegendI[localhost.memtotal]: Memory Usage: 
LegendO[localhost.memtotal]:
Legend1[localhost.memtotal]: Memory Usage, not including swap, in bytes
Colours[localhost.memtotal]: Blue#1000ff, Black#000000, Gray#CCCCCC, Yellow#FFFF00
# get swap memory
Target[localhost.swap]:( .1.3.6.1.4.1.2021.4.3.0&.1.3.6.1.4.1.2021.4.3.0:public@localhost ) - ( .1.3.6.1.4.1.2021.4.4.0&.1.3.6.1.4.1.2021.4.4.0:public@localhost)
PageTop[localhost.swap]: <h1> Swap Usage </h1>
Options[localhost.swap]: nopercent,growright,gauge,noinfo
Title[localhost.swap]: Swap Usage
MaxBytes[localhost.swap]: 100000000 
kMG[localhost.swap]: k,M,G,T,P,X
YLegend[localhost.swap]: bytes
ShortLegend[localhost.swap]: bytes
LegendI[localhost.swap]: Swap Usage:
LegendO[localhost.swap]:
Legend1[localhost.swap]: Swap memory avail, in bytes
Colours[localhost.swap]: Blue#1000ff,Violet#ff00ff,Black#000000, Gray#CCCCCC
# get number of processes running
Target[localhost.procs]: `/usr/local/mrtg/linux_porc.pl`
Title[localhost.procs]: Process Statistics
PageTop[localhost.procs]: <h1> Process Statistics </h1>
MaxBytes[localhost.procs]: 10000
YLegend[localhost.procs]: Processes  
LegendI[localhost.procs]:   Blocked Processes:
LegendO[localhost.procs]:   Run Queue:
Legend1[localhost.procs]: Number of Blocked Processes 
Legend2[localhost.procs]: Number of Processes in Run Queue
Legend3[localhost.procs]: Maximal Blocked Processes
Legend4[localhost.procs]: Maximal Processes in Run Queue
Options[localhost.procs]: growright, integer, nopercent, gauge
# get number of established connections
Target[localhost.estconn]: `/usr/local/mrtg/linux_estconn.pl`
Title[localhost.estconn]: Established connections
PageTop[localhost.estconn]: <h1> Established connections </h1>
MaxBytes[localhost.estconn]: 100000
YLegend[localhost.estconn]: Established connections
LegendI[localhost.estconn]:   Established connections: 
LegendO[localhost.estconn]: Number of Established connections: 
Options[localhost.estconn]: growright, integer, nopercent, gauge
Colours[localhost.estconn]: Red#FF0000,Blue#0066CC,Black#000000, White#FFFFFF
# get number of current users
Target[localhost.users]: `/usr/local/mrtg/linux_users.pl`
Title[localhost.users]: logged in users
PageTop[localhost.users]: <h1> number of users </h1>
MaxBytes[localhost.users]: 100000
YLegend[localhost.users]: users count 
#Legend0[localhost.users]: logged in users count
Options[localhost.users]: growright, integer, nopercent, gauge
Colours[localhost.users]: Red#FF0000,White#FFFFFF,Blue#0066CC,Black#000000
  1. Become root: sudo su -
  2. Become MRTG user: su mrtg
  3. Run indexmaker: indexmaker ./mrtg.cfg > index.html
  4. Exit MRTG user by pressing Ctrl+D.
  5. Move the index file to html folder: mv index.html html
  6. Create dir for scripts: mkdir /usr/local/mrtg
  7. Save script 1: nano /usr/local/mrtg/linux_porc.pl
  8. Paste the script:
#!/usr/bin/perl
open(COMD,"ps -ef | wc -l|");
$num = <COMD>;
close(COMD);
	
print int($num);
  1. Save script 2: nano /usr/local/mrtg/linux_estconn.pl
  2. Paste inside:
#!/usr/bin/perl
open(COMD,"ss -an | grep ESTABLISHED | wc -l|");
$num = <COMD>;
close(COMD);
	
print int($num);
  1. Save script 3: nano /usr/local/mrtg/linux_users.pl
  2. Paste following:
#!/usr/bin/perl
open(COMD,"w | grep -v load | grep -v USER | wc -l|");
$num = <COMD>;
close(COMD);
	
print int($num);
  1. Open your web-browser with this address: http://localhost/mrtg/html/

Security XIII

Version 0.1 beta -> probably this will not work for you perfectly -> please use only as reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment