File: supermon_example.rb

package info (click to toggle)
sfsexp 1.4.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 808 kB
  • sloc: ansic: 5,959; sh: 119; cpp: 61; python: 49; perl: 43; makefile: 42; ruby: 39
file content (61 lines) | stat: -rw-r--r-- 2,032 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#
# SFSEXP: Small, Fast S-Expression Library version 1.0
# Written by Matthew Sottile (matt@lanl.gov)
# 
# Copyright (2003-2006). The Regents of the University of California. This
# material was produced under U.S. Government contract W-7405-ENG-36 for Los
# Alamos National Laboratory, which is operated by the University of
# California for the U.S. Department of Energy. The U.S. Government has rights
# to use, reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR
# THE UNIVERSITY MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY
# LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to produce
# derivative works, such modified software should be clearly marked, so as not
# to confuse it with the version available from LANL.
# 
# Additionally, this library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of the
# License, or (at your option) any later version.
# 
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
# for more details.
# 
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, U SA
# 
# LA-CC-04-094
# 

#
# sample client for supermon written in ruby!
#
require "Sexp"
require "socket"

s = TCPsocket.open("localhost",2709)

100.times {
  
  s.write("0x40S\n")
  str = s.recv(65535)
  
  sx = Sexp.new(str)
  
  a = sx.getAry()
  
  avg = [0.0,0.0,0.0]
  nn = a.length
  
  a.each do |samp|
    avg[0] = avg[0] + ((samp[4][1]+0.0) / nn)
    avg[1] = avg[1] + ((samp[4][2]+0.0) / nn)
    avg[2] = avg[2] + ((samp[4][3]+0.0) / nn)
  end;
  
  puts sprintf("%f %f %f",avg[0],avg[1],avg[2])
 
  sleep 10
}