erikng / cacher Goto Github PK
View Code? Open in Web Editor NEWA python script for extracting macOS Caching Server data
License: Apache License 2.0
A python script for extracting macOS Caching Server data
License: Apache License 2.0
Hi,
Thanks for the work on this script. Just deployed and it works a treat.
Is there any chance you could add metrics on drive space used by the cache or overall used/free ?
Also there is a typo bandwidth is showing as bandwith
Shane
I noticed that when using --configureserver
, while the values were set, the Caching server did not respect the values until the service was restarted.
Cacher should restart the service to ensure this is set.
I get an error with the script:
Traceback (most recent call last):
File "./test.py", line 940, in <module>
main()
File "./test.py", line 923, in main
cacherdata = cacher(rawLog.readlines(), targetDate, friendlyNames, site_name)
File "./test.py", line 324, in cacher
x).group(1).replace('OS X ', 'macOS/').split('/')[0]
AttributeError: 'NoneType' object has no attribute 'group'
Attached is the debug log that causes this error (the target date is 2017-02-18
Running the script on a different target date of 2017-02-28 works fine however.
Attached is the debug log for that target date as well.
Debug_28-02.log.zip
I was wondering if it is possible that the script show me the IP addresses of clients who downloaded files from my server?
Answer: It can but it would need to be written.
I'll try to write it, but I don't know much about python if you want do this with me I'll appreciate.
I get the following errors if nothing was served yesterday, on say a Sunday.
(standard_in) 2: parse error
(standard_in) 2: parse error
(standard_in) 2: parse error
(standard_in) 2: parse error
(standard_in) 1: parse error
(standard_in) 1: parse error
(standard_in) 1: parse error
(standard_in) 1: parse error
(standard_in) 1: parse error
(standard_in) 1: parse error
(standard_in) 1: parse error
(standard_in) 1: parse error
Seems to be related to what is passed to bc
:
sudo bash -x ./Cacher
++ ifconfig en0
++ grep 'inet '
++ grep -v 127.0.0.1
++ awk '{print $2}'
++ sed 's/./ /g'
++ awk '{print $1}'
78 IP Addresses hit the Caching Server yesterday consisting of:
3 Unique IP Addresses.
A total of 0 iOS devices hit the Caching Server yesterday consisting of:
0 iOS 8.0 Devices
0 iOS 8.0.2 Devices
0 iOS 8.1 Devices
0 iOS 8.1.1 Devices
0 iOS 8.1.2 Devices
0 iOS 8.1.3 Devices
0 iOS 8.2 Devices
0 iOS 8.3 Devices
Of these devices, here is the model breakdown:
0 Total AppleTVs
0 3rd Generation Apple TVs
0 4th Generation Apple TVs
0 Total iPhones
0 iPhone 4 [GSM]
0 iPhone 4 [CDMA]
0 iPhone 4S
0 iPhone 5 [GSM]
0 iPhone 5 [CDMA]
0 iPhone 5C
0 iPhone 5S
0 iPhone 5S [China Model]
0 iPhone 6
0 iPhone 6 Plus
0 Total iPads
0 iPad 2nd Generation [Wifi]
0 iPad 2nd Generation [Wifi + GSM]
0 iPad 2nd Generation [Wifi + CDMA]
0 iPad 2nd Generation [M2012 Wifi Revision]
0 iPad 3rd Generation [Wifi]
0 iPad 3rd Generation [Wifi + GSM]
0 iPad 3rd Generation [Wifi + CDMA]
0 iPad 4th Generation [Wifi]
0 iPad 4th Generation [Wifi + GSM]
0 iPad 4th Generation [Wifi + CDMA]
0 iPad Air 1st Generation [Wifi]
0 iPad Air 1st Generation [Wifi + Cellular]
0 iPad Air 2nd Generation [Wifi]
0 iPad Air 2nd Generation [Wifi + Cellular]
0 iPad Mini 1st Generation [Wifi]
0 iPad Mini 1st Generation [Wifi + GSM]
0 iPad Mini 1st Generation [Wifi + CDMA]
0 iPad Mini 2nd Generation [Wifi]
0 iPad Mini 2nd Generation [Wifi + Cellular]
0 iPad Mini 3rd Generation [Wifi]
0 iPad Mini 3rd Generation [Wifi + Cellular]
0 Total iPods
0 iPod Touch 5th Generation
A total of 0 OS X devices hit the Caching Server yesterday consisting of:
0 OS X Yosemite 10.10.0/10.10.1 Devices [Cannot distinguish between builds]
0 OS X Yosemite 10.10.2 Devices
0 OS X Yosemite 10.10.3 Devices
A total of 26 files were downloaded from the Caching Server yesterday consisting of:
0 Books
0 iOS Apps
0 Mac Apps
0 Zip files
26 Apple Server Registrations
1 Unique files were downloaded from the Caching Server yesterday consisting of:
0 Unique Books
0 Unique iOS Apps
0 Unique Mac Apps
0 Unique Zip files'
78 IP Addresses hit the Caching Server yesterday consisting of:
3 Unique IP Addresses.
A total of 0 iOS devices hit the Caching Server yesterday consisting of:
0 iOS 8.0 Devices
0 iOS 8.0.2 Devices
0 iOS 8.1 Devices
0 iOS 8.1.1 Devices
0 iOS 8.1.2 Devices
0 iOS 8.1.3 Devices
0 iOS 8.2 Devices
0 iOS 8.3 Devices
Of these devices, here is the model breakdown:
0 Total AppleTVs
0 3rd Generation Apple TVs
0 4th Generation Apple TVs
0 Total iPhones
0 iPhone 4 [GSM]
0 iPhone 4 [CDMA]
0 iPhone 4S
0 iPhone 5 [GSM]
0 iPhone 5 [CDMA]
0 iPhone 5C
0 iPhone 5S
0 iPhone 5S [China Model]
0 iPhone 6
0 iPhone 6 Plus
0 Total iPads
0 iPad 2nd Generation [Wifi]
0 iPad 2nd Generation [Wifi + GSM]
0 iPad 2nd Generation [Wifi + CDMA]
0 iPad 2nd Generation [M2012 Wifi Revision]
0 iPad 3rd Generation [Wifi]
0 iPad 3rd Generation [Wifi + GSM]
0 iPad 3rd Generation [Wifi + CDMA]
0 iPad 4th Generation [Wifi]
0 iPad 4th Generation [Wifi + GSM]
0 iPad 4th Generation [Wifi + CDMA]
0 iPad Air 1st Generation [Wifi]
0 iPad Air 1st Generation [Wifi + Cellular]
0 iPad Air 2nd Generation [Wifi]
0 iPad Air 2nd Generation [Wifi + Cellular]
0 iPad Mini 1st Generation [Wifi]
0 iPad Mini 1st Generation [Wifi + GSM]
0 iPad Mini 1st Generation [Wifi + CDMA]
0 iPad Mini 2nd Generation [Wifi]
0 iPad Mini 2nd Generation [Wifi + Cellular]
0 iPad Mini 3rd Generation [Wifi]
0 iPad Mini 3rd Generation [Wifi + Cellular]
0 Total iPods
0 iPod Touch 5th Generation
A total of 0 OS X devices hit the Caching Server yesterday consisting of:
0 OS X Yosemite 10.10.0/10.10.1 Devices [Cannot distinguish between builds]
0 OS X Yosemite 10.10.2 Devices
0 OS X Yosemite 10.10.3 Devices
A total of 26 files were downloaded from the Caching Server yesterday consisting of:
0 Books
0 iOS Apps
0 Mac Apps
0 Zip files
26 Apple Server Registrations
1 Unique files were downloaded from the Caching Server yesterday consisting of:
0 Unique Books
0 Unique iOS Apps
0 Unique Mac Apps
0 Unique Zip files'
print "Server version is %s and not compatible" % serverversion()
should be
print "Server version is %s and not compatible" % get_serverversion()
I think the device counts are calculated incorrectly.
It looks to be counting the device number based upon the get request numbers rather than actual devices.
For example $TOTAL_IOS_NUMBER
is just a calculation of of how many requests were made $yesterday
that included iOS user agents. A single device might make 20 requests a day.
That doesn't mean 20 devices hit the caching server.
We should look at unique IP addresses and then break down that list and look for iOS (or other) devices based on that. Still an assumption that a device has the same IP address for a 24 hour period. But possibly more accurate.
Does this work on Mojave with the Server App no longer managing it?
This will reduce logging errors.
I have some problems because I don't know how will I run the scrip in my Mac. I installed python but when I set the command "sudo cacher.py --configureserver" the command wasn't found.
I don't used python before. Please I hope you can help me with a some manual or something with the steps for installing the scrip.
Since the caching service was removed from Server in 10.13 log location has moved as well, breaking Cacher. Any plans to update Cacher for 10.13? Thanks!
When rebooting the server (say for an upgrade) the bandwidth statistics may be off the following day.
This will occur due when a small application is first downloaded followed by larger applications, ie MB content served first and GB content served later in the day.
I am getting an error, any help would be appreciated.
IOS-CCS:Cacher-master-2 macmini$ python cacher.py --targetdate "2019-09-19" --deviceids --teamsalert --teamswebhook "https://outlook.office.com/webhook/792f5196-ea16-45b3-a7e7-07708470b74b@e7119446-0f7e-4a91-a73a-7873a46c3354/IncomingWebhook/3b42557b61d54d91b7b3ca6c833b507d/f0031761-94c3-46db-xxxx"
Traceback (most recent call last):
File "cacher.py", line 891, in
main()
File "cacher.py", line 876, in main
cacherdata = cacher(rawLog.readlines(), targetDate, friendlyNames)
File "cacher.py", line 233, in cacher
totalbytesserved.append(bytes_served)
UnboundLocalError: local variable 'bytes_served' referenced before assignment
output a message.
Getting on the following error on OS X Server 3.2.2 box, probably also occurs on OS X Server 4.0 since there are no bz2 files.
bzip2: Can't open input file *.bz2: No such file or directory.
Just installed the latest Cacher (2.0), and am getting this error. I'm getting 0 for all the other stats too.
Not sure if we are using cacher correctly, I just manually run the script everyday. Should I be using launchd or some other process?
macOS 10.12.1 (Build 16B2659)
Server 5.2 (Build 16S1195)
Cacher
Last Updated: 01-04-2017
version = '3.0'
With cache personal iCloud Data ON, cacher provides incorrect device counts. Mac OS device counts will be in the hundreds when there are less than 100 on the network.
3.0.4 has a great update to calculating the totals.
I'm just curious as to why I would be seeing such a large difference between what cahcer and my server logs say.
2017-03-06 12:53:20.673 Since server start: 7.09 GB returned to clients, 1.46 GB stored from Internet, 0 bytes from peers; 0 bytes imported.
Cacher has retrieved the following stats for 2017-03-06:
4.8 GB of bandwith served to client devices.
1.4 GB of bandwith requested from Apple
0.0 bytes of bandwith requested from other Caching Servers
My server only runs between 6am and 11pm each day, so there's no crossover between dates.
I get this error at the end of the script when it tries to create an alert.
2015-06-29 11:28:53.107 server[76024:507] Error Domain=AlertsDaemon Code=150 "Error: Insufficient entitlements." UserInfo=0x7ff268d01c60 {NSLocalizedDescription=Error: Insufficient entitlements.}
I have 3 servers I tried this on, all on 5.0.4, all 10.10.5, all with caching enabled and data in it.
The first one ran fine (copied the script file to each machine locally and ran from terminal, I also tried running through casper, also all had individually modified plist file and all hat the log client id command run).
The 2nd one throws back - Script result: bzip2: Can't open input file *.bz2: No such file or directory.
the 3rd one - bzip2: Can't open input file *.bz2: No such file or directory.
(standard_in) 2: parse error
(standard_in) 1: parse error
(standard_in) 1: parse error
(standard_in) 1: parse error
(standard_in) 1: parse error
G'day eriking,
I have tried to use you cacher.py script on my caching server as I too need a nice way to to show this is saving us bandwidth.
Ever time i call cacher.py in terminal, i get the following output;
Traceback (most recent call last):
File "/usr/local/bin/cacher.py", line 913, in
main()
File "/usr/local/bin/cacher.py", line 896, in main
cacherdata = cacher(rawLog.readlines(), targetDate, friendlyNames)
File "/usr/local/bin/cacher.py", line 167, in cacher
frompeers_size = linesplit[17]
IndexError: list index out of range
python is not my strong suit and I hope this error is a simple misconfig on my behalf.
Any input from yourself would be greatly appreciated.
cheers Damien C
LogClientIdentity is not set
Please run sudo Cacher --configureserver and delete your log files.
sudo python ./Cacher --configureserver
LogClientIdentity is not set
Please run sudo Cacher --configureserver and delete your log files.
This is due to improper logic.
Upon Run the following shows:
(standard_in) 2: parse error
(standard_in) 2: parse error
(standard_in) 2: parse error
(standard_in) 2: parse error
(standard_in) 1: parse error
(standard_in) 1: parse error
(standard_in) 1: parse error
(standard_in) 1: parse error
(standard_in) 1: parse error
(standard_in) 1: parse error
(standard_in) 1: parse error
(standard_in) 1: parse error
X IP Addresses hit the Caching Server yesterday consisting of:
This is something I ran into recently while trying to get Cacher working with a new 5.2 server. I've always just manually ran sudo serveradmin settings caching:LogClientIdentity = 1
and had no issues. This time I tried to use sudo Cacher --configureserver
. This reports a success, but Cacher never finds any stats. I think this is because --configureserver
tries to set this setting with "yes", rather than "1". After manually running the appropriate serveradmin
commands, Cacher is working without issue.
Looks like this line is what needs changed: https://github.com/erikng/Cacher/blob/master/Cacher#L636
I would like to pass in a different date than yesterday and get a report for that day. Appropriate errors should be issued for dates where logs do not exist anymore.
I see this error:
./cacher.py --targetdate=2017-06-20
Traceback (most recent call last):
File "./cacher.py", line 950, in <module>
main()
File "./cacher.py", line 933, in main
cacherdata = cacher(rawLog.readlines(), targetDate, friendlyNames)
File "./cacher.py", line 177, in cacher
frompeers_size = linesplit[17]
IndexError: list index out of range
It seems to be because the "Served all" line isn't using KB / MB / or GB:
bzgrep "Served all" /Library/Server/Caching/Logs/Debug-2017.06.20-07:16.log.bz2
2017-06-20 09:27:13.810 #ASDOW8CvyaXH Served all 530 of 530 bytes; 0 from cache, 530 stored from Internet, 0 from peers
2017-06-20 09:27:14.228 #Gv2SiVDKnjfx Served all 3061 of 3061 bytes; 0 from cache, 3061 stored from Internet, 0 from peers
2017-06-20 09:27:14.868 #0Bjo9F70zTHp Served all 530 of 530 bytes; 530 from cache, 0 stored from Internet, 0 from peers
2017-06-20 09:27:14.893 #Rv5z5LZVfqs/ Served all 3061 of 3061 bytes; 3061 from cache, 0 stored from Internet, 0 from peers
2017-06-20 09:27:17.353 #BYopVZ61tik+ Served all 3061 of 3061 bytes; 3061 from cache, 0 stored from Internet, 0 from peers
2017-06-20 19:08:24.110 #HRFS8tdWl/oo Served all 2671077 of 2671077 bytes; 0 from cache, 2671077 stored from Internet, 0 from peers
2017-06-20 22:09:51.306 #OYiGr6J5oTU2 Served all 3530118 of 3530118 bytes; 0 from cache, 3530118 stored from Internet, 0 from peers
2017-06-20 22:09:51.535 #Hi/jXmnizsOC Served all 2518340 of 2518340 bytes; 0 from cache, 2518340 stored from Internet, 0 from peers
2017-06-20 22:34:11.190 #3t7x/+Ft9289 Served all 5022 of 5022 bytes; 5022 from cache, 0 stored from Internet, 0 from peers
2017-06-20 22:34:11.190 #qB0Ld3yWIDf0 Served all 5023 of 5023 bytes; 5023 from cache, 0 stored from Internet, 0 from peers
2017-06-20 22:34:11.320 #HdH6mXxXQpq/ Served all 5639 of 5639 bytes; 5639 from cache, 0 stored from Internet, 0 from peers
2017-06-20 22:34:11.695 #MFU/uJqbMIOr Served all 5024 of 5024 bytes; 5024 from cache, 0 stored from Internet, 0 from peers
2017-06-20 22:34:13.309 #okBzTwaHA8D9 Served all 5979 of 5979 bytes; 5979 from cache, 0 stored from Internet, 0 from peers
2017-06-21 00:02:20.900 #FDN+/XnFoNtc Served all 2671077 of 2671077 bytes; 2671077 from cache, 0 stored from Internet, 0 from peers
2017-06-21 02:03:57.147 #dqwnWQVRnLIB Served all 35055540 of 35055540 bytes; 13572 from cache, 35041968 stored from Internet, 0 from peers
I'm using the latest version of El Capitan's Server app.
Will you add support Microsoft Teams?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.