In this post I’m going to explain how you can track the number of likes for any fb page, its a lot simpler than i imagined it’d be, all in all it took little less than 1 hour to cook up. which means I get to use all the time I have assigned fort this task to write about it.
We are going to be using the facebook graph API, based on json you send in the argument in the URL and it generates a json response with all the data you need, in my case I was reading the data off of vodafoneEgypt page
the numerical string in the url is the page ID, which you extract from the facebook page’s display photo URL
So now you have the API link, and the page ID, a simple script takes care of extracting the number of likes from the page, go to your cacti scripts folder, create a new directory for fb likes trackers, fire up vi and paste in the following script. make sure to set up the permissions correctly for the file and directory.
Test the script by running #./FBLikes.sh 19973233436 if everything is working as it should the script should spit out the number of page likes.
The remainder of the post is about how to integrate it with cacti so if you are familiar with that go ahead and do it directly if not open up your cacti instance and log in as admin.
go to “Data input methods”, click add on the top right side of the page, you’ll be taken to the data input creation page, feed it in an appropriate name, personally I named it FBLikes. set the “input type” drop down to “Script/Command”, finally tghe input string should be something like :
sh /tmp/getlikes/FBLikes.sh <Page_Id>
once you click create two new headers should appear, in the input field click on the add button, in the creation page just put in a “Friendly Name” and click on create, click on add on the output field header, in the creation page set the field and friendly name, make sure that “Update RRD File” is ticked, click on create and then save.
Click on the “Data sources” link on the left, then click on Add, you’ll be taken to a new page, click on the create button to bring up the creation interface, and set “Name”, “Data Input Method” and “Internal Data Source Name”, then click on create, a new header would appear “Custom Data” input the page ID in the text box and click on save. Now the data is being harvested all you need to do now is to represent it, next stop, graph creation.
click on Graph management >add>create, exactly like the last step, you get the creation page, set the “title” and click create, a new header “graph times” will appear, click on the add button, in the creation page select the data source from the drop down menu to match the one you created earlier, pick a nice colour, set “graph item type” to area and “consolidation function” to average and click on create, you should see the graph by now, so click on save.
DONE, now you are charting the number of face book likes on cacti.