Group/Aggregate by tag in a custom metric - promql

I have my own custom counter:
Counter.builder(NAMESPACE + "country_code")
.tag("country", country_code)
.description("Total number of requests per country code (e.g. 0049, 0043, 0044, ...)")
.register(meterRegistry);
I want to get amount of requests grouped by tag country
I have so far:
count(test_country_code_total)
My question: Is it possible to group by tag in promql or is there any alternatives?

Related

Accessing Span Elements

When trying to scrape out the integer value for movie reviews from IMDB reviews , i am confused on how to access the rating when its inspect html is just listed as, 10, and changes for each individual rating (i.e 7 . How would I use the soup.find_all to access these values and add them to a list- i am confused how to do this when there is no class listed for the variable?
rate=soup.find_all('span')
rate_list=[]
for i in range(0,len(rate)):
rate_list.append(rate[i].get_text())
Try using the fact the target span sits next to the star
ratings = [i.text for i in soup.select('.ipl-star-icon + span')]
But, in case there are ratings for everything I would probably loop reviews (for review in soup.select('.lister-item-content): .....) and test if review.select_one('.ipl-star-icon + span') is not None

How to use Django iterator with value list?

I have Profile table with a huge number of rows. I was trying to filter out profiles based on super_category and account_id (these are the fields in the model Profile).
Assume I have a list of ids in the form of bulk_account_ids and super_categories
list_of_ids = Profile.objects.filter(account_id__in=bulk_account_ids, super_category__in=super_categories).values_list('id', flat=True))
list_of_ids = list(list_of_ids)
SomeTask.delay(ids=list_of_ids)
This particular query is timing out while it gets evaluated in the second line.
Can I use .iterator() at the end of the query to optimize this?
i.e list(list_of_ids.iterator()), if not what else I can do?

Jmeter - Usage of item based on the condition

I have defined multiple countries at user defined variables as list:
Then in another sample i use specific country as ex: PL
What is the easiest way, based of the usage of specific country, to enter in the loop?
I know with ${__groovy(vars.get("countries") == "AR")} is possible to compare with 1 country, but how can i compare extracted country with all the countries in the list?
If you need to iterate all the countries it's better to go for the ForEach Controller, in this case you need to transform the countries variable into the following pattern:
country_1=PL
country_2=PT
country_3=RO
etc.
If you're looking for a Groovy code to do the conversion:
Add JSR223 Sampler at the place where you need to "enter the loop"
Put the following code into "Script" area:
vars.get('countries').trim().split(' ').eachWithIndex { country, index ->
vars.put('country_' + ++index, country.trim())
}
Add ForEach Controller after the JSR223 Sampler and configure it like:
That's it, you should be able to iterate all the countries, defined in the countries variable

Insert values into API request dynamically?

I have an API request I'm writing to query OpenWeatherMap's API to get weather data. I am using a city_id number to submit a request for a unique place in the world. A successful API query looks like this:
r = requests.get('http://api.openweathermap.org/data/2.5/group?APPID=333de4e909a5ffe9bfa46f0f89cad105&id=4456703&units=imperial')
The key part of this is 4456703, which is a unique city_ID
I want the user to choose a few cities, which then I'll look through a JSON file for the city_ID, then supply the city_ID to the API request.
I can add multiple city_ID's by hard coding. I can also add city_IDs as variables. But what I can't figure out is if users choose a random number of cities (could be up to 20), how can I insert this into the API request. I've tried adding lists and tuples via several iterations of something like...
#assume the user already chose 3 cities, city_ids are below
city_ids = [763942, 539671, 334596]
r = requests.get(f'http://api.openweathermap.org/data/2.5/groupAPPID=333de4e909a5ffe9bfa46f0f89cad105&id={city_ids}&units=imperial')
Maybe a list is not the right data type to use?
Successful code would look something like...
r = requests.get(f'http://api.openweathermap.org/data/2.5/group?APPID=333de4e909a5ffe9bfa46f0f89cad105&id={city_id1},{city_id2},{city_id3}&units=imperial')
Except, as I stated previously, the user could choose 3 cities or 10 so that part would have to be updated dynamically.
you can use some string methods and list comprehensions to append all the variables of a list to single string and format that to the API string as following:
city_ids_list = [763942, 539671, 334596]
city_ids_string = ','.join([str(city) for city in city_ids_list]) # Would output "763942,539671,334596"
r = requests.get('http://api.openweathermap.org/data/2.5/group?APPID=333de4e909a5ffe9bfa46f0f89cad105&id={city_ids}&units=imperial'.format(city_ids=city_ids_string))
hope it helps,
good luck

cassandra data model for web logging

Been playing around with Cassandra and I am trying to evaluate what would be the best data model for storing things like views or hits for unique page id's? Would it best to have a single column family per pageid, or 1 Super-column (logs) with columns pageid? Each page has a unique id, then would like to store date and some other metrics on the view.
I am just not sure which solution handles better scalability, lots of column family OR 1 giant super-column?
page-92838 { date:sept 2, browser:IE }
page-22939 { date:sept 2, browser:IE5 }
OR
logs {
page-92838 {
date:sept 2,
browser:IE
}
page-22939 {
date:sept 2,
browser:IE5
}
}
And secondly, how to handle lots of different date: entries for page-92838?
You don't need a column-family per pageid.
One solution is to have a row for each page, keyed on the pageid.
You could then have a column for each page-view or hit, keyed and sorted on time-UUID (assuming having the views in time-sorted order would be useful) or other unique, always-increasing counter. Note that all Cassandra columns are time-stamped anyway, so you would have a precise timestamp 'for free' regardless of what other time- or date- stamps you use. Using a precise time-UUID as the key also solves the problem of storing many hits on the same date.
The value of each column could then be a textual value or JSON document containing any other metadata you want to store (such as browser).
page-12345 -> {timeuuid1:metadata1}{timeuuid2:metadata2}{timeuuid3:metadata3}...
page-12346 -> ...
With cassandra, it is best to start with what queries you need to do, and model your schema to support those queries.
Assuming you want to query hits on a page, and hits by browser, you can have a counter column for each page like,
stats { #cf
page-id { #key
hits : # counter column for hits
browser-ie : #counts of views with ie
browser-firefox : ....
}
}
If you need to do time based queries, look at how twitters rainbird denormalizes as it writes to cassandra.

Resources