Ad Widget

Collapse

Monitoring ESX datastore

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jay
    Junior Member
    • Dec 2009
    • 11

    #1

    Monitoring ESX datastore

    Hi,

    Here is a small script to monitor ESX datastore. It is very simple so be free to improve it :

    ZABBIX_SERVER="zabbixhostname";
    ZABBIX_PORT="zabbixport";

    ZABBIX_SENDER="/pathtozabbixsender";
    KEY=$1;
    HOST="ESXhostname"
    TOTAL=100
    VALUE=""

    VALUE=`/usr/sbin/vdf -h | grep /vmfs/volumes/$1 | awk '{print $4}' | sed 's/%//g'`

    if [[ $VALUE = [0-9][0-9] ]] || [[ $VALUE = [0-9] ]]; then
    VALUE=$(( $TOTAL -$VALUE ))
    $ZABBIX_SENDER -z $ZABBIX_SERVER -p $ZABBIX_PORT -s $HOST -k $KEY -o $VALUE
    else
    $ZABBIX_SENDER -z $ZABBIX_SERVER -p $ZABBIX_PORT -s $HOST -k $KEY -o "0"
    fi


    Regards

    Jay
  • benito103e
    Junior Member
    • Jun 2010
    • 24

    #2
    details

    Hi,

    Thanks for the script, i'm a beginner in zabbix monitoring and i'm french So please excuse me if i make mistakes.

    I would want to know how you use this script?
    What is the language ? is it just algo ?

    I'm searching the best way to monitoring my ESX 4:
    - Zabbix agent
    - snmp (with Vsphere?)

    ?

    Thanks you.

    Comment

    • Murilex
      Senior Member
      • Nov 2009
      • 124

      #3
      It's a little bit difficult to have all configured, but I use and recommend the usage of the scripts presented on this post:



      My hardware is not HP and I could easily adapt the scripts in order to get them working.

      Comment

      • benito103e
        Junior Member
        • Jun 2010
        • 24

        #4
        Originally posted by Murilex
        ...but I use and recommend the usage of the scripts presented on this post:



        My hardware is not HP and I could easily adapt the scripts in order to get them working.
        Ok But how do you use these scripts?

        I've Dells

        - Did you install zabbix agent on the esx (I have the impression that is what dima_dm did?? )

        Excuse me, I find it not easy to understand all the procedure because of my tongue

        Thanks for your help

        Comment

        • Murilex
          Senior Member
          • Nov 2009
          • 124

          #5
          Although the scripts were made for ESX machines, I successfully use them to monitor ESXi (freeware version of VMware ESX) servers.

          To use the scripts, you first have to elect a machine that will collect the ESX data. One option is to use zabbix server. As those scripts use to degread a little bit the server performance, I've decided to use another machine to collect the ESX data and send them to zabbix server.

          On this elected machine I've installed "VMware Infrastructure (VI) Perl Toolkit" and "WBEM wbemcli" as required on the post http://www.zabbix.com/forum/showthread.php?t=15691. Then I've configured cron to run "/etc/zabbix/zabbix_wbem_vmware.pl" and "/etc/zabbix/zabbix_perl_api_vmware.pl" regularly and send the output to zabbix server. On the zabbix server I've created a script that reads this output.

          Comment

          • benito103e
            Junior Member
            • Jun 2010
            • 24

            #6
            Very Interesting

            Is there a software required in ESX (to add ?) ?

            Originally posted by Murilex
            On the zabbix server I've created a script that reads this output.
            does Your script use the zabbix_sender??

            I think I will use Zabbix_server to collect ESX data, and change a little bit the script to send directly information to zabbix and not write it on a file (perhaps the two things at the same time)
            --> zabbix server will launch the script : deleting cron

            Thanks !
            Last edited by benito103e; 02-06-2010, 16:55.

            Comment

            • Murilex
              Senior Member
              • Nov 2009
              • 124

              #7
              No, it's not necessary to install any software in ESX. I don't use zabbix_sender presently, but this is for sure a good alternative.

              Comment

              • benito103e
                Junior Member
                • Jun 2010
                • 24

                #8
                Ok,

                So what do you use to get data in Zabbix ?

                I will read the manuel to how use script, and get back information in zabbix server !

                Thank you very much !

                Comment

                • Murilex
                  Senior Member
                  • Nov 2009
                  • 124

                  #9
                  Hello benito103e. As I said, I use a simple script on zabbix server that read data from a plain file. This plain file is generated on a helper machine (that I elected) and moved to zabbix server from times to times (by using scp!).

                  Comment

                  • benito103e
                    Junior Member
                    • Jun 2010
                    • 24

                    #10
                    Hi Murilex,

                    Thanks for all your precision, It lights me

                    I'll choose my way to get data, with your advice.

                    Comment

                    • gavind
                      Member
                      • Mar 2013
                      • 59

                      #11
                      Originally posted by benito103e
                      Hi Murilex,

                      Thanks for all your precision, It lights me

                      I'll choose my way to get data, with your advice.
                      Hi buddy, were you able to set this up for production already? How is it?

                      Comment

                      • Voxie
                        Junior Member
                        • Jul 2009
                        • 24

                        #12
                        We have created a Windows powershell script:

                        Code:
                        @"
                        ===============================================================================
                        Title: 			Report-Datastores.ps1
                        Description: 	Report Datastore usage for all Datastores managed by vCenter
                        Requirements: 	Windows Powershell and the VI Toolkit
                        Usage:			.\Report-Datastores.ps1
                        ===============================================================================
                        "@
                        
                        #ADD VMWARE PSSNAPIN 
                        Add-PSSnapin -Name “VMware.VimAutomation.Core”
                        #FORCE TO LOAD VMWARE POWERSHELL PLUGIN 
                        [Reflection.Assembly]::LoadWithPartialName(“vmware.vim”)
                        
                        
                        #Global Functions
                        #This function generates a nice HTML output that uses CSS for style formatting.
                        function Generate-Report {
                        
                         
                        				Foreach ($store in $report){
                        					
                        					echo $($store.name)
                        					cmd.exe /c "C:\Zabbix\zabbix_sender.exe -z <zabbixip> -s $($store.name) -k data.store.total.space -o $($store.CapacityMB)" 
                        					cmd.exe /c "C:\Zabbix\zabbix_sender.exe -z <zabbixip> -s $($store.name) -k data.store.free.space -o $($store.FreeMB)" 
                        					cmd.exe /c "C:\Zabbix\zabbix_sender.exe -z <zabbixip> -s $($store.name) -k data.store.free.percent -o $($store.PercFRee)" 
                        
                        				}
                        
                        	}
                        
                        #Login details
                        $username = '<username>'
                        $password = '<password>'
                        
                        #Current, Previous, Difference File information
                        $digits = 2
                        $Folder = 'C:\Reports'
                        
                        #List of servers including Virtual Center Server.  The account this script will run as will need at least Read-Only access to Virtual Center
                        $VIServer = "<vcenter server"	
                        
                        #Initialise Array
                        $Report = @()
                        
                        # Connect to Virtual Center
                        $VC = Connect-VIServer $VIServer -user $username -password $password
                        
                        # Get all datastores and put them in alphabetical order
                        #$datastores = Get-Datastore | Sort-Object Name
                        
                        #Get all datastores and put them in alphabetical order
                        		foreach ($server in $serverlist){
                        		
                        		# Check is server is a Virtual Center Server and connect with current user
                        		if ($server -eq "VCServer"){Connect-VIServer $VIServer}
                        		
                        		# Use specific login details for the rest of servers in $serverlist
                        		else {Connect-VIServer $VIServer -user $username -password $password}
                        		
                        		
                        		Get-Datastore | Sort-Object Name | %{
                        			$Store = {} | Select Name, CapacityMB, FreeMB, PercFree
                        			$Store.Name = $_.name
                        			$Store.CapacityMB = [math]::Round(($_.capacityMB*1024)*1024,0)
                        			$Store.FreeMB = [math]::Round(($_.FreeSpaceMB*1024)*1024,0)
                        			$Store.PercFree = [math]::Round(100*$_.FreeSpaceMB/$_.CapacityMB,$digits)
                        			$Report += $Store
                        								}
                        		# Disconnect from Virtual Center
                        		Disconnect-VIServer -Confirm:$False
                        		}
                        										
                        # Disconnect from Virtual Center
                        Disconnect-VIServer -Confirm:$False
                        
                        # Generate the report and email it as a HTML body of an email
                        Generate-Report

                        You only have to change:
                        <zabbixip> = IP of the zabbix server
                        <username> = Username for vCenter
                        <password> = Password for vCenter

                        We run the script on a Windows server with the vSphere client and commandline tools installed.


                        In zabbix we have created a template:

                        Code:
                        <?xml version="1.0" encoding="UTF-8"?>
                        <zabbix_export version="1.0" date="17.07.13" time="14.30">
                          <hosts>
                            <host name="Databalance - VMWare datastores">
                              <proxy_hostid>0</proxy_hostid>
                              <useip>1</useip>
                              <dns></dns>
                              <ip>127.0.0.1</ip>
                              <port>10050</port>
                              <status>3</status>
                              <useipmi>0</useipmi>
                              <ipmi_ip>127.0.0.1</ipmi_ip>
                              <ipmi_port>623</ipmi_port>
                              <ipmi_authtype>0</ipmi_authtype>
                              <ipmi_privilege>2</ipmi_privilege>
                              <ipmi_username></ipmi_username>
                              <ipmi_password></ipmi_password>
                              <groups>
                                <group>Templates</group>
                              </groups>
                              <triggers>
                                <trigger>
                                  <description>Low space on datastore</description>
                                  <type>0</type>
                                  <expression>{Databalance - VMWare datastores:data.store.free.space.last(0)}&lt;53687091200</expression>
                                  <url></url>
                                  <status>0</status>
                                  <priority>4</priority>
                                  <comments></comments>
                                </trigger>
                                <trigger>
                                  <description>Low space on datastore</description>
                                  <type>0</type>
                                  <expression>{Databalance - VMWare datastores:data.store.free.space.last(0)}&lt;70530636800 &amp; {Databalance - VMWare datastores:data.store.free.space.last(0)}&gt;53687091200</expression>
                                  <url></url>
                                  <status>0</status>
                                  <priority>2</priority>
                                  <comments></comments>
                                </trigger>
                              </triggers>
                              <items>
                                <item type="2" key="data.store.free.percent" value_type="0">
                                  <description>Free Percent Datastore</description>
                                  <ipmi_sensor></ipmi_sensor>
                                  <delay>60</delay>
                                  <history>90</history>
                                  <trends>365</trends>
                                  <status>0</status>
                                  <data_type>0</data_type>
                                  <units>%</units>
                                  <multiplier>0</multiplier>
                                  <delta>0</delta>
                                  <formula>0</formula>
                                  <lastlogsize>0</lastlogsize>
                                  <logtimefmt></logtimefmt>
                                  <delay_flex></delay_flex>
                                  <authtype>0</authtype>
                                  <username></username>
                                  <password></password>
                                  <publickey></publickey>
                                  <privatekey></privatekey>
                                  <params></params>
                                  <trapper_hosts></trapper_hosts>
                                  <snmp_community></snmp_community>
                                  <snmp_oid></snmp_oid>
                                  <snmp_port>161</snmp_port>
                                  <snmpv3_securityname></snmpv3_securityname>
                                  <snmpv3_securitylevel>0</snmpv3_securitylevel>
                                  <snmpv3_authpassphrase></snmpv3_authpassphrase>
                                  <snmpv3_privpassphrase></snmpv3_privpassphrase>
                                  <valuemapid>0</valuemapid>
                                  <applications>
                                    <application>VMWare Datastores</application>
                                  </applications>
                                </item>
                                <item type="2" key="data.store.free.space" value_type="3">
                                  <description>Free Space Datastore</description>
                                  <ipmi_sensor></ipmi_sensor>
                                  <delay>60</delay>
                                  <history>90</history>
                                  <trends>365</trends>
                                  <status>0</status>
                                  <data_type>0</data_type>
                                  <units>B</units>
                                  <multiplier>0</multiplier>
                                  <delta>0</delta>
                                  <formula>0</formula>
                                  <lastlogsize>0</lastlogsize>
                                  <logtimefmt></logtimefmt>
                                  <delay_flex></delay_flex>
                                  <authtype>0</authtype>
                                  <username></username>
                                  <password></password>
                                  <publickey></publickey>
                                  <privatekey></privatekey>
                                  <params></params>
                                  <trapper_hosts></trapper_hosts>
                                  <snmp_community></snmp_community>
                                  <snmp_oid></snmp_oid>
                                  <snmp_port>161</snmp_port>
                                  <snmpv3_securityname></snmpv3_securityname>
                                  <snmpv3_securitylevel>0</snmpv3_securitylevel>
                                  <snmpv3_authpassphrase></snmpv3_authpassphrase>
                                  <snmpv3_privpassphrase></snmpv3_privpassphrase>
                                  <valuemapid>0</valuemapid>
                                  <applications>
                                    <application>VMWare Datastores</application>
                                  </applications>
                                </item>
                                <item type="2" key="data.store.total.space" value_type="3">
                                  <description>Total Space Datastore</description>
                                  <ipmi_sensor></ipmi_sensor>
                                  <delay>60</delay>
                                  <history>90</history>
                                  <trends>365</trends>
                                  <status>0</status>
                                  <data_type>0</data_type>
                                  <units>B</units>
                                  <multiplier>0</multiplier>
                                  <delta>0</delta>
                                  <formula>0</formula>
                                  <lastlogsize>0</lastlogsize>
                                  <logtimefmt></logtimefmt>
                                  <delay_flex></delay_flex>
                                  <authtype>0</authtype>
                                  <username></username>
                                  <password></password>
                                  <publickey></publickey>
                                  <privatekey></privatekey>
                                  <params></params>
                                  <trapper_hosts></trapper_hosts>
                                  <snmp_community></snmp_community>
                                  <snmp_oid></snmp_oid>
                                  <snmp_port>161</snmp_port>
                                  <snmpv3_securityname></snmpv3_securityname>
                                  <snmpv3_securitylevel>0</snmpv3_securitylevel>
                                  <snmpv3_authpassphrase></snmpv3_authpassphrase>
                                  <snmpv3_privpassphrase></snmpv3_privpassphrase>
                                  <valuemapid>0</valuemapid>
                                  <applications>
                                    <application>VMWare Datastores</application>
                                  </applications>
                                </item>
                              </items>
                              <templates/>
                              <graphs>
                                <graph name="Datastore space" width="900" height="200">
                                  <ymin_type>0</ymin_type>
                                  <ymax_type>0</ymax_type>
                                  <ymin_item_key></ymin_item_key>
                                  <ymax_item_key></ymax_item_key>
                                  <show_work_period>0</show_work_period>
                                  <show_triggers>0</show_triggers>
                                  <graphtype>0</graphtype>
                                  <yaxismin>0.0000</yaxismin>
                                  <yaxismax>100.0000</yaxismax>
                                  <show_legend>0</show_legend>
                                  <show_3d>0</show_3d>
                                  <percent_left>0.0000</percent_left>
                                  <percent_right>0.0000</percent_right>
                                  <graph_elements>
                                    <graph_element item="Databalance - VMWare datastores:data.store.total.space">
                                      <drawtype>2</drawtype>
                                      <sortorder>0</sortorder>
                                      <color>000000</color>
                                      <yaxisside>0</yaxisside>
                                      <calc_fnc>2</calc_fnc>
                                      <type>0</type>
                                      <periods_cnt>5</periods_cnt>
                                    </graph_element>
                                    <graph_element item="Databalance - VMWare datastores:data.store.free.space">
                                      <drawtype>1</drawtype>
                                      <sortorder>1</sortorder>
                                      <color>009900</color>
                                      <yaxisside>0</yaxisside>
                                      <calc_fnc>2</calc_fnc>
                                      <type>0</type>
                                      <periods_cnt>5</periods_cnt>
                                    </graph_element>
                                  </graph_elements>
                                </graph>
                              </graphs>
                              <macros/>
                            </host>
                          </hosts>
                          <dependencies/>
                        </zabbix_export>
                        With schedule tasks we run the script every 30 minutes.
                        It generates a trigger when datastore is almost full.


                        Hopefully somebody can use the script.

                        Comment

                        • hemaworst
                          Junior Member
                          • Mar 2014
                          • 1

                          #13
                          Originally posted by Voxie
                          We have created a Windows powershell script:

                          You only have to change:
                          <zabbixip> = IP of the zabbix server
                          <username> = Username for vCenter
                          <password> = Password for vCenter

                          We run the script on a Windows server with the vSphere client and commandline tools installed.


                          In zabbix we have created a template:



                          With schedule tasks we run the script every 30 minutes.
                          It generates a trigger when datastore is almost full.


                          Hopefully somebody can use the script.
                          Hi,

                          I've tried this script but run into this error message:
                          ESXVOL1
                          the system can not find the file specified
                          the system can not find the file specified
                          the system can not find the file specified
                          ESXVOL2
                          the system can not find the file specified
                          the system can not find the file specified
                          the system can not find the file specified

                          etc.

                          Maybe you can help?

                          p.s. sorry for my engelish

                          Comment

                          Working...