My application producers counters. I'd like to use grafana to view them. It seems grafana depends on influxDB or elasticsearch.
Is there a way to make grafana read data from my own app so I don't need to store them in another backend?
You can include an OpenTSDB datasource in between your App and Grafana.
Like this:
datasources: {
'OpenTSDB-TEST': {
default: true,
type: 'opentsdb',
url: "http://my_opentsdb_server:4242"
}
}
See more OpenTSDB configuration details here
You can use this plugin: https://github.com/grafana/datasource-plugin-genericdatasource
To configure it with version 2.6 do the following:
Put the plugin's files to folder, let's say, "genericdatasource".
Then copy this folder to /public/app/plugins/datasource/.
In directives.js change templateUrl of query.editor.html to:
'public/app/plugins/datasource/genericdatasource/partials/query.editor.html'
also change templateUrl of query.options.html to:
'public/app/plugins/datasource/genericdatasource/partials/query.options.html'
In plugin.json change module to:
'app/plugins/datasource/genericdatasource/datasource',
and change config to:
'public/app/plugins/datasource/genericdatasource/partials/config.html'
Then restart grafana-server. The new data source should now be avalilable in the data source type dropdown in the Add Data Source View.
Use option "proxy" there (not "direct") to work correctly with cross-domain requests.
You just need to implement 3 methods in your backend: /,search, query.
Look at examples here:
https://gist.github.com/bergquist/bc4aa5baface3cffa109
https://gist.github.com/tral/1fe649455fe2de9fb8fe
Related
I’m new to Strapi and to GraphQL.
I successfully created a website that uses Apollo to query data from my Strapi website.
So functionally I have everything I need.
For my DX I’m wondering:
Since I installed the GraphQL IntelliJ plugin: Where do I find the schemas for it? I read something about remote schema detection - is that supported with Strapi GraphQL Plugin? Where can I read about it? Otherwise how can I export GraphQL schema files from Strapi?
If I got 1) to work: Will TypeScript types work out of the box? Would I use one of the GraphQL schema to TS converters out there? It feels like there might be something working automatically, but I can’t tell till I get 1) to work.
First, you asked two separate questions and should therefore separate then in two separate threads.
To answer your first question: Here is how you can utilise the GraphQL IntelliJ plugin:
You need to create a .graphlconfig file. In Webstorm select your project folder and go to 'File' -> 'New' -> 'GraphQl Configuration File'.
Change the endpoint url to your strapi endpoint.
Visit the GraphQl Tool Window, double click your endpoint and select 'Get GraphQl Schema from Endpoint (introspection)'. This will retrieve the schema file from strapi and save it to schema.graphql.
Now you can run queries against your endpoint, e.g. create a new Scratch File scratch.graphql and run queries against your endpoint or try to figure out how to solve your second question ;)
Thank you for the answer! This was helpful!
Further to this, one query - typically, is .graphlconfig committed to git repo and scratch.graphql ignored from the git repo?
In addition for others looking for a similar solution - you could use values from .env. using the format below:
{
"name": "Strapi GraphQL Schema",
"schemaPath": "schema.graphql",
"extensions": {
"endpoints": {
"Default GraphQL Endpoint": {
"url": "${env:GRAPHQL_HOST}/graphql",
"headers": {
"Authorization": "Bearer ${env:GRAPHQL_TOKEN}",
"user-agent": "JS GraphQL"
},
"introspect": false
}
}
}
}
I want to move the appsettings.json file inside the app folder, but when I do that the object Configuration in the startup class cannot access to connection string.
If I leave the appsettings.json file in the root as it comes by default, everything works correctly. Does anyone know what it is due to and how to solve it?
You can try to set the app's configuration by calling ConfigureAppConfiguration when building the host, like below.
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "app", "appsettings.json"),
optional: false, reloadOnChange: false);
})
For more information about configuring the JSON configuration provider to load the specific json settings file, please check this doc: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-5.0#json-configuration-provider
I have exported the dashboard in json format.
I want to import the json file manually to create the same dashboard in new grafana instance.
While googling i got some related information but finding difficulties to implement successfully.
From the site Grafana API link i got the code snippet like,
POST /api/dashboards/db HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
{
“dashboard”: {
“id”: null,
“uid”: null,
“title”: “Production Overview”,
“tags”: [ “templated” ],
“timezone”: “browser”,
“schemaVersion”: 16,
“version”: 0
},
“folderId”: 0,
“overwrite”: false
}
The above code snippet looks like we can create new dashboard with existing json file but i have no idea of how to implement this code snippet successfully.
Somebody guide me how to achieve this?
There are two techniques to copy the current dashboard -
if you want to export this
Go to Current Grafana Dashboard
Select the Share button on the top
Select the Export Button and Copy the JSON or save it as JSON
Create new Grafana dashboard and copy this JSON model to
Click on the Setting button on the top
Click on JSON Model - from left panel
Past the JSON & Save the dashboard and run
Please let me know if you have any issue.
I found and answer to your question - how to import a dashboard in grafana by api - in this post on the community board of Grafana:
https://community.grafana.com/t/how-create-dashboard-and-panel-via-api/10947
Haven't tried this out yet though (we are planning on doing something like this as well).
I will quote the original question in this post:
Hi All,
I know how to create a dashboard via API but I don’t find instructions to how to create panels within that dashboard still via API. Any idea?
the part of the message that explains the answer:
And the response that contains the answer to the question:
The panels need to be defined within the JSON that you submit in your POST request.
The example in the docs doesn’t spell this out, beyond
dashboard – The complete dashboard model
To get hands-on with this, you can (1) create a new dashboard with some panels manually, (2) export that dashboard’s definition as JSON, (3) put the exported dashboard definition inside the “dashboard” field of a new JSON object, (4) POST the resulting JSON object to the API endpoint. This will create a copy of your original dashboard. From there on, you can edit the JSON model you’re posting in order to modify or add any panels you desire.
So to your original question, if you want to add a panel to an existing dashboard you can obtain its definition via the API, add the panel to the JSON object, and push the updated model. (keep the same id/uid and set "overwrite": true)"
Note that (now?) grafana has a nice import function too:
I write the code for couchbase view. follow this https://blog.couchbase.com/understanding-grouplevel-view-queries-compound-keys/
const mapDate = `function(doc, meta) {
emit(dateToArray(doc.updatedAt), {
_id: meta.id,
_rev: meta.rev,
updatedAt: doc.updatedAt
});
}`
and when I call http://localhost:4984/{db}/_design/{ddoc}/_view/{view} I got an error
Error running map function: ReferenceError: dateToArray is not defined
error image
I use sync-gateway version 1.4
What should I do?
In order to be able to query views via the Sync Gateway, you should be creating it through the Sync Gateway REST interface. You cannot query for views directly created on Couchbase Server.
This link should provide more insights into creating and querying views via Sync Gateway
The blog post you're referring to is about Couchbase Server, not Sync Gateway. So, it looks like dateToArray is not a pre-defined function available on Sync Gateway.
Context to this post is I'm a java developer attempting to teach myself Ember. It isn't going well. I realize this question is pretty vague so I apologize, I'm not even sure what I should be asking...
I need to pull data into a model, i.e. via some sort of query, from a heroku json endpoint. In the application.js file, I have the following:
import DS from ‘ember-data’;
export default DS.JSONAPIAdapter.extend({
host: 'https://cag-brain.herokuapp.com'
});
Ideally I would like to pull this data into a user model, then display that data on a page as a sort of proof of concept. This unfortunately gets me nothing. Nor am I even sure I'm going about this correctly. Should I be doing something different than attempting to use Host Customization? Any guidance would be much appreciated!
There are different things involved for retrieving records via ember-data.
First of all you should define your models:
// app/models/post.js
import DS from 'ember-data';
export default DS.Model.extend({
title: DS.attr('string')
});
You should retrieve records in a model hook of a route.
// app\routes\posts.js
import Route from '#ember/routing/route';
export default Route.extend({
model() {
return this.get('store').findAll('post');
}
});
Then you should configure your api host and maybe a namespace. You included that step in your question:
// app/adapters/application.js
import DS from ‘ember-data’;
export default DS.JSONAPIAdapter.extend({
host: 'https://cag-brain.herokuapp.com'
});
If your api does not implement JSON Api specification you need to customize your serializer and adapter. Ember-data ships with a RESTAdapter/RestSerializer additionally to the default adapter and serializer which implements JSON Api spec. There is also one abstract adapter and serializer If you need to start from scratch. Before that I would definitely have a look if there is any community adapter/serializer fitting your needs.
To decouple api and client development and to speed up tests I would recommend ember-cli-mirage which allows you to mock your api.