PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/disk/diskio.py/diskio.py

http://github.com/ganglia/gmetric
Python | 58 lines | 32 code | 7 blank | 19 comment | 4 complexity | c2f54280d6970628f1c7362d2bf95522 MD5 | raw file
  1. #!/usr/bin/python
  2. ###############################################################
  3. # gmetric For Disk IO
  4. ###############################################################
  5. # REQs: pminfo, gmetric
  6. # DATE: 21 December 2004
  7. # (C)2004 DigiTar, All Rights Reserved
  8. ###############################################################
  9. import os, re, time
  10. ### Set Sampling Interval (in secs)
  11. interval = 1
  12. ### Set PCP Config Parameters
  13. cmdPminfo = "/usr/bin/pminfo -f "
  14. reDiskIO = re.compile(r'"(\w+)"] value (\d+)\n') # RegEx To Compute Value
  15. ### Set Ganglia Config Parameters
  16. gangliaMetricType = "uint32"
  17. gangliaMcastPort = "8649"
  18. ### NOTE: To add a new PCP disk metric, add the appropriate entry to each dictionary item of gangliaMetrics
  19. ### Each "vertical" column of the dictionary is a different metric entry group.
  20. gangliaMetrics = { "pcpmetric": ["disk.dev.read", "disk.dev.write", "disk.dev.blkread", "disk.dev.blkwrite"], \
  21. "name": ["diskio_readbytes", "diskio_writebytes", "diskio_readblks", "diskio_writeblks"], \
  22. "unit": ["Kbytes/s", "Kbytes/s", "Blocks/s", "Blocks/s"], \
  23. "type": ["uint32", "uint32", "uint32", "uint32"]}
  24. cmdGmetric = "/usr/bin/gmetric"
  25. ### Zero Sample Lists
  26. ### NOTE: Make sure each sample array has as many (device) sub-arrays as there are pcpmetrics being sampled
  27. ### NOTE: Sub-arrays are artificially sized at 4 disk devices...if you have more disk devices than 4, increase this size.
  28. lastSample = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
  29. currSample = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
  30. ### Read PCP Metrics
  31. while(1):
  32. # Interate Through Each PCP Disk IO Metric Desired
  33. for x in range(0, len(gangliaMetrics["pcpmetric"])):
  34. pminfoInput, pminfoOutput = os.popen2(cmdPminfo + gangliaMetrics["pcpmetric"][x], 't')
  35. deviceLines = pminfoOutput.readlines()
  36. pminfoInput.close()
  37. pminfoOutput.close()
  38. # Output Metric Data For Each Device Returned By The PCP Metric
  39. deviceIndex = 2 # Skip the first two lines in the buffer
  40. while(deviceIndex < len(deviceLines)):
  41. result = reDiskIO.search(deviceLines[deviceIndex])
  42. if(result):
  43. currSample[x][deviceIndex] = int(result.group(2))
  44. cmdExec = cmdGmetric + " --name=" + gangliaMetrics["name"][x] + "_" + \
  45. result.group(1) + " --value=" + str((currSample[x][deviceIndex] - lastSample[x][deviceIndex])) + \
  46. " --type=" + gangliaMetrics["type"][x] + " --units=\"" + gangliaMetrics["unit"][x] + "\"" + \
  47. " --mcast_port=" + gangliaMcastPort
  48. gmetricResult = os.system(cmdExec)
  49. lastSample[x][deviceIndex] = currSample[x][deviceIndex]
  50. deviceIndex = deviceIndex + 1
  51. time.sleep(interval)