\doxysection{stats.\+h}
\label{stats_8h_source}\index{include/osmocom/core/stats.h@{include/osmocom/core/stats.h}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{1 \textcolor{comment}{/*}}
\DoxyCodeLine{2 \textcolor{comment}{ * (C) 2015 by sysmocom -\/ s.f.m.c. GmbH}}
\DoxyCodeLine{3 \textcolor{comment}{ *}}
\DoxyCodeLine{4 \textcolor{comment}{ * All Rights Reserved}}
\DoxyCodeLine{5 \textcolor{comment}{ *}}
\DoxyCodeLine{6 \textcolor{comment}{ * This program is free software; you can redistribute it and/or modify}}
\DoxyCodeLine{7 \textcolor{comment}{ * it under the terms of the GNU General Public License as published by}}
\DoxyCodeLine{8 \textcolor{comment}{ * the Free Software Foundation; either version 2 of the License, or}}
\DoxyCodeLine{9 \textcolor{comment}{ * (at your option) any later version.}}
\DoxyCodeLine{10 \textcolor{comment}{ *}}
\DoxyCodeLine{11 \textcolor{comment}{ * This program is distributed in the hope that it will be useful,}}
\DoxyCodeLine{12 \textcolor{comment}{ * but WITHOUT ANY WARRANTY; without even the implied warranty of}}
\DoxyCodeLine{13 \textcolor{comment}{ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the}}
\DoxyCodeLine{14 \textcolor{comment}{ * GNU General Public License for more details.}}
\DoxyCodeLine{15 \textcolor{comment}{ *}}
\DoxyCodeLine{16 \textcolor{comment}{ */}}
\DoxyCodeLine{17 \textcolor{preprocessor}{\#pragma once}}
\DoxyCodeLine{18 }
\DoxyCodeLine{23 \textcolor{comment}{/* a bit of a crude way to disable building/using this on (bare iron)}}
\DoxyCodeLine{24 \textcolor{comment}{ * embedded systems.  We cannot use the autoconf-\/defined HAVE\_... macros}}
\DoxyCodeLine{25 \textcolor{comment}{ * here, as that only works at library compile time, not at application}}
\DoxyCodeLine{26 \textcolor{comment}{ * compile time */}}
\DoxyCodeLine{27 \textcolor{preprocessor}{\#if defined(unix) || defined(\_\_APPLE\_\_)}}
\DoxyCodeLine{28 }
\DoxyCodeLine{29 \textcolor{preprocessor}{\#include <sys/socket.h>}}
\DoxyCodeLine{30 \textcolor{preprocessor}{\#include <arpa/inet.h>}}
\DoxyCodeLine{31 }
\DoxyCodeLine{32 \textcolor{preprocessor}{\#include <osmocom/core/linuxlist.h>}}
\DoxyCodeLine{33 }
\DoxyCodeLine{34 \textcolor{preprocessor}{\#include <stdint.h>}}
\DoxyCodeLine{35 }
\DoxyCodeLine{36 \textcolor{keyword}{struct }msgb;}
\DoxyCodeLine{37 \textcolor{keyword}{struct }osmo\_stat\_item\_group;}
\DoxyCodeLine{38 \textcolor{keyword}{struct }osmo\_stat\_item\_desc;}
\DoxyCodeLine{39 \textcolor{keyword}{struct }rate\_ctr\_group;}
\DoxyCodeLine{40 \textcolor{keyword}{struct }rate\_ctr\_desc;}
\DoxyCodeLine{41 }
\DoxyCodeLine{43 \textcolor{keyword}{enum} osmo\_stats\_class \{}
\DoxyCodeLine{44         OSMO\_STATS\_CLASS\_UNKNOWN,       }
\DoxyCodeLine{45         OSMO\_STATS\_CLASS\_GLOBAL, }
\DoxyCodeLine{46         OSMO\_STATS\_CLASS\_PEER,             }
\DoxyCodeLine{47         OSMO\_STATS\_CLASS\_SUBSCRIBER, }
\DoxyCodeLine{48 \};}
\DoxyCodeLine{49 }
\DoxyCodeLine{51 \textcolor{keyword}{enum} osmo\_stats\_reporter\_type \{}
\DoxyCodeLine{52         OSMO\_STATS\_REPORTER\_LOG, }
\DoxyCodeLine{53         OSMO\_STATS\_REPORTER\_STATSD,   }
\DoxyCodeLine{54 \};}
\DoxyCodeLine{55 }
\DoxyCodeLine{57 \textcolor{keyword}{struct }osmo\_stats\_reporter \{}
\DoxyCodeLine{59         \textcolor{keyword}{enum} osmo\_stats\_reporter\_type type;}
\DoxyCodeLine{61         \textcolor{keywordtype}{char} *name;}
\DoxyCodeLine{62 }
\DoxyCodeLine{63         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} have\_net\_config : 1;}
\DoxyCodeLine{64 }
\DoxyCodeLine{65         \textcolor{comment}{/* config */}}
\DoxyCodeLine{66         \textcolor{keywordtype}{int} enabled;             }
\DoxyCodeLine{67         \textcolor{keywordtype}{char} *name\_prefix;   }
\DoxyCodeLine{68         \textcolor{keywordtype}{char} *dest\_addr\_str;       }
\DoxyCodeLine{69         \textcolor{keywordtype}{char} *bind\_addr\_str;       }
\DoxyCodeLine{70         \textcolor{keywordtype}{int} dest\_port;         }
\DoxyCodeLine{71         \textcolor{keywordtype}{int} mtu;             }
\DoxyCodeLine{72         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} flush\_period;  }
\DoxyCodeLine{75         \textcolor{keyword}{enum} osmo\_stats\_class max\_class;}
\DoxyCodeLine{76 }
\DoxyCodeLine{77         \textcolor{comment}{/* state */}}
\DoxyCodeLine{78 }
\DoxyCodeLine{79         \textcolor{keywordtype}{int} running;                     }
\DoxyCodeLine{80         \textcolor{keyword}{struct }sockaddr dest\_addr;     }
\DoxyCodeLine{81         \textcolor{keywordtype}{int} dest\_addr\_len;         }
\DoxyCodeLine{82         \textcolor{keyword}{struct }sockaddr bind\_addr;     }
\DoxyCodeLine{83         \textcolor{keywordtype}{int} bind\_addr\_len;         }
\DoxyCodeLine{84         \textcolor{keywordtype}{int} fd;                               }
\DoxyCodeLine{85         \textcolor{keyword}{struct }msgb *buffer;          }
\DoxyCodeLine{86         \textcolor{keywordtype}{int} agg\_enabled;             }
\DoxyCodeLine{87         \textcolor{keywordtype}{int} force\_single\_flush;               }
\DoxyCodeLine{88         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} flush\_period\_counter;  }
\DoxyCodeLine{90         \textcolor{keyword}{struct }llist\_head list;}
\DoxyCodeLine{91         int (*open)(\textcolor{keyword}{struct }osmo\_stats\_reporter *srep);}
\DoxyCodeLine{92         int (*close)(\textcolor{keyword}{struct }osmo\_stats\_reporter *srep);}
\DoxyCodeLine{93         int (*send\_counter)(\textcolor{keyword}{struct }osmo\_stats\_reporter *srep,}
\DoxyCodeLine{94                 \textcolor{keyword}{const} \textcolor{keyword}{struct }rate\_ctr\_group *ctrg,}
\DoxyCodeLine{95                 \textcolor{keyword}{const} \textcolor{keyword}{struct }rate\_ctr\_desc *desc,}
\DoxyCodeLine{96                 int64\_t value, int64\_t delta);}
\DoxyCodeLine{97         int (*send\_item)(\textcolor{keyword}{struct }osmo\_stats\_reporter *srep,}
\DoxyCodeLine{98                 \textcolor{keyword}{const} \textcolor{keyword}{struct }osmo\_stat\_item\_group *statg,}
\DoxyCodeLine{99                 \textcolor{keyword}{const} \textcolor{keyword}{struct }osmo\_stat\_item\_desc *desc,}
\DoxyCodeLine{100                 int64\_t value);}
\DoxyCodeLine{101 \};}
\DoxyCodeLine{102 }
\DoxyCodeLine{103 \textcolor{keyword}{struct }osmo\_stats\_config \{}
\DoxyCodeLine{104         \textcolor{keywordtype}{int} interval;}
\DoxyCodeLine{105 \};}
\DoxyCodeLine{106 }
\DoxyCodeLine{107 \textcolor{keyword}{extern} \textcolor{keyword}{struct }llist\_head osmo\_stats\_reporter\_list;}
\DoxyCodeLine{108 \textcolor{keyword}{extern} \textcolor{keyword}{struct }osmo\_stats\_config *osmo\_stats\_config;}
\DoxyCodeLine{109 }
\DoxyCodeLine{110 \textcolor{keywordtype}{void} osmo\_stats\_init(\textcolor{keywordtype}{void} *ctx);}
\DoxyCodeLine{111 \textcolor{keywordtype}{int} osmo\_stats\_report(\textcolor{keywordtype}{void});}
\DoxyCodeLine{112 }
\DoxyCodeLine{113 \textcolor{keywordtype}{int} osmo\_stats\_set\_interval(\textcolor{keywordtype}{int} interval);}
\DoxyCodeLine{114 }
\DoxyCodeLine{115 \textcolor{keyword}{struct }osmo\_stats\_reporter *osmo\_stats\_reporter\_alloc(\textcolor{keyword}{enum} osmo\_stats\_reporter\_type type,}
\DoxyCodeLine{116         \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name);}
\DoxyCodeLine{117 \textcolor{keywordtype}{void} osmo\_stats\_reporter\_free(\textcolor{keyword}{struct} osmo\_stats\_reporter *srep);}
\DoxyCodeLine{118 }
\DoxyCodeLine{119 \textcolor{keyword}{struct }osmo\_stats\_reporter *osmo\_stats\_reporter\_find(\textcolor{keyword}{enum} osmo\_stats\_reporter\_type type,}
\DoxyCodeLine{120         \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name);}
\DoxyCodeLine{121 }
\DoxyCodeLine{122 \textcolor{keywordtype}{int} osmo\_stats\_reporter\_set\_remote\_addr(\textcolor{keyword}{struct} osmo\_stats\_reporter *srep, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *addr);}
\DoxyCodeLine{123 \textcolor{keywordtype}{int} osmo\_stats\_reporter\_set\_remote\_port(\textcolor{keyword}{struct} osmo\_stats\_reporter *srep, \textcolor{keywordtype}{int} port);}
\DoxyCodeLine{124 \textcolor{keywordtype}{int} osmo\_stats\_reporter\_set\_local\_addr(\textcolor{keyword}{struct} osmo\_stats\_reporter *srep, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *addr);}
\DoxyCodeLine{125 \textcolor{keywordtype}{int} osmo\_stats\_reporter\_set\_mtu(\textcolor{keyword}{struct} osmo\_stats\_reporter *srep, \textcolor{keywordtype}{int} mtu);}
\DoxyCodeLine{126 \textcolor{keywordtype}{int} osmo\_stats\_reporter\_set\_max\_class(\textcolor{keyword}{struct} osmo\_stats\_reporter *srep,}
\DoxyCodeLine{127         \textcolor{keyword}{enum} osmo\_stats\_class class\_id);}
\DoxyCodeLine{128 \textcolor{keywordtype}{int} osmo\_stats\_reporter\_set\_name\_prefix(\textcolor{keyword}{struct} osmo\_stats\_reporter *srep, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *prefix);}
\DoxyCodeLine{129 \textcolor{keywordtype}{int} osmo\_stats\_reporter\_enable(\textcolor{keyword}{struct} osmo\_stats\_reporter *srep);}
\DoxyCodeLine{130 \textcolor{keywordtype}{int} osmo\_stats\_reporter\_disable(\textcolor{keyword}{struct} osmo\_stats\_reporter *srep);}
\DoxyCodeLine{131 \textcolor{keywordtype}{int} osmo\_stats\_reporter\_set\_flush\_period(\textcolor{keyword}{struct} osmo\_stats\_reporter *srep, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} period);}
\DoxyCodeLine{132 }
\DoxyCodeLine{133 \textcolor{comment}{/* reporter creation */}}
\DoxyCodeLine{134 \textcolor{keyword}{struct }osmo\_stats\_reporter *osmo\_stats\_reporter\_create\_log(\textcolor{keyword}{const} \textcolor{keywordtype}{char} *name);}
\DoxyCodeLine{135 \textcolor{keyword}{struct }osmo\_stats\_reporter *osmo\_stats\_reporter\_create\_statsd(\textcolor{keyword}{const} \textcolor{keywordtype}{char} *name);}
\DoxyCodeLine{136 }
\DoxyCodeLine{137 \textcolor{comment}{/* helper functions for reporter implementations */}}
\DoxyCodeLine{138 \textcolor{keywordtype}{int} osmo\_stats\_reporter\_send(\textcolor{keyword}{struct} osmo\_stats\_reporter *srep, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *data,}
\DoxyCodeLine{139         \textcolor{keywordtype}{int} data\_len);}
\DoxyCodeLine{140 \textcolor{keywordtype}{int} osmo\_stats\_reporter\_send\_buffer(\textcolor{keyword}{struct} osmo\_stats\_reporter *srep);}
\DoxyCodeLine{141 \textcolor{keywordtype}{int} osmo\_stats\_reporter\_udp\_open(\textcolor{keyword}{struct} osmo\_stats\_reporter *srep);}
\DoxyCodeLine{142 \textcolor{keywordtype}{int} osmo\_stats\_reporter\_udp\_close(\textcolor{keyword}{struct} osmo\_stats\_reporter *srep);}
\DoxyCodeLine{143 }
\DoxyCodeLine{144 \textcolor{preprocessor}{\#endif }\textcolor{comment}{/* unix || \_\_APPLE\_\_ */}\textcolor{preprocessor}{}}

\end{DoxyCode}
