![Reporting Customized Metrics to FSO Platform Utilizing the OpenTelemetry SDK Reporting Customized Metrics to FSO Platform Utilizing the OpenTelemetry SDK](https://geeks-news.com/wp-content/uploads/https://storage.googleapis.com/blogs-images/ciscoblogs/1/2023/10/FSO-metrics-featured-scaled.jpg)
[ad_1]
With Cisco FSO Platform, metrics may be reported instantly from the code. Not like utilizing any form of auto-instrumentation characteristic, that is helpful when a service proprietor is aware of what must be reported. A typical use case can be enabling reporting of area particular metrics – like variety of objects within the catalogue for e-shops, variety of unfinished orders, SQL queries to particular desk, and so on. Mainly, something which is perhaps fascinating to watch for some time frame, or in contrast amongst completely different implementation variations.
Arms-on steerage on easy methods to set this up
Open Telemetry has a advisable means of how the metric reporting needs to be routed to any software program. The service which will likely be reporting the info goes to ship them to the open telemetry collector, which is a fairly handy common receiver, processor and exported of (not solely) open telemetry formatted information. Open Telemetry collector will then be configured to relay all the info to the FSO Platform tenant.
The very first thing that that you must safe is a FSO Platform tenant, to which the info will circulate. I occur to have one prepared, however I have to get the principal and clientId and clientSecret used to export information. After logging in, I opened a “Configuration” tab, then chosen “Kubernetes and APM,” named my configuration, and adopted the knowledge introduced to me:
![FSO Platform - Getting Agent Principal](https://storage.googleapis.com/blogs-images/ciscoblogs/1/2023/09/Screenshot-2023-08-25-at-14.42.15-blurred-1024x717.jpg)
That needs to be all I have to configure my Open Telemetry collector.
Open Telemetric Collector configuration
Subsequent, I used Docker picture otel/opentelemetry-collector-contrib:newest, since that’s the only means for me to run the collector. All I have to do is to offer the proper configuration, which is completed by supplying –config parameter.
After some quick analysis, I made a decision to make use of the next configuration:
![OTEL Collector configuration](https://storage.googleapis.com/blogs-images/ciscoblogs/1/2023/09/Screenshot-2023-09-04-at-10.06.53-1024x756.png)
Then the one factor left to do is to begin the collector:
% docker run --rm -t -v $PWD/otel-config.yaml:/and so on/otel-collector-config.yaml -p 4317:4317 otel/opentelemetry-collector-contrib:newest --config=/and so on/otel-collector-config.yaml
The collector begins actually rapidly, I solely verified that every one the extensions I added are initialised, no errors printed out.
My go-to language is Java, so lets strive that first. Open Telemetry supplies a fairly intensive record of SDK libraries for any trendy languages and runtimes. The Java SDK appears to be probably the most mature one on that record. This doesn’t imply that Java is the one selection. Realistically, there may be already assist for reporting Open Telemetry information from any actively used language. And if not, there may be all the time an choice to report information utilizing completely different receivers. For instance, you need to use Prometheus or Zipkin assist which your programming or runtime surroundings already has.
Metric Knowledge Supply
Since I don’t have any software prepared for this experiment, I selected to do the guide instrumentation (it’s going to almost definitely be extra enjoyable anyway).
After establishing a undertaking and a dependency on the newest SDK model accessible (1.29.0), I put collectively the next class package deal com.cisco.fso:
![Java Class reporting OTEL Metric](https://storage.googleapis.com/blogs-images/ciscoblogs/1/2023/09/Screenshot-2023-09-04-at-10.07.37-1024x965.png)
Let’s undergo some necessary components of this code snippet.
First one is the Useful resource declaration. In Open Telemetry, each information level must be reported within the context of a useful resource, together with metrics. Right here I’m declaring my useful resource as one thing with the attributes service.title and service.occasion.id — which is a de-facto normal, described as a part of the Open Telemetry semantic conventions.
When you discover that house extra, you’ll discover a lot of different conventions, defining which useful resource attributes needs to be reported for varied parts, like container, pod, service operating deployed on some cloud supplier and plenty of extra. By utilizing service.title and service.occasion.id, we’re reporting a service. On FSO Platform that is mapped to the sort apm:service_instance.
One other half value mentioning is the metric initialization. You may see that I named my metric “my.first.metric”, set the sort to gauge, declared that will probably be reporting lengthy values, and registered a callback, which does return random lengthy values. Not very helpful, however needs to be ok to get some information in.
After executing this system, you will notice new logs reported by the Open Telemetry Collector we began earlier than:
![OTEL Collector log](https://storage.googleapis.com/blogs-images/ciscoblogs/1/2023/09/Screenshot-2023-09-04-at-10.08.11-1024x484.png)
Exploring ingested metrics utilizing FSO Platform
This can be a good signal that the info arrived from my Java program to the collector. Additionally, the collector accommodates additional logs which counsel that it was capable of report the info to the platform. So, let’s get again to the browser and take a look at whether or not we will see reported information.
![FSO Platform Entity Centric Service view](https://storage.googleapis.com/blogs-images/ciscoblogs/1/2023/09/Screenshot-2023-08-25-at-16.06.41-1024x625.png)
Apparently my service was registered by the platform, however there usually are not a lot information reported. And, any metrics that are displayed by default, usually are not populated. Why is that occuring?
All of the metrics that are there are derived from spans and traces which might be reported by any normal APM Service and even any framework which you’d be utilizing. The Open Telemetry SDK has good auto-discoverable options for Spring, Micronaut, and different instruments you is perhaps utilizing. After placing some load to your service, you’d see these. However that’s not what we wish to do in the present day. We wish to see our essential “my.first.metric” information factors.
For that, we might want to use Question Builder, a System Utility of FSO Platform, which lets you question saved information instantly utilizing Unified Question Language.
FETCH metrics(dynamicmetrics:my.first.metric) FROM entities(apm:service_instance)[attributes(service.name)='manualService']
This specific question fetches the reported metric for the apm:service_instance, which was mapped from the useful resource reported utilizing the Java snippet above. It retrieves values of a metric my.first.metric and reveals them on the output. The dynamicmetrics string represents a particular namespace for metrics, which have been ingested however usually are not outlined in any of the options which the present tenant is at the moment subscribed to.
![FSO Platform - Query Builder](https://storage.googleapis.com/blogs-images/ciscoblogs/1/2023/09/Screenshot-2023-08-28-at-16.44.12-1024x732.png)
Clearly, that is solely the start and most of you wouldn’t be solely reporting customized metrics by hand, you’d be instrumenting code of your current purposes, infrastructure, cloud suppliers and something you’ll be able to mannequin.
Able to strive? Get acknowledged with Cisco FSO Platform
Associated sources
Share:
[ad_2]