{ "info": { "author": "Danny Lawrence", "author_email": "dannyla@linux.com", "bugtrack_url": null, "classifiers": [], "description": "# Total, a tribute to awk\n\nWhile writing my last post I made up some syntax ( pseudo syntax ) that dose not work, for a command that dose not exist... however I think that it should.\n\nThe syntax was to get the average CPU idle time from the last 3 seconds, via the vmstat command.\n\n```sh\nvmstat 1 3 | total '$id:average'\n```\n\nThis made me stop writing the post and start working on the new command and then this post.\n\n[![Build Status](https://travis-ci.org/daniellawrence/total.png?branch=master)](https://travis-ci.org/daniellawrence/total)\n\ntotal\n------\n\nThe command is called *total* and is very much inspired by awk.\n\nThe total command is a trade in awk massive power inlue of easy syntax, for the common problems.\n\n\nexample time\n-------------\n\nThe problem that I was facing working out the average of a set of numbers generated by a command: in this case it was *vmstat*\n\n```sh\n$ vmstat 1 3\nprocs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----\n r b swpd free buff cache si so bi bo in cs us sy id wa\n 0 0 0 6207264 85564 949404 0 0 29 4 107 178 2 1 98 0\n 0 0 0 6201800 85564 955036 0 0 0 0 403 396 0 0 100 0\n 0 0 0 6201552 85572 955244 0 0 0 80 591 677 2 1 98 0\n```\n\nI wanted to grab the average cpu idle, this is case it is column 15, pictured above its values are: 'id', '98', '100' and '98'\n\n```sh\n$ vmstat 1 3 | awk 'BEGIN {id_total=0; count=0}\n{id_total+=$15;count+=1}\nEND{print id_total/count}'\n```\n\nThe above is a try at doing this in awk, however i know that is going to fail because one of the values is 'id', which is not a number.\n\nEnter total\n-----------\n\nTo add everything up in the 15th column, you just need the syntax of '''$15'''\n\n```sh\n$ vmstat 1 3 | total '$15'\n297\n```\n\nOne of the advantages of total is that its *header aware*.\nIn the case of the first sample of vmstat, it will understand that the 15 column is called \"id\".\n\nThis means that you can do the following, to get the total id.\n\n```sh\n$ vmstat 1 3 | total '$id'\n297\n```\n\nYou can reference the data as either the name of the column (:total is the default)\n```sh\n# vmstat 1 3 | ./total/total.py '$cache $cache:total $6 $6:total'\n8262988 8262988 8262988 8262988\n```\n\nTotaling or a Sum is nice, However the total amount of idle cpu time isn't a very good marker.\nWhat you really want is the average id...\n\n```sh\n$ vmstat 1 3 | total '$id:avg'\n99\n```\n\nOr maybe just the max id\n\n```sh\n$ vmstat 1 3 | total '$id:max'\n100\n```\n\nOr maybe you want to have this formatted for a email or alert.\n\n```sh\n$ vmstat 1 3 | total 'The average idle cpu was $id:avg, with the max of $id:max'\nThe average idle cpu was 97, with the max of 98\n```\n\n\nOR maybe something crazy like the average cache minus the average buff\n\n```sh\nvmstat 1 2 | total '$cache:avg - $buff:avg'|bc\n1932560\n```\n\nTo get a list of all the *keys* that can be used in the *$* ( dollar ) notation you can just run total with --list\n\n```sh\n$ vmstat 1 2 | totat --list ''\nYou can use the following cols for: :total, :avg, :min, :max\nbo, buff, cache, cs, free, id, in, r, si, so, swpd, sy, us, wa\n```\n\nIts not just for vmstat either...\n\n```sh\nnetstat -i | total --list ''\nYou can use the following cols for: :total, :avg, :min, :max\nflg, iface, met, mtu, rx-drp, rx-err, rx-ok, rx-ovr, tx-drp, tx-err, tx-ok, tx-ovr\n```\n\nHow to Install!\n--------\n\nInstall from pip\n\n```sh\n$ sudo pip install total\n# test\n$ vmstat 1 3 | total '$id:avg'\n```\n\nInstall from source\n\n```sh\n$ git clone git://github.com/daniellawrence/total\n$ cd total\n$ sudo ./setup.py install\n# test\n$ vmstat 1 3 | total '$id:avg'\n```", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/daniellawrence/total", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "total", "package_url": "https://pypi.org/project/total/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/total/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/daniellawrence/total" }, "release_url": "https://pypi.org/project/total/0.0.7/", "requires_dist": null, "requires_python": null, "summary": "Simple AWK tasks, made awesome", "version": "0.0.7" }, "last_serial": 862836, "releases": { "0.0.2": [ { "comment_text": "", "digests": { "md5": "024c58ee31bdf2f0a26836240b8d9edb", "sha256": "32d6d0422a1a40da94cb8bea96b95a9f36017cea8bf5ba5571fc68f6b5d47e0a" }, "downloads": -1, "filename": "total-0.0.2.tar.gz", "has_sig": false, "md5_digest": "024c58ee31bdf2f0a26836240b8d9edb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3597, "upload_time": "2013-09-11T10:45:09", "url": "https://files.pythonhosted.org/packages/f4/c9/bfde5c0f72fbb79c7981286c69f94d89587d98fc0035b33a4abe95bad700/total-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "8632f807c4e8499037f48c49968c7308", "sha256": "e63347c063528928ff526b210f9b6a7c8f60f95c1502c5668277b65b2eee26da" }, "downloads": -1, "filename": "total-0.0.3.tar.gz", "has_sig": false, "md5_digest": "8632f807c4e8499037f48c49968c7308", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5016, "upload_time": "2013-09-11T10:48:06", "url": "https://files.pythonhosted.org/packages/b5/b7/8231681b40c43d7b46647016940bcecb2375ed9268a1290b345b3e65764d/total-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "13d3587757fd5d6132d77099c7e1a930", "sha256": "c4fd482645fd2eb7e09da2c7794e0b0c000903d9dd1b0696b57ee2e2a05001c1" }, "downloads": -1, "filename": "total-0.0.4.tar.gz", "has_sig": false, "md5_digest": "13d3587757fd5d6132d77099c7e1a930", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5051, "upload_time": "2013-09-11T13:07:38", "url": "https://files.pythonhosted.org/packages/6c/af/9727e9ce91f3ef8a9e2a541517c22d79e26ad3f9592043682f8e6efd6bd5/total-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "c4c77a9a03c12059e96de4848877255d", "sha256": "0aecf43ec19fc2c4f63a3bcb4a9718b09ed591d2d4c52748ba68348452912f5f" }, "downloads": -1, "filename": "total-0.0.5.tar.gz", "has_sig": false, "md5_digest": "c4c77a9a03c12059e96de4848877255d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3809, "upload_time": "2013-09-11T13:16:25", "url": "https://files.pythonhosted.org/packages/bd/7c/30955e523fcf9de54a4147cf3234ea457a07b6cea205e0657fb50d1c62fe/total-0.0.5.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "73ff650fb883151f24204ea14a2f5535", "sha256": "b069eecac47636b8040d07908ff1dab6718645cdba82cf1f0d2a11bbd728e784" }, "downloads": -1, "filename": "total-0.0.6.tar.gz", "has_sig": false, "md5_digest": "73ff650fb883151f24204ea14a2f5535", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5288, "upload_time": "2013-09-11T14:08:41", "url": "https://files.pythonhosted.org/packages/17/a2/fe96b12aa2a62f4e35a09354267e46112ba64766d96808ab310103c55489/total-0.0.6.tar.gz" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "6d520e3f8d8dceae176ec8fc0de42a7c", "sha256": "dff683ccaab01fa5ee27230562362f7ff2965cc0239ae4e286086621649e3985" }, "downloads": -1, "filename": "total-0.0.7.tar.gz", "has_sig": false, "md5_digest": "6d520e3f8d8dceae176ec8fc0de42a7c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5300, "upload_time": "2013-09-11T15:11:22", "url": "https://files.pythonhosted.org/packages/3d/81/d9e4bbcdad8aed3bc13c2d78e587906138d71df3bc032a1da52326794a56/total-0.0.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6d520e3f8d8dceae176ec8fc0de42a7c", "sha256": "dff683ccaab01fa5ee27230562362f7ff2965cc0239ae4e286086621649e3985" }, "downloads": -1, "filename": "total-0.0.7.tar.gz", "has_sig": false, "md5_digest": "6d520e3f8d8dceae176ec8fc0de42a7c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5300, "upload_time": "2013-09-11T15:11:22", "url": "https://files.pythonhosted.org/packages/3d/81/d9e4bbcdad8aed3bc13c2d78e587906138d71df3bc032a1da52326794a56/total-0.0.7.tar.gz" } ] }