Changeset 700
- Timestamp:
- 03/21/13 16:38:54 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/0.4/jobmond/jobmond.py
r699 r700 1691 1691 del self.jobs[ id ] 1692 1692 1693 #1694 # Gmetric by Nick Galbreath - nickg(a.t)modp(d.o.t)com1695 # Version 1.0 - 21-April2-20071696 # http://code.google.com/p/embeddedgmetric/1697 #1698 # Modified by: Ramon Bastiaans1699 # For the Job Monarch Project, see: https://subtrac.sara.nl/oss/jobmonarch/1700 #1701 # added: DEFAULT_TYPE for Gmetric's1702 # added: checkHostProtocol to determine if target is multicast or not1703 # changed: allow default for Gmetric constructor1704 # changed: allow defaults for all send() values except dmax1705 #1706 1707 1693 GMETRIC_DEFAULT_TYPE = 'string' 1708 1694 GMETRIC_DEFAULT_HOST = '127.0.0.1' 1709 1695 GMETRIC_DEFAULT_PORT = '8649' 1710 GMETRIC_DEFAULT_UNITS 1696 GMETRIC_DEFAULT_UNITS = '' 1711 1697 1712 1698 class Gmetric: … … 1714 1700 global GMETRIC_DEFAULT_HOST, GMETRIC_DEFAULT_PORT 1715 1701 1716 slope = { 'zero' : 0, 'positive' : 1, 'negative' : 2, 'both' : 3, 'unspecified' : 4 }1717 type = ( '', 'string', 'uint16', 'int16', 'uint32', 'int32', 'float', 'double', 'timestamp' )1718 protocol = ( 'udp', 'multicast' )1702 slope = { 'zero' : 0, 'positive' : 1, 'negative' : 2, 'both' : 3, 'unspecified' : 4 } 1703 type = ( '', 'string', 'uint16', 'int16', 'uint32', 'int32', 'float', 'double', 'timestamp' ) 1704 protocol = ( 'udp', 'multicast' ) 1719 1705 1720 1706 def __init__( self, host=GMETRIC_DEFAULT_HOST, port=GMETRIC_DEFAULT_PORT ): 1721 1707 1722 1708 global GMETRIC_DEFAULT_TYPE 1723 1709 1724 1710 self.prot = self.checkHostProtocol( host ) 1725 self.msg = xdrlib.Packer() 1711 self.data_msg = xdrlib.Packer() 1712 self.meta_msg = xdrlib.Packer() 1726 1713 self.socket = socket.socket( socket.AF_INET, socket.SOCK_DGRAM ) 1727 1714 … … 1747 1734 MULTICAST_ADDRESS_MAX = ( "239", "255", "255", "255" ) 1748 1735 1749 ip_fields = ip.split( '.' )1736 ip_fields = ip.split( '.' ) 1750 1737 1751 1738 if ip_fields >= MULTICAST_ADDRESS_MIN and ip_fields <= MULTICAST_ADDRESS_MAX: … … 1758 1745 1759 1746 if len( units ) == 0: 1760 units 1747 units = GMETRIC_DEFAULT_UNITS 1761 1748 1762 1749 if len( typestr ) == 0: 1763 typestr = GMETRIC_DEFAULT_TYPE 1764 1765 msg = self.makexdr( name, value, typestr, units, self.slopestr, self.tmax, dmax ) 1766 1767 return self.socket.sendto( msg, self.hostport ) 1768 1769 def makexdr( self, name, value, typestr, unitstr, slopestr, tmax, dmax ): 1750 typestr = GMETRIC_DEFAULT_TYPE 1751 1752 (meta_msg, data_msg) = self.makexdr( name, value, typestr, units, self.slopestr, self.tmax, dmax ) 1753 1754 meta_rt = self.socket.sendto( meta_msg, self.hostport ) 1755 data_rt = self.socket.sendto( data_msg, self.hostport ) 1756 1757 return ( meta_rt, data_rt ) 1758 1759 def makexdr( self, name, value, typestr, unitstr, slopestr, tmax, dmax, group=None, spoof=None ): 1760 1761 hostname = "unset" 1770 1762 1771 1763 if slopestr not in self.slope: … … 1781 1773 raise ValueError( "Name must be non-empty" ) 1782 1774 1783 self.msg.reset() 1784 self.msg.pack_int( 0 ) 1785 self.msg.pack_string( typestr ) 1786 self.msg.pack_string( name ) 1787 self.msg.pack_string( str( value ) ) 1788 self.msg.pack_string( unitstr ) 1789 self.msg.pack_int( self.slope[ slopestr ] ) 1790 self.msg.pack_uint( int( tmax ) ) 1791 self.msg.pack_uint( int( dmax ) ) 1792 1793 return self.msg.get_buffer() 1775 self.meta_msg.reset() 1776 self.meta_msg.pack_int( 128 ) 1777 1778 if not spoof: 1779 self.meta_msg.pack_string( hostname ) 1780 else: 1781 self.meta_msg.pack_string( spoof ) 1782 1783 self.meta_msg.pack_string( name ) 1784 1785 if not spoof: 1786 self.meta_msg.pack_int( 0 ) 1787 else: 1788 self.meta_msg.pack_int( 1 ) 1789 1790 self.meta_msg.pack_string( typestr ) 1791 self.meta_msg.pack_string( name ) 1792 self.meta_msg.pack_string( unitstr ) 1793 self.meta_msg.pack_int( self.slope[ slopestr ] ) 1794 self.meta_msg.pack_uint( int( tmax ) ) 1795 self.meta_msg.pack_uint( int( dmax ) ) 1796 1797 if not group: 1798 self.meta_msg.pack_int( 0 ) 1799 else: 1800 self.meta_msg.pack_int( 1 ) 1801 self.meta_msg.pack_string( "GROUP" ) 1802 self.meta_msg.pack_string( group ) 1803 1804 self.data_msg.reset() 1805 self.data_msg.pack_int( 128+5 ) 1806 1807 if not spoof: 1808 self.data_msg.pack_string( hostname ) 1809 else: 1810 self.data_msg.pack_string( spoof ) 1811 1812 self.data_msg.pack_string( name ) 1813 1814 if not spoof: 1815 self.data_msg.pack_int( 0 ) 1816 else: 1817 self.data_msg.pack_int( 1 ) 1818 1819 self.data_msg.pack_string( "%s" ) 1820 self.data_msg.pack_string( str( value ) ) 1821 1822 return ( self.meta_msg.get_buffer(), self.data_msg.get_buffer() ) 1794 1823 1795 1824 def printTime( ):
Note: See TracChangeset
for help on using the changeset viewer.