2

I've got CPanel hosting with a few subdomains. Each one tracks its own stats using AWstats.

Is there any way to parse the HTML tables that are generated to get the bandwidth used?

Thanks for all.

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
Brookete
  • 251
  • 1
  • 4
  • 13
  • I'd like to see a good parse script that get's all the relevant data. The one lined from geekthis doesn't include the pages people hit. – drooh Oct 14 '19 at 18:02

2 Answers2

3

An alternative to reading the HTML directly is to directly use the stats files that awstats uses to render the HTML. cpanel should store them somewhere accessible (on my hosting they're in tmp/). It's a simple text file, with well marked sections that are easily found, and within the section is space-separated CSV representing the tables. This page on parsing the files with PHP is a good place for information on how to do it with code. I'm sure with a bit of linux know-how you can use sed and awk to respectively chop the file and return the columns you need to gather up the stats you need from these summaries.

FokeyJoe
  • 81
  • 5
0

Use a DOMXPath query the get the text of each row in the "kB F" column, such as the following for the first row:

$doc = new DOMDocument;

//Path to Webalizer or AWStats file
$doc->Load('stats.html');

$xpath = new DOMXPath($doc);

// Get the first bandwidth record in the table
$query = "//tr[7]/td[7]/font/text()";

$bandwidth1 = $xpath->query($query);

References

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
  • this is not working for me with webalizer - Warning: DOMDocument::load(): Space required after the Public Identifier – drooh Jul 13 '20 at 19:57