Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major overhaul of chronometer script #193

Merged
merged 4 commits into from
Jan 18, 2016
Merged

Major overhaul of chronometer script #193

merged 4 commits into from
Jan 18, 2016

Conversation

PromoFaux
Copy link
Member

Added -j option to output stats as JSON formatted string. If run with no option, then chronometer runs as normal.

Fixed calculations to match those on the web dashboard.

Total number of domains now takes whether or not IPv6 is used into consideration.

As this will output a JSON string, this can also be consumed by index.php AND api.php on the web dashboard.

i.e Change api.php to simply read:

(corrected)
Though I don't know anything about PHP, so someone may wish to correct that.

Similarly index.php can read the output of this script and parse the JSON to populate the dashboard.

Plus, think of all the other crazy things you could do with the data.

image

…ing. If run with no option, then chronometer runs as normal. Fixed calculations to match those on the web dashboard.
What, me? Reference the wrong file?
echo "-------------------------------"
# Uncomment to continually read the log file and display the current domain being blocked
#tail -f /var/log/pihole.log | awk '/\/etc\/pihole\/gravity.list/ {if ($7 != "address" && $7 != "name" && $7 != "/etc/pihole/gravity.list") print $7; else;}'
# (at your opercentBlockedTodayion) any later version.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opercentBlockedTodayion? You coined a new word without even noticing! 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Note to self, Find&Replace>Replace All is a bad idea.
@AzureMarker
Copy link
Contributor

In your comment about changing api.php, I don't think you need }' in the string.

@PromoFaux
Copy link
Member Author

Currently api.php a JSON string like this:
{"domains_being_blocked":"136774","dns_queries_today":"6114","ads_blocked_today":"764","ads_percentage_today":12.49591102388}

and this script change outputs this:
{"domains_being_blocked":"68387","dns_queries_today":"6095","ads_blocked_today":"764","ads_percentage_today":"12.53"}

Edit: Note, Numbers are different in the script output because the log file is being parsed for todays date. The current dashboard does not.

@AzureMarker
Copy link
Contributor

What's the difference?

@PromoFaux
Copy link
Member Author

Oh, wait, I see you're referencing my php psuedocode!

@AzureMarker
Copy link
Contributor

It should be <?php echo exec("/usr/local/bin/chronometer.sh -j"); ?> (Without the {')

@PromoFaux PromoFaux changed the title Major overhaul. Major overhaul of chronometer script Jan 18, 2016
@PromoFaux
Copy link
Member Author

But other than that, valid PHP script?

@AzureMarker
Copy link
Contributor

I believe so. There's a feature that I think is standard, where you don't need the ?> if there's only php in the file (and ends with *.php), so it could even be shortened to:

<?php
echo exec("/usr/local/bin/chronometer.sh -j");

@PromoFaux
Copy link
Member Author

I was brave and tried the PHP changes myself!

@AzureMarker
Copy link
Contributor

Do they work?

@PromoFaux
Copy link
Member Author

Of course they work, I would not commit untested code (anymore!!)

jacobsalmela added a commit that referenced this pull request Jan 18, 2016
Major overhaul of chronometer script
@jacobsalmela jacobsalmela merged commit 9ba38e6 into pi-hole:master Jan 18, 2016
@PromoFaux PromoFaux deleted the Chronometer branch January 19, 2016 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants