Prometheus Java Client : Export String based Metrics - java

I`m Currently trying to write an Exporter for Minecraft to display some Metrics in our Grafana Dashboard. While most Metrics are working fine with the Metric Types Counter and Gauge, i couldn't find any documentation on how to export Strings as Metrics. I need those to export Location Data, so that we can have an Overview about where our Players are from, so we can focus localization on these regions. I wasn't able to find anything about that in the official Documentation, nor was I able to find anything in the Github Repository that could help me.
Anyone can help me with that?
With kind regards
thelooter

Metrics are always numeric. But you can use a labels to export string values, this is typically used to export build or version information. E.g.
version_info{version="1.23", builtOn="Windows", built_by="myUserName" gitTag="version_1.0"} = 1
so you can show in Grafana which version is currently running.
But (!!!) Prometheus is not designed to handle a lot of label combinations. Prometheus creates a new file for every unique label value combination. This would mean that you creat a file per player if you had one metric per player. (And you still need to calculate the amount of players per Region)
What you could do is define regions in your software and export a gauge for every region representing the amount of players logged in from this region:
player_count{region="Europe"} 234
player_count{region="North America"} 567
...
If you don't want to hardcode the regions in your software, you should export the locations of the players into a database and do the statistics later based on the raw data.

Related

Counting agents in discrete system during Parameter Variation Experiment

I am working on a project for personnel allocation during a Navy maintenance availability using AnyLogic. I have the simulation running and have set the parameters (the personnel) variable up and running. However, I am trying to pull the numbers of checks entering the system and those leaving the system for each simulation run to assess the efficiency of the manpower allocation. I'm not able to do that because I cannot convert "agent" to "double". How can I fix this?
I tried creating new agents, trying to make the count into a variable to gather it on the ParametersVariation page and that did not work either.

Grafana dashboard separating "boundedElastic" vs "parallel" for executor pool

Small question regarding how to build Grafana dashboards which separates "boundedElastic" vs "parallel" please.
Currently with a Spring Webflux app, I get out of the box very useful metrics for Reactor Core.
executor_pool_size_threads
executor_pool_core_threads
executor_pool_max_threads
etc
The Reactor Team even provides default dashboard so we can have visuals on the states:
https://github.com/reactor/reactor-monitoring-demo
Unfortunately, the current dashboards mix "boundedElastic" and "parallel", I am trying to build the same dashboards, but with "boundedElastic" and "parallel" separated.
I tried:
sum(executor_pool_size_threads{_ws_="my_workspace"}) by (reactor_scheduler_id, boundedElastic)
But no luck so far.
May I ask what is the correct way to do it please?
Thank you
In the demo project, the metrics are stored in Prometheus and are queried using PromQL. Each metric can have several labels and each label can have several values. The metrics can be selected by labels and values, e.g. my_metric{first_label="first_value", second_label="another_value"} selects my_metric where both labels are matching corresponding values.
So in your example the metric executor_pool_size_threads has the label reactor_scheduler_id. However, the values contain more information beyond scheduler name. On my machine (because of default pool size) the values are: parallel(8,"parallel") and boundedElastic("boundedElastic",maxThreads=80,maxTaskQueuedPerThread=100000,ttl=60s). So regex-match is useful here for matching the values with =~ operator.
PromQL query only for parallel:
sum (executor_pool_size_threads{reactor_scheduler_id=~"parallel.*"}) by (reactor_scheduler_id)
PromQL query only for boundedElastic:
sum (executor_pool_size_threads{reactor_scheduler_id=~"boundedElastic.*"}) by (reactor_scheduler_id)

Custom time stamp for time series collected with Prometheus in java

I have a java application which uses the Prometheus library in order to collect metrics during execution.
Later I link the Prometheus server to Grafana in order to visualize those metrics. I was wondering if it is possible to make Grafana show a custom X axis for those metrics?
The usual X axis is in local time. Can I make it show data with timestamps in GPS / UTC time? Is it possible? If it is, what would it require? An additional metric parameter that holds the timestamps?
I declare the metric variable like this:
private static Counter someCounter = Counter.build()
.name("someCounter_name").help("information counter").labelNames("SomeLable").register();
And add data like this:
someCounter.labels("test").inc();
Any help would be appreciated. Thank you.
This is something to handle in Grafana. If you look at the dashboard (not panel) settings, under General there's a Timezone drop-down that allows you to select UTC rather than browser local time.

Kubernetes, Java and Grafana - How to display only the running containers?

I'm working on a setup where we run our Java services in docker containers hosted on a kubernetes platform.
On want to create a dashboard where I can monitor the heap usage of all instances of a service in my grafana. Writing metrics to statsd with the pattern:
<servicename>.<containerid>.<processid>.heapspace works well, I can see all heap usages in my chart.
After a redeployment, the container names change, so new values are added to the existing graph. My problem is, that the old lines continue to exist at the position of the last value received, but the containers are already dead.
Is there any simple solution for this in grafana? Can I just say: if you didn't receive data for a metric for more than X seconds, abort the chart line?
Update:
Upgrading to the newest Grafana Version and Setting "null" as value for "Null value" in Stacking and Null Value didn't work.
Maybe it's a problem with statsd?
I'm sending data to statsd in form of:
felix.javaclient.machine<number>-<pid>.heap:<heapvalue>|g
Is anything wrong with this?
This can happen for 2 reasons, because grafana is using the "connected" setting for null values, and/or (as is the case here) because statsd is sending the previously-seen value for the gauge when there are no updates in the current period.
Grafana Config
You'll want to make 2 adjustments to your graph config:
First, go to the "Display" tab and under "Stacking & Null value" change "Null value" to "null", that will cause Grafana to stop showing the lines when there is no data for a series.
Second, if you're using a legend you can go to the "Legend" tab and under "Hide series" check the "With only nulls" checkbox, that will cause items to only be displayed in the legend if they have a non-null value during the graph period.
statsd Config
The statsd documentation for gauge metrics tells us:
If the gauge is not updated at the next flush, it will send the
previous value. You can opt to send no metric at all for this gauge,
by setting config.deleteGauges
So, the grafana changes alone aren't enough in this case, because the values in graphite aren't actually null (since statsd keeps sending the last reading). If you change the statsd config to have deleteGauges: true then statsd won't send anything and graphite will contain the null values we expect.
Graphite Note
As a side note, a setup like this will cause your data folder to grow continuously as you create new series each time a container is launched. You'll definitely want to look into removing old series after some period of inactivity to avoid filling up the disk. If you're using graphite with whisper that can be as simple as a cron task running find /var/lib/graphite/whisper/ -name '*.wsp' -mtime +30 -delete to remove whisper files that haven't been modified in the last 30 days.
To do this, I would use
maximumAbove(transformNull(felix.javaclient.*.heap, 0), 0)
The transformNull will take any datapoint that is currently null, or unreported for that instant in time, and turn it into a 0 value.
The maximumAbove will only display the series' that have a maximum value above 0 for the selected time period.
Using maximumAbove, you can see all history containers, if you wish to see only the currently running containers, you should use just that: currentAbove

Tracking a variable using Google Analytics

I'm extremely new to Google Analytics on Android.
I've searched quite a bit for this, but I'm not sure I have understood it correctly, but here goes :
I want Google Analytics to track a particular variable in my app.
So for instance, a variable a has a separate value for every user of the app, is it possible for me to display the average of the value of the variable in a Google Analytics dashboard ?
As per my understanding goes, we can do this using Custom Dimensions and Metrics.
I haven't been able to find any tutorial for the same.
I'd be grateful if someone could help me with a tutorial or point me to something other than the developer pages from Google.
Thank You!
UPDATE
Firebase Analytics is now Google’s recommended solution for mobile app analytics. It’s user and event-centric and comes with unlimited app event reporting, cross-network attribution, and postbacks.
Older Answer
You may use GA Event Tracking
Check this guide and this one to check rate limits before you try this.
Events are a useful way to collect data about a user's interaction
with interactive components of your app, like button presses or the
use of a particular item in a game.
An event consists of four fields that you can use to describe a user's
interaction with your app content:
Field Name Type Required Description
Category String Yes The event category
Action String Yes The event action
Label String No The event label
Value Long No The event value
To send an event to Google Analytics, use HitBuilders.EventBuilder and send the hit, as shown in this example:
// Get tracker.
Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
TrackerName.APP_TRACKER);
// Build and send an Event.
tracker.send(new HitBuilders.EventBuilder()
.setCategory("Achievement")
.setAction("Earned")
.setLabel("5 Dragons Rescued")
.setValue(1)
.build());
On GA console you can see something like this:
where event value is
and avg value is
If you want to track users with specific attributes/traits/metadata then custom dimensions can be used to send this type of data to Google Analytics.
See Set up or edit custom dimensions (Help Center) and then update the custom dimension value as follows:
// Get tracker.
Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
TrackerName.APP_TRACKER);
t.setScreenName("Home Screen");
// Send the custom dimension value with a screen view.
// Note that the value only needs to be sent once.
t.send(new HitBuilders.ScreenViewBuilder()
.setCustomMetric(1, 5)
.build()
);
It is possible to send additional data to Google Analytics, using either Custom Dimensions or Custom Metrics.
Custom Dimensions are used for labels and identifiers that you will later use to separate your data. For example, you might have a Custom Dimension that tracks log-in status. This would allow you to break down your reports and compare logged-in traffic to not logged-in. These can contain text; while AB testing your site you might set up a custom dimension with the options 'alpha' and 'beta'. They can also contain numeric values, such as the time '08:15', or a unique identifier that you've generated (although you should be careful to follow Google's advice here, lest you include PII and rick account deletion https://developers.google.com/analytics/solutions/crm-integration#user_id).
Custom Metrics are used for numeric variables such as engagement time, or shopping cart value. They are a lot like custom dimensions, but are intended to be compared across dimensions. For example, you could compare the shopping basket value of your Organic users to those who come in via a paid link.
If you wanted to calculate an average, you would also require a calculated metric. This takes two metrics you already have, and produces a third. For example, if you site was all about instant engagement, and you wanted to track the time before the first click event on each page, you could set up that event click time as a custom metric. But this would only tell you what the total is; surely more customers are a good thing, but they make that total go up! So you set up a calculated metric that divides this total by the number of page views, giving you a value per page viewed.
There's a great guide by Simo Ahava about tracking Content Engagement that includes instructions for setting up Custom Metrics and Calculated Metrics.
http://www.simoahava.com/analytics/track-content-engagement-part-2/
However, I should warn you that his guide uses Google Tag Manager, which greatly simplifies the process of adding such customisation to your tags. If you don't want to take that step, you will have to code it manually, as recommended by Google's support https://support.google.com/analytics/answer/2709828?hl=en

Categories