root / plugins / kamailio / kamailio_memory @ 17f78427
Historique | Voir | Annoter | Télécharger (3,15 ko)
| 1 | 72e4561a | Oussama Hammami | #!/usr/bin/perl |
|---|---|---|---|
| 2 | # -*- perl -*- |
||
| 3 | |||
| 4 | =head1 NAME |
||
| 5 | |||
| 6 | Munin plugin to monitor the usage of memory on Voxtrot Sip Server (Kamailio + Freeswitch + RTPproxy). |
||
| 7 | |||
| 8 | =head1 CONFIGURATION |
||
| 9 | |||
| 10 | No configuration |
||
| 11 | |||
| 12 | =head1 AUTHOR |
||
| 13 | |||
| 14 | Copyright 2012 - Voxtrot <www.voxtrot.com> |
||
| 15 | Oussama Hammami <oussamacvoxtrot.com> |
||
| 16 | |||
| 17 | =head1 LICENSE |
||
| 18 | |||
| 19 | GPLv2 |
||
| 20 | |||
| 21 | =head1 VERSION |
||
| 22 | |||
| 23 | $Id: kamailio_memory 2012-04-19 15:09 $ |
||
| 24 | |||
| 25 | =head1 MAGIC MARKERS |
||
| 26 | |||
| 27 | #%# family=manual |
||
| 28 | #%# capabilities=autoconf |
||
| 29 | |||
| 30 | =cut |
||
| 31 | |||
| 32 | use strict; |
||
| 33 | |||
| 34 | 17f78427 | Lars Kruse | my %WANTED = ( "kamailio" => "ram_total", |
| 35 | 72e4561a | Oussama Hammami | "rtpproxy" => "ram_rtpproxy", |
| 36 | 17f78427 | Lars Kruse | "freeswitch" => "ram_freeswitch", |
| 37 | 72e4561a | Oussama Hammami | ); |
| 38 | |||
| 39 | my %VALUE = ( "ram_total" => 0, |
||
| 40 | "ram_rtpproxy" => 0, |
||
| 41 | "ram_freeswitch" => 0, |
||
| 42 | ); |
||
| 43 | |||
| 44 | my $arg = shift(); |
||
| 45 | |||
| 46 | if ($arg eq 'config') {
|
||
| 47 | print_config(); |
||
| 48 | exit(); |
||
| 49 | } elsif ($arg eq 'autoconf') {
|
||
| 50 | unless (test_service() ) {
|
||
| 51 | print "yes\n"; |
||
| 52 | } else {
|
||
| 53 | print "no\n"; |
||
| 54 | } |
||
| 55 | exit 0; |
||
| 56 | } |
||
| 57 | |||
| 58 | for my $key (keys %WANTED) {
|
||
| 59 | $VALUE{$WANTED{$key}}=get_memory($key);
|
||
| 60 | } |
||
| 61 | |||
| 62 | $VALUE{"ram_total"}+=$VALUE{"ram_rtpproxy"}+$VALUE{"ram_freeswitch"};
|
||
| 63 | |||
| 64 | for my $key (keys %VALUE) {
|
||
| 65 | print ("$key.value $VALUE{$key}\n");
|
||
| 66 | } |
||
| 67 | |||
| 68 | sub print_config {
|
||
| 69 | print ("graph_title Voxtrot SIP Server Memory\n");
|
||
| 70 | # Arguments to "rrdtool graph". In this case, tell it that the |
||
| 71 | # lower limit of the graph is '0', and that 1k=1000 (not 1024). |
||
| 72 | print("graph_args --base 1024 --lower-limit 0\n");
|
||
| 73 | print("graph_vlabel MB\n");
|
||
| 74 | print("graph_scale no\n");
|
||
| 75 | c4b2d9a8 | dipohl | print("graph_category voip\n");
|
| 76 | 72e4561a | Oussama Hammami | print("graph_info The graph describes the usage of memory in Voxtrot Sip Server.\n");
|
| 77 | print("ram_total.label total (kam+fs+rtp)\n");
|
||
| 78 | print("ram_freeswitch.label freeswitch\n");
|
||
| 79 | print("ram_rtpproxy.label rtpproxy\n");
|
||
| 80 | print("ram_total.info Average total memory used by kamailio, freeswitch and rtpproxy for the five minutes.\n");
|
||
| 81 | print("ram_freeswitch.info Average used memory by freeswitch for the five minutes.\n");
|
||
| 82 | print("ram_rtpproxy.info Average real used memory by rtpproxy for the five minutes.\n");
|
||
| 83 | print("graph_order ram_total ram_freeswitch ram_rtpproxy\n");
|
||
| 84 | print("ram_total.type GAUGE\n");
|
||
| 85 | print("ram_freeswitch.type GAUGE\n");
|
||
| 86 | print("ram_rtpproxy.type GAUGE\n");
|
||
| 87 | print("ram_total.draw AREA\n");
|
||
| 88 | print("ram_freeswitch.draw AREA\n");
|
||
| 89 | print("ram_rtpproxy.draw LINE1\n");
|
||
| 90 | print("ram_total.colour 6699FF\n");
|
||
| 91 | print("ram_freeswitch.colour FF6633\n");
|
||
| 92 | print("ram_rtpproxy.colour 993399\n");
|
||
| 93 | # Ensure min values (useful when using 'DERIVE' as 'type'). |
||
| 94 | print("ram_total.min 0\n");
|
||
| 95 | print("ram_freeswitch.min 0\n");
|
||
| 96 | print("ram_rtpproxy.min 0\n");
|
||
| 97 | # Divide the got value by 1048576 to get MB. |
||
| 98 | print("ram_total.cdef ram_total,1048576,/\n");
|
||
| 99 | print("ram_freeswitch.cdef ram_freeswitch,1048576,/\n");
|
||
| 100 | print("ram_rtpproxy.cdef ram_rtpproxy,1048576,/\n");
|
||
| 101 | } |
||
| 102 | |||
| 103 | |||
| 104 | sub test_service {
|
||
| 105 | print "yes\n"; |
||
| 106 | exit 0; |
||
| 107 | } |
||
| 108 | |||
| 109 | ######################### |
||
| 110 | # function Get Memory |
||
| 111 | |||
| 112 | sub get_memory {
|
||
| 113 | my $proc=shift; |
||
| 114 | my $i = 0; |
||
| 115 | my @cmd = `ps auwx | grep $proc | grep -v grep | grep -v kamailio_memory`; |
||
| 116 | foreach (@cmd) {
|
||
| 117 | my @return = split(/ +/, $_); |
||
| 118 | $i += @return[5]*1024; |
||
| 119 | } |
||
| 120 | return $i; |
||
| 121 | } |
