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 -
output = rrdtool.fetch("mutime.rrd", 'AVERAGE')
-
trmaxTuples = output[2]
-
n = len(trmaxTuples)
-
for n in trmaxTuples:
-
if (trmaxTuples > 100):
-
print n
-
else:
-
print "0"
-
-
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
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. - trmaxTuples = ((43.0,),(46.0,),(69.0,),(41.0,),(51.0,),(62.0,),(55.0,))
-
-
for item in trmaxTuples:
-
n = item[0]
-
if n > 50:
-
print n
-
else:
-
print "x"
The output: - >>> x
-
x
-
69.0
-
x
-
51.0
-
62.0
-
55.0
-
>>>
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. - trmaxTuples = ((43.0,),(46.0,),(69.0,),(41.0,),(51.0,),(62.0,),(55.0,))
-
-
for item in trmaxTuples:
-
n = item[0]
-
if n > 50:
-
print n
-
else:
-
print "x"
The output: - >>> x
-
x
-
69.0
-
x
-
51.0
-
62.0
-
55.0
-
>>>
Smashing!! Thanks a lot bvdet this worked.
I am trying to extend this code for an rrd file with multiple datasources.
When i run this code -
trmaxTuples = rrdtool.fetch("mutime.rrd", 'AVERAGE', '-s -2hr')
-
for item in trmaxTuples:
-
n = item[1]
-
if n > 50:
-
print n
-
else:
-
print "x"
-
i get the results below -
-bash-3.2$ /opt/csw/bin/python alarming.py
-
1425417900
-
second
-
(9637507.0800000001, 10465039.640000001, 98183.733333333337, 84958.386666666673)
-
-bash-3.2$
-
When i run rrdtool fetch from the command line here is what i get -
-bash-3.2$ /opt/csw/bin/rrdtool fetch mutime.rrd AVERAGE -s -2hr
-
first second third fourth
-
-
1425410700: 9.7907263600e+06 1.0574282213e+07 9.9081866667e+04 8.6084040000e+04
-
1425411000: 9.6375070800e+06 1.0465039640e+07 9.8183733333e+04 8.4958386667e+04
-
1425411300: 9.5396297067e+06 1.0361895200e+07 9.7132146667e+04 8.4087973333e+04
-
1425411600: 9.4494586067e+06 1.0304070603e+07 9.6382913333e+04 8.3760376667e+04
-
1425411900: 9.4662621467e+06 1.0230560960e+07 9.6236346667e+04 8.3033670000e+04
-
1425412200: 9.3551098567e+06 1.0105500320e+07 9.4713120000e+04 8.2404246667e+04
-
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
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. -
trmaxTuples = rrdtool.fetch("mutime.rrd", 'AVERAGE', '-s -2hr')
-
n = trmaxTuples[2]
-
p = 0
-
for p in range(len(n)):
-
s = n[p]
-
print s
-
first = s[0]
-
print first
-
second = s[1]
-
print second
-
third = s[2]
-
print third
-
fourth = s[3]
-
print fourth
-
p = p + 1
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: novffal |
last post by:
how to get values from db in DHTML popup window
|
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");
...
|
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...
|
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...
|
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$) {
}
...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |