MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / mod_init

Function mod_init

modules/prometheus/prometheus.c:154–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152};
153
154static int mod_init(void)
155{
156 struct list_head *it;
157 struct prom_stat *s;
158
159 prom_http_root.len = strlen(prom_http_root.s);
160 prom_prefix.len = strlen(prom_prefix.s);
161 prom_delimiter.len = strlen(prom_delimiter.s);
162 prom_grp_prefix.len = strlen(prom_grp_prefix.s);
163 prom_grp_label.len = strlen(prom_grp_label.s);
164
165 if (prometheus_script_route.s) {
166 prometheus_script_route.len = strlen(prometheus_script_route.s);
167
168 prometheus_route_ref = ref_script_route_by_name(prometheus_script_route.s,
169 sroutes->request, RT_NO , REQUEST_ROUTE, 0);
170 if ( !ref_script_route_is_valid(prometheus_route_ref) ) {
171 LM_ERR("Prometheus route <%s> not defined!\n", prometheus_script_route.s);
172 return -1;
173 }
174 }
175
176 if (prom_grp_mode < PROM_GROUP_MODE_NONE || prom_grp_mode >= PROM_GROUP_MODE_INVALID) {
177 LM_ERR("invalid group mode %d\n", prom_grp_mode);
178 return -1;
179 }
180
181 /* Load httpd api */
182 if(load_httpd_api(&prom_httpd_api)<0) {
183 LM_ERR("Failed to load httpd api\n");
184 return -1;
185 }
186
187 /* try to resolve as many stats as possible now */
188 list_for_each(it, &prom_stats) {
189 s = list_entry(it, struct prom_stat, list);
190 s->stat = shm_malloc(sizeof *s->stat);
191 if (!s->stat) {
192 LM_ERR("oom for stat!\n");
193 return -1;
194 }
195 *s->stat = get_stat(&s->name);
196 /* if we don't find it now, don't panic, we might find it later */
197 }
198
199 /* Load httpd hooks */
200 prom_httpd_api.register_httpdcb(exports.name, &prom_http_root,
201 &prom_answer_to_connection,
202 &prom_flush_data,
203 HTTPD_TEXT_PLAIN_PROMETHEUS_TYPE,
204 NULL);
205
206 return 0;
207}
208
209
210static ssize_t prom_flush_data(void *cls, uint64_t pos, char *buf,

Callers

nothing calls this directly

Calls 5

ref_script_route_by_nameFunction · 0.85
load_httpd_apiFunction · 0.85
shm_mallocFunction · 0.85
get_statFunction · 0.85
list_entryClass · 0.50

Tested by

no test coverage detected