statvfs

Discussion in 'Python' started by Korthrun, Oct 29, 2007.

  1. Korthrun

    Korthrun Guest

    I'm writing some scripts to populate RRD's, mainly for practicing python.

    As such I've decided to play with statvfs in order to build disk
    graphs. Here is what I have and what I get. What I'm curious about
    here is the meaning of the "L" charcter, as that fubars math.

    ###start code###

    from os import statvfs, path
    from statvfs import *

    mps = [ '/', '/home', '/www', '/var', '/storage/backups',
    '/storage/snd' ]

    for fs in mps:
    data = statvfs(fs)
    print data

    ###end code, start output###
    (4096, 4096, 4883593L, 4045793L, 4045793L, 0L, 0L, 0L, 1024, 255)
    (4096, 4096, 1220889L, 1114718L, 1114718L, 0L, 0L, 0L, 0, 255)
    (4096, 4096, 19267346L, 18273138L, 18273138L, 0L, 0L, 0L, 0, 255)
    (4096, 4096, 3662687L, 3492397L, 3492397L, 0L, 0L, 0L, 0, 255)
    (4096, 4096, 3417702L, 2116063L, 2116063L, 0L, 0L, 0L, 0, 255)
    (4096, 4096, 25885944L, 21799115L, 21799115L, 0L, 0L, 0L, 0, 255)
    ###end output###

    Ideally I'll just do some blocksize * number of blocks math to get
    the % of used space. I know I could just .strip() the L, but I'd
    to know what it means

    Thanks,

    Korth
    Korthrun, Oct 29, 2007
    #1
    1. Advertising

  2. On Mon, 29 Oct 2007 16:52:12 -0500, Korthrun wrote:

    > I'm writing some scripts to populate RRD's, mainly for practicing python.
    >
    > As such I've decided to play with statvfs in order to build disk
    > graphs. Here is what I have and what I get. What I'm curious about
    > here is the meaning of the "L" charcter, as that fubars math.


    The L means its a `long` literal, i.e. an integer value that can be
    arbitrary big. Well its limited by memory of course.

    And it doesn't "fubar" math, the L just shows up in the string
    representation but you don't calculate with strings but numbers.

    > ###start code###
    >
    > from os import statvfs, path
    > from statvfs import *
    >
    > mps = [ '/', '/home', '/www', '/var', '/storage/backups',
    > '/storage/snd' ]
    >
    > for fs in mps:
    > data = statvfs(fs)
    > print data
    >
    > ###end code, start output###
    > (4096, 4096, 4883593L, 4045793L, 4045793L, 0L, 0L, 0L, 1024, 255)
    > (4096, 4096, 1220889L, 1114718L, 1114718L, 0L, 0L, 0L, 0, 255)
    > (4096, 4096, 19267346L, 18273138L, 18273138L, 0L, 0L, 0L, 0, 255)
    > (4096, 4096, 3662687L, 3492397L, 3492397L, 0L, 0L, 0L, 0, 255)
    > (4096, 4096, 3417702L, 2116063L, 2116063L, 0L, 0L, 0L, 0, 255)
    > (4096, 4096, 25885944L, 21799115L, 21799115L, 0L, 0L, 0L, 0, 255)
    > ###end output###
    >
    > Ideally I'll just do some blocksize * number of blocks math to get
    > the % of used space.


    Just go ahead and do it:

    In [185]: stat = os.statvfs('/')

    In [186]: stat.f_bsize
    Out[186]: 4096

    In [187]: stat.f_blocks
    Out[187]: 2622526L

    In [188]: stat.f_bsize * stat.f_blocks
    Out[188]: 10741866496L

    Ciao,
    Marc 'BlackJack' Rintsch
    Marc 'BlackJack' Rintsch, Oct 29, 2007
    #2
    1. Advertising

  3. Korthrun

    Korthrun Guest

    At 2007-10-29, expressed thier undying love for me by saying:
    > On Mon, 29 Oct 2007 16:52:12 -0500, Korthrun wrote:
    >
    >> I'm writing some scripts to populate RRD's, mainly for practicing python.
    >>
    >> As such I've decided to play with statvfs in order to build disk
    >> graphs. Here is what I have and what I get. What I'm curious about
    >> here is the meaning of the "L" charcter, as that fubars math.

    >
    > The L means its a `long` literal, i.e. an integer value that can be
    > arbitrary big. Well its limited by memory of course.
    >
    > And it doesn't "fubar" math, the L just shows up in the string
    > representation but you don't calculate with strings but numbers.
    >
    >> ###start code###
    >>
    >> from os import statvfs, path
    >> from statvfs import *
    >>
    >> mps = [ '/', '/home', '/www', '/var', '/storage/backups',
    >> '/storage/snd' ]
    >>
    >> for fs in mps:
    >> data = statvfs(fs)
    >> print data
    >>
    >> ###end code, start output###
    >> (4096, 4096, 4883593L, 4045793L, 4045793L, 0L, 0L, 0L, 1024, 255)
    >> (4096, 4096, 1220889L, 1114718L, 1114718L, 0L, 0L, 0L, 0, 255)
    >> (4096, 4096, 19267346L, 18273138L, 18273138L, 0L, 0L, 0L, 0, 255)
    >> (4096, 4096, 3662687L, 3492397L, 3492397L, 0L, 0L, 0L, 0, 255)
    >> (4096, 4096, 3417702L, 2116063L, 2116063L, 0L, 0L, 0L, 0, 255)
    >> (4096, 4096, 25885944L, 21799115L, 21799115L, 0L, 0L, 0L, 0, 255)
    >> ###end output###
    >>
    >> Ideally I'll just do some blocksize * number of blocks math to get
    >> the % of used space.

    >
    > Just go ahead and do it:
    >
    > In [185]: stat = os.statvfs('/')
    >
    > In [186]: stat.f_bsize
    > Out[186]: 4096
    >
    > In [187]: stat.f_blocks
    > Out[187]: 2622526L
    >
    > In [188]: stat.f_bsize * stat.f_blocks
    > Out[188]: 10741866496L
    >
    > Ciao,
    > Marc 'BlackJack' Rintsch

    Thanks for the response, I'll have to play with it more, as I'm
    obviously misunderstanding the error that I'm getting.
    I didn't include the part of the script that did the math, as it
    wasn't important to my base question.

    I was getting TypeError: "sequence index must be integer", so I
    thought the L was making python see it as a string.

    Thanks for the insight

    Josh
    Korthrun, Oct 30, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sreejith K

    statvfs clearance

    Sreejith K, Apr 4, 2009, in forum: Python
    Replies:
    3
    Views:
    521
    Albert Hopkins
    Apr 4, 2009
Loading...

Share This Page