Hiển thị các bài đăng có nhãn Monitor. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Monitor. Hiển thị tất cả bài đăng

Thứ Sáu, 26 tháng 2, 2016

MongoDB Munin Plugin

A plugin is available that provide metrics for:

  • B-Tree stats
  • Current connections
  • Memory usage
  • Database operations (inserts, updates, queries etc.)

The plugin can be installed on each node where MongoDB. For requirements and instructions to installing the MongoDB Munin Plugin.

Check your setup

After installing the plugin and making the configuration changes, force the server to update the information to check that your setup is correct using the following:
sudo -u munin /usr/share/munin/munin-update
If everything is set up correctly, you will get a chart like this:

Plugins

  • mongo_ops : operations/second
  • mongo_mem : mapped, virtual and resident memory usage
  • mongo_btree : btree access/misses/etc...
  • mongo_conn : current connections
  • mongo_lock : write lock info
  • mongo_docs : number of documents (inserted, updated...)

Requirements

  • MongoDB 2.4+
  • python/pymongo

Installation (ubuntu)

Install pip:

sudo apt-get install build-essential python-dev python-setuptools
sudo easy_install pip
sudo pip install --upgrade virtualenv 

Install pymongo:

sudo pip install pymongo

Install plugins:

git clone https://github.com/comerford/mongo-munin.git /tmp/mongo-munin
sudo cp /tmp/mongo-munin/mongo_* /usr/share/munin/plugins
sudo ln -sf /usr/share/munin/plugins/mongo_btree /etc/munin/plugins/mongo_btree
sudo ln -sf /usr/share/munin/plugins/mongo_conn /etc/munin/plugins/mongo_conn
sudo ln -sf /usr/share/munin/plugins/mongo_lock /etc/munin/plugins/mongo_lock
sudo ln -sf /usr/share/munin/plugins/mongo_mem /etc/munin/plugins/mongo_mem
sudo ln -sf /usr/share/munin/plugins/mongo_ops /etc/munin/plugins/mongo_ops
sudo ln -sf /usr/share/munin/plugins/mongo_docs /etc/munin/plugins/mongo_docs
sudo chmod +x /usr/share/munin/plugins/mongo_*
sudo service munin-node restart
Check if plugins are running:
munin-node-configure | grep "mongo_"
Test plugin output:
munin-run mongo_ops

Configuration

How to configure custom db connection?
munin-node can set env value in below file: /etc/munin/plugin-conf.d/munin-node
[mongo_*]
env.MONGO_DB_URI mongodb://user:password@host:port/dbname

Thứ Năm, 25 tháng 2, 2016

Setting Up MUNIN on Ubuntu Server 14.04 with NGINX

This post explains how to configure munin on a single Ubuntu 14.04 server that uses nginx.

sudo apt-get update
sudo apt-get install nginx
Monitoring is supposed to save time by debugging and predicting / avoiding catastrophes. However, setting up munin on Ubuntu was a time-consuming trial-and-error process for me. The official instructions and various blog posts that cover this topic skip important steps, such as having monit's FastCGI processes start automatically at boot time. I have documented the setup that worked for me, hoping that others can reuse my work.


Ubuntu packages

Run the following command to install the packages needed for munin.

sudo apt-get install munin munin-node spawn-fcgi libcgi-fast-perl
The following sections configure the munin packages.

Munin configuration

Write the munin configuration below to /etc/munin/munin-conf.d/90-fcgi

graph_strategy cgi
html_strategy cgi
cgiurl_graph /munin/munin-cgi-graph

NGINX configuration

Write the nginx configuration below to /etc/nginx/sites-available/munin.conf

server {
  #listen 443 ssl;
  listen 7000;
  charset utf-8;
  #server_name munin.your-domain.com;
  location ~ ^/munin/munin-cgi-graph/ {
    fastcgi_split_path_info ^(/munin/munin-cgi-graph)(.*);
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_pass unix:/var/run/munin/fastcgi-graph.sock;
    include fastcgi_params;
  }
  location /munin/static/ {
    alias /etc/munin/static/;
    expires modified +1w;
  }
  location /munin/ {
    fastcgi_split_path_info ^(/munin)(.*);
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_pass unix:/var/run/munin/fastcgi-html.sock;
    include fastcgi_params;
  }
  location / {
    rewrite ^/$ munin/ redirect; break;
  }
}
This configuration assumes that you have a DNS entry set aside for reaching the monit pages. I have separate DNS entries for all my applications, and they're all CNAMEs for the (same) machine that they're running on.
Once you're done tweaking the script, reload nginx.

sudo /etc/init.d/nginx reload

FastCGI daemons

Write the script below to /etc/init.d/munin-fcgi
#!/bin/bash

### BEGIN INIT INFO
# Provides:          munin-fcgi
# Required-Start:    $remote_fs $syslog $network
# Required-Stop:     $remote_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start munin FCGI processes at boot time
# Description:       Start the FCGI processes behind http://munin.*/
### END INIT INFO

graph_pidfile="/var/run/munin/fcgi_graph.pid"
# Ubuntu 12.10: /usr/lib/cgi-bin/munin-cgi-graph
graph_cgi="/usr/lib/munin/cgi/munin-cgi-graph"
html_pidfile="/var/run/munin/fcgi_html.pid"
# Ubuntu 12.10: /usr/lib/cgi-bin/munin-cgi-html
html_cgi="/usr/lib/munin/cgi/munin-cgi-html"

retval=0

. /lib/lsb/init-functions

start() {
  echo -n "Starting munin graph FastCGI: "
  start_daemon -p ${graph_pidfile} /usr/bin/spawn-fcgi -u munin -g munin \
      -s /var/run/munin/fastcgi-graph.sock -U www-data ${graph_cgi}
  echo
  echo -n "Starting munin html FastCGI: "
  start_daemon -p ${html_pidfile} /usr/bin/spawn-fcgi -u munin -g munin \
      -s /var/run/munin/fastcgi-html.sock -U www-data ${html_cgi}
  echo
  retval=$?
}
stop() {
  echo -n "Stopping munin graph FastCGI: "
  killproc -p ${graph_pidfile} ${graph_cgi} -QUIT
  echo
  echo -n "Stopping munin html FastCGI: "
  killproc -p ${html_pidfile} ${html_cgi} -QUIT
  echo
  retval=$?
}
case "$1" in
  start)
    start
  ;;
  stop)
    stop
  ;;
  restart)
    stop
    start
  ;;
  *)
    echo "Usage: munin-fcgi {start|stop|restart}"
    exit 1
  ;;
esac
exit $retval
Make the script executable, and fix some permissions while you're at it.

sudo chmod +x /etc/init.d/munin-fcgi
sudo chown munin /var/log/munin/munin-cgi-*
Now that the init.d script is in place, start it and have it run on every boot.

sudo /etc/init.d/munin-fcgi start
sudo update-rc.d munin-fcgi defaults

Debugging

You should be able to point your browser to http://[ip_address]:7000 and see many graphs. If that doesn't work out, the logs below should give you a clue as to what went wrong.

/var/log/nginx/error.log
/var/log/munin/munin-cgi-graph.log
/var/log/munin/munin-cgi-html.log

Conclusion

I hope that you have found my post useful, and I hope that it helped you get your munin monitoring setup up and running in a manner of minutes.

Thứ Tư, 24 tháng 2, 2016

MONITOR MACOSX USING MUNIN

Munin
Munin is a great monitoring tool that I started using on one of my daily work projects(linux servers recently), it gives you beautiful graphs out of the box, without all the installing problems of other great tools (nagios, cacti).
Due that the documentation in the official page is somewhat incomplete for a full installation case, I found that these steps are the most easy to follow to make your Mac up&running with monitoring on!

Install
1. Install Xcode
2. Install Xcode Developer Tools, the easy way is to type in terminal:
sudo xcode-select --install
3. Install MacPorts
4. Update port(always useful)
sudo port selfupdate
5. Check that you have Java SE SDK installed(javac required) if not install it
6. Install munin(server & node) using port:
sudo port install munin +server
if this fails install rrdtool first and try again, rrdtool is a dependency of munin, but in my case port failed building rrdtool the firts time
sudo port install rrdtool
7. Install suggested plugins
sudo -u munin munin-node-configure --suggest --shell | sudo sh
8. Enable munin at startup
sudo port load munin
9. Munin paths
We need apache(or some web server) to fetch the graphs, with this in mind is useful to mention that this default installation creates several paths, with the relevant ones being:

Munin pid
/opt/local/var/run/munin/munin-node.pid
Config scripts
/opt/local/etc/munin/munin.conf
/opt/local/etc/munin/munin-node.conf
Html dir
/opt/local/www/munin
Data dir
/opt/local/var/munin


10. Creating virtual host for munin
Uncomment in /etc/apache2/httpd.conf
from
#Include /private/etc/apache2/extra/httpd-vhosts.conf
to
Include /private/etc/apache2/extra/httpd-vhosts.conf
Add virtual host in /private/etc/apache2/extra/httpd-vhosts.conf

<VirtualHost *:80>
    ServerName munin.localhost
    DocumentRoot "/opt/local/www/"
    ErrorLog "/private/var/log/apache2/munin.localhost-error_log"
    CustomLog "/private/var/log/apache2/munin.localhost-access_log" common
    <Directory "/opt/local/www/munin">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from 127.0.0.1
    </Directory>
</VirtualHost>
11. Modify /etc/hosts to your liking adding the following line
127.0.0.1    munin.localhost
12. Start apache:
sudo apachectl start
13. .htaccess permissions
By default munin places an .htaccess file in /opt/local/www/munin/.htaccess that configures basic http auth, in my case, i have my apache listening only in 127.0.0.1 so I disabled the basic auth commenting the lines:
#AuthUserFile /opt/local/etc/munin/munin-htpasswd
#AuthName "Munin"
#AuthType Basic
#require valid-user
14. Make apache load on startup[optional]:
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
15. In a couple of minutes go to your monitoring page and have fun port default: 4949. http://munin.localhost:4949/munin
And that’s all.