473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

fetching values from rrd file

20
Hi
I am trying to cycle through values i fetch from an rrd file with a python script and this is the code i have
Expand|Select|Wrap|Line Numbers
  1. output = rrdtool.fetch("mutime.rrd", 'AVERAGE')
  2. trmaxTuples = output[2]
  3. n  = len(trmaxTuples)
  4. for n in trmaxTuples:
  5.     if (trmaxTuples > 100):
  6.         print n
  7.     else:
  8.         print "0"
  9.  
  10.  
Here is the result i get
(43.0,)
(46.0,)
(69.0,)
(41.0,)
(51.0,)
(62.0,)
(55.0,)

But i am trying to extract the values one at a time out of the brackets and use them in making a comparison.

I will appreciate your help very much.

Thanks
Apr 16 '13 #1

✓ answered by bvdet

You assign len(trmaxTuples) to "n", but you reassign "n" to each element of trmaxTuples in the for loop. Do you want to print "n" if it is greater than 100? The following prints "n" if greater than 50.
Expand|Select|Wrap|Line Numbers
  1. trmaxTuples = ((43.0,),(46.0,),(69.0,),(41.0,),(51.0,),(62.0,),(55.0,))
  2.  
  3. for item in trmaxTuples:
  4.     n = item[0]
  5.     if n > 50:
  6.         print n
  7.     else:
  8.         print "x"
The output:
Expand|Select|Wrap|Line Numbers
  1. >>> x
  2. x
  3. 69.0
  4. x
  5. 51.0
  6. 62.0
  7. 55.0
  8. >>> 

4 8451
bvdet
2,851 Expert Mod 2GB
You assign len(trmaxTuples) to "n", but you reassign "n" to each element of trmaxTuples in the for loop. Do you want to print "n" if it is greater than 100? The following prints "n" if greater than 50.
Expand|Select|Wrap|Line Numbers
  1. trmaxTuples = ((43.0,),(46.0,),(69.0,),(41.0,),(51.0,),(62.0,),(55.0,))
  2.  
  3. for item in trmaxTuples:
  4.     n = item[0]
  5.     if n > 50:
  6.         print n
  7.     else:
  8.         print "x"
The output:
Expand|Select|Wrap|Line Numbers
  1. >>> x
  2. x
  3. 69.0
  4. x
  5. 51.0
  6. 62.0
  7. 55.0
  8. >>> 
Apr 16 '13 #2
kaf3773
20
Smashing!! Thanks a lot bvdet this worked.
Apr 16 '13 #3
kaf3773
20
I am trying to extend this code for an rrd file with multiple datasources.

When i run this code
Expand|Select|Wrap|Line Numbers
  1. trmaxTuples = rrdtool.fetch("mutime.rrd", 'AVERAGE', '-s -2hr')
  2. for item in trmaxTuples:
  3.         n = item[1]
  4.         if n > 50:
  5.             print n
  6.         else:
  7.             print "x"
  8.  
i get the results below
Expand|Select|Wrap|Line Numbers
  1. -bash-3.2$ /opt/csw/bin/python alarming.py 
  2. 1425417900
  3. second
  4. (9637507.0800000001, 10465039.640000001, 98183.733333333337, 84958.386666666673)
  5. -bash-3.2$ 
  6.  
When i run rrdtool fetch from the command line here is what i get

Expand|Select|Wrap|Line Numbers
  1. -bash-3.2$ /opt/csw/bin/rrdtool fetch mutime.rrd AVERAGE -s -2hr
  2.                        first            second            third            fourth
  3.  
  4. 1425410700: 9.7907263600e+06 1.0574282213e+07 9.9081866667e+04 8.6084040000e+04
  5. 1425411000: 9.6375070800e+06 1.0465039640e+07 9.8183733333e+04 8.4958386667e+04
  6. 1425411300: 9.5396297067e+06 1.0361895200e+07 9.7132146667e+04 8.4087973333e+04
  7. 1425411600: 9.4494586067e+06 1.0304070603e+07 9.6382913333e+04 8.3760376667e+04
  8. 1425411900: 9.4662621467e+06 1.0230560960e+07 9.6236346667e+04 8.3033670000e+04
  9. 1425412200: 9.3551098567e+06 1.0105500320e+07 9.4713120000e+04 8.2404246667e+04
  10.  
I would appreciate if you can help me cycle through the values of first and i am assuming it will be the same way to cycle through the values of second, third and fourth which are the datasources in the rrd file.

Thanks
Mar 3 '15 #4
kaf3773
20
After a number of hours at this here is the code i came up with that works for me. improvements to this will be very much appreciated.
Expand|Select|Wrap|Line Numbers
  1. trmaxTuples = rrdtool.fetch("mutime.rrd", 'AVERAGE', '-s -2hr')
  2. n = trmaxTuples[2]
  3. p = 0
  4. for p in range(len(n)):
  5.     s = n[p]
  6.     print s
  7.     first = s[0]
  8.     print first
  9.     second = s[1]
  10.     print second
  11.     third = s[2]
  12.     print third
  13.     fourth = s[3]
  14.     print fourth
  15. p = p + 1
  16.  
  17.  
Mar 4 '15 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: David Jacques | last post by:
I have to write a console application which will fetch a zip on a daily basis. This zip file is hotlinked in a web page. The name of this .zip file will change every day. I've been able to start...
4
by: Mark | last post by:
I am loading source files into several iframes, with each load happening after some user-generated event (like clicking a button). The loading works but I need to determine when the source file is...
6
by: Divya | last post by:
Hi, I have a web page which generates a CSV file based on some user input. When this file is downloaded by the user, the file is being automatically converted to .xls. Any idea how I can prevent...
2
by: Simon Verona | last post by:
Hi, This must be simple (I hope)! I've tried a google search but can't seem to find what I want (probably using the wrong search keys!) I'm trying to simply save a complete dataset as a CSV...
8
by: Andrew Robert | last post by:
Hi Everyone. I tried the following to get input into optionparser from either a file or command line. The code below detects the passed file argument and prints the file contents but the...
9
by: warezguy05 | last post by:
Hello I'm experiencing a problem; I've written a small script where volunteers can be booked for work-activities at a festival. The festival has 5 different departments so i've created a...
2
by: novffal | last post by:
how to get values from db in DHTML popup window
2
by: padmaja3 | last post by:
Hi all, I have written a query like this. ---------------------------------------------------------- $dbh= DBI->connect("dbi:mysql:dbname=$database;host=$hostname", "$username", "$password"); ...
4
by: Bob Altman | last post by:
Hi all, I have a C++/CLI project (VS 2005) that produces a DLL that exports C bindings. Internally, this DLL contains routines compiled with /clr. I notice that my DLL doesn't have a version...
3
by: sweetneel | last post by:
i have a file named abc.pcl i want to convert it abc.dat in c#.net how to do it. i am fetching this file from a directory, and i have to save it as abc.dat. file name should be same, but...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.