npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

glink

v0.0.15

Published

generate graphite links

Downloads

7

Readme

glink

Build Status

create customizable links to your graphite targets.

Why

Creating links to view graphite visualizations isn't difficult, it's just tedious. I generally find that there are a small number of targets ( i.e. stats.timers.beta.request.users.index.{median,mean,upper_90}) that I use. I just switch out a few variables. glink lets you create a template with default variables, and then pass those variables in to create a url.

Usage

Install globally for cli usage

npm install -g glink

Or add to your current project for library usage

npm install --save glink

CLI Usage

The CLI uses a config located at ~/.glinkrc. If you don't have one, upon first usage it will write a default config for you (see config.default.json for the current defaults). Once your config is there it will always use it. Update it as needed.

glink your items here --param1=value --param2=value

Config Options

The config allows you to customize glink to be used with any type of target and potential substitution varialbes you may need. The CLI simply takes each arg you pass in and applies them, in order, to the variables defined in your config template. If you pass in less variables than you have defined in your config template, the config templateDefaults will be used.

For example, assume the following config:

{
  "hostname": "graphite.example.com",
  "template": "foo.bar.##controller##.##action##.median",
  "templateDefaults": [
    "##controller##===user",
    "##action##===index"
  ],
  "paramsDefaults": {}
}

Note that there are two variables defined in the template (##controller## and ##action##), and two corresponding templateDefaults that use the same syntax (You choose whatever syntax works for you... more below).

So given that config, if you run the following:

glink admins create --from=-1w

You would end up with the following link:

https://graphite.example.com/render?target=foo.bar.admins.create.median&from=-1w

Note that ##controller## has been substituted for the first arg (admins), and ##action## with the second (create).

Given the same config, the following:

glink admins --from=-1w

Would produce the following link:

https://graphite.example.com/render?target=foo.bar.admins.index.median&from=-1w

Note that the first arg has been used and the default for ##action## (in this case index) was used as there was no second variable. The param (--from=-1w) was still used and added as a query param.

Params

Params (arguments in the shape of --paramName=value) are appended to the created link as query params. You can define defaults using the paramsDefaults key in your config. This is a great place to define things that you don't want to have to type into the CLI args, but will always want. They are overriden by any values you pass in as arguments. See Graphite Graph Parameter Docs for more info on the available params.

Library Usage

To use the library, pass in a config (same options as the cli config, but as a JS object), and an array of arguments (just like you do in the cli)

var glink = require('glink');

var config = {
  hostname: 'graphite.example.com',
  template: 'foo.bar.##controller##.##action##.mean',
  templateDefaults: [
    '##controller##***user',
    '##action##***index',
  ],
  templateDefaultDelimiter: '***',
  paramsDefaults: {
      width: '800',
      height: '600'
  }
};

var link = glink(config, ['admins', 'create', '--from=-4months'];);
// https://graphite.example.com/render?width=800&height=600&target=foo.bar.admins.create.mean&from=-4months

Config Values and Defaults

KeyName | Required? | Default | Notes ----------- | --------- | ------------- | ------- | protocol | | https | i.e. http or https | hostname | X | | i.e. graphite.example.com | port | | | i.e. 443 | template | X | | define your variables as needed, with whatever syntax | templateDefaults| X | | An array of strings | templateDefaultDelimiter| | === | value used to split templateDefaults into variable and default value | paramsDefaults | | {} | an object with key, value param and value defaults to apply | absoluteTimes | | false | [experimental*] convert relative 'from' and 'until' times to absolute |

templates

Your config template is a template used to create a graphite target. You can substitute variables out of the template based on arguments passed into glink. Define your variables with any syntax you want. In the examples above we are using a ##variableName## syntax. These will be replaced with arguments or the values in your templateDefaults config values.

templateDefaults

Your ability to use any variable naming in your template is due to having defaults defined in templateDefaults. This config option holds an array of strings in a special syntax:

##variableName##===defaultValue

Where ##variableName## is whatever you used in your template and defaultValue is the default value to use should there not be enough args provided. In this case we are using the === as a delimiter between the variable and default. This is the default templateDefaultDelimiter. Should you wish to use another delimiter make sure you update the templateDefaultDelimiter config value as well.

For sanity define your templateDefaults in the same order they appear in your template.

Utilities

There are several modules that may be useful on their own within glink. Here are a few of them:

createTarget

createTarget(values:array, config:object)

The config object can be the same config object as used in the main glink function. createTarget will look for template, templateDefaults, and templateDefaultDelimiter. See the table above for explanations with regards to the config. The values arg takes an array of values to be substituted into the template, in the order they are defined in the the templateDefaults.

var createTarget = require('glink/lib/createTarget');

var config = {};
config.template = 'stats.timers.app.!!#controller#!!.!!#action#!!.mean';
config.templateDefaults = [
  '!!#controller#!!===files',
  '!!#action#!!===index'
];
var values = ['admin', 'show']
var target = createTarget(values, config);
// stats.timers.prod.request.admin.show.mean

wrapTarget

wrapTarget(target:string, func:string, value:string|number)

Takes a graphite target (i.e. stats.timers.requests.users.index.mean), and wraps it in a graphite function (i.e. alias), with the value.

var wrapTarget = require('glink/lib/wrapTarget');

var target = 'stats.timers.requests.users.index.mean';
var newTarget = wrapTarget(target, 'alias', 'users index');
// "alias(stats.timers.requests.users.index.mean, 'users index')"

Contributing

  1. Fork it ( https://github.com/knomedia/glink/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License and Copyright

MIT License

(c) 2015 Jason Madsen