Skip to content
This repository was archived by the owner on May 30, 2019. It is now read-only.

Commit 843e516

Browse files
committed
Updating readme to reflect the functions being bundled in a module.
1 parent ff76677 commit 843e516

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

README.md

+32-32
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ More details at [http://www.hodgkins.net.au/mswindows/using-powershell-to-send-m
99
* Sends Metrics to Graphite's Carbon daemon using TCP or UDP
1010
* Can collect Windows Performance Counters
1111
* Can collect values by using T-SQL queries against MS SQL databases
12-
* Will convert time zones; If the server you want the metrics sent from is in a different time zone to your Graphite server, the script will convert the time so metrics come in with a time that matches the Graphite server
12+
* Converts time to UTC on sending
1313
* All configuration can be done from a simple XML file
1414
* Reloads the XML configuration file automatically. For example, if more counters are added to the configuration file, the script will notice and start sending metrics for them to Graphite in the next send interval
1515
* Additional functions are exposed that allow you to send data to Graphite from PowerShell easily. [Here](#functions) is the list of included functions
@@ -19,10 +19,13 @@ More details at [http://www.hodgkins.net.au/mswindows/using-powershell-to-send-m
1919

2020
## Installation
2121

22-
1. Download the *Graphite-PowerShell.ps1* file and the *StatsToGraphiteConfig.xml* configuration file into the same directory, for example *C:\GraphitePowerShell*
23-
2. Make sure the files are un-blocked by right clicking on them and going to properties.
24-
3. Modify *StatsToGraphiteConfig.xml* configuration file. Instructions [here](#config).
25-
4. Open PowerShell and ensure you set your Execution Policy to allow scripts be run. For example `Set-ExecutionPolicy RemoteSigned`.
22+
1. Download the repository and place into a PowerShell Modules directory called **Graphite-Powershell**. The module directories can be found by running `$env:PSModulePath` in PowerShell. For example, `C:\Program Files\WindowsPowerShell\Modules\Graphite-PowerShell`
23+
1. Verify your folder structure looks like this, with the *.psd1* and *.psm1* files inside the **Graphite-Powershell** folder:
24+
25+
![alt text](http://i.imgur.com/4wE9Xq5.jpg "Start-StatsToGraphite with Verbose Output")
26+
3. Make sure the files are un-blocked by right clicking on them and going to properties.
27+
4. Modify the *StatsToGraphiteConfig.xml* configuration file. Instructions [here](#config).
28+
5. Open PowerShell and ensure you set your Execution Policy to allow scripts be run. For example `Set-ExecutionPolicy RemoteSigned`.
2629

2730
### Modifying the Configuration File
2831

@@ -36,8 +39,7 @@ CarbonServer | The server name where Carbon is running. The Carbon daemon is usu
3639
CarbonServerPort | The port number for Carbon. Its default port number is 2003.
3740
MetricPath | The path of the metric you want to be sent to the server. If you are using HostedGraphite, put your API key before the rest of the metric path, for example `YOUR-API-KEY.datacenter1.servers`.
3841
MetricSendIntervalSeconds | The interval to send metrics to Carbon; I recommend 5 seconds or greater. The more metrics you are collecting the longer it takes to send them to the Graphite server. You can see how long it takes to send the metrics each time the loop runs by using running the `Start-StatsToGraphite` function and having *VerboseOutput* set to *True*.
39-
TimeZoneOfGraphiteServer | Set this to the time zone of your Graphite server and the **Start-StatsToGraphite** function will convert the local time zone of the server to the time zone of the Graphite server. This is useful if you have servers in different time zones. To get a list of valid options run **Convert-TimeZone -ListTimeZones** and use the applicable ID.
40-
SendUsingUDP | Sends metrics via UDP instead of TCP. This doesn't seem to work with HostedGraphite, but works with self-hosted.
42+
SendUsingUDP | Sends metrics via UDP instead of TCP.
4143

4244
#### Performance Counters Configuration Section
4345

@@ -101,11 +103,11 @@ VerboseOutput | Will provide each of the metrics that were sent over to Carbon a
101103

102104
The following shows how to use the `Start-StatsToGraphite`, which will collect Windows performance counters and send them to Graphite.
103105

104-
1. In PowerShell, enter the directory in which you downloaded the script.
105-
2. Dot source the script by running `. .\Graphite-PowerShell.ps1`
106-
3. Start the script by using the function `Start-StatsToGraphite`. If you want Verbose detailed use `Start-StatsToGraphite -Verbose`.
106+
1. Open PowerShell
107+
2. Import the Module by running `Import-Module -Name Graphite-PowerShell`
108+
3. Start the script by using the function `Start-StatsToGraphite`. If you want Verbose details, use `Start-StatsToGraphite -Verbose`.
107109

108-
You may need to run the PowerShell instance with Administrative rights depending on the performance counters you want to access. This is due to the scripts use of the `Get-Counter` CmdLet.
110+
You may need to run the PowerShell instance with Administrative rights depending on the performance counters you want to access. This is due to the scripts use of the `Get-Counter` CmdLet.
109111

110112
From the [Get-Counter help page on TechNet](http://technet.microsoft.com/library/963e9e51-4232-4ccf-881d-c2048ff35c2a(v=wps.630).aspx):
111113

@@ -121,8 +123,8 @@ That is all there is to getting your Windows performance counters into Graphite.
121123

122124
The following shows how to use the `Start-SQLStatsToGraphite`, which will execute any SQL queries listed in the configuration file and send the result (which needs to be an integer) to Graphite.
123125

124-
1. In PowerShell, enter the directory in which you downloaded the script.
125-
2. Dot source the script by running `. .\Graphite-PowerShell.ps1`
126+
1. Open PowerShell
127+
2. Import the Module by running `Import-Module -Name Graphite-PowerShell`
126128
3. Start the script by using the function `Start-SQLStatsToGraphite`. If you want Verbose detailed use `Start-SQLStatsToGraphite -Verbose`. If you want to see what would be sent to Graphite, without actually sending the metrics, use `Start-SQLStatsToGraphite -Verbose -TestMode`
127129

128130
The below image is what `Start-SQLStatsToGraphite` like with **VerboseOutput** turned on in the XML configuration file looks like.
@@ -131,7 +133,7 @@ The below image is what `Start-SQLStatsToGraphite` like with **VerboseOutput** t
131133

132134
This function requires the Microsoft SQL PowerShell Modules/SnapIns. The easiest way to get these is to download them from the [SQL 2012 R2 SP1 Feature Pack](http://www.microsoft.com/en-us/download/details.aspx?id=35580). You will need to grab the following:
133135
* Microsoft® SQL Server® 2012 Shared Management Object
134-
* Microsoft® System CLR Types for Microsoft® SQL Server® 2012
136+
* Microsoft® System CLR Types for Microsoft® SQL Server® 2012
135137
* Microsoft® Windows PowerShell Extensions for Microsoft® SQL Server® 2012
136138

137139
## Installing as a Service
@@ -144,7 +146,7 @@ The easiest way to achieve this is using NSSM - the Non-Sucking Service Manager.
144146
2. Open up an Administrative command prompt and run `nssm install GraphitePowerShell`. (You can call the service whatever you want).
145147
3. A dialog will pop up allowing you to enter in settings for the new service. The following two tables below contains the settings to use.
146148

147-
![alt text](http://i.imgur.com/xkiRZgu.jpg "NSSM Dialog")
149+
![alt text](http://i.imgur.com/sDjBcjl.jpg "NSSM Dialog")
148150

149151
4. Click *Install Service*
150152
5. Make sure the service is started and it is set to Automatic
@@ -154,46 +156,44 @@ The below configurations will show how to run either `Start-StatsToGraphite` or
154156

155157
### Running Start-StatsToGraphite as a Service
156158

157-
The following configuration can be used to run `Start-StatsToGraphite` as a service.
159+
The following configuration can be used to run `Start-StatsToGraphite` as a service.
158160

159161
Setting Name | Value
160162
--- | ---
161163
Path | C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
162-
Startup Directory | C:\GraphitePowerShell
163-
Options | -command "& { . C:\GraphitePowerShell\Graphite-PowerShell.ps1; Start-StatsToGraphite }"
164+
Startup Directory | Leave Blank
165+
Options | -command "& { Import-Module -Name Graphite-PowerShell ; Start-StatsToGraphite }"
164166

165167
### Running Start-SQLStatsToGraphite as a Service
166168

167-
The following configuration can be used to run `Start-SQLStatsToGraphite` as a service.
169+
The following configuration can be used to run `Start-SQLStatsToGraphite` as a service.
168170

169171
Setting Name | Value
170172
--- | ---
171173
Path | C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
172-
Startup Directory | C:\GraphitePowerShell
173-
Options | -command "& { . C:\GraphitePowerShell\Graphite-PowerShell.ps1; Start-SQLStatsToGraphite }"
174+
Startup Directory | Leave Blank
175+
Options | -command "& { Import-Module -Name Graphite-PowerShell ; Start-SQLStatsToGraphite }"
174176

175177
If you want to remove a service, read the NSSM documentation [http://nssm.cc/commands](http://nssm.cc/commands) for instructions.
176178

177179
### Installing as a Service Using PowerShell
178-
1. Download nssm from [nssm.cc](http://nssm.cc) and save it into your `C:\GraphitePowerShell` directory
179-
2. Open an Administrative PowerShell console
180-
3. Run `Start-Process -FilePath .\nssm.exe -ArgumentList 'install GraphitePowerShell "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-command "& { . C:\GraphitePowerShell\Graphite-PowerShell.ps1; Start-StatsToGraphite }"" ' -NoNewWindow -Wait`
180+
1. Download nssm from [nssm.cc](http://nssm.cc) and save it into a directory
181+
2. Open an Administrative PowerShell consolen and browse to the directory you saved NSSM
182+
3. Run `Start-Process -FilePath .\nssm.exe -ArgumentList 'install GraphitePowerShell "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-command "& { Import-Module -Name Graphite-PowerShell ; Start-StatsToGraphite }"" ' -NoNewWindow -Wait`
181183
4. Check the service installed successfully `Get-Service -Name GraphitePowerShell`
182184
5. Start the service `Start-Service -Name GraphitePowerShell`
183185

184186
## <a name="functions">Included Functions</a>
185187

186-
There are several functions that are exposed by the script which available to use in an ad-hoc manner.
188+
There are several functions that are exposed by the module which are available to use in an ad-hoc manner.
187189

188-
For full help for these functions run the PowerShell command `Get-Help | <Function Name>`
190+
For a list of functions in the module, run `Get-Command -Module Graphite-PowerShell`. For full help for these functions run `Get-Help | <Function Name>`
189191

190192
Function Name | Description
191193
--- | ---
192-
Start-StatsToGraphite | The function to collect Windows Performance Counters. This is an endless loop which will send metrics to Graphite.
193-
Start-SQLStatsToGraphite | The function to query SQL. This is an endless loop which will send metrics to Graphite.
194-
Send-GraphiteEvent | Sends an event to Graphite using the Graphite Event API. More information about the events API can be found [in this blog post](http://obfuscurity.com/2014/01/Graphite-Tip-A-Better-Way-to-Store-Events).
195194
ConvertTo-GraphiteMetric | Takes the Windows Performance counter name and coverts it to something that Graphite can use.
196-
Send-GraphiteMetric | Allows you to send metrics to Graphite in an ad-hoc manner.
197195
Send-BulkGraphiteMetrics | Sends several Graphite Metrics to a Carbon server with one request. Bulk requests save a lot of resources for Graphite server.
198-
Convert-TimeZone | Converts from one time zone to another.
199-
Import-XMLConfig | Loads the XML Configuration file. Not really useful out side of the script.
196+
Send-GraphiteEvent | Sends an event to Graphite using the Graphite Event API. More information about the events API can be found [in this blog post](http://obfuscurity.com/2014/01/Graphite-Tip-A-Better-Way-to-Store-Events).
197+
Send-GraphiteMetric | Allows you to send metrics to Graphite in an ad-hoc manner.
198+
Start-SQLStatsToGraphite | The function to query SQL. This is an endless loop which will send metrics to Graphite.
199+
Start-StatsToGraphite | The function to collect Windows Performance Counters. This is an endless loop which will send metrics to Graphite.

0 commit comments

Comments
 (0)