haavard82 has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I'm writing a perl script that reads the /proc/diskstats file and it's supposed to calculate how many blocks per second is written to the harddisk. I just can't figure how to do the calculations. I have read the documentation file for /proc/diskstats but still can't figure it out. SHould I look at the number of sectors, writes merged, completed writes, or what? I hope someone has got some pointers for me, because I'm stuck :(
  • Comment on (OT) Get the number of blocks per second by reading the proc diskstats file

Replies are listed 'Best First'.
Re: (OT) Get the number of blocks per second by reading the proc diskstats file
by keszler (Priest) on Nov 13, 2011 at 15:40 UTC

      Thank you for your comment. :)

      I just figured I could use tune2fs in combination with some other piped commands in order to get the block size from the device. Then I'll just assume that one write is one block equal to the block size of the device. I guess I'm thinking correct, yes? (block devices are really not my strong side)

      And another thing. I decided to try out Perlmonks' forum because of the good reputation I discovered this site had when doing some Google-ing after some good Perl forums.

      As to the discussion above where bad-mouthing and smart-assing towards my question as it seems to be ridiculous by another user I can just say that I barely came back to this forum because of that.

      But anyhow, I am fairly capable of programming in Perl, though my question seemed non-Perl-ish by the content of the post.

      I still hope someone has some tricks up their sleeves when it comes to handling the /proc/diskstats file when it comes to calculating different statistics from the data within that file.

      Thank you

        Take a look at the source for Sys::Statistics::Linux::DiskStats. It includes comments like:

        # ------------------------------------------------------------ +-- # The sectors are equivalent with blocks and have a size of 51 +2 # bytes since 2.4 kernels. This value is needed to calculate t +he # amount of disk i/o's in bytes. # ------------------------------------------------------------ +-- blocksize => 512,
        Reading the code and seeing how the module's author calculates values should be helpful.

      Thanks for coming back and sharing the progress you've made. There are some great people here. Take a look around the site when you have some time. Read sections like PerlMonks FAQ, Selected Best Nodes and check out some of the members' home nodes. Keep posting. :)

Re: (OT) Get the number of blocks per second by reading the proc diskstats file
by ww (Archbishop) on Nov 13, 2011 at 15:02 UTC
    Asserting that you're "writing a perl script" doesn't make your actual question a Perl question.

    Use a search engine and the keywords "proc diskstats" if you want answers about the content of /proc/diskstats.

    Helpful addendum: /proc is NOT where disk statistics live on every distro of Linux, so you may wish to consult the docs for your flavor and/or use "diskstats Linux"as your SE keywords.

      Thank you for your answer. I agree that the question might not be an actual Perl question, but since I'm scripting with Perl I had some hopes that someone had some experience to share. I already used Google for tons of searches without any luck. If someone knows how to create some snippets of code and perhaps share some ideas of which values to use from the diskstats file, and also how to do the actual calculation, it would be very helpful. I'm sorry if my question is slightly non-Perl, but this place is one of my last hopes at the moment.

        "if my question is slightly non-Perl....

        No, your question is entirely non-Perl; in fact, somewhat akin to:

        "I'm cooking a turkey for dinner. Please provide a synopsis of Turkish history"

        As to "tons of searchs," didn't you find man proc referenced somewhere... or the documentation itself, http://linux.die.net/man/5/proc?

        man proc will tell you, among other things:

        /proc/pid/stat
        Status information about the process. This is used by ps(1). It is defined in /usr/src/linux/fs/proc/array.c.
        The fields, in order, with their proper scanf(3) format specifiers, are:
        ....

        Update: If you don't Read The Fine Manual, you really shouldn't expect the Monks to do your reading, interpretation and coding for you. See On asking for help and How do I post a question effectively?