The Internet of Things (IoT) is about connecting people, processes, data, and things, and is changing the way we monitor and interact with things. An active incorporation of information and communication technology coupled with sophisticated data analytics approaches has the potential to transform some of the oldest industries in the world, including dairy farming. It presents a great opportunity for verticals such as the dairy industry to increase productivity by getting actionable insights to improve farming practices, thereby increasing efficiency and yield. Dairy farms have all the constraints of a modern business -- they have a fixed production capacity, a herd to manage, expensive farm labor, and other varied farm-related processes to take care of. In this technology-driven era farmers look for assistance from smart solutions to increase profitability and to help manage their farms well. We present an end-to-end IoT application system with fog assistance and cloud support that analyzes data generated from wearables on cows' feet to detect anomalies in animal behavior that relate to illness such as lameness. The solution leverages behavioral analytics to generate early alerts toward the animals' well being, thus assisting the farmer in livestock monitoring. This in turn also helps in increasing productivity and milk yield by identifying potential diseases early on. The project specializes in detecting lameness in dairy cattle at an early stage, before visible signs appear to the farmer or an animal expert. Our trial results in a real-world smart dairy farm setup, consisting of a dairy herd of 150 cows in Ireland, demonstrate that the designed system delivers a lameness detection alert up to three days in advance of manual observation.