Measuring failure of a setup to preserve some structure giving interesting notions I am looking for some examples of failure of some structures giving interesting notions. For example, we have the following situation:
Let $P(M,G)$ be a principal bundle. Let $\Gamma\subseteq TP$ be a connection on $P(M,G)$. Given a vector field $X:M\rightarrow TM$ on $M$, connection $\Gamma$ gives a unique (horizantal) vector field $\widetilde{X}:P\rightarrow TP$ on $P$. Thus, given a connection $\Gamma$ on $P(M,G)$, we have a set level map $\Phi:\mathfrak{X}(M)\rightarrow \mathfrak{X}(P)$ that sends a vector field $X$ on $M$ to its lift $\widetilde{X}$ on $P$. It is clear that this map $\Phi:\mathfrak{X}(M)\rightarrow \mathfrak{X}(P)$   is $\mathbb{R}$-linear. Observe that the $\mathbb{R}$-vector spaces $\mathfrak{X}(M)$ and $\mathfrak{X}(P)$ has an extra structure of being a Lie algebra over $\mathbb{R}$. So, next question is to see if the map $\Phi:\mathfrak{X}(M)\rightarrow \mathfrak{X}(P)$ is a morphism of Lie algebras or not.  Failure of this map to preserve the structure of  a Lie algebra morphism, measured by the difference $$\Phi([X,Y])-[\Phi(X),\Phi(Y)]:P\rightarrow TP$$ has a special name called the curvature   of the connection $\Gamma$. It is already famous enough that I do not have to say anything more about it. Note that it is not in the usual form. But, one can assign a $2$-form on $M$ for this difference which is the usual notion of curvature of a connection on a principal bundle $P(M,G)$.
So, what are the interesting concepts/theories that came out of something not preserving the structure?
 A: Here is a huge family of examples.  Let $F:\mathcal{C}\to \mathcal{D}$ be, let's say, an additive functor between abelian categories.  Let's say, $F$ is right or left exact.  Its failure to be exact is measured by its left or right derived functors.
To be more specific, if $F$ is the tensor product, one gets $Tor$, and, of course, in the simplest situation $Tor^1$ gives the set of appropriate torsion elements.  To be concrete, let's take the  categories $\mathcal{C}$ and 
$\mathcal{D}$ to be the category of abelian groups.  Given an abelian group $M$, the functor $A\to M\otimes A$ doesn't quite preserve the "structure" of exactness, that is if  $$0\to A\to B \to C \to 0$$ is an exact sequence, we get an exactness sequence of the form $$Tor _1(M,C) \to M\otimes A \to M\otimes B \to M\otimes C \to 0.$$  Here $Tor_1$ happens to have its "own" definition, let's say, when $M$ is of the form $M=Z/n$.  $Tor _1(Z/n,C)$ is the set of $n$-torsion elements in $C$, i.e., set of elements annihilated by $n$.
Similarly for $Ext$, which is not only the left derived functor of $Hom$, but classifies extensions.  Of course, the notion of derived functors include many homology and cohomology theories.
In the above, I took a simplest example.  The notion of torsion precedes that of exactness historically and pedagogically, so this might not be an appropriate answer for your question.  However, many of what we call "homology" or "cohomology" arises this way.  Here is a more elaborate example that relates to the example in OP.
Let $G$ be a group and Consider the category of $Z[G]$-modules.  Then the first left derived functor of $(-)_{Z[G]}\otimes Z$ with the trivial $G$ action on $Z$, also called $H_1(G,Z)$ is the abelianization of $G$, i.e., the quotient of $G$ by its commutator subgroup.
One can find about this in any standard textbook of homological algebra.  e.g.  Homology, S.MacLane
A: Let $p:P\rightarrow M$ be a $G$-principal bundle, consider an extension of Lie group $1\rightarrow H\rightarrow K\rightarrow G\rightarrow 1$  ($H$ is commutative). Suppose that $K\rightarrow G$ has local sections,  and let $(U_i,g_{ij})$ a trivialization of $p$.
Since $l:K\rightarrow G$ has local sections, we can suppose that there exists a map $g'_{ij}:U_{ij}:\rightarrow K$ such that $l\circ g'_{ij}=g_{ij}$. 
The map $g'_{ij}g'_{jk}$ is not always equal to $g'_{ik}$ and $c_{ijk}=g'_{ij}g'_{jk}g'_{ki}$ is the classification cocycle of a gerbe bounded by the sheaf of $H$-valued functions defined on $M$. In this sense,we can say that the notion of gerbe arises as the failure of the preservation of the notion of bundle.
