show_ip_stats.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. #
  3. # Copyright (c) 2017-2018 Joe Clarke <jclarke@cisco.com>
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. # 1. Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. # notice, this list of conditions and the following disclaimer in the
  13. # documentation and/or other materials provided with the distribution.
  14. #
  15. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  16. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  19. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. # SUCH DAMAGE.
  26. $contents = file_get_contents("/home/jclarke/cached_ip_stats.dat");
  27. $contents = trim($contents);
  28. $stats = explode(" ", $contents);
  29. $total = $stats[0] + $stats[1];
  30. $p4 = ($stats[0] / $total) * 100;
  31. $p6 = ($stats[1] / $total) * 100;
  32. $p4 = number_format($p4, 2);
  33. $p6 = number_format($p6, 2);
  34. $g4 = ($stats[0] / (1000*1000*1000));
  35. $g6 = ($stats[1] / (1000*1000*1000));
  36. $mtime = date ("F d Y H:i:s", filemtime("/home/jclarke/cached_ip_stats.dat"));
  37. ?>
  38. <html>
  39. <head>
  40. <link href="/c3.css" rel="stylesheet" type="text/css">
  41. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  42. <script src="/d3.min.js" charset="utf-8"></script>
  43. <script src="/c3.min.js"></script>
  44. <script>
  45. setTimeout("location.reload(true);", 300000);
  46. </script>
  47. <style type="text/css">
  48. .c3-grid line {
  49. stroke: none;
  50. }
  51. .c3-axis-x > path.domain, .tick > line[x2="-6"] {
  52. visibility: hidden;
  53. }
  54. .c3 svg {
  55. font-size: 16pt;
  56. }
  57. .DeviceTable { table-layout: fixed; }
  58. </style>
  59. </head>
  60. <body>
  61. <h1 style="text-align: center">IPv4 / IPv6 Traffic Ratio</h1>
  62. <div style="text-align: right; font-size: 10pt;"><b>Last Updated: <?=$mtime?></b></div>
  63. <div id="chart_div" class="rChart uvcharts"></div>
  64. <div align="center" style="margin-top: 10px; font-size: 18pt; font-weight: bold;">% of Traffic</div>
  65. <script language="javascript">
  66. var chart = c3.generate({
  67. bindto: '#chart_div',
  68. bar: {
  69. width: 40,
  70. units: ' %'
  71. },
  72. padding: {
  73. left: 120
  74. },
  75. color: {
  76. pattern: ['#006666', '#666699']
  77. },
  78. data: {
  79. x: 'x',
  80. columns: [
  81. ['x', 'IPv4 Traffic', 'IPv6 Traffic'],
  82. ['value', <?=$p4?>, <?=$p6?>],
  83. ],
  84. type: 'bar',
  85. labels: {
  86. format: {
  87. value: function (v, id, i, j) { return v + "%"; }
  88. }
  89. },
  90. color: function(inColor, data) {
  91. var colors = ['#006666', '#666699']
  92. if (data.index !== undefined) {
  93. return colors[data.index];
  94. }
  95. return inColor;
  96. }
  97. },
  98. axis: {
  99. rotated: true,
  100. x: {
  101. type: 'category'
  102. }
  103. },
  104. legend: {
  105. show: false
  106. }
  107. });
  108. </script>
  109. <table class="DeviceTable" align="center" border="1"
  110. cellpadding="2" cellspacing="2" width="40%" style="margin-top: 20px;">
  111. <tr>
  112. <th>Protocol</th>
  113. <th>Total Gigabytes</th>
  114. </tr>
  115. <tr>
  116. <td align="left">IPv4</td>
  117. <td align="right"><?=number_format($g4, 2, '.', ' ')?> GB</td>
  118. </tr>
  119. <tr>
  120. <td align="left">IPv6</td>
  121. <td align="right"><?=number_format($g6, 2, '.', ' ')?> GB</td>
  122. </tr>
  123. </table>
  124. </body>
  125. </html>