Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for publishing custom prometheus data ( not stat driven ) #3310

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 66 additions & 3 deletions modules/prometheus/README
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Prometheus Module
1.3.6. group_mode(int)
1.3.7. statistics(string)
1.3.8. labels(string)
1.3.9. script_route(string)
1.3.10. script_route_avp_result(string)

1.4. Exported Functions
1.5. Examples
Expand Down Expand Up @@ -51,7 +53,9 @@ Prometheus Module
1.6. Set group_mode parameter
1.7. Set statistics parameter
1.8. Set statistics parameter
1.9. Prometheus Scrape Config
1.9. Set script_route parameter
1.10. Set script_route parameter
1.11. Prometheus Scrape Config

Chapter 1. Admin Guide

Expand Down Expand Up @@ -230,6 +234,65 @@ modparam("prometheus", "labels", "group: /^(.*)_(.*)$/\1:gateway=\"\2\"/
")
...

1.3.9. script_route(string)

Specifies the route name to be used to for adding custom
prometheus information.

The default value is "" - no custom route called.

Example 1.9. Set script_route parameter
...
modparam("prometheus", "script_route", "my_custom_prometheus_route")
...

1.3.10. script_route_avp_result(string)

Specifies the AVP spec name to be used to for returning custom
prometheus information.

The AVP is expected to contain a JSON format, containing an
array of arrays of custom statistics to export to prometheus.
See section for the format itself.

The default value is "" - no custom route called.

Example 1.10. Set script_route parameter
...
modparam("prometheus", "script_route", "my_custom_prometheus_route")
modparam("prometheus", "script_route_avp_result", "$avp(prometheus_out_j
son)")
...
route[my_custom_prometheus_route] {
# the OUT JSON needs to contain an array of objects containing a
header and a values field
# the header field to contain the custom prometheus stats header
# the values field is an array itself, of name/value objects
# used for individual stats publishing
$avp(prometheus_out_json) = "
[ {
"header": "# TYPE opensips_cps gauge",
"values": [
{
"name": "opensips_total_cps",
"value": 3
}
]
},
{
"header": "# TYPE opensips_disabled_rtpengine gauge",
"values": [
{
"name": "opensips_disabled_rtpengine",
"value": 0
}
]
},
]";

}
...

1.4. Exported Functions

No function exported to be used from configuration file.
Expand All @@ -242,7 +305,7 @@ modparam("prometheus", "labels", "group: /^(.*)_(.*)$/\1:gateway=\"\2\"/
config, indicating the IP and port you've configured the httpd
module to listen on (default: 0.0.0.0:8888).

Example 1.9. Prometheus Scrape Config
Example 1.11. Prometheus Scrape Config

scrape_configs:
- job_name: opensips
Expand Down Expand Up @@ -300,4 +363,4 @@ Chapter 3. Documentation

Documentation Copyrights:

Copyright © 2021 www.opensips-solutions.com
Copyright © 2021 www.opensips-solutions.com
69 changes: 69 additions & 0 deletions modules/prometheus/doc/prometheus_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,75 @@ modparam("prometheus", "labels", "group: /^(.*)_(.*)$/\1:gateway=\"\2\"/")
</programlisting>
</example>
</section>

<section id="param_script_route" xreflabel="script_route">
<title><varname>script_route</varname>(string)</title>
<para>
Specifies the route name to be used to for adding custom prometheus information.
</para>
<para>
<emphasis>The default value is "" - no custom route called.</emphasis>
</para>
<example>
<title>Set <varname>script_route</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("prometheus", "script_route", "my_custom_prometheus_route")
...
</programlisting>
</example>
</section>

<section id="param_script_route_avp_result" xreflabel="script_route_avp_result">
<title><varname>script_route_avp_result</varname>(string)</title>
<para>
Specifies the AVP spec name to be used to for returning custom prometheus information.
</para>
<para>
The AVP is expected to contain a JSON format, containing an array of arrays of custom statistics to export to prometheus. See section for the format itself.
</para>
<para>
<emphasis>The default value is "" - no custom route called.</emphasis>
</para>
<example>
<title>Set <varname>script_route</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("prometheus", "script_route", "my_custom_prometheus_route")
modparam("prometheus", "script_route_avp_result", "$avp(prometheus_out_json)")
...
route[my_custom_prometheus_route] {
# the OUT JSON needs to contain an array of objects containing a header and a values field
# the header field to contain the custom prometheus stats header
# the values field is an array itself, of name/value objects
# used for individual stats publishing
$avp(prometheus_out_json) = "
[ {
"header": "# TYPE opensips_cps gauge",
"values": [
{
"name": "opensips_total_cps",
"value": 3
}
]
},
{
"header": "# TYPE opensips_disabled_rtpengine gauge",
"values": [
{
"name": "opensips_disabled_rtpengine",
"value": 0
}
]
},
]";

}
...
</programlisting>
</example>
</section>

</section>

<section id="exported_functions" xreflabel="exported_functions">
Expand Down
Loading
Loading