newrelic-experimental / nr1-viz-geo-location

Geographic based visualisation of business and performance data. Supporting status markers, regions and heat maps.
Apache License 2.0
4 stars 0 forks source link
leaflet-map map newrelic react sales-analysis typescript

New Relic Open Source experimental project banner.

Geo Location Map Visualization

Geo Location Map Visualization is a dynamic web application designed to visually represent business or telemetry data on a geographical map. This tool is particularly useful for businesses seeking to data across different physical locations. It utilizes New Relic's custom visualization capabilities, alongside React and Leaflet, to provide a user-friendly and interactive map interface.

Visualization Overview Visualization Overview with status Visualisation showing Regions only Visualisation showing regions and markers together Visualisation showing heatmap onUS region Visualisation showing high density mode Visualisation showing PNG and SVG icons

Features

Prerequisites

Before we start, make sure you have the following installed:

  1. Node.js (>=12.13.0).
  2. New Relic CLI (>=0.25.0).

Also, make sure you are logged in to your New Relic account. (alternatively check out the Set up your development environment guide).

Installation

Clone the repository and run npm install to install dependencies.

You will need a development profile, you can read more about how to set up on the New Relic developer site

To summarise the steps required:

Testing

You can test locally by running nr1 nerdpack:serve

Deploy to account

To use the custom visualisation you must deploy it to your account following these steps:

The custom visualization should now appear as an option in the Custom Visualizations app (in the Apps > Custom Visualizations). Select the custom visualization, configure it and save to a dashboard.

Pro tip: Once a custom visualization is on a dashboard, you can click the ellipses to duplicate it.

Configuration

The visualization is highly configurable, allowing users to tailor its behavior and appearance to their specific needs. Configuration is managed primarily managed through config options and by providing data in an NRQL query.

You may also change color schemes etc by editing the values in the constants.ts file, this will affect all instances of the visualization.

Configuration Options

The following options can be configured using the visualization configuration panel:

Markers Query

For the most flexibility, you can provide a number of configuration and data values via the NRQL query as named fields. If supplied, the fields perform the following actions:

Regions Query

Regions can be rendered as an alternative or in additon to markers. Use the same configuration opttions as above with following changes:

More details regarding region setup can be found here.

Precision, prefix and suffix

Its possible to specify the precision of numbers and add prefix/suffix to values. These adjustments can be made to the icon_label and tooltip_xxx fields by providing extra fields:

You may also override the default precision (2) of the icon value by setting value_precision if you are not providing an icon label.

Example Query

Here is a basic example query, that utilises a lookup table (containing storeID/lat/lng/city) to supply the latitude, longitude to the data:

FROM Transaction left join (from lookup(geoCities) select storeId, city as city, lat, lng limit max) on storeId
select rate(count(*), 1 hour) as value,
latest(lat) as latitude,
latest(lng) as longitude
facet city as name limit max

Here is a more complex query that demonstrates additional features as described above:

FROM Transaction left join (from lookup(geoCities)
select storeId,city as city,lat,lng limit max) on storeId
select

rate(count(*), 1 hour) as value,
10000 as threshold_critical,
5000 as threshold_warning,

latest(lat) as latitude,
latest(lng) as longitude,

rate(count(*)/1000,1 hour) as icon_label,
1 as 'icon_label_precision',
'£' as icon_label_prefix,
'm' as icon_label_suffix,

'https://www.newrelic.com' as link,

count(*) as 'tooltip_count',

latest(city) as 'tooltip_city',

average(duration) as 'tooltip_avg_duration',
2 as 'tooltip_avg_duration_precision'

facet city as 'name' limit max

Geo Regions

The Geo regions are defined in countries.geojson.json. This is a GEOJSON file contiaing the country region polygons. You may want to edit these to suit your needs.

Geo Lookup Tables

The following data tables may be useful to join your data to. Upload as lookup tables and join to them through NRQL:

Tip: If you need to convert a UK post code to the 'outcode' format in order to perform a join, convert it using capture(postcode,r'^(?P<outcode>[\d\w]+)\s*\d[A-Z]{2}') as outcode. Here's an example:

with capture(my_full_delivery_postcode,r'^(?P<outcode>[\d\w]+)\s*\d[A-Z]{2}') as outcode 
 FROM MyOrderEvent 
 left JOIN (
  FROM lookup(uk_postcode_outcodes) select postcode, latitude, longitude, region_latitude, region_longitude, area,post_town, region 
 ) ON outcode = postcode
 SELECT count(*) as value, 
   2 + (count(*)*3) as icon_radius,
   latest(postcode) as atooltip_postcode,
   latest(post_town) as btooltip_town,
   latest(area) as ctooltip_area,
   latest(longitude) as longitude,
   latest(latitude) as latitude
 where outcode is not null
 facet postcode
 limit 100

Architecture

The following diagram illustrates the architecture of the visualization:

Architecture Diagram

Support

New Relic hosts and moderates an online forum where customers can interact with New Relic employees as well as other customers to get help and share best practices.

Contributing

We encourage your contributions to improve Store Map Visualisation! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at opensource@newrelic.com.

A note about vulnerabilities

As noted in our security policy, New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.

If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through HackerOne.

License

New Relic Store Map Visualisation is licensed under the Apache 2.0 License.