Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[gentoo-user] [OT] rrd to CSV

1 view
Skip to first unread message

Mick

unread,
Jul 4, 2009, 11:40:10 AM7/4/09
to
Hi All,

I know that rrdtool dump will export the rrd data into XML, but is there
something to either directly or via rrdtool create a CSV file for me? Will
probably want to run this on a cron job and email/save it.
--
Regards,
Mick

signature.asc

Mark Shields

unread,
Jul 4, 2009, 12:30:18 PM7/4/09
to
Judging from a few cursory google searches, it won't output to CSV, but you can easily convert it.  Try piping the file/output to these commands (yanked from Cacti forums):

| grep -v NaN | grep '<row>' | tr e ' ' \
| awk {'print "Q"$2"qcq"$3"qcq"$9"Q"'} \ 
| tr Q '"' | tr c ',' | tr q '"'"


Haven't tested it, but looks like it should work.
--
- Mark Shields

Mick

unread,
Jul 4, 2009, 3:30:18 PM7/4/09
to

Thanks Mark, will give it a go and let you know.

--
Regards,
Mick

signature.asc

Mick

unread,
Jul 5, 2009, 6:10:11 PM7/5/09
to
On Saturday 04 July 2009, Mark Shields wrote:

Hmm, I don't think it gets anywhere:
=======================================
cat test.xml | grep -v NaN | grep '<row>' | tr e ' ' | awk
{'print "Q"$2"qcq"$3"qcq"$9"Q"'} | tr Q '"' | tr c ',' | tr q '"'" > test.csv
>
=======================================

It just sits there at the > cursor. I think it needs something more to it, or
I am not feeding the XML file to it correctly?

--
Regards,
Mick

signature.asc

Willie Wong

unread,
Jul 6, 2009, 12:20:12 PM7/6/09
to
On Sun, Jul 05, 2009 at 11:07:23PM +0100, Penguin Lover Mick squawked:

> > from Cacti forums):
> > | grep -v NaN | grep '<row>' | tr e ' ' \
> > | awk {'print "Q"$2"qcq"$3"qcq"$9"Q"'} \
> > | tr Q '"' | tr c ',' | tr q '"'"
> >
> > Haven't tested it, but looks like it should work.
>
> Hmm, I don't think it gets anywhere:
> =======================================
> cat test.xml | grep -v NaN | grep '<row>' | tr e ' ' | awk
> {'print "Q"$2"qcq"$3"qcq"$9"Q"'} | tr Q '"' | tr c ',' | tr q '"'" > test.csv
> >
> =======================================
>
> It just sits there at the > cursor. I think it needs something more to it, or

Looks like a syntax error with improperly nested quotations marks.

The last command in the sequence, which reads

tr q '"'"

try replacing that with

tr q '"'

(remove the final double quote)

W
--
"`Eddies,' said Ford, `in the space-time continuum.'
`Ah,' nodded Arthur, `is he? Is he?'"

- Arthur failing in his first lesson of galactic physics
in four years.
Sortir en Pantoufles: up 941 days, 15:00

Mick

unread,
Jul 11, 2009, 11:00:18 AM7/11/09
to
On Monday 06 July 2009, Willie Wong wrote:
> On Sun, Jul 05, 2009 at 11:07:23PM +0100, Penguin Lover Mick squawked:
> > > from Cacti forums):
> > > | grep -v NaN | grep '<row>' | tr e ' ' \
> > > | awk {'print "Q"$2"qcq"$3"qcq"$9"Q"'} \
> > > | tr Q '"' | tr c ',' | tr q '"'"
> > >
> > > Haven't tested it, but looks like it should work.
> >
> > Hmm, I don't think it gets anywhere:
> > =======================================
> > cat test.xml | grep -v NaN | grep '<row>' | tr e ' ' | awk
> > {'print "Q"$2"qcq"$3"qcq"$9"Q"'} | tr Q '"' | tr c ',' | tr q '"'" >
> > test.csv
> >
> > =======================================
> >
> > It just sits there at the > cursor. I think it needs something more to
> > it, or
>
> Looks like a syntax error with improperly nested quotations marks.
>
> The last command in the sequence, which reads
>
> tr q '"'"
>
> try replacing that with
>
> tr q '"'
>
> (remove the final double quote)
>
> W

Thank you both! It works to a point. This is what the xml file contains:

<database>
<!-- 2009-07-02 07:41:00 EDT / 1246534860 --> <row><v>
7.3395000000e+01 </v><v> 4.7990000000e+01 </v></row>

The CSV file only shows the first value and then it does not pick up the fact
that it is exponential:

"2009-07-02","07:41:00","7.3395000000"

How could it be tweaked to a)account for e+01, b)include additional value
fields?

Thanks again.
--
Regards,
Mick

signature.asc

Willie Wong

unread,
Jul 12, 2009, 8:00:17 PM7/12/09
to
On Sat, Jul 11, 2009 at 03:57:26PM +0100, Penguin Lover Mick squawked:

> > > Hmm, I don't think it gets anywhere:
> > > =======================================
> > > cat test.xml | grep -v NaN | grep '<row>' | tr e ' ' | awk
> > > {'print "Q"$2"qcq"$3"qcq"$9"Q"'} | tr Q '"' | tr c ',' | tr q '"'" >
> > > test.csv
> > >
> > > =======================================
> > >
> > > It just sits there at the > cursor. I think it needs something more to
> > > it, or
> >
> > Looks like a syntax error with improperly nested quotations marks.
> >
> > The last command in the sequence, which reads
> >
> > tr q '"'"
> >
> > try replacing that with
> >
> > tr q '"'
> >
> > (remove the final double quote)
> >
> > W
>
> Thank you both! It works to a point. This is what the xml file contains:
>
> <database>
> <!-- 2009-07-02 07:41:00 EDT / 1246534860 --> <row><v>
> 7.3395000000e+01 </v><v> 4.7990000000e+01 </v></row>
>
> The CSV file only shows the first value and then it does not pick up the fact
> that it is exponential:
>
> "2009-07-02","07:41:00","7.3395000000"
>
> How could it be tweaked to a)account for e+01, b)include additional value
> fields?
>

Try:

cat test.xml | grep -v NaN | grep '<row>' | awk {'print "Q"$2"qcq"$3"qcq"$9"qcq"$11"Q"'} | tr Q '"' | tr c ',' | tr q '"'" > test.csv

Just to help you help yourself later: the 'tr' command "translates".
So the command

tr e ' '

swaps occurences of the letter e with a blank space. Removing that
command keeps the e in the numbers. (Though I am not certain how CSV
files deal with e notations...). awk prints the space-separated
fields. $2, $3, etc are the number of the field respectively. So
adding $11 allows printing the one additional field.

This, of course, only works if you have the same number of records in
each row.

HTH,

W
--
A gossip is someone with a great sense of rumour.
Sortir en Pantoufles: up 947 days, 22:39

0 new messages