{"_id":"57fcc4870312b20e00ac64f7","version":{"_id":"57fcc4860312b20e00ac64c0","project":"5435687035740020002a1c04","__v":1,"createdAt":"2016-10-11T10:52:54.637Z","releaseDate":"2016-10-11T10:52:54.637Z","categories":["57fcc4860312b20e00ac64c1","57fcc4860312b20e00ac64c2","57fcc4860312b20e00ac64c3","57fcc4860312b20e00ac64c4","57fcc4860312b20e00ac64c5","57fcc4860312b20e00ac64c6","57fcc4860312b20e00ac64c7","57fcc4860312b20e00ac64c8","57fcc4860312b20e00ac64c9","57fcc4860312b20e00ac64ca","57fcc4860312b20e00ac64cb"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"[APP-1265], [APP-1035]","version_clean":"5.2.0","version":"5.2"},"category":{"_id":"57fcc4860312b20e00ac64c9","__v":0,"version":"57fcc4860312b20e00ac64c0","project":"5435687035740020002a1c04","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-05-01T21:33:28.863Z","from_sync":false,"order":8,"slug":"integration-examples","title":"Integration Examples"},"user":"5435682035740020002a1c01","parentDoc":null,"project":"5435687035740020002a1c04","__v":1,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-05-01T21:34:32.187Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Source Code Available\",\n  \"body\": \"The source code for this example is available on the [Telemetry Agents Examples](https://github.com/telemetryapp/agent_examples) Github repository.\"\n}\n[/block]\nThis page serves to give you an example on how to use a Telemetry Agent to run an executable and send the resulting metrics to a Telemetry flow.    The executable in this particular example will be a node.js script.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/OyVB9rkXQb6va3tsr1BE_exec.png\",\n        \"exec.png\",\n        \"993\",\n        \"210\",\n        \"#1097f8\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n# Requirements\n\nYou'll need an OSX or Linux computer system to run through this guide. Windows is supported with Telemetry but some of the details here would be slightly different and thus it's out of scope.\n\nWhile this model of Telemetry works with any language that can be executed from the command line we chose to do this example in javascript (and node.js) as it's one of the most common languages available today.   There's nothing stopping you from using Ruby, Python, PHP,  Java, C++, .NET and so forth.\n\nYou'll need node.js installed and ready to run local node scripts.   Without node you'll be able to follow the concepts but not actually execute the script.  Hopefully, the examples will serve to help you in whatever language is your choice.  \n\n# Installation\n\nGet the most recent agent from the [Telemetry Agent](https://github.com/telemetryapp/gotelemetry_agent/releases) Github repository.\n\n# Configure Board\n\nVisit the [Telemetry Manager](https://manager.telemetryapp.com) application, login and either create a new board or use an existing one. Add a gauge to the board and take note of the flow_tag. You'll use this tag to send data to.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/180b645-Screen_Shot_2017-07-26_at_10.42.52_AM.png\",\n        \"Screen Shot 2017-07-26 at 10.42.52 AM.png\",\n        263,\n        170,\n        \"#232a34\"\n      ]\n    }\n  ]\n}\n[/block]\n# Configure Agent\n\nNext, we'll need to configure the agent to run the node script and send it to Telemetry.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#\\n# Server Configuration Parameters\\n#\\n\\n[server]\\n# API token found in the Agents tab in manager.telemetryapp.com\\napi_token = \\\"abc123abc123abc123abc123abc123abc123\\\"\\n# Submit new metrics in a batch at most every 1 second\\nsubmission_interval = \\\"1s\\\"\\n\\n#\\n# Data Configuration Parameters\\n#\\n\\n[data]\\n# path = \\\"c:\\\\\\\\telemetry_agent.db\\\"\\n# WINDOWS USERS - Uncomment the line above and comment or remove the line below\\npath = \\\"/tmp/telemetry_agent.db\\\"\\n\\n#\\n# Flow Configurations \\n#\\n\\n#\\n# A specific flow\\n#\\n[[flow]]\\n# The flow tag\\ntag = \\\"database_gauge_1\\\"\\n# run the script every 2 seconds\\ninterval = \\\"2s\\\"\\n# The node.js program to execute to generate updates\\nexec = \\\"database.js\\\"\\n\",\n      \"language\": \"toml\"\n    }\n  ]\n}\n[/block]\n# Write the Node Script\n\nWrite an executable node.js script that looks like the following\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#!/usr/bin/env node\\n\\n//\\n// Node.js example for querying a database and sending it to a Telemetry flow\\n// We assume we have a database named database and a users collection inside it\\n//\\n\\n// Make sure you have mongodb installed (npm install mongodb)\\nvar mongodb = require('mongodb');\\n\\n// Create a client\\nvar MongoClient = mongodb.MongoClient;\\n\\n// Your database\\nvar url = 'mongodb://localhost:27017/database';\\n\\n// Use connect method to connect to the Server\\nMongoClient.connect(url, function (err, db) {\\n  if (err) {\\n    console.log('Unable to connect to the mongoDB server. Error:', err);\\n    process.exit(1);\\n\\n  } else {\\n    // Get the users collection\\n    var users = db.collection('users');\\n\\n    // Get the users count\\n    users.count(function (err, count) {\\n      if (err) {\\n        console.error(err);\\n        process.exit(1);\\n      }\\n\\n      // Create the response based on the number flow structure\\n      var metrics = {\\n        number: {\\n          value: count\\n        }\\n      };\\n\\n      // Output the metrics\\n      console.log(JSON.stringify(metrics));\\n\\n      db.close();\\n    });\\n  }\\n});\\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n# Run the Agent\n\nWith the agent binary and the config file in the same directory start the agent by typing in your console:\n\n    gotelemetry_agent run -c config.toml\n\n\n# Viewing your Board and Notifications\n\nGo to [https://viewer.telemetryapp.com](https://viewer.telemetryapp.com) to create a new viewer and input its pairing code in the manager at [https://manager.telemetryapp.com/viewers](https://manager.telemetryapp.com/viewers)","excerpt":"","slug":"querying-a-database","type":"basic","title":"Database"}
[block:callout] { "type": "info", "title": "Source Code Available", "body": "The source code for this example is available on the [Telemetry Agents Examples](https://github.com/telemetryapp/agent_examples) Github repository." } [/block] This page serves to give you an example on how to use a Telemetry Agent to run an executable and send the resulting metrics to a Telemetry flow. The executable in this particular example will be a node.js script. [block:image] { "images": [ { "image": [ "https://files.readme.io/OyVB9rkXQb6va3tsr1BE_exec.png", "exec.png", "993", "210", "#1097f8", "" ] } ] } [/block] # Requirements You'll need an OSX or Linux computer system to run through this guide. Windows is supported with Telemetry but some of the details here would be slightly different and thus it's out of scope. While this model of Telemetry works with any language that can be executed from the command line we chose to do this example in javascript (and node.js) as it's one of the most common languages available today. There's nothing stopping you from using Ruby, Python, PHP, Java, C++, .NET and so forth. You'll need node.js installed and ready to run local node scripts. Without node you'll be able to follow the concepts but not actually execute the script. Hopefully, the examples will serve to help you in whatever language is your choice. # Installation Get the most recent agent from the [Telemetry Agent](https://github.com/telemetryapp/gotelemetry_agent/releases) Github repository. # Configure Board Visit the [Telemetry Manager](https://manager.telemetryapp.com) application, login and either create a new board or use an existing one. Add a gauge to the board and take note of the flow_tag. You'll use this tag to send data to. [block:image] { "images": [ { "image": [ "https://files.readme.io/180b645-Screen_Shot_2017-07-26_at_10.42.52_AM.png", "Screen Shot 2017-07-26 at 10.42.52 AM.png", 263, 170, "#232a34" ] } ] } [/block] # Configure Agent Next, we'll need to configure the agent to run the node script and send it to Telemetry. [block:code] { "codes": [ { "code": "#\n# Server Configuration Parameters\n#\n\n[server]\n# API token found in the Agents tab in manager.telemetryapp.com\napi_token = \"abc123abc123abc123abc123abc123abc123\"\n# Submit new metrics in a batch at most every 1 second\nsubmission_interval = \"1s\"\n\n#\n# Data Configuration Parameters\n#\n\n[data]\n# path = \"c:\\\\telemetry_agent.db\"\n# WINDOWS USERS - Uncomment the line above and comment or remove the line below\npath = \"/tmp/telemetry_agent.db\"\n\n#\n# Flow Configurations \n#\n\n#\n# A specific flow\n#\n[[flow]]\n# The flow tag\ntag = \"database_gauge_1\"\n# run the script every 2 seconds\ninterval = \"2s\"\n# The node.js program to execute to generate updates\nexec = \"database.js\"\n", "language": "toml" } ] } [/block] # Write the Node Script Write an executable node.js script that looks like the following [block:code] { "codes": [ { "code": "#!/usr/bin/env node\n\n//\n// Node.js example for querying a database and sending it to a Telemetry flow\n// We assume we have a database named database and a users collection inside it\n//\n\n// Make sure you have mongodb installed (npm install mongodb)\nvar mongodb = require('mongodb');\n\n// Create a client\nvar MongoClient = mongodb.MongoClient;\n\n// Your database\nvar url = 'mongodb://localhost:27017/database';\n\n// Use connect method to connect to the Server\nMongoClient.connect(url, function (err, db) {\n if (err) {\n console.log('Unable to connect to the mongoDB server. Error:', err);\n process.exit(1);\n\n } else {\n // Get the users collection\n var users = db.collection('users');\n\n // Get the users count\n users.count(function (err, count) {\n if (err) {\n console.error(err);\n process.exit(1);\n }\n\n // Create the response based on the number flow structure\n var metrics = {\n number: {\n value: count\n }\n };\n\n // Output the metrics\n console.log(JSON.stringify(metrics));\n\n db.close();\n });\n }\n});\n", "language": "javascript" } ] } [/block] # Run the Agent With the agent binary and the config file in the same directory start the agent by typing in your console: gotelemetry_agent run -c config.toml # Viewing your Board and Notifications Go to [https://viewer.telemetryapp.com](https://viewer.telemetryapp.com) to create a new viewer and input its pairing code in the manager at [https://manager.telemetryapp.com/viewers](https://manager.telemetryapp.com/viewers)